Skip to content

Commit 66a5973

Browse files
committed
Initial upload
1 parent 1d707b3 commit 66a5973

File tree

197 files changed

+17239
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

197 files changed

+17239
-0
lines changed

.gitignore

+9
Original file line numberDiff line numberDiff line change
@@ -231,3 +231,12 @@ _Pvt_Extensions
231231

232232
# FAKE - F# Make
233233
.fake/
234+
235+
# Visual Paradigm
236+
.vpprefdata/
237+
*.vpp~*
238+
*.vpp.working
239+
*.vpp.working-journal
240+
*.lock
241+
*.vux
242+
tmp/*

README.md

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Orleans.Activities
2+
3+
Workflow Foundation (.Net 4.x System.Activities workflows) over Orleans framework to provide stable, long-running, extremely scalable processes with XAML designer support.
4+
5+
__NOTE:__ This project currently is an __experiment__, not production quality! There is no NuGet package for it.
6+
7+
~~Help Wanted Issues~~ (soon)
8+
9+
~~Documentation~~ (see [HelloWorld](docs/HelloWorld/HelloWorld.md) sample)
10+
11+
## Concept
12+
13+
![Overview](docs/Orleans.Activities-Overview.png)
14+
15+
This is a very high level view:
16+
17+
* Each WorkflowGrain is indistinguishable from a normal grain and backed by a WorkflowHost.
18+
* The WorkflowHost is responsible to handle the lifecycle of the WorkflowInstance, mainly recreate it from a previous persisted state when it aborts.
19+
* The communication between the WorkflowGrain and the WorkflowHost is based on 2 developer defined interfaces for the incoming and outgoing requests (TAffector and TEffector). These interfaces' methods can be referenced from the workflow activities to accept incoming or to initiate outgoing requests.
20+
* The methods of the TAffector and TEffector interfaces are independent from the grain's external public interface, you can merge different public requests into one method or vice versa. Or a reentrant grain even can execute (read-only) public interface methods independently from the current running workflow operations.
21+
* The method's signatures are restricted, their parameters and return values are lazy, async delegates with 1 optional parameter/return value. The delegates executed by the workflow activities if/when they accept them (command pattern).
22+
* There are design-, build- and static-run-time checks to keep the interfaces and the workflows in sync.
23+
24+
A typical workflow grain manages operations in other grain(s) and handles only the process specific data in it's own state.
25+
26+
The goal, is to keep the C# code in the grain, and use the workflow only to decide what to do next. This way we can avoid a steep learning curve to use workflows: the developer doesn't need to write or to understand anything about activities, he/she can build workflows with the provided activities in a designer.
27+
28+
## Functionality
29+
30+
Implemented:
31+
32+
* Persistence (compatible with legacy workflow extensions), but it can run without any persistence
33+
* Reminders (redirected from System.Activities Timers, 1 min. is the minimum)
34+
* Tracking
35+
* Designer support
36+
37+
Extra implemented features:
38+
39+
* TAP async API
40+
* Optionally idempotent request processing for forward recovery
41+
* Automatic reactivation after failure
42+
* Workflow can be persisted during processing an incoming request (ReceiveRequestSendResponseScope is __NOT__ an implicit NoPersistScope)
43+
* Executing code "in the background" after a request returns it's response
44+
* Workflow is informed whether it is running in a reloaded state after failure (to determine necessary recovery)
45+
* Notification participant (to notify extensions when the workflow is idle)
46+
47+
Not tested, but should work:
48+
49+
* CancellationScope
50+
* CompensableActivity and CompensationExtension
51+
52+
Under construction:
53+
54+
* Tests (currently semi manual, semi automatic MSTest, don't even look at them)
55+
* More elaborate sample with
56+
* DI/Autofac
57+
* Strategy and Humble Object patterns, to show an arhitecture, where the application logic can be tested independently from Orleans and from Orleans.Activities workflows
58+
59+
Not implemented, help wanted (for design and for implementation):
60+
61+
* DynamicUpdateMap support (updating loaded workflows to a newer definition version), though the separation of the application logic (the plain C# delegates) and the process (the diagram) results in a very simple workflow diagram, that has a big chance you won't need to update when it runs
62+
* TransactionScope activity support (see https://github.com/dotnet/orleans/issues/1090)
63+
64+
And there are nearly unlimited issues...
65+
66+
## Samples
67+
68+
[HelloWorld](docs/HelloWorld/HelloWorld.md)
69+
70+
## Details
71+
72+
This is still an overview, all the details of the classes are hidden. The goal is to give a map to understand the relations between the classes. See the comments in the source!
73+
74+
![Overview](docs/Orleans.Activities-Details.png)

docs/HelloWorld/HelloActivity.png

18.4 KB
Loading

docs/HelloWorld/HelloWorld.md

+143
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
# Hello World
2+
3+
Based on Orleans [Hello World](http://dotnet.github.io/orleans/Samples-Overview/Hello-World) sample.
4+
5+
## Overview
6+
7+
![SequenceDiagram](SequenceDiagram-Overview.png)
8+
9+
## Interface
10+
11+
IHello is the same.
12+
13+
```c#
14+
public interface IHello : IGrainWithGuidKey
15+
{
16+
Task<string> SayHello(string greeting);
17+
}
18+
```
19+
20+
## Grain
21+
22+
Before the grain, you have to define 3 things: State, Affector and Effector interfaces
23+
24+
### State
25+
26+
Workflows always have a state. Even if they never persist it. You can use the `WorkflowState` base class or implement the `IWorkflowState` interface.
27+
28+
```c#
29+
public class HelloGrainState : WorkflowState
30+
{ }
31+
```
32+
33+
### Affector interface
34+
35+
These are the operations that the grain calls on the workflow, these operations should __NOT__ be the same as the public grain interface methods (see `IHello`)!
36+
37+
There are 2 restrictions on the methods:
38+
39+
* must have 1 parameter, with type `Func<Task<anything>>` or `Func<Task>` (executed when the workflow accepts the request)
40+
* the return type must be `Task` or `Task<anything>`
41+
42+
```c#
43+
public interface IHelloAffector
44+
{
45+
Task<string> GreetClient(Func<Task<string>> clientSaid);
46+
}
47+
```
48+
49+
### Effector interface
50+
51+
These are the operations that the workflow calls back on the grain.
52+
53+
There are 2 restrictions on the methods:
54+
55+
* can have max. 1 parameter with any type
56+
* the return type must be `Task<Func<Task<anything>>>` or `Task<Func<Task>>` (executed when the workflow accepts the response)
57+
58+
```c#
59+
public interface IHelloEffector
60+
{
61+
Task<Func<Task<string>>> WhatShouldISay(string clientSaid);
62+
}
63+
```
64+
65+
### Grain
66+
67+
The class definition, where we define the TState, TAffector and TEffector type parameters.
68+
69+
__NOTE:__ The grain must implement (if possible explicitly) the effector interface (see `IHelloEffector`).
70+
71+
```c#
72+
public sealed class HelloGrain : WorkflowGrain<HelloGrainState, IHelloAffector, IHelloEffector>, IHello, IHelloEffector
73+
```
74+
75+
Constructor, in this example without Dependency Injection, just define the activity factory and leave the workflow definition identity null.
76+
77+
```c#
78+
public HelloGrain()
79+
: base((wi) => new HelloActivity(), null)
80+
{ }
81+
```
82+
83+
Optionally see what happens during the workflow execution with tracking, this can be left out, there is a default empty implementation in the base class.
84+
85+
```c#
86+
protected override IEnumerable<object> CreateExtensions()
87+
{
88+
yield return new GrainTrackingParticipant(GetLogger());
89+
}
90+
```
91+
92+
A mandatory (boilerplate) implementation of the unhandled exception handler. Because workflows can run in the backround after an incoming call returns the result, we can't propagate back exceptions after this point. Workflow will by default abort in case of unhandled exception, depending on the `Parameters` property.
93+
94+
```c#
95+
protected override Task OnUnhandledExceptionAsync(Exception exception, Activity source)
96+
{
97+
GetLogger().Error(0, $"OnUnhandledExceptionAsync: the workflow is going to {Parameters.UnhandledExceptionAction}", exception);
98+
return Task.CompletedTask;
99+
}
100+
```
101+
102+
The public grain interface method, that does nothing just calls the workflow's only affector operation. A normal grain can store data from the incoming message in the state, call other grains, closure the necessary data into the parameter delegate. After the await it can build a complex response message based on the value the workflow returned and the grain state, or any other information.
103+
104+
The parameter delegate executed when the workflow accepts the incoming call.
105+
106+
It also shows how to implement idempotent responses for the incoming calls. In the repeated case, the parameter delegate won't be executed!
107+
108+
```c#
109+
public async Task<string> SayHello(string greeting)
110+
{
111+
try
112+
{
113+
return await WorkflowAffector.GreetClient(() =>
114+
Task.FromResult(greeting));
115+
}
116+
catch (RepeatedOperationException<string> e)
117+
{
118+
return e.PreviousResponseParameter;
119+
}
120+
}
121+
```
122+
123+
This is the explicit implementation of the effector interface's only method, that does nearly nothing. A normal grain can modify the grain's State, call other grain's operations or do nearly anything a normal grain method can.
124+
125+
The return value delegate executed when the workflow accepts the outgoing call's response.
126+
127+
```c#
128+
Task<Func<Task<string>>> IHelloEffector.WhatShouldISay(string clientSaid) =>
129+
Task.FromResult<Func<Task<string>>>(() =>
130+
Task.FromResult(string.IsNullOrEmpty(clientSaid) ? "Who are you?" : "Hello!"));
131+
```
132+
133+
And see the Workflow. It calls back the grain, and returns the response to the grain at the end.
134+
135+
![HelloActivity.xaml](HelloActivity.png)
136+
137+
That's all. Ctrl+F5, and it works.
138+
139+
## Details
140+
141+
If you want to dig deep into the source and understand the detailed events in the background, this sequence diagram can help (this is not a completely valid diagram, but displaying every asnyc details, even the AsyncAutoResetEvent idle-queue, this would be 2 times bigger).
142+
143+
![SequenceDiagram](SequenceDiagram-Details.png)

docs/HelloWorld/HelloWorld.vpp

559 KB
Binary file not shown.
79.4 KB
Loading
11.2 KB
Loading

docs/Orleans.Activities-Details.png

63.9 KB
Loading

docs/Orleans.Activities-Overview.png

18.3 KB
Loading

docs/Orleans.Activities.vpp

470 KB
Binary file not shown.

src/GlobalAssemblyInfo.cs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
using System.Reflection;
2+
3+
[assembly: AssemblyCompany("https://github.com/lmagyar")]
4+
[assembly: AssemblyProduct("Orleans.Activities - https://github.com/lmagyar/Orleans.Activities")]
5+
[assembly: AssemblyCopyright("Copyright © https://github.com/lmagyar 2016")]
6+
7+
[assembly: AssemblyVersion("0.1.0.0")]
8+
[assembly: AssemblyInformationalVersion("0.1.0")]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System.Threading.Tasks;
2+
using Orleans;
3+
4+
namespace Orleans.Activities.Sample.HelloWorld.GrainInterfaces
5+
{
6+
public interface IHello : IGrainWithGuidKey
7+
{
8+
Task<string> SayHello(string greeting);
9+
}
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="..\packages\Microsoft.Orleans.Templates.Interfaces.1.1.1\build\Microsoft.Orleans.Templates.Interfaces.props" Condition="Exists('..\packages\Microsoft.Orleans.Templates.Interfaces.1.1.1\build\Microsoft.Orleans.Templates.Interfaces.props')" />
4+
<Import Project="$(SolutionDir)packages\Microsoft.Orleans.Templates.Interfaces.1.1.0\build\Microsoft.Orleans.Templates.Interfaces.props" Condition="Exists('$(SolutionDir)packages\Microsoft.Orleans.Templates.Interfaces.1.1.0\build\Microsoft.Orleans.Templates.Interfaces.props')" />
5+
<PropertyGroup>
6+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
7+
<Platform>AnyCPU</Platform>
8+
<SchemaVersion>2.0</SchemaVersion>
9+
<ProjectGuid>{2A2508A0-34A7-467C-9AA7-EA2B319DA474}</ProjectGuid>
10+
<OutputType>Library</OutputType>
11+
<AppDesignerFolder>Properties</AppDesignerFolder>
12+
<RootNamespace>Orleans.Activities.Sample.HelloWorld.GrainInterfaces</RootNamespace>
13+
<AssemblyName>Orleans.Activities.Sample.HelloWorld.GrainInterfaces</AssemblyName>
14+
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
15+
<FileAlignment>512</FileAlignment>
16+
<NuGetPackageImportStamp>
17+
</NuGetPackageImportStamp>
18+
<TargetFrameworkProfile />
19+
</PropertyGroup>
20+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
21+
<DebugSymbols>true</DebugSymbols>
22+
<DebugType>full</DebugType>
23+
<Optimize>false</Optimize>
24+
<OutputPath>bin\Debug\</OutputPath>
25+
<DefineConstants>DEBUG;TRACE</DefineConstants>
26+
<ErrorReport>prompt</ErrorReport>
27+
<WarningLevel>4</WarningLevel>
28+
<Prefer32Bit>false</Prefer32Bit>
29+
<NoWarn>CSE0001 CSE0003</NoWarn>
30+
</PropertyGroup>
31+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
32+
<DebugType>pdbonly</DebugType>
33+
<Optimize>true</Optimize>
34+
<OutputPath>bin\Release\</OutputPath>
35+
<DefineConstants>TRACE</DefineConstants>
36+
<ErrorReport>prompt</ErrorReport>
37+
<WarningLevel>4</WarningLevel>
38+
<Prefer32Bit>false</Prefer32Bit>
39+
<NoWarn>CSE0001 CSE0003</NoWarn>
40+
</PropertyGroup>
41+
<ItemGroup>
42+
<Reference Include="Microsoft.CodeAnalysis, Version=1.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
43+
<HintPath>..\packages\Microsoft.CodeAnalysis.Common.1.1.1\lib\net45\Microsoft.CodeAnalysis.dll</HintPath>
44+
<Private>True</Private>
45+
</Reference>
46+
<Reference Include="Microsoft.CodeAnalysis.CSharp, Version=1.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
47+
<HintPath>..\packages\Microsoft.CodeAnalysis.CSharp.1.1.1\lib\net45\Microsoft.CodeAnalysis.CSharp.dll</HintPath>
48+
<Private>True</Private>
49+
</Reference>
50+
<Reference Include="Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
51+
<HintPath>..\packages\Newtonsoft.Json.8.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
52+
<Private>True</Private>
53+
</Reference>
54+
<Reference Include="Orleans, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
55+
<HintPath>..\packages\Microsoft.Orleans.Core.1.1.1\lib\net451\Orleans.dll</HintPath>
56+
<Private>True</Private>
57+
</Reference>
58+
<Reference Include="OrleansCodeGenerator, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
59+
<HintPath>..\packages\Microsoft.Orleans.OrleansCodeGenerator.1.1.1\lib\net451\OrleansCodeGenerator.dll</HintPath>
60+
<Private>True</Private>
61+
</Reference>
62+
<Reference Include="System" />
63+
<Reference Include="Microsoft.CSharp" />
64+
<Reference Include="System.Collections.Immutable, Version=1.1.37.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
65+
<HintPath>..\packages\System.Collections.Immutable.1.1.37\lib\dotnet\System.Collections.Immutable.dll</HintPath>
66+
<Private>True</Private>
67+
</Reference>
68+
<Reference Include="System.Core" />
69+
<Reference Include="System.Data" />
70+
<Reference Include="System.Data.DataSetExtensions" />
71+
<Reference Include="System.Reflection.Metadata, Version=1.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
72+
<HintPath>..\packages\System.Reflection.Metadata.1.1.0\lib\dotnet5.2\System.Reflection.Metadata.dll</HintPath>
73+
<Private>True</Private>
74+
</Reference>
75+
<Reference Include="System.Xml" />
76+
<Reference Include="System.Xml.Linq" />
77+
</ItemGroup>
78+
<ItemGroup>
79+
<Compile Include="IHello.cs" />
80+
<Compile Include="Properties\AssemblyInfo.cs" />
81+
<Compile Include="Properties\orleans.codegen.cs" />
82+
</ItemGroup>
83+
<ItemGroup>
84+
<None Include="app.config" />
85+
<None Include="packages.config" />
86+
</ItemGroup>
87+
<ItemGroup>
88+
<Analyzer Include="..\packages\Microsoft.CodeAnalysis.Analyzers.1.1.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.Analyzers.dll" />
89+
<Analyzer Include="..\packages\Microsoft.CodeAnalysis.Analyzers.1.1.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CSharp.Analyzers.dll" />
90+
</ItemGroup>
91+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
92+
<Import Project="$(SolutionDir)packages\Microsoft.Orleans.Templates.Interfaces.1.1.0\build\Microsoft.Orleans.Templates.Interfaces.targets" Condition="Exists('$(SolutionDir)packages\Microsoft.Orleans.Templates.Interfaces.1.1.0\build\Microsoft.Orleans.Templates.Interfaces.targets')" />
93+
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
94+
<PropertyGroup>
95+
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
96+
</PropertyGroup>
97+
<Error Condition="!Exists('..\packages\Microsoft.Orleans.Templates.Interfaces.1.1.1\build\Microsoft.Orleans.Templates.Interfaces.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Orleans.Templates.Interfaces.1.1.1\build\Microsoft.Orleans.Templates.Interfaces.props'))" />
98+
<Error Condition="!Exists('..\packages\Microsoft.Orleans.Templates.Interfaces.1.1.1\build\Microsoft.Orleans.Templates.Interfaces.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Orleans.Templates.Interfaces.1.1.1\build\Microsoft.Orleans.Templates.Interfaces.targets'))" />
99+
</Target>
100+
<Import Project="..\packages\Microsoft.Orleans.Templates.Interfaces.1.1.1\build\Microsoft.Orleans.Templates.Interfaces.targets" Condition="Exists('..\packages\Microsoft.Orleans.Templates.Interfaces.1.1.1\build\Microsoft.Orleans.Templates.Interfaces.targets')" />
101+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
102+
Other similar extension points exist, see Microsoft.Common.targets.
103+
<Target Name="BeforeBuild">
104+
</Target>
105+
<Target Name="AfterBuild">
106+
</Target>
107+
-->
108+
</Project>

0 commit comments

Comments
 (0)