• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# ISagaData类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中ISagaData的典型用法代码示例。如果您正苦于以下问题:C# ISagaData类的具体用法?C# ISagaData怎么用?C# ISagaData使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ISagaData类属于命名空间,在下文中一共展示了ISagaData类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: Update

        /// <summary>
        /// Updates the saga data
        /// </summary>
        public async Task Update(ISagaData sagaData, IEnumerable<ISagaCorrelationProperty> correlationProperties)
        {
            var id = GetId(sagaData);

            lock (_lock)
            {
                if (!_data.ContainsKey(id))
                {
                    throw new ConcurrencyException("Saga data with ID {0} no longer exists and cannot be updated", id);
                }

                VerifyCorrelationPropertyUniqueness(sagaData, correlationProperties);

                var existingCopy = _data[id];

                if (existingCopy.Revision != sagaData.Revision)
                {
                    throw new ConcurrencyException("Attempted to update saga data with ID {0} with revision {1}, but the existing data was updated to revision {2}",
                        id, sagaData.Revision, existingCopy.Revision);
                }

                var clone = Clone(sagaData);
                clone.Revision++;
                _data[id] = clone;
                sagaData.Revision++;
            }
        }
开发者ID:lsfera,项目名称:Rebus,代码行数:30,代码来源:InMemorySagaStorage.cs


示例2: Insert

        public async Task Insert(ISagaData sagaData, IEnumerable<ISagaCorrelationProperty> correlationProperties)
        {
            if (sagaData.Id == Guid.Empty)
            {
                throw new InvalidOperationException($"Saga data {sagaData.GetType()} has an uninitialized Id property!");
            }

            if (sagaData.Revision != 0)
            {
                throw new InvalidOperationException($"Attempted to insert saga data with ID {sagaData.Id} and revision {sagaData.Revision}, but revision must be 0 on first insert!");
            }

            using (var session = _documentStore.OpenAsyncSession())
            {
                session.Advanced.UseOptimisticConcurrency = true;

                var sagaDataDocumentId = SagaDataDocument.GetIdFromGuid(sagaData.Id);

                var existingSagaDataDocument = await session.LoadAsync<SagaDataDocument>(sagaDataDocumentId);

                if (existingSagaDataDocument != null)
                {
                    throw new ConcurrencyException("Cannot insert document with an id that already exists");
                }

                var sagaDataDocument = new SagaDataDocument(sagaData);
                await session.StoreAsync(sagaDataDocument, sagaDataDocumentId);

                var correlationPropertyDocumentIds = await SaveCorrelationProperties(session, sagaData, correlationProperties, sagaDataDocumentId);
                sagaDataDocument.SagaCorrelationPropertyDocumentIds = correlationPropertyDocumentIds;

                await session.SaveChangesAsync();
            }
        }
开发者ID:RichieYang,项目名称:Rebus,代码行数:34,代码来源:RavenDbSagaStorage.cs


