当前位置: 首页>>代码示例>>C#>>正文


C# ISagaData类代码示例

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


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


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