Skip to content

Commit dc0f776

Browse files
committed
small facelifting in sample code
1 parent ced72d3 commit dc0f776

File tree

11 files changed

+31
-27
lines changed

11 files changed

+31
-27
lines changed

Samples/src/Orleans.Activities.Samples.Arithmetical.GrainInterfaces/IAdder.cs Samples/src/Orleans.Activities.Samples.Arithmetical.GrainInterfaces/IAdderGrain.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace Orleans.Activities.Samples.Arithmetical.GrainInterfaces
55
{
6-
public interface IAdder : IGrainWithGuidKey
6+
public interface IAdderGrain : IGrainWithGuidKey
77
{
88
Task<int> AddAsync(int arg1, int arg2);
99
}

Samples/src/Orleans.Activities.Samples.Arithmetical.GrainInterfaces/IMultiplier.cs Samples/src/Orleans.Activities.Samples.Arithmetical.GrainInterfaces/IMultiplierGrain.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace Orleans.Activities.Samples.Arithmetical.GrainInterfaces
55
{
66
// The IMultiplier will use a callback call to deliver the result.
77
// This is a demonstration for a long running workflow. A real grain can use streams or callback other grains to deliver the result.
8-
public interface IMultiplier : IGrainWithGuidKey
8+
public interface IMultiplierGrain : IGrainWithGuidKey
99
{
1010
Task MultiplyAsync(int arg1, int arg2);
1111

Samples/src/Orleans.Activities.Samples.Arithmetical.GrainInterfaces/Orleans.Activities.Samples.Arithmetical.GrainInterfaces.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@
118118
<Compile Include="..\GlobalAssemblyInfo.cs">
119119
<Link>Properties\GlobalAssemblyInfo.cs</Link>
120120
</Compile>
121-
<Compile Include="IMultiplier.cs" />
122-
<Compile Include="IAdder.cs" />
121+
<Compile Include="IMultiplierGrain.cs" />
122+
<Compile Include="IAdderGrain.cs" />
123123
<Compile Include="Properties\AssemblyInfo.cs" />
124124
</ItemGroup>
125125
<ItemGroup>

Samples/src/Orleans.Activities.Samples.Arithmetical.Grains/AdderGrain.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace Orleans.Activities.Samples.Arithmetical.Grains
1717
// WorkflowGrain<TGrain, TGrainState> base type with the default WorkflowState as TGrainState. But this is optional, the full blown
1818
// WorkflowGrain<TGrain, TGrainState, TWorkflowInterface, TWorkflowCallbackInterface> base type can be used also if there are outgoing calls or incoming callbacks.
1919
[StorageProvider(ProviderName = "MemoryStore")]
20-
public sealed class AdderGrain : WorkflowGrain<AdderGrain, WorkflowState>, IAdder
20+
public sealed class AdderGrain : WorkflowGrain<AdderGrain, WorkflowState>, IAdderGrain
2121
{
2222
private static Activity workflowDefinition = new AdderActivity();
2323

@@ -40,7 +40,7 @@ protected override Task OnUnhandledExceptionAsync(Exception exception, Activity
4040
// it is propagated back to the caller. If the workflow persist itself but due to a failure it aborts later and propagates the exception back to the caller,
4141
// it will be reloaded when the caller repeats the request or by a reactivation reminder. If the caller repeats the call only after the workflow is reloaded and completed,
4242
// this not a problem, it will get the same output arguments or OperationCanceledException or the exception that caused the workflow to terminate.
43-
async Task<int> IAdder.AddAsync(int arg1, int arg2)
43+
async Task<int> IAdderGrain.AddAsync(int arg1, int arg2)
4444
{
4545
// IMPORTANT: Do not copy values from the grain's state into the input arguments, because input arguments will be persisted by the workflow also.
4646
// Closure directly the necessary values from the incoming public grain method call's parameters into the delegate.

Samples/src/Orleans.Activities.Samples.Arithmetical.Grains/MultiplierGrain.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace Orleans.Activities.Samples.Arithmetical.Grains
1717
// WorkflowGrain<TGrain, TGrainState> base type with the default WorkflowState as TGrainState. But this is optional, the full blown
1818
// WorkflowGrain<TGrain, TGrainState, TWorkflowInterface, TWorkflowCallbackInterface> base type can be used also if there are outgoing calls or incoming callbacks.
1919
[StorageProvider(ProviderName = "MemoryStore")]
20-
public sealed class MultiplierGrain : WorkflowGrain<MultiplierGrain, WorkflowState>, IMultiplier
20+
public sealed class MultiplierGrain : WorkflowGrain<MultiplierGrain, WorkflowState>, IMultiplierGrain
2121
{
2222
private static Activity workflowDefinition = new MultiplierActivity();
2323

@@ -34,9 +34,9 @@ public MultiplierGrain()
3434
// Don't use callbacks on Completed event when there is no implicit or explicit persistence before, because the incoming request that started the workflow will run
3535
// the workflow to the first idle moment, if the first idle is the completion, the callback will happen during the incoming request (usually also a problem),
3636
// and the exception during the callback will be propagated back to the caller and the caller has to repeat the incoming request to restart the workflow.
37-
WorkflowControl.CompletedAsync = (ActivityInstanceState _activityInstanceState, IDictionary<string, object> _outputArguments, Exception _terminationException) =>
37+
WorkflowControl.CompletedAsync = (activityInstanceState, outputArguments, terminationException) =>
3838
{
39-
subsManager.Notify(_subscriber => _subscriber.ReceiveResult((int)_outputArguments["result"]));
39+
subsManager.Notify(subscriber => subscriber.ReceiveResult((int)outputArguments["result"]));
4040
return Task.CompletedTask;
4141
};
4242
}
@@ -48,7 +48,7 @@ protected override Task OnUnhandledExceptionAsync(Exception exception, Activity
4848
}
4949

5050
// MultiplierGrain only executes the workflow until it gets idle, from that moment the workflow executes in the "background" and calls the Completed event when it completes.
51-
async Task IMultiplier.MultiplyAsync(int arg1, int arg2)
51+
async Task IMultiplierGrain.MultiplyAsync(int arg1, int arg2)
5252
{
5353
// IMPORTANT: Do not copy values from the grain's state into the input arguments, because input arguments will be persisted by the workflow also.
5454
// Closure directly the necessary values from the incoming public grain method call's parameters into the delegate.
@@ -71,13 +71,13 @@ public override async Task OnActivateAsync()
7171
subsManager = new ObserverSubscriptionManager<IMultiplierResultReceiver>();
7272
}
7373

74-
Task IMultiplier.SubscribeAsync(IMultiplierResultReceiver observer)
74+
Task IMultiplierGrain.SubscribeAsync(IMultiplierResultReceiver observer)
7575
{
7676
subsManager.Subscribe(observer);
7777
return Task.CompletedTask;
7878
}
7979

80-
Task IMultiplier.UnsubscribeAsync(IMultiplierResultReceiver observer)
80+
Task IMultiplierGrain.UnsubscribeAsync(IMultiplierResultReceiver observer)
8181
{
8282
subsManager.Unsubscribe(observer);
8383
return Task.CompletedTask;

Samples/src/Orleans.Activities.Samples.Arithmetical.SiloHost/Program.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ static void Main(string[] args)
7878
// This is the place your custom logic, for example calling client logic
7979
// or initializing an HTTP front end for accepting incoming requests.
8080

81-
var adderGrain = GrainClient.GrainFactory.GetGrain<IAdder>(Guid.NewGuid());
82-
var multiplierGrain = GrainClient.GrainFactory.GetGrain<IMultiplier>(Guid.NewGuid());
81+
var adderGrain = GrainClient.GrainFactory.GetGrain<IAdderGrain>(Guid.NewGuid());
82+
var multiplierGrain = GrainClient.GrainFactory.GetGrain<IMultiplierGrain>(Guid.NewGuid());
8383
try
8484
{
8585
WriteLine("\n\nCalling Add...\n\n");

Samples/src/Orleans.Activities.Samples.HelloWorld.GrainInterfaces/IHello.cs Samples/src/Orleans.Activities.Samples.HelloWorld.GrainInterfaces/IHelloGrain.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace Orleans.Activities.Samples.HelloWorld.GrainInterfaces
55
{
6-
public interface IHello : IGrainWithGuidKey
6+
public interface IHelloGrain : IGrainWithGuidKey
77
{
88
Task<string> SayHelloAsync(string greeting);
99
Task<string> SayByeAsync();

Samples/src/Orleans.Activities.Samples.HelloWorld.GrainInterfaces/Orleans.Activities.Samples.HelloWorld.GrainInterfaces.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@
118118
<Compile Include="..\GlobalAssemblyInfo.cs">
119119
<Link>Properties\GlobalAssemblyInfo.cs</Link>
120120
</Compile>
121-
<Compile Include="IHello.cs" />
121+
<Compile Include="IHelloGrain.cs" />
122122
<Compile Include="Properties\AssemblyInfo.cs" />
123123
</ItemGroup>
124124
<ItemGroup>

Samples/src/Orleans.Activities.Samples.HelloWorld.Grains/HelloActivity.xaml

+4-4
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,15 @@
6262
<AssemblyReference>Orleans.Activities.Samples.HelloWorld.Grains</AssemblyReference>
6363
</sco:Collection>
6464
</TextExpression.ReferencesForImplementation>
65-
<oa:WorkflowActivity x:TypeArguments="local:IHelloWorkflowInterface, local:IHelloWorkflowCallbackInterface" sap2010:WorkflowViewState.IdRef="WorkflowActivity`2_1">
65+
<oa:WorkflowActivity x:TypeArguments="local:IHelloWorkflow, local:IHelloWorkflowCallback" sap2010:WorkflowViewState.IdRef="WorkflowActivity`2_1">
6666
<Sequence sap2010:WorkflowViewState.IdRef="Sequence_6">
6767
<oa:ReceiveRequestSendResponseScope sap2010:WorkflowViewState.IdRef="ReceiveRequestSendResponseScope_3">
6868
<Sequence sap2010:WorkflowViewState.IdRef="Sequence_5">
6969
<Sequence.Variables>
7070
<Variable x:TypeArguments="x:String" Name="clientSaid" />
7171
<Variable x:TypeArguments="x:String" Name="iSay" />
7272
</Sequence.Variables>
73-
<oa:ReceiveRequest x:TypeArguments="x:String" sap2010:WorkflowViewState.IdRef="ReceiveRequest`1_3" OperationName="IHelloWorkflowInterface.GreetClientAsync">
73+
<oa:ReceiveRequest x:TypeArguments="x:String" sap2010:WorkflowViewState.IdRef="ReceiveRequest`1_3" OperationName="IHelloWorkflow.GreetClientAsync">
7474
<oa:ReceiveRequest.RequestResult>
7575
<OutArgument x:TypeArguments="x:String">
7676
<mca:CSharpReference x:TypeArguments="x:String">clientSaid</mca:CSharpReference>
@@ -79,7 +79,7 @@
7979
</oa:ReceiveRequest>
8080
<oa:SendRequestReceiveResponseScope sap2010:WorkflowViewState.IdRef="SendRequestReceiveResponseScope_2">
8181
<Sequence sap2010:WorkflowViewState.IdRef="Sequence_4">
82-
<oa:SendRequest x:TypeArguments="x:String" sap2010:WorkflowViewState.IdRef="SendRequest`1_2" OperationName="IHelloWorkflowCallbackInterface.WhatShouldISayAsync">
82+
<oa:SendRequest x:TypeArguments="x:String" sap2010:WorkflowViewState.IdRef="SendRequest`1_2" OperationName="IHelloWorkflowCallback.WhatShouldISayAsync">
8383
<oa:SendRequest.RequestParameter>
8484
<InArgument x:TypeArguments="x:String">
8585
<mca:CSharpValue x:TypeArguments="x:String">clientSaid</mca:CSharpValue>
@@ -108,7 +108,7 @@
108108
<Pick sap2010:WorkflowViewState.IdRef="Pick_1">
109109
<PickBranch DisplayName="Branch1" sap2010:WorkflowViewState.IdRef="PickBranch_1">
110110
<PickBranch.Trigger>
111-
<oa:ReceiveRequest sap2010:WorkflowViewState.IdRef="ReceiveRequest_1" OperationName="IHelloWorkflowInterface.FarewellClientAsync" />
111+
<oa:ReceiveRequest sap2010:WorkflowViewState.IdRef="ReceiveRequest_1" OperationName="IHelloWorkflow.FarewellClientAsync" />
112112
</PickBranch.Trigger>
113113
<oa:SendResponse x:TypeArguments="x:String" sap2010:WorkflowViewState.IdRef="SendResponse`1_4" Idempotent="True" ResponseParameter="Bye, my friend!" ThrowIfReloaded="False" />
114114
</PickBranch>

Samples/src/Orleans.Activities.Samples.HelloWorld.Grains/HelloGrain.cs

+10-6
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace Orleans.Activities.Samples.HelloWorld.Grains
1515
public class HelloGrainState : WorkflowState
1616
{ }
1717

18-
public interface IHelloWorkflowInterface
18+
public interface IHelloWorkflow
1919
{
2020
// These are the operations that the grain calls on the workflow, these shouldn't be the same as the IHello grain interface method!
2121
// There are 2 restrictions on the methods:
@@ -25,7 +25,7 @@ public interface IHelloWorkflowInterface
2525
Task<string> FarewellClientAsync(Func<Task> request);
2626
}
2727

28-
public interface IHelloWorkflowCallbackInterface
28+
public interface IHelloWorkflowCallback
2929
{
3030
// This is the operation that the workflow calls back on the grain.
3131
// There are 2 restrictions on the methods:
@@ -35,7 +35,7 @@ public interface IHelloWorkflowCallbackInterface
3535
}
3636

3737
[StorageProvider(ProviderName = "MemoryStore")]
38-
public sealed class HelloGrain : WorkflowGrain<HelloGrain, HelloGrainState, IHelloWorkflowInterface, IHelloWorkflowCallbackInterface>, IHello, IHelloWorkflowCallbackInterface
38+
public sealed class HelloGrain : WorkflowGrain<HelloGrain, HelloGrainState, IHelloWorkflow, IHelloWorkflowCallback>, IHelloGrain, IHelloWorkflowCallback
3939
{
4040
// Without DI and versioning, just directly create the singleton workflow definition.
4141
private static Activity workflowDefinition = new HelloActivity();
@@ -55,7 +55,7 @@ protected override Task OnUnhandledExceptionAsync(Exception exception, Activity
5555

5656
// The parameter delegate executed when the workflow accepts the incoming call,
5757
// it can modify the grain's State or do nearly anything a normal grain method can (command pattern).
58-
async Task<string> IHello.SayHelloAsync(string greeting)
58+
async Task<string> IHelloGrain.SayHelloAsync(string greeting)
5959
{
6060
Task<string> ProcessRequestAsync(string _request) => Task.FromResult(_request);
6161
Task<string> CreateResponseAsync(string _responseParameter) => Task.FromResult(_responseParameter);
@@ -74,7 +74,7 @@ await WorkflowInterface.GreetClientAsync(
7474

7575
// The parameter delegate executed when the workflow accepts the incoming call,
7676
// it can modify the grain's State or do nearly anything a normal grain method can (command pattern).
77-
async Task<string> IHello.SayByeAsync()
77+
async Task<string> IHelloGrain.SayByeAsync()
7878
{
7979
Task ProcessRequestAsync() => Task.CompletedTask;
8080
Task<string> CreateResponseAsync(string _responseParameter) => Task.FromResult(_responseParameter);
@@ -89,6 +89,10 @@ await WorkflowInterface.FarewellClientAsync(
8989
{
9090
return await CreateResponseAsync(e.PreviousResponseParameter);
9191
}
92+
catch (InvalidOperationException)
93+
{
94+
return "Sorry, you must say hello first, before farewell!";
95+
}
9296
catch (OperationCanceledException)
9397
{
9498
return "Sorry, we have waited for your farewell, but gave up!";
@@ -97,7 +101,7 @@ await WorkflowInterface.FarewellClientAsync(
97101

98102
// The return value delegate executed when the workflow accepts the outgoing call's response,
99103
// it can modify the grain's State or do nearly anything a normal grain method can (command pattern).
100-
async Task<Func<Task<string>>> IHelloWorkflowCallbackInterface.WhatShouldISayAsync(string clientSaid)
104+
async Task<Func<Task<string>>> IHelloWorkflowCallback.WhatShouldISayAsync(string clientSaid)
101105
{
102106
Task<string> CreateRequestAsync(string _requestParameter) => Task.FromResult(_requestParameter);
103107
Task<string> SomeExternalStuffAsync(string _request) => Task.FromResult(string.IsNullOrEmpty(_request) ? "Who are you?" : "Hello!");

Samples/src/Orleans.Activities.Samples.HelloWorld.SiloHost/Program.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ static void Main(string[] args)
4949
// This is the place your custom logic, for example calling client logic
5050
// or initializing an HTTP front end for accepting incoming requests.
5151

52-
var helloGrain = GrainClient.GrainFactory.GetGrain<IHello>(Guid.NewGuid());
52+
var helloGrain = GrainClient.GrainFactory.GetGrain<IHelloGrain>(Guid.NewGuid());
5353
try
5454
{
5555
WriteLine("\n\nCalling SayHello...\n\n");

0 commit comments

Comments
 (0)