Beispiel #1
0
        public override IActionResult OnInvoke(IActionRequest <IContractProcessingPayload> request)
        {
            var contractPayload        = request.Payload as IContractProcessingPayload;
            var currentProcessingState = request.Context.ProcessingState as ContractProcessingState;

            var newProcessingState = currentProcessingState;

            if (!newProcessingState.ContractState.IsMaterialChange.HasValue)
            {
                var isAvailabilityChange = (contractPayload.Contract?.GroupHeader?.HoldFromApproval ?? false) !=
                                           (contractPayload.PreviousVersion?.GroupHeader?.HoldFromApproval ?? false);

                //TODO - Check for material change;
                var isMaterialChange = false;

                //update the external state
                newProcessingState = newProcessingState.Clone(s => s.SetIsMaterialChange(isAvailabilityChange || isMaterialChange)
                                                              .And()
                                                              .SetIsAvailable(null));
            }

            //update the public state
            newProcessingState = newProcessingState.Clone(s => s.SetCurrentFromIsMaterialChange());

            return(new SuccessStateChange(request.Payload, newProcessingState));
        }
Beispiel #2
0
 private void DeletePendingRequest(IActionRequest request)
 {
     if (!(request is null))
     {
         _requirements.RequestPersistence.DeletePendingRequest(request.RequestId);
     }
 }
Beispiel #3
0
        public void OnReceiveRequest(IActionRequest request)
        {
            //TODO add error handling and logging

            var actionType = _requirements.PipelineConfiguration.ActionTypes[request.ActionName];
            var action     = _allowedActions[request.ActionName];

            if (action is null)
            {
                action = _requirements.PipelineConfiguration.CreateAction(actionType);
                _allowedActions[request.ActionName] = action;
            }

            try
            {
                var stateChange = action.Invoke(request);
                var response    = new ActionResponse(request, stateChange);

                Context.Parent.Tell(response);
            }
            catch (Exception ex)
            {
                _log.Error($"Failed to process action '{request.ActionName}'. RequestName: {request.RequestName}, RequestId: {request.RequestId}), Details: {ex.Message}");
            }
        }
Beispiel #4
0
        public override IActionResult OnInvoke(IActionRequest <IContractProcessingPayload> request)
        {
            var contractPayload        = request.Payload as IContractProcessingPayload;
            var currentProcessingState = request.Context.ProcessingState as ContractProcessingState;

            var newProcessingState = currentProcessingState;

            if (!newProcessingState.ContractState.IsPendingApproval.GetValueOrDefault())
            {
                var contractTracking = new ContractTrackingReference(contractPayload.TrackingReference);

                if (_persistence.CreateContractTrackingReference(contractTracking).IsSaved)
                {
                    //update the external state
                    newProcessingState = currentProcessingState.Clone(s => s.SetIsPendingApproval(true));
                }
            }

            if (newProcessingState.ContractState.IsPendingApproval.GetValueOrDefault())
            {
                //update the public state
                newProcessingState = newProcessingState.Clone(s => s.SetCurrentFromIsPendingApproval()
                                                              .And()
                                                              .SetContractStatus(ContractStatus.InFlight));
            }

            return(new SuccessStateChange(request.Payload, newProcessingState));
        }
Beispiel #5
0
 public ActionRequestContext(
     IActionProcessorUser user,
     IActorRef originatingActor,
     IActionRequest originatingRequest)
     : this(user, originatingActor, originatingRequest, null, null)
 {
 }
Beispiel #6
0
        private bool CanHandleRequest(IActionRequest request)
        {
            //TODO add error handling and logging
            var canHandle = _allowedActions.ContainsKey(request.ActionName);

            return(canHandle);
        }
Beispiel #7
0
 private void SavePendingRequest(IActionRequest request)
 {
     if (!request.IsRecoveryRequest)
     {
         _requirements.RequestPersistence.SavePendingRequest(request);
     }
 }
        public override IActionResult OnInvoke(IActionRequest <IContractProcessingPayload> request)
        {
            var currentProcessingState = request.Context.ProcessingState as ContractProcessingState;

            //TODO
            return(new SuccessStateChange(request.Payload, currentProcessingState));
        }
        public override IActionResult OnInvoke(IActionRequest <IContractProcessingPayload> request)
        {
            var contractProcessingState = request.Context.ProcessingState as ContractProcessingState;

            var newProcessingState = contractProcessingState.Clone(s => s.SetCurrentFromIsPendingResubmit());

            return(new SuccessStateChange(request.Payload, newProcessingState));
        }
 private void SetRejected(IActionRequest request, string message)
 {
     if (!(request is null))
     {
         var context  = request.Context;
         var response = UnhandledResponse.New(request, message);
         Sender.Tell(response);
         context.CompletionSource.TrySetResult(response);
     }
 }
 public void SetCurrentState(IActionRequest request, IActionProcessingState newState)
 {
     if (_stateStore.ContainsKey(request.Payload.TrackingReference))
     {
         _stateStore[request.Payload.TrackingReference] = newState;
     }
     else
     {
         _stateStore.Add(request.Payload.TrackingReference, newState);
     }
 }
 public IActionProcessingState GetCurrentState(IActionRequest request)
 {
     if (_stateStore.ContainsKey(request.Payload.TrackingReference))
     {
         return(_stateStore[request.Payload.TrackingReference]);
     }
     else
     {
         return(null);
     }
 }
