コード例 #1
0
        /// <summary>
        /// Simulates the processing of a restock request by advancing the processing status each time this method is invoked
        /// until it reaches the complete stage.
        /// </summary>
        /// <returns></returns>
        internal async Task RestockPipeline()
        {
            RestockRequestActorState state = await this.StateManager.GetStateAsync <RestockRequestActorState>(ActorStatePropertyName);

            ActorEventSource.Current.ActorMessage(this, "RestockRequestActor: {0}: Pipeline change reminder", state);

            switch (state.Status)
            {
            case RestockRequestStatus.Accepted:

                // Change to next step and let it "execute" until the reminder fires again
                state.Status = RestockRequestStatus.Manufacturing;
                break;

            case RestockRequestStatus.Manufacturing:

                // Changet the step to completed to indicate the "processing" is complete.
                state.Status = RestockRequestStatus.Completed;

                // Raise the event to let interested parties (RestockRequestManager) know that the restock is complete
                this.SignalRequestStatusChange(state);

                // Done, so unregister the reminder
                await this.UnregisterRestockPipelineChangeReminderAsync();

                break;

            default:
                throw new InvalidOperationException(string.Format("{0}: remainder received in invalid status", state));
            }

            await this.StateManager.SetStateAsync <RestockRequestActorState>(ActorStatePropertyName, state);

            return;
        }
コード例 #2
0
        /// <summary>
        /// Accepts a restock request and changes the Actor's state accordingly. The request is processed
        /// async and the caller will be notified when the processing is done.
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public async Task AddRestockRequestAsync(RestockRequest request)
        {
            RestockRequestActorState state = await this.StateManager.GetStateAsync <RestockRequestActorState>(ActorStatePropertyName);

            if (state.IsStarted()) //Don't accept a request that is already started
            {
                ActorEventSource.Current.Message(string.Format("RestockRequestActor: {0}: Can't accept restock request in this state", state));
                throw new InvalidOperationException(string.Format("{0}: Can't accept restock request in this state", state));
            }

            // Accept the request
            ActorEventSource.Current.ActorMessage(this, "RestockRequestActor: Accept update quantity request {0}", request);

            state.Status  = RestockRequestStatus.Accepted;
            state.Request = request;

            await this.StateManager.SetStateAsync <RestockRequestActorState>(ActorStatePropertyName, state);

            // Start a reminder to go through the processing pipeline.
            // A reminder keeps the actor from being garbage collected due to lack of use,
            // which works better than a timer in this case.
            await this.RegisterReminderAsync(
                RestockRequestReminderNames.RestockPipelineChangeReminderName,
                null,
                PipelineStageVerificationDelay,
                PipelineStageProcessingDuration);

            return;
        }
コード例 #3
0
        private void SignalRequestStatusChange(RestockRequestActorState state)
        {
            ActorEventSource.Current.ActorMessage(this, "RestockRequestActor: {0}: Raise event for state change", state);

            IRestockRequestEvents events = this.GetEvent <IRestockRequestEvents>();

            events.RestockRequestCompleted(this.Id, state.Request);
        }
        private void SignalRequestStatusChange(RestockRequestActorState state)
        {
            ActorEventSource.Current.ActorMessage(this, "RestockRequestActor: {0}: Raise event for state change", state);

            IRestockRequestEvents events = this.GetEvent<IRestockRequestEvents>();
            events.RestockRequestCompleted(this.Id, state.Request);
        }