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


C# ISagaData.GetType方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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());

            var result = collection.Insert(sagaData);

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

示例6: 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

示例7: 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

示例8: Update

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

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

            sagaData.Revision++;

            var result = collection.Update(criteria, MongoDB.Driver.Builders.Update.Replace(sagaData));

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

示例9: 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

示例10: 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

示例11: 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!");
            }

            using (var session = _documentStore.OpenAsyncSession())
            {
                var sagaDataDocumentId = SagaDataDocument.GetIdFromGuid(sagaData.Id);
                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:nls75,项目名称:Rebus,代码行数:19,代码来源:RavenDbSagaStorage.cs

示例12: 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 connection = await _connectionHelper.GetConnection())
            {
                using (var command = connection.CreateCommand())
                {
                    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.CommandText =
                        [email protected]"

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

";

                    try
                    {
                        command.ExecuteNonQuery();
                    }
                    catch (NpgsqlException exception)
                    {
                        throw new ConcurrencyException(exception, "Saga data {0} with ID {1} in table {2} could not be inserted!",
                            sagaData.GetType(), sagaData.Id, _dataTableName);
                    }
                }

                var propertiesToIndex = GetPropertiesToIndex(sagaData, correlationProperties);

                if (propertiesToIndex.Any())
                {
                    await CreateIndex(sagaData, connection, propertiesToIndex);
                }

                connection.Complete();
            }
        }
开发者ID:RichieYang,项目名称:Rebus,代码行数:50,代码来源:PostgreSqlSagaStorage.cs

示例13: CreateIndex

        async Task CreateIndex(ISagaData sagaData, PostgresConnection connection, IEnumerable<KeyValuePair<string, string>> propertiesToIndex)
        {
            var sagaTypeName = GetSagaTypeName(sagaData.GetType());
            var parameters = propertiesToIndex
                .Select((p, i) => new
                {
                    PropertyName = p.Key,
                    PropertyValue = p.Value ?? "",
                    PropertyNameParameter = $"@n{i}",
                    PropertyValueParameter = $"@v{i}"
                })
                .ToList();

            // lastly, generate new index
            using (var command = connection.CreateCommand())
            {
                // generate batch insert with SQL for each entry in the index
                var inserts = parameters
                    .Select(a =>
                        [email protected]"

INSERT
    INTO ""{_indexTableName}"" (""saga_type"", ""key"", ""value"", ""saga_id"") 
    VALUES (@saga_type, {a.PropertyNameParameter}, {a.PropertyValueParameter}, @saga_id)

");

                var sql = string.Join(";" + Environment.NewLine, inserts);

                command.CommandText = sql;

                foreach (var parameter in parameters)
                {
                    command.Parameters.Add(parameter.PropertyNameParameter, NpgsqlDbType.Text).Value = parameter.PropertyName;
                    command.Parameters.Add(parameter.PropertyValueParameter, NpgsqlDbType.Text).Value = parameter.PropertyValue;
                }

                command.Parameters.Add("saga_type", NpgsqlDbType.Text).Value = sagaTypeName;
                command.Parameters.Add("saga_id", NpgsqlDbType.Uuid).Value = sagaData.Id;

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

示例14: OptimisticLockingException

 /// <summary>
 /// Constructs the exception with an error message that explains how a race condition was detected on the specified saga data,
 /// supplying as extra information a caught exception
 /// </summary>
 public OptimisticLockingException(ISagaData sagaData, Exception innerException)
     : base(string.Format(@"Could not update saga of type {0} with _id {1} _rev {2} because someone else beat us to it",
     sagaData.GetType(), sagaData.Id, sagaData.Revision), innerException)
 {
 }
开发者ID:plillevold,项目名称:Rebus,代码行数:9,代码来源:OptimisticLockingException.cs

示例15: VerifyCorrelationPropertyUniqueness

        void VerifyCorrelationPropertyUniqueness(ISagaData sagaData, IEnumerable<ISagaCorrelationProperty> correlationProperties)
        {
            foreach (var property in correlationProperties)
            {
                var valueFromSagaData = Reflect.Value(sagaData, property.PropertyName);

                foreach (var existingSagaData in _data.Values)
                {
                    if (existingSagaData.Id == sagaData.Id) continue;
                    if (existingSagaData.GetType() != sagaData.GetType()) continue;

                    var valueFromExistingInstance = Reflect.Value(existingSagaData, property.PropertyName);

                    if (Equals(valueFromSagaData, valueFromExistingInstance))
                    {
                        throw new ConcurrencyException("Correlation property '{0}' has value '{1}' in existing saga data with ID {2}",
                            property.PropertyName, valueFromExistingInstance, existingSagaData.Id);
                    }
                }
            }
        }
开发者ID:lsfera,项目名称:Rebus,代码行数:21,代码来源:InMemorySagaStorage.cs


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