internal override object BuildSagaData(CommandWrapper command, RuntimeSagaInfo sagaInfo, IContainSagaData sagaData) { var writer = command.LeaseWriter(); sagaInfo.ToJson(sagaData, writer); return(writer.ToCharSegment()); }
static void ValidatePropertyName <TSagaData>(string propertyName, RuntimeSagaInfo sagaInfo) where TSagaData : IContainSagaData { if (!sagaInfo.HasCorrelationProperty) { throw new Exception($"Cannot retrieve a {typeof(TSagaData).FullName} using property \'{propertyName}\'. The saga has no correlation property."); } if (propertyName != sagaInfo.CorrelationProperty) { throw new Exception($"Cannot retrieve a {typeof(TSagaData).FullName} using property \'{propertyName}\'. Can only be retrieve using the correlation property '{sagaInfo.CorrelationProperty}'"); } }
static void AddTransitionalParameter(IContainSagaData sagaData, RuntimeSagaInfo sagaInfo, CommandWrapper command) { if (!sagaInfo.HasTransitionalCorrelationProperty) { return; } var transitionalId = sagaInfo.TransitionalAccessor(sagaData); if (transitionalId == null) { //TODO: validate non default for value types throw new Exception($"Null transitionalCorrelationProperty is not allowed. SagaDataType: {sagaData.GetType().FullName}."); } command.AddParameter("TransitionalCorrelationId", transitionalId); }
internal virtual object BuildSagaData(CommandWrapper command, RuntimeSagaInfo sagaInfo, IContainSagaData sagaData) { return(sagaInfo.ToJson(sagaData)); }
static async Task <Concurrency <TSagaData> > GetSagaData <TSagaData>(SynchronizedStorageSession session, string commandText, RuntimeSagaInfo sagaInfo, ParameterAppender appendParameters) where TSagaData : class, IContainSagaData { var sqlSession = session.SqlPersistenceSession(); using (var command = sagaInfo.CreateCommand(sqlSession.Connection)) { command.CommandText = commandText; command.Transaction = sqlSession.Transaction; var dbCommand = command.InnerCommand; appendParameters(dbCommand.CreateParameter, parameter => dbCommand.Parameters.Add(parameter)); // to avoid loading into memory SequentialAccess is required which means each fields needs to be accessed using (var dataReader = await command.ExecuteReaderAsync(CommandBehavior.SingleRow | CommandBehavior.SequentialAccess).ConfigureAwait(false)) { if (!await dataReader.ReadAsync().ConfigureAwait(false)) { return(default);
static async Task <Concurrency <TSagaData> > GetSagaData <TSagaData>(SynchronizedStorageSession session, string commandText, RuntimeSagaInfo sagaInfo, ParameterAppender appendParameters) where TSagaData : IContainSagaData { var sqlSession = session.SqlPersistenceSession(); using (var command = sagaInfo.CreateCommand(sqlSession.Connection)) { command.CommandText = commandText; command.Transaction = sqlSession.Transaction; var dbCommand = command.InnerCommand; appendParameters(dbCommand.CreateParameter, parameter => dbCommand.Parameters.Add(parameter)); // to avoid loading into memory SequentialAccess is required which means each fields needs to be accessed using (var dataReader = await command.ExecuteReaderAsync(CommandBehavior.SingleRow | CommandBehavior.SequentialAccess).ConfigureAwait(false)) { if (!await dataReader.ReadAsync().ConfigureAwait(false)) { return(new Concurrency <TSagaData>(default(TSagaData), 0)); } var id = await dataReader.GetGuidAsync(0).ConfigureAwait(false); var sagaTypeVersionString = await dataReader.GetFieldValueAsync <string>(1).ConfigureAwait(false); var sagaTypeVersion = Version.Parse(sagaTypeVersionString); var concurrency = await dataReader.GetFieldValueAsync <int>(2).ConfigureAwait(false); ReadMetadata(dataReader, out var originator, out var originalMessageId); using (var textReader = dataReader.GetTextReader(4)) { var sagaData = sagaInfo.FromString <TSagaData>(textReader, sagaTypeVersion); sagaData.Id = id; sagaData.Originator = originator; sagaData.OriginalMessageId = originalMessageId; return(new Concurrency <TSagaData>(sagaData, concurrency)); } } } }