-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
310 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 15 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SchoolBook.Admin", "SchoolBook.Admin.csproj", "{CF32E94B-FDAC-46BA-B387-0A3AC1911FCA}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{CF32E94B-FDAC-46BA-B387-0A3AC1911FCA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{CF32E94B-FDAC-46BA-B387-0A3AC1911FCA}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{CF32E94B-FDAC-46BA-B387-0A3AC1911FCA}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{CF32E94B-FDAC-46BA-B387-0A3AC1911FCA}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...k.core/lifebook.core.processmanager/lifebook.core.processmanager/Aggregates/ModelEvent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System; | ||
using System.IO; | ||
using System.Runtime.Serialization.Formatters.Binary; | ||
using lifebook.core.cqrses.Domains; | ||
using Newtonsoft.Json.Linq; | ||
|
||
namespace lifebook.core.processmanager.Aggregates | ||
{ | ||
internal class ModelEvent | ||
{ | ||
public string EventName { get; internal set; } | ||
public int EventVersion { get; internal set; } | ||
public JObject Data { get; internal set; } | ||
|
||
internal AggregateEvent Merge(AggregateEvent aggregateEvent) | ||
{ | ||
var deepCopy = JObject.FromObject(aggregateEvent).DeepClone().ToObject<AggregateEvent>(); | ||
deepCopy.Data = new eventstore.domain.models.Data(ObjectToByteArray(Data)); | ||
deepCopy.EventName = EventName; | ||
deepCopy.EventVersion = EventVersion; | ||
return deepCopy; | ||
} | ||
|
||
private static byte[] ObjectToByteArray(Object obj) | ||
{ | ||
BinaryFormatter bf = new BinaryFormatter(); | ||
using (var ms = new MemoryStream()) | ||
{ | ||
bf.Serialize(ms, obj); | ||
return ms.ToArray(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
....core/lifebook.core.processmanager/lifebook.core.processmanager/Aggregates/ProcessStep.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using lifebook.core.cqrses.Domains; | ||
using lifebook.core.eventstore.domain.models; | ||
|
||
namespace lifebook.core.processmanager.Aggregates | ||
{ | ||
internal class ProcessStep | ||
{ | ||
public bool Initiated { get; internal set; } | ||
public Guid CorrelationId { get; internal set; } | ||
public Guid? CausationId { get; internal set; } | ||
public string StepName { get; internal set; } | ||
public EventSpecifier[] EventSpecifier { get; internal set; } | ||
public AggregateEvent CausedBy { get; internal set; } | ||
public List<Exception> Exceptions { get; internal set; } = new List<Exception>(); | ||
public ProcessStepStatus Status { get; internal set; } | ||
public int Hash { get => HashCode.ToHashCode(); } | ||
public HashCode HashCode | ||
{ | ||
get | ||
{ | ||
var hashCode = new HashCode(); | ||
hashCode.Add($"{DateTime.Now.ToLongTimeString()}"); | ||
hashCode.Add($"{CorrelationId}"); | ||
hashCode.Add($"{Initiated}"); | ||
return HashCode; | ||
} | ||
} | ||
|
||
private ProcessStep() { } | ||
|
||
public class ProcessStepBuilder | ||
{ | ||
private readonly ProcessStep _processStep; | ||
|
||
private ProcessStepBuilder(ProcessStep processStep) | ||
{ | ||
_processStep = processStep; | ||
} | ||
|
||
public static ProcessStepBuilder UsingProcessStep(ProcessStep processStep) | ||
{ | ||
return new ProcessStepBuilder(processStep); | ||
} | ||
|
||
public static ProcessStepBuilder WithRequiredProperties(Guid correlationId, string stepName, EventSpecifier[] eventSpecifier) | ||
{ | ||
var processStep = new ProcessStep(); | ||
processStep.CorrelationId = correlationId; | ||
processStep.StepName = stepName; | ||
processStep.EventSpecifier = eventSpecifier; | ||
return new ProcessStepBuilder(processStep); | ||
} | ||
|
||
public ProcessStepBuilder Initalized() | ||
{ | ||
_processStep.Initiated = true; | ||
return this; | ||
} | ||
|
||
public ProcessStepBuilder CausedBy(AggregateEvent aggregateEvent) | ||
{ | ||
_processStep.CausedBy = aggregateEvent; | ||
_processStep.CausationId = aggregateEvent.CausationId; | ||
return this; | ||
} | ||
|
||
|
||
public ProcessStepBuilder AddException(Exception exception) | ||
{ | ||
_processStep.Exceptions.Add(exception); | ||
return this; | ||
} | ||
|
||
public ProcessStepBuilder ChangeProcessStatus(ProcessStepStatus status) | ||
{ | ||
_processStep.Status = status; | ||
return this; | ||
} | ||
|
||
internal ProcessStep Build() | ||
{ | ||
return _processStep; | ||
} | ||
} | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
...lifebook.core.processmanager/lifebook.core.processmanager/Aggregates/ProcessStepStatus.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
public enum ProcessStepStatus | ||
{ | ||
Failed, | ||
Completed, | ||
Started | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.