示例#1
0
        // TODO: Put strings into the resources.
        //
        void P_EnsureInitialStateValid(LocalSubscriptionStates initialState)
        {
            var invalidFlags = ~(LocalSubscriptionStates.PublisherOwnsSubscription | LocalSubscriptionStates.Suspended | LocalSubscriptionStates.OwnsSubscriber) & initialState;

            if (invalidFlags != LocalSubscriptionStates.None)
            {
                throw new ArgumentOutOfRangeException(paramName: nameof(initialState), message: $"Указано недопустимое исходное состояние подписки '{invalidFlags.ToString()}'.");
            }
        }
示例#2
0
 public Task <ILocalSubscription> SubscribeAsync <TPayload>(ProcessLocalMessage <TPayload> process, LocalSubscriptionStates subscriptionInitialState = default)
 => InnerPublisher.SubscribeAsync(process: process, state: subscriptionInitialState);
示例#3
0
 public virtual Task <ILocalSubscription> SubscribeAsync <TPayload>(ProcessLocalMessage <TPayload> process, LocalPublicationFilter <TPayload> publicationFilter = default, LocalSubscriptionStates subscriptionInitialState = default)
 => InnerPublisher.SubscribeAsync(publicationFilter: publicationFilter, process: process, subscriptionInitialState: subscriptionInitialState);
示例#4
0
 public Task <ILocalSubscription> SubscribeAsync <TData>(ProcessLocalMessage <TData> processMessage, LocalSubscriptionStates state = default(LocalSubscriptionStates))
 => SubscribeAsync(process: processMessage, publicationFilter: null, subscriptionInitialState: state);
示例#5
0
        public virtual async Task <ILocalSubscription> SubscribeAsync <TData>(ProcessLocalMessage <TData> process, LocalPublicationFilter <TData> publicationFilter = null, LocalSubscriptionStates subscriptionInitialState = default)
        {
            var subscription = default(ILocalSubscription);
            var subscriber   = default(ILocalSubscriber);

            try {
                subscriber   = new DelegateLocalSubscriber <TData>(process: process, publicationFilter: publicationFilter);
                subscription = new LocalSubscription(publisher: this, subscriber: subscriber, initialState: LocalSubscriptionStates.OwnsSubscriber | LocalSubscriptionStates.PublisherOwnsSubscription | subscriptionInitialState);
                return(await SubscribeAsync(subscription : subscription).ConfigureAwait(false));
            }
            catch (Exception exception) {
                DisposeMany(exception, subscriber, subscription);
                throw;
            }
        }
示例#6
0
 public LocalSubscription(ILocalPublisher publisher, ILocalSubscriber subscriber, LocalSubscriptionStates initialState)
 {
     publisher.EnsureNotNull(nameof(publisher));
     subscriber.EnsureNotNull(nameof(subscriber));
     P_EnsureInitialStateValid(initialState);
     //
     _state = (int)initialState;
     unchecked {
         _hashCode = (publisher.GetHashCode() * 17) ^ (subscriber.GetHashCode() * 23);
     }
     _publisher         = publisher;
     _publisherInfoText = publisher.ToString();
     _publisherAsIPublicationFilterListener = publisher as ILocalPublicationFilterListener;
     _subscriber         = subscriber;
     _subscriberInfoText = subscriber.ToString();
     _subscriberAsIPublicationFilterListener = subscriber as ILocalPublicationFilterListener;
     _activateControl = new RunControl <LocalSubscription>(options: RunControlOptions.SingleStart, component: this, attemptState: null, beforeStart: null, start: P_DoActivationAsync, stop: P_DoDeactivationAsync);
     //
     publisher.BeforeDispose  += P_EH_PublisherOrSubscriber_BeforeDispose;
     subscriber.BeforeDispose += P_EH_PublisherOrSubscriber_BeforeDispose;
 }
示例#7
0
 LocalSubscriptionStates P_ChangeStateXor(LocalSubscriptionStates state)
 => (LocalSubscriptionStates)InterlockedUtilities.Xor(ref _state, (int)state);