Beispiel #13
0
        public override IActionResult OnInvoke(IActionRequest <IntegerPayload> request)
        {
            var payload     = request.Payload as IntegerPayload;
            var newPayload  = IntegerPayload.New(payload.Value + 1);
            var newState    = TestState.New(newPayload.Value > 0 ? "Positive" : newPayload.Value < 0 ? "Negative" : "Zero");
            var stateChange = new StateChangeResult(newPayload, newState, string.Empty);

            Injected.SavePayload(newPayload);

            return(stateChange);
        }
 public override bool CanInvoke(IActionRequest <TPayload> request)
 {
     if (_canInvoke is null)
     {
         return(base.CanInvoke(request));
     }
     else
     {
         return(_canInvoke(request));
     }
 }
Beispiel #15
0
        public IActionProcessingStateChange InvokeChangeState(IActionRequest request)
        {
            var typedRequest = request as TRequest;

            if (typedRequest is null)
            {
                throw new ArgumentException($"The request is not compatible with the requred requet type: '{typeof(TRequest).Name}'");
            }

            return(OnInvoke(request as TRequest));
        }
Beispiel #16
0
        private bool UpdateState(IActionRequest request, IActionResponse response)
        {
            var stateChange = response.Result as IActionProcessingStateChange;
            var newState    = stateChange.NewState;

            if (!(request is null) &&
                request is IRequestWithState &&
                request.Context.ProcessingState != newState)
            {
                _stateManager.Tell(UpdateStateRequest.New(request, response));
                return(true);
            }
Beispiel #17
0
 public ActionRequestContext(
     IActionProcessorUser user,
     IActorRef originatingActor,
     IActionRequest originatingRequest,
     IActionProcessingState currentState,
     TaskCompletionSource <IResponse> completionSource)
 {
     User = user;
     OriginatingRequest = originatingRequest;
     OriginatingActor   = originatingActor;
     ProcessingState    = currentState;
     CompletionSource   = completionSource;
 }
 private bool ValidateAction(IActionRequest request)
 {
     if (!(_requirements.PipelineConfiguration.ActionTypes.ContainsKey(request.ActionName)))
     {
         SetRejected(request, $"Request Rejected. The requested action '{request.ActionName}' is not valid.");
         return(false);
     }
     else if (!typeof(IExternalAction).IsAssignableFrom(_requirements.PipelineConfiguration.ActionTypes[request.ActionName]))
     {
         SetRejected(request, $"Request Rejected. The requested action '{request.ActionName}' is not accessible.");
         return(false);
     }
     return(true);
 }
        public void OnProcessAction(IActionRequest request)
        {
            //TODO add error handling and logging

            if (_state == ActionProcessorState.Started)
            {
                var canProcess = request.Context.ProcessingState is null?
                                 ValidateAction(request) :
                                     ValidateStateAndAction(request);

                if (canProcess)
                {
                    _actionPipeline.Tell(request);
                }
            }
        }
Beispiel #20
0
        private bool CanHandleRequest(IActionRequest request)
        {
            //TODO add error handling and logging

            var canHandle = _requirements.PipelineConfiguration.ActionTypes.ContainsKey(request.ActionName);

            if (canHandle)
            {
                if (!typeof(IStateCheckAction).IsAssignableFrom(request.RequestType) &&
                    !(request.Context.ProcessingState is null))
                {
                    canHandle = canHandle && _requirements.PipelineConfiguration.AllowedStates.ContainsKey(request.Context.ProcessingState.CurrentState);
                }
            }

            return(canHandle);
        }
Beispiel #21
0
        public override IActionResult OnInvoke(IActionRequest <WorkflowResponseProcessingPayload> request)
        {
            var workflowResponsePayload = request.Payload as WorkflowResponseProcessingPayload;
            var workflowAction          = workflowResponsePayload.WorkflowResponse;

            var currentProcessingState = request.Context.ProcessingState as ContractProcessingState;
            var newProcessingState     = currentProcessingState;

            if (newProcessingState.ContractState.IsPendingApproval.GetValueOrDefault())
            {
                var trackingReference = workflowResponsePayload.TrackingReference;
                var contractTracking  = _persistence.GetContractTrackingReference(trackingReference);
                var actionTracking    = contractTracking.Actions.SingleOrDefault(a => a.ActionReference == workflowAction.ActionReference);

                actionTracking.State = workflowAction.ActionState.ToActionTrackingState();

                var newContractStatus = contractTracking.Actions.Any(a => a.State == ActionTrackingState.Rejected) ? ContractStatus.Rejected :
                                        contractTracking.Actions.All(a => a.State == ActionTrackingState.Approved) ? ContractStatus.Approved :
                                        ContractStatus.InFlight;

                if (newContractStatus == ContractStatus.Approved || newContractStatus == ContractStatus.Rejected)
                {
                    contractTracking.State = ContractTrackingState.ActionsComplete;
                }
                else
                {
                    contractTracking.State = ContractTrackingState.ActionsPending;
                }

                var result = _persistence.UpdateContractTrackingReference(contractTracking);
                if (result.IsSaved)
                {
                    if (contractTracking.State != ContractTrackingState.ActionsPending)
                    {
                        //update the external state
                        newProcessingState = newProcessingState.Clone(s => s.SetIsPendingApproval(false)
                                                                      .And()
                                                                      .SetContractStatus(newContractStatus));
                    }
                }

                newProcessingState = newProcessingState.Clone(s => s.SetCurrentFromIsPendingApproval());
            }

            return(new SuccessStateChange(request.Payload, newProcessingState));
        }
Beispiel #22
0
        public override IActionResult OnInvoke(IActionRequest <IContractProcessingPayload> request)
        {
            var contractPayload         = request.Payload as IContractProcessingPayload;
            var contractProcessingState = request.Context.ProcessingState as ContractProcessingState;

            var newProcessingState = contractProcessingState;

            if (!newProcessingState.ContractState.IsNew.HasValue)
            {
                //TODO - Check if new;
                var isNew = false;
                newProcessingState = newProcessingState.Clone(s => s.SetIsNew(isNew));
            }

            newProcessingState = newProcessingState.Clone(s => s.SetCurrentFromIsNew());

            return(new SuccessStateChange(request.Payload, newProcessingState));
        }
Beispiel #23
0
        public override IActionResult OnInvoke(IActionRequest <IContractProcessingPayload> request)
        {
            var contractPayload        = request.Payload as IContractProcessingPayload;
            var currentProcessingState = request.Context.ProcessingState as ContractProcessingState;

            var newProcessingState = currentProcessingState;

            if (newProcessingState.ContractState.IsPendingApproval.GetValueOrDefault())
            {
                //update the external state
                newProcessingState = currentProcessingState.Clone(s => s.SetIsPendingCancel(true));
            }

            //update the public state
            newProcessingState = newProcessingState.Clone(s => s.SetCurrentFromIsPendingCancel());

            return(new SuccessStateChange(request.Payload, newProcessingState));
        }
        private bool ValidateStateAndAction(IActionRequest request)
        {
            var allowedStates = _requirements.PipelineConfiguration.AllowedStates;
            var currentState  = request.Context.ProcessingState?.CurrentState;

            if (!allowedStates.ContainsKey(currentState) || !typeof(IExternalState).IsAssignableFrom(allowedStates[currentState].GetType()))
            {
                SetRejected(request, $"Request Rejected. The specified current state '{request.Context.ProcessingState.CurrentState}' is not a known state.");
                return(false);
            }

            if (!allowedStates[currentState].AllowedActions.ContainsKey(request.ActionName))
            {
                SetRejected(request, $"Request Rejected. The requested action '{request.ActionName}' is not valid for the current state '{request.Context.ProcessingState.CurrentState}'.");
                return(false);
            }

            return(ValidateAction(request));
        }
Beispiel #25
0
        public override IActionResult OnInvoke(IActionRequest <IContractProcessingPayload> request)
        {
            var contractPayload        = request.Payload as IContractProcessingPayload;
            var currentProcessingState = request.Context.ProcessingState as ContractProcessingState;

            var newProcessingState = currentProcessingState;

            if (newProcessingState.ContractState.IsAvailable.GetValueOrDefault())
            {
                //update the external state
                newProcessingState = newProcessingState.Clone(s => s.SetIsAvailable(false));
            }

            //update the public state
            newProcessingState = newProcessingState.Clone(s => s.SetCurrentFromIsAvailable()
                                                          .And()
                                                          .SetContractStatus(ContractStatus.HoldFromApproval));

            return(new SuccessStateChange(request.Payload, newProcessingState));
        }
Beispiel #26
0
        public override IActionResult OnInvoke(IActionRequest <IContractProcessingPayload> request)
        {
            var contractPayload        = request.Payload as IContractProcessingPayload;
            var currentProcessingState = request.Context.ProcessingState as ContractProcessingState;

            var newProcessingState = currentProcessingState;

            if (!newProcessingState.ContractState.IsValid.HasValue)
            {
                var result = _validation.ValidateContract(contractPayload.Contract);

                //update the external state
                newProcessingState = currentProcessingState.Clone(s => s.SetIsValid(result.IsValid));
            }

            //update the public state
            newProcessingState = newProcessingState.Clone(s => s.SetCurrentFromIsValid());

            return(new SuccessStateChange(request.Payload, newProcessingState));
        }
Beispiel #27
0
        public override IActionResult OnInvoke(IActionRequest <IContractProcessingPayload> request)
        {
            var contractPayload        = request.Payload as IContractProcessingPayload;
            var currentProcessingState = request.Context.ProcessingState as ContractProcessingState;
            var currentContractState   = currentProcessingState.ContractState;

            var newProcessingState = currentProcessingState;

            if (!currentContractState.IsAvailable.HasValue)
            {
                var onHold = contractPayload.Contract.GroupHeader.HoldFromApproval;

                //update the external state
                newProcessingState = newProcessingState.Clone(s => s.SetIsAvailable(!onHold));
            }

            //update the public state
            newProcessingState = newProcessingState.Clone(s => s.SetCurrentFromIsAvailable());

            return(new SuccessStateChange(request.Payload, newProcessingState));
        }
        public override IActionResult OnInvoke(IActionRequest <RuleResponseProcessingPayload> request)
        {
            var ruleResponsePayload    = request.Payload as RuleResponseProcessingPayload;
            var currentProcessingState = request.Context.ProcessingState as ContractProcessingState;

            var newProcessingState = currentProcessingState;

            if (newProcessingState.ContractState.IsPendingApproval.GetValueOrDefault())
            {
                var contractTracking = _persistence.GetContractTrackingReference(ruleResponsePayload.TrackingReference);
                if (!(contractTracking is null))
                {
                    contractTracking.State   = ruleResponsePayload.RuleResponse.TriggeredActions.Count == 0 ? ContractTrackingState.NoActions : ContractTrackingState.ActionsPending;
                    contractTracking.Actions = ruleResponsePayload.RuleResponse.TriggeredActions.Select(ta => new ActionTrackingReference
                    {
                        State           = ActionTrackingState.Pending,
                        ActionReference = ta.ActionReference
                    })
                                               .ToList();

                    var result = _persistence.UpdateContractTrackingReference(contractTracking);
                    if (result.IsSaved)
                    {
                        if (ruleResponsePayload.RuleResponse.TriggeredActions.Count == 0)
                        {
                            //update the external state
                            newProcessingState = newProcessingState.Clone(s => s.SetIsPendingApproval(false)
                                                                          .And()
                                                                          .SetContractStatus(ContractStatus.Approved));
                        }
                    }

                    newProcessingState = newProcessingState.Clone(s => s.SetCurrentFromIsPendingApproval());
                }
            }

            return(new SuccessStateChange(request.Payload, newProcessingState));
        }
        public override bool Equals(IActionRequest other)
        {
            if (!base.Equals(other))
            {
                return(false);
            }

            var otherThisType = (WateringCanRefillRequest)other;

            if (this.ItemsToConsumeForRefill == null &&
                otherThisType.ItemsToConsumeForRefill == null)
            {
                return(true);
            }

            if (this.ItemsToConsumeForRefill != null &&
                otherThisType.ItemsToConsumeForRefill != null)
            {
                return(this.ItemsToConsumeForRefill
                       .SequenceEqual(otherThisType.ItemsToConsumeForRefill));
            }

            return(false);
        }
Beispiel #30
0
        public override IActionResult OnInvoke(IActionRequest <IContractProcessingPayload> request)
        {
            var cancelResult = base.OnInvoke(request);

            if (!(cancelResult is SuccessStateChange))
            {
                return(cancelResult);
            }

            var newProcessingState = (cancelResult as SuccessStateChange).NewState as ContractProcessingState;

            if (!newProcessingState.ContractState.IsPendingResubmit.GetValueOrDefault())
            {
                //update the external state
                newProcessingState = newProcessingState.Clone(s => s.SetIsPendingResubmit(true));
            }

            //update the public state
            newProcessingState = newProcessingState.Clone(s => s.SetCurrentFromIsPendingResubmit()
                                                          .And()
                                                          .SetContractStatus(ContractStatus.InFlight));

            return(new SuccessStateChange(request.Payload, newProcessingState));
        }