示例3: Save

        /// <summary>
        /// Saves a snapshot of the saga data along with the given metadata
        /// </summary>
        public async Task Save(ISagaData sagaData, Dictionary<string, string> sagaAuditMetadata)
        {
            using (var connection = await _connectionProvider.GetConnection())
            {
                using (var command = connection.CreateCommand())
                {
                    command.CommandText = string.Format(@"

INSERT INTO [{0}] (
    [id],
    [revision],
    [data],
    [metadata]
) VALUES (
    @id, 
    @revision, 
    @data,
    @metadata
)

", _tableName);
                    command.Parameters.Add("id", SqlDbType.UniqueIdentifier).Value = sagaData.Id;
                    command.Parameters.Add("revision", SqlDbType.Int).Value = sagaData.Revision;
                    command.Parameters.Add("data", SqlDbType.NVarChar).Value = JsonConvert.SerializeObject(sagaData, DataSettings);
                    command.Parameters.Add("metadata", SqlDbType.NVarChar).Value = JsonConvert.SerializeObject(sagaAuditMetadata, MetadataSettings);

                    await command.ExecuteNonQueryAsync();
                }

                await connection.Complete();
            }
        }
开发者ID:netojoaop,项目名称:Rebus,代码行数:35,代码来源:SqlServerSagaSnapshotStorage.cs


示例4: Save

        public async Task Save(ISagaData sagaData, Dictionary<string, string> sagaAuditMetadata)
        {
            using (var connection = await _connectionHelper.GetConnection())
            {
                using (var command = connection.CreateCommand())
                {
                    command.CommandText =
                        [email protected]"

INSERT
    INTO ""{_tableName}"" (""id"", ""revision"", ""data"", ""metadata"")
    VALUES (@id, @revision, @data, @metadata);

";
                    command.Parameters.Add("id", NpgsqlDbType.Uuid).Value = sagaData.Id;
                    command.Parameters.Add("revision", NpgsqlDbType.Integer).Value = sagaData.Revision;
                    command.Parameters.Add("data", NpgsqlDbType.Bytea).Value = _objectSerializer.Serialize(sagaData);
                    command.Parameters.Add("metadata", NpgsqlDbType.Jsonb).Value =
                        _dictionarySerializer.SerializeToString(sagaAuditMetadata);

                    await command.ExecuteNonQueryAsync();
                }
                
                connection.Complete();
            }
        }
开发者ID:RichieYang,项目名称:Rebus,代码行数:26,代码来源:PostgreSqlSagaSnapshotStorage.cs


示例5: Insert

 public void Insert(ISagaData sagaData, IEnumerable<ISagaCorrelationProperty> correlationProperties)
 {
     var indexItems = ReadIndexItems();
     indexItems.RemoveAll(i => i.SagaId == sagaData.Id);
     indexItems.AddRange(GetPropertiesToIndex(sagaData, correlationProperties));
     var path = SagaFilePath(sagaData.Id);
     File.WriteAllText(path, JsonConvert.SerializeObject(sagaData, _serializerSettings));
     WriteSagaIndexItems(indexItems);
 }
开发者ID:RichieYang,项目名称:Rebus,代码行数:9,代码来源:FilesystemSagaIndex.cs


示例6: Save

        public async Task Save(ISagaData sagaData, Dictionary<string, string> sagaAuditMetadata)
        {
            var document = new BsonDocument
            {
                {"_id", new {Id = sagaData.Id, Revision = sagaData.Revision}.ToBsonDocument()},
                {"Metadata", sagaAuditMetadata.ToBsonDocument()},
                {"Data", sagaData.ToBsonDocument()}
            };

            await _snapshots.InsertOneAsync(document);
        }
开发者ID:RichieYang,项目名称:Rebus,代码行数:11,代码来源:MongoDbSagaSnapshotStorage.cs


示例7: Insert

        public async Task Insert(ISagaData sagaData, IEnumerable<ISagaCorrelationProperty> correlationProperties)
        {
            if (sagaData.Id == Guid.Empty)
            {
                throw new InvalidOperationException(string.Format("Attempted to insert saga data {0} without an ID", sagaData.GetType()));
            }

            var collection = GetCollection(sagaData.GetType());

            await collection.InsertOneAsync(sagaData.ToBsonDocument()).ConfigureAwait(false);
        }
开发者ID:nls75,项目名称:Rebus,代码行数:11,代码来源:MongoDbSagaStorage.cs


示例8: AddInstance

 internal void AddInstance(ISagaData sagaData)
 {
     lock (_lock)
     {
         var instance = Clone(sagaData);
         if (instance.Id == Guid.Empty)
         {
             instance.Id = Guid.NewGuid();
         }
         _data[instance.Id] = instance;
     }
 }
开发者ID:RichieYang,项目名称:Rebus,代码行数:12,代码来源:InMemorySagaStorage.cs


示例9: GetMetadata

 Dictionary<string, string> GetMetadata(ISagaData sagaData, object handler, Message message)
 {
     return new Dictionary<string, string>
     {
         {SagaAuditingMetadataKeys.HandleQueue, _transport.Address},
         {SagaAuditingMetadataKeys.SagaDataType, sagaData.GetType().GetSimpleAssemblyQualifiedName()},
         {SagaAuditingMetadataKeys.SagaHandlerType, handler.GetType().GetSimpleAssemblyQualifiedName()},
         {SagaAuditingMetadataKeys.MessageType, message.GetMessageType()},
         {SagaAuditingMetadataKeys.MessageId, message.GetMessageId()},
         {SagaAuditingMetadataKeys.MachineName, Environment.MachineName},
     };
 }
开发者ID:netojoaop,项目名称:Rebus,代码行数:12,代码来源:SaveSagaDataSnapshotStep.cs


示例10: Save

        public async Task Save(ISagaData sagaData, Dictionary<string, string> sagaAuditMetadata)
        {
            var logData = new
            {
                Data = sagaData,
                Metadata = sagaAuditMetadata
            };
            
            var jsonText = JsonConvert.SerializeObject(logData, Formatting.None);

            _log.Info(jsonText);
        }
开发者ID:netojoaop,项目名称:Rebus,代码行数:12,代码来源:LoggerSagaSnapperShotter.cs


示例11: Delete

        public async Task Delete(ISagaData sagaData)
        {
            var collection = GetCollection(sagaData.GetType());

            var result = await collection.DeleteManyAsync(new BsonDocument("_id", sagaData.Id)).ConfigureAwait(false);

            if (result.DeletedCount != 1)
            {
                throw new ConcurrencyException("Saga data {0} with ID {1} in collection {2} could not be deleted", 
                    sagaData.GetType(), sagaData.Id, collection.CollectionNamespace);
            }
        }
开发者ID:RichieYang,项目名称:Rebus,代码行数:12,代码来源:MongoDbSagaStorage.cs


示例12: Save

 /// <summary>
 /// Archives the given saga data under its current ID and revision
 /// </summary>
 public async Task Save(ISagaData sagaData, Dictionary<string, string> sagaAuditMetadata)
 {
     var dataRef = $"{sagaData.Id:N}/{sagaData.Revision:0000000000}/data.json";
     var metaDataRef = $"{sagaData.Id:N}/{sagaData.Revision:0000000000}/metadata.json";
     var dataBlob = _container.GetBlockBlobReference(dataRef);
     var metaDataBlob = _container.GetBlockBlobReference(metaDataRef);
     dataBlob.Properties.ContentType = "application/json";
     metaDataBlob.Properties.ContentType = "application/json";
     await dataBlob.UploadTextAsync(JsonConvert.SerializeObject(sagaData, DataSettings), TextEncoding, DefaultAccessCondition, DefaultRequestOptions, DefaultOperationContext);
     await metaDataBlob.UploadTextAsync(JsonConvert.SerializeObject(sagaAuditMetadata, MetadataSettings), TextEncoding, DefaultAccessCondition, DefaultRequestOptions, DefaultOperationContext);
     await dataBlob.SetPropertiesAsync();
     await metaDataBlob.SetPropertiesAsync();
 }
开发者ID:RichieYang,项目名称:Rebus,代码行数:16,代码来源:AzureStorageSagaSnapshotStorage.cs


示例13: Delete

        public void Delete(ISagaData sagaData)
        {
            var collection = database.GetCollection(collectionName);

            if (Transaction.Current != null)
            {
                var hack = new AmbientTxHack(() => collection.Remove(Query.EQ("_id", sagaData.Id)));
                Transaction.Current.EnlistVolatile(hack, EnlistmentOptions.None);
            }
            else
            {
                collection.Remove(Query.EQ("_id", sagaData.Id));
            }
        }
开发者ID:larsudengaard,项目名称:Rebus,代码行数:14,代码来源:MongoDbSagaPersister.cs


示例14: Delete

        public void Delete(ISagaData sagaData)
        {
            var collection = database.GetCollection(collectionName);

            var query = Query.And(Query.EQ("_id", sagaData.Id),
                                  Query.EQ("_rev", sagaData.Revision));

            var safeModeResult = collection.Remove(query, SafeMode.True);

            EnsureResultIsGood(safeModeResult,
                               "delete saga data of type {0} with _id {1} and _rev {2}",
                               sagaData.GetType(),
                               sagaData.Id,
                               sagaData.Revision);
        }
开发者ID:karmerk,项目名称:Rebus,代码行数:15,代码来源:MongoDbSagaPersister.cs


示例15: Delete

        public void Delete(ISagaData sagaData)
        {
            using (var connection = new SqlConnection(connectionString))
            {
                connection.Open();

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = @"delete from sagas where id = @id;
                                            delete from saga_index where saga_id = @id";
                    command.Parameters.AddWithValue("id", sagaData.Id);
                    command.ExecuteNonQuery();
                }
            }
        }
