-
Notifications
You must be signed in to change notification settings - Fork 216
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add json and datacontract variations with memoryInstanceStore
- Loading branch information
1 parent
9a01688
commit 6df2a97
Showing
6 changed files
with
97 additions
and
23 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
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
27 changes: 27 additions & 0 deletions
27
src/Test/WorkflowApplicationTestExtensions/Persistence/MemoryInstanceStore.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,27 @@ | ||
using System; | ||
using System.Collections.Concurrent; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
|
||
namespace WorkflowApplicationTestExtensions.Persistence; | ||
|
||
public class MemoryInstanceStore(IWorkflowSerializer workflowSerializer) : AbstractInstanceStore(workflowSerializer) | ||
{ | ||
private readonly ConcurrentDictionary<Guid, MemoryStream> _cache = new(); | ||
|
||
public MemoryInstanceStore() : this(new JsonWorkflowSerializer()) { } | ||
|
||
protected override void OnReadStreamDisposed(Guid instanceId, Stream stream) | ||
=> _cache.Remove(instanceId, out _); | ||
|
||
protected override Task<Stream> GetReadStream(Guid instanceId) | ||
{ | ||
_cache[instanceId].TryGetBuffer(out var buffer); | ||
return Task.FromResult<Stream>(new MemoryStream(buffer.Array, buffer.Offset, buffer.Count)); | ||
} | ||
|
||
protected override Task<Stream> GetWriteStream(Guid instanceId) | ||
=> Task.FromResult<Stream>(_cache[instanceId] = new MemoryStream()); | ||
} | ||
|
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