コード例 #1
0
        public Task Complete(IContainSagaData sagaData, SynchronizedStorageSession session, ContextBag context)
        {
            var documentSession = session.MartenSession();

            documentSession.Delete <SagaDocument>(sagaData.Id);

            return(Task.CompletedTask);
        }
コード例 #2
0
        public async Task <TSagaData> Get <TSagaData>(Guid sagaId, SynchronizedStorageSession session, ContextBag context) where TSagaData : IContainSagaData
        {
            var documentSession = session.MartenSession();
            var sagaDocument    = await documentSession.LoadAsync <SagaDocument>(sagaId);

            if (sagaDocument == null)
            {
                return(default(TSagaData));
            }

            return((TSagaData)sagaDocument.SagaData);
        }
コード例 #3
0
        public async Task <TSagaData> Get <TSagaData>(string propertyName, object propertyValue, SynchronizedStorageSession session, ContextBag context) where TSagaData : IContainSagaData
        {
            var documentSession = session.MartenSession();

            var sagaType = typeof(TSagaData).FullName;

            var sagaDocument = await documentSession.Query <SagaDocument>()
                               .Where(x => x.CorrelationProperty == propertyName)
                               .Where(x => x.CorrelationPropertyValue == propertyValue.ToString())
                               .Where(x => x.Type == sagaType)
                               .FirstOrDefaultAsync();

            if (sagaDocument == null)
            {
                return(default(TSagaData));
            }

            return((TSagaData)sagaDocument.SagaData);
        }
コード例 #4
0
        public async Task Save(IContainSagaData sagaData, SagaCorrelationProperty correlationProperty, SynchronizedStorageSession session, ContextBag context)
        {
            var documentSession = session.MartenSession();

            if (sagaData == null)
            {
                return;
            }

            var sagaDocument = new SagaDocument
            {
                Id                       = sagaData.Id,
                SagaData                 = sagaData,
                CorrelationProperty      = correlationProperty.Name,
                CorrelationPropertyValue = correlationProperty.Value.ToString(),
                Type                     = sagaData.GetType().FullName
            };

            documentSession.Store(sagaDocument);
        }