开发者ID:larsudengaard,项目名称:Rebus,代码行数:15,代码来源:SqlServerSagaPersister.cs


示例16: Delete

        public async Task Delete(ISagaData sagaData)
        {
            var collection = GetCollection(sagaData.GetType());

            var result = collection.Remove(Query.EQ("_id", sagaData.Id));

            try
            {
                CheckResult(result, 1);
            }
            catch (Exception exception)
            {
                throw new ConcurrencyException(exception, "Saga data {0} with ID {1} in collection {2} could not be deleted", 
                    sagaData.GetType(), sagaData.Id, collection.Name);
            }
        }
开发者ID:geffzhang,项目名称:Rebus,代码行数:16,代码来源:MongoDbSagaStorage.cs


示例17: Insert

        public async Task Insert(ISagaData sagaData, IEnumerable<ISagaCorrelationProperty> correlationProperties)
        {
            if (sagaData.Id == Guid.Empty)
            {
                throw new InvalidOperationException($"Attempted to insert saga data {sagaData.GetType()} without an ID");
            }

            if (sagaData.Revision != 0)
            {
                throw new InvalidOperationException($"Attempted to insert saga data with ID {sagaData.Id} and revision {sagaData.Revision}, but revision must be 0 on first insert!");
            }

            var collection = GetCollection(sagaData.GetType());

            await collection.InsertOneAsync(sagaData.ToBsonDocument()).ConfigureAwait(false);
        }
