-
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.
Merge pull request #23 from JaimeStill/service
update processing library + test
- Loading branch information
Showing
9 changed files
with
150 additions
and
58 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,8 @@ | ||
namespace Arma.Demo.Core.Processing; | ||
public enum Intent | ||
{ | ||
Approve, | ||
Acquire, | ||
Transfer, | ||
Destroy | ||
} |
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
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
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,12 @@ | ||
namespace Arma.Demo.Core.Processing; | ||
public static class ProcessingExtensions | ||
{ | ||
public static string ToActionString(this Intent intent) => intent switch | ||
{ | ||
Intent.Acquire => "Acquisition", | ||
Intent.Approve => "Approval", | ||
Intent.Destroy => "Destruction", | ||
Intent.Transfer => "Transfer", | ||
_ => throw new ArgumentOutOfRangeException("An unexpected intent was provided") | ||
}; | ||
} |
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 @@ | ||
namespace Arma.Demo.Core.Processing; | ||
public class Resource | ||
{ | ||
public Guid Key => Guid.NewGuid(); | ||
public string Name { get; set; } | ||
} |
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
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
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,47 @@ | ||
using Arma.Demo.Core.Processing; | ||
|
||
namespace Processor; | ||
public class ProcessingEngine | ||
{ | ||
public Package Package { get; private set; } | ||
public Process Process { get; private set; } | ||
|
||
public ProcessingEngine(Package package) | ||
{ | ||
Package = package; | ||
Process = GenerateProcess(package); | ||
} | ||
|
||
public async Task Execute() | ||
{ | ||
Console.WriteLine($"Submitting package {Package.Name} for {Package.Intent.ToActionString()}"); | ||
Console.WriteLine("Package Items:"); | ||
|
||
foreach (Resource resource in Package.Resources) | ||
Console.WriteLine(resource.Name); | ||
|
||
await Task.Delay(800); | ||
|
||
Console.WriteLine($"Package {Package.Name} assigned process {Process.Name}"); | ||
|
||
foreach (ProcessTask task in Process.Tasks) | ||
{ | ||
Console.WriteLine($"Current step: {task.Name}"); | ||
await Task.Delay(task.Duration); | ||
Console.WriteLine($"Package {Package.Name} was approved by {task.Section}"); | ||
} | ||
|
||
Console.WriteLine($"Package {Package.Name} was successfully approved"); | ||
} | ||
|
||
static Process GenerateProcess(Package package) => package.Intent switch | ||
{ | ||
Intent.Approve => ProcessGenerator.ApprovalProcess(), | ||
Intent.Acquire => ProcessGenerator.AcquisitionProcess(), | ||
Intent.Transfer => ProcessGenerator.TransferProcess(), | ||
Intent.Destroy => ProcessGenerator.DestructionProcess(), | ||
_ => throw new ArgumentOutOfRangeException( | ||
"An unexpected intent was provided and no associated process could be found" | ||
) | ||
}; | ||
} |
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 |
---|---|---|
@@ -1,21 +1,6 @@ | ||
using Arma.Demo.Core.Processing; | ||
using Processor; | ||
|
||
Package package = PackageGenerator.ApprovalPackage(); | ||
|
||
Console.WriteLine($"Submitting package {package.Name} for approval"); | ||
|
||
await Task.Delay(1200); | ||
|
||
Process process = ProcessGenerator.ApprovalProcess(); | ||
|
||
Console.WriteLine($"Package {package.Name} assigned process {process.Name}"); | ||
|
||
foreach (ProcessTask task in process.Tasks) | ||
{ | ||
Console.WriteLine($"Current step: {task.Name}"); | ||
await Task.Delay(task.Duration); | ||
Console.WriteLine($"Package {package.Name} was approved by {task.Section}"); | ||
} | ||
|
||
Console.WriteLine($"Package {package.Name} was successfully approved"); | ||
await new ProcessingEngine( | ||
PackageGenerator.ApprovalPackage() | ||
).Execute(); |