Commit 2e3b5fe6 by dingsongjie

添加部分 sagas 代码

parent 0d514eaf
......@@ -39,6 +39,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Pole.Orleans.Provider.Entit
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Pole.Samples.Backet.Api", "test\Pole.Samples.Backet.Api\Pole.Samples.Backet.Api.csproj", "{FB3D2F52-123A-4606-B682-9159BD7913AE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Pole.Sagas", "src\Pole.Sagas\Pole.Sagas.csproj", "{1F06D877-E4EC-4908-9057-38EDCE5E54E6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Pole.Sagas.Storage.PostgreSql", "src\Pole.Sagas.Storage.PostgreSql\Pole.Sagas.Storage.PostgreSql.csproj", "{9505BDFC-395B-4257-AEB3-2B44611147A4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
......@@ -93,6 +97,14 @@ Global
{FB3D2F52-123A-4606-B682-9159BD7913AE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FB3D2F52-123A-4606-B682-9159BD7913AE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FB3D2F52-123A-4606-B682-9159BD7913AE}.Release|Any CPU.Build.0 = Release|Any CPU
{1F06D877-E4EC-4908-9057-38EDCE5E54E6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1F06D877-E4EC-4908-9057-38EDCE5E54E6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1F06D877-E4EC-4908-9057-38EDCE5E54E6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1F06D877-E4EC-4908-9057-38EDCE5E54E6}.Release|Any CPU.Build.0 = Release|Any CPU
{9505BDFC-395B-4257-AEB3-2B44611147A4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9505BDFC-395B-4257-AEB3-2B44611147A4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9505BDFC-395B-4257-AEB3-2B44611147A4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9505BDFC-395B-4257-AEB3-2B44611147A4}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
......@@ -113,6 +125,8 @@ Global
{548EFDBB-252F-48DD-87F4-58ABFBD4963C} = {9932C965-8B38-4F70-9E43-86DC56860E2B}
{0DA75F4A-BF47-4B52-B932-48BB6A709934} = {9932C965-8B38-4F70-9E43-86DC56860E2B}
{FB3D2F52-123A-4606-B682-9159BD7913AE} = {655E719B-4A3E-467C-A541-E0770AB81DE1}
{1F06D877-E4EC-4908-9057-38EDCE5E54E6} = {9932C965-8B38-4F70-9E43-86DC56860E2B}
{9505BDFC-395B-4257-AEB3-2B44611147A4} = {9932C965-8B38-4F70-9E43-86DC56860E2B}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {DB0775A3-F293-4043-ADB7-72BAC081E87E}
......
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
</Project>
using System;
using System.Collections.Generic;
using System.Text;
namespace Pole.Sagas.Core
{
public class ActivityExecuteResult
{
public bool IsSuccess { get; set; }
public string Message { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace Pole.Sagas.Core.Exceptions
{
public class SagaNotFoundException:Exception
{
public SagaNotFoundException(string sagaName):base($"Saga:{sagaName} not found")
{
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace Pole.Sagas.Core
{
public interface IActivity<TData>
{
Task<ActivityExecuteResult> Execute(TData data);
Task<bool> Compensate(TData data);
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace Pole.Sagas.Core
{
public interface ISaga
{
void AddActivity<TData>(IActivity<TData> activity);
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace Pole.Sagas.Core
{
public interface ISagaFactory
{
TSaga CreateSaga<TSaga>(TimeSpan timeOut) where TSaga : ISaga;
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace Pole.Sagas.Core
{
class Saga : ISaga
{
private System.Collections.Concurrent.ConcurrentQueue<>
public void AddActivity<TData>(IActivity<TData> activity)
{
throw new NotImplementedException();
}
}
}
using Pole.Core.Utils.Abstraction;
using System;
using System.Collections.Generic;
using System.Text;
namespace Pole.Sagas.Core
{
class SagaFactory : ISagaFactory
{
private readonly ISnowflakeIdGenerator _snowflakeIdGenerator;
public SagaFactory(ISnowflakeIdGenerator snowflakeIdGenerator)
{
_snowflakeIdGenerator = snowflakeIdGenerator;
}
public TSaga CreateSaga<TSaga>(TimeSpan timeOut) where TSaga : ISaga
{
var name = typeof(TSaga).FullName;
var SagaFlow = SagasCollection.Get(name);
var newId = _snowflakeIdGenerator.NextId();
throw new NotImplementedException();
}
}
}
using Pole.Sagas.Core.Exceptions;
using System;
using System.Collections.Generic;
using System.Text;
namespace Pole.Sagas.Core
{
public class SagasCollection : Dictionary<string, ISaga>
{
private static System.Collections.Concurrent.ConcurrentDictionary<string, ISaga> _sagas = new System.Collections.Concurrent.ConcurrentDictionary<string, ISaga>();
public static ISaga Get(string name)
{
if (!_sagas.TryGetValue(name, out ISaga saga))
{
throw new SagaNotFoundException(name);
}
return saga;
}
public static bool Add(ISaga saga)
{
var name = saga.GetType().FullName;
return _sagas.TryAdd(name, saga);
}
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Folder Include="Client\" />
<Folder Include="Server\Storage\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Pole.Core\Pole.Core.csproj" />
</ItemGroup>
</Project>
using System;
using System.Collections.Generic;
using System.Text;
namespace Pole.Sagas.Server.Events
{
class SagaStartedEvent:IEvent
{
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace Pole.Sagas.Server
{
public interface IEvent
{
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment