Exemplo n.º 1
0
        public async Task <ClientOutboxMessageV2> GetAsync(Guid messageId, SynchronizedStorageSession synchronizedStorageSession)
        {
            var sqlStorageSession = synchronizedStorageSession.GetSqlStorageSession();

            using (var command = sqlStorageSession.Connection.CreateCommand())
            {
                command.CommandText = GetCommandText;
                command.CommandType = CommandType.Text;
                command.Transaction = sqlStorageSession.Transaction;
                command.AddParameter("MessageId", messageId);

                using (var reader = await command.ExecuteReaderAsync(CommandBehavior.SingleRow).ConfigureAwait(false))
                {
                    if (await reader.ReadAsync().ConfigureAwait(false))
                    {
                        var endpointName        = reader.GetString(0);
                        var transportOperations = JsonConvert.DeserializeObject <List <TransportOperation> >(reader.GetString(1), new JsonSerializerSettings {
                            TypeNameHandling = TypeNameHandling.Auto
                        });
                        var clientOutboxMessage = new ClientOutboxMessageV2(messageId, endpointName, transportOperations);

                        return(clientOutboxMessage);
                    }

                    throw new KeyNotFoundException($"Client outbox data not found where MessageId = '{messageId}'");
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Retrieves a <see cref="IContainSagaData"/> instance. Used when implementing a <see cref="IFindSagas{T}"/>.
        /// </summary>
        /// <typeparam name="TSagaData">The <see cref="IContainSagaData"/> type to return.</typeparam>
        /// <param name="session">Used to provide an extension point and access the current <see cref="DbConnection"/> and <see cref="DbTransaction"/>.</param>
        /// <param name="context">Used to append a concurrency value that can be verified when the SagaData is persisted.</param>
        /// <param name="whereClause">The SQL where clause to append to the retrieve saga SQL statement.</param>
        /// <param name="appendParameters">Used to append <see cref="DbParameter"/>s used in the <paramref name="whereClause"/>.</param>
        public static Task <TSagaData> GetSagaData <TSagaData>(this SynchronizedStorageSession session, ReadOnlyContextBag context, string whereClause, ParameterAppender appendParameters)
            where TSagaData : class, IContainSagaData
        {
            Guard.AgainstNull(nameof(session), session);
            Guard.AgainstNull(nameof(context), context);
            Guard.AgainstNull(nameof(appendParameters), appendParameters);
            Guard.AgainstNullAndEmpty(nameof(whereClause), whereClause);
            var writableContextBag = (ContextBag)context;
            var sqlSession         = session.GetSqlStorageSession();

            return(SagaPersister.GetByWhereClause <TSagaData>(whereClause, session, writableContextBag, appendParameters, sqlSession.InfoCache));
        }
Exemplo n.º 3
0
        public Task SetAsDispatchedAsync(Guid messageId, SynchronizedStorageSession synchronizedStorageSession)
        {
            var sqlStorageSession = synchronizedStorageSession.GetSqlStorageSession();

            using (var command = sqlStorageSession.Connection.CreateCommand())
            {
                command.CommandText = SetAsDispatchedCommandText;
                command.CommandType = CommandType.Text;
                command.Transaction = sqlStorageSession.Transaction;
                command.AddParameter("MessageId", messageId);
                command.AddParameter("DispatchedAt", _dateTimeService.UtcNow);

                return(command.ExecuteNonQueryAsync());
            }
        }
        /// <summary>
        /// Retrieves a <see cref="IContainSagaData"/> instance. Used when implementing a <see cref="IFindSagas{T}"/>.
        /// </summary>
        /// <typeparam name="TSagaData">The <see cref="IContainSagaData"/> type to return.</typeparam>
        /// <param name="session">Used to provide an extension point and access the current <see cref="DbConnection"/> and <see cref="DbTransaction"/>.</param>
        /// <param name="context">Used to append a concurrency value that can be verified when the SagaData is persisted.</param>
        /// <param name="whereClause">The SQL where clause to append to the retrieve saga SQL statement.</param>
        /// <param name="appendParameters">Used to append <see cref="DbParameter"/>s used in the <paramref name="whereClause"/>.</param>
        public static Task <TSagaData> GetSagaData <TSagaData>(this SynchronizedStorageSession session, ReadOnlyContextBag context, string whereClause, ParameterAppender appendParameters)
            where TSagaData : class, IContainSagaData
        {
            Guard.AgainstNull(nameof(session), session);
            Guard.AgainstNull(nameof(context), context);
            Guard.AgainstNull(nameof(appendParameters), appendParameters);
            Guard.AgainstNullAndEmpty(nameof(whereClause), whereClause);

            var writableContextBag = (ContextBag)context;
            var sqlSession         = session.GetSqlStorageSession();

            if (sqlSession.InfoCache == null)
            {
                throw new Exception("Cannot load saga data because the Sagas feature is disabled in the endpoint.");
            }
            return(SagaPersister.GetByWhereClause <TSagaData>(whereClause, session, writableContextBag, appendParameters, sqlSession.InfoCache));
        }
        /// <summary>
        /// Retrieves a <see cref="IContainSagaData"/> instance. Used when implementing a <see cref="IFindSagas{T}"/>.
        /// </summary>
        /// <typeparam name="TSagaData">The <see cref="IContainSagaData"/> type to return.</typeparam>
        /// <param name="session">Used to provide an extension point and access the current <see cref="DbConnection"/> and <see cref="DbTransaction"/>.</param>
        /// <param name="context">Used to append a concurrency value that can be verified when the SagaData is persisted.</param>
        /// <param name="whereClause">The SQL where clause to append to the retrieve saga SQL statement.</param>
        /// <param name="appendParameters">Used to append <see cref="DbParameter"/>s used in the <paramref name="whereClause"/>.</param>
        public static Task <TSagaData> GetSagaData <TSagaData>(this SynchronizedStorageSession session, ReadOnlyContextBag context, string whereClause, ParameterAppender appendParameters)
            where TSagaData : IContainSagaData
        {
            Guard.AgainstNull(nameof(session), session);
            Guard.AgainstNull(nameof(context), context);
            Guard.AgainstNull(nameof(appendParameters), appendParameters);
            Guard.AgainstNullAndEmpty(nameof(whereClause), whereClause);
            var writableContextBag = (ContextBag)context;
            var sqlSession         = session.GetSqlStorageSession();
            var sagaInfoCache      = sqlSession.InfoCache;

            if (sagaInfoCache == null)
            {
                throw new Exception($"{nameof(GetSagaData)} can only be executed when Sagas have been enabled on the endpoint.");
            }
            return(SagaPersister.GetByWhereClause <TSagaData>(whereClause, session, writableContextBag, appendParameters, sagaInfoCache));
        }