Task <SagaSearchResult> ISearchForSaga.Search(SagaSearchMethod searchMethod, object message, CancellationToken cancellationToken)
 {
     Contract.Requires <ArgumentNullException>(searchMethod != null, nameof(searchMethod));
     Contract.Requires <ArgumentNullException>(message != null, nameof(message));
     Contract.Ensures(Contract.Result <Task <SagaSearchResult> >() != null);
     return(null);
 }
        /// <summary>
        /// Seaches for saga data using the specified search method and message.
        /// </summary>
        /// <param name="searchMethod">The <see cref="SagaSearchMethod">search method</see> used to find the saga data.</param>
        /// <param name="messsage">The correlated message used to find the saga data.</param>
        /// <param name="cancellationToken">The <see cref="CancellationToken">token</see> that can be used to cancel the operation.</param>
        /// <returns>A <see cref="Task{TResult}">task</see> containing the <see cref="SagaSearchResult">search result</see>.</returns>
        public async Task <SagaSearchResult> Search(SagaSearchMethod searchMethod, object messsage, CancellationToken cancellationToken)
        {
            Arg.NotNull(searchMethod, nameof(searchMethod));
            Arg.NotNull(messsage, nameof(messsage));

            if (!(searchMethod is ByPropertySagaSearchMethod propertySearchMethod))
            {
                return(new SagaSearchResult());
            }

            var messagePropertyValue = propertySearchMethod.ReadMessageProperty(messsage);
            var sagaPropertyName     = propertySearchMethod.PropertyName;
            var properties           = new Dictionary <string, object>()
            {
                [sagaPropertyName] = messagePropertyValue
            };
            var data = default(TData);

            if (messagePropertyValue == null)
            {
                return(new SagaSearchResult(data, properties));
            }

            if (StringComparer.OrdinalIgnoreCase.Equals(sagaPropertyName, nameof(ISagaData.Id)))
            {
                data = await store.Retrieve <TData>((Guid)messagePropertyValue, cancellationToken).ConfigureAwait(false);
            }
            else
            {
                data = await store.Retrieve <TData>(sagaPropertyName, messagePropertyValue, cancellationToken).ConfigureAwait(false);
            }

            return(new SagaSearchResult(data, properties));
        }
Пример #3
0
 /// <summary>
 /// Attempts to resolve the saga search method for the specified message type.
 /// </summary>
 /// <param name="messageType">The qualified name of the message type to retrieve the search method for.</param>
 /// <param name="searchMethod">The resolved <see cref="SagaSearchMethod">search method</see> or <c>null</c> of no search method is matched.</param>
 /// <returns>True if the <paramref name="searchMethod">search method</paramref> is matched; otherwise, false.</returns>
 public bool TryGetSearchMethod(string messageType, out SagaSearchMethod searchMethod) =>
 searchMethods.TryGetValue(messageType, out searchMethod);