开发者ID:RichieYang,项目名称:Rebus,代码行数:16,代码来源:MongoDbSagaStorage.cs


示例18: Update

        public async Task Update(ISagaData sagaData, IEnumerable<ISagaCorrelationProperty> correlationProperties)
        {
            var collection = GetCollection(sagaData.GetType());

            var criteria = Builders<BsonDocument>.Filter.And(Builders<BsonDocument>.Filter.Eq("_id", sagaData.Id),
                Builders<BsonDocument>.Filter.Eq("Revision", sagaData.Revision));

            sagaData.Revision++;

            var result = await collection.ReplaceOneAsync(criteria, sagaData.ToBsonDocument(sagaData.GetType())).ConfigureAwait(false);

            if (!result.IsModifiedCountAvailable || result.ModifiedCount != 1)
            {
                throw new ConcurrencyException("Saga data {0} with ID {1} in collection {2} could not be updated!",
                    sagaData.GetType(), sagaData.Id, collection.CollectionNamespace);
            }
        }
开发者ID:RichieYang,项目名称:Rebus,代码行数:17,代码来源:MongoDbSagaStorage.cs


示例19: Update

        public async Task Update(ISagaData sagaData, IEnumerable<ISagaCorrelationProperty> correlationProperties)
        {
            using (var session = _documentStore.OpenAsyncSession())
            {
                var documentId = SagaDataDocument.GetIdFromGuid(sagaData.Id);
                var existingSagaData = await session.LoadAsync<SagaDataDocument>(documentId);
                sagaData.Revision++;
                existingSagaData.SagaData = sagaData;
                
                await DeleteCorrelationPropertyDataForSaga(existingSagaData, session);

                //add the new saga correlation documents
                var correlationPropertyDocumentIds = await SaveCorrelationProperties(session, sagaData, correlationProperties, existingSagaData.Id);
                existingSagaData.SagaCorrelationPropertyDocumentIds = correlationPropertyDocumentIds;

                await session.SaveChangesAsync();
            }
        }
开发者ID:lsfera,项目名称:Rebus,代码行数:18,代码来源:RavenDbSagaStorage.cs


示例20: Save

        /// <summary>
        /// Saves a snapshot of the saga data along with the given metadata
        /// </summary>
        public async Task Save(ISagaData sagaData, Dictionary<string, string> sagaAuditMetadata)
        {
            var jsonText = JsonConvert.SerializeObject(new Snapshot
            {
                Data = sagaData,
                Metadata = sagaAuditMetadata
            }, Formatting.Indented);

            var snapshotFilePath = Path.Combine(_snapshotDirectory, string.Format("{0:N}-{1}.json", sagaData.Id, sagaData.Revision));

            using (var file = File.OpenWrite(snapshotFilePath))
            {
                using (var writer = new StreamWriter(file, Encoding.UTF8))
                {
                    await writer.WriteAsync(jsonText);
                }
            }
        }
开发者ID:nls75,项目名称:Rebus,代码行数:21,代码来源:FileSystemSagaSnapshotStorage.cs



注:本文中的ISagaData类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# ISampleGrabber类代码示例发布时间:2022-05-24
下一篇:
C# ISSHChannelEventReceiver类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap