コード例 #1
0
 public MenuItem(string i_NameOfMenu, IDoAction i_DoAction)
 {
     m_ListMenuItems = new List <MenuItem>();
     m_NameOfMenu    = i_NameOfMenu;
     m_Father        = null;
     m_DoAction      = i_DoAction;
 }
コード例 #2
0
ファイル: JumpSlideFSM.cs プロジェクト: AUEzzat/Overoll
 // Change to a new state after concluding the current one
 bool ChangeState(IDoAction nextState)
 {
     if (actionsDic[currentState].Contains(nextState))
     {
         currentState.OnStateExit(mAnimator);
         nextState.OnStateEnter(mAnimator);
         currentState = nextState;
         return(true);
     }
     return(false);
 }
コード例 #3
0
ファイル: JumpSlideFSM.cs プロジェクト: AUEzzat/Overoll
    public virtual void ScriptReset()
    {
        mCollider.center = colliderPosition;
        mCollider.size   = colliderSize;
        Vector3 pos = transform.position;

        pos.y = yPos;
        transform.position = pos;

        actionQueue  = new Queue <IDoAction>();
        currentState = runState;
    }
コード例 #4
0
ファイル: JumpSlideFSM.cs プロジェクト: AUEzzat/Overoll
    public void FixedUpdate(float fixedDeltaTime)
    {
        //Debug.Log("List: " + string.Join(", ", actionQueue));

        bool executing = currentState.OnStateExecution(transform, fixedDeltaTime);

        if (!executing)
        {
            IDoAction nextState = actionQueue.Dequeue();
            ChangeState(nextState);
        }
    }
コード例 #5
0
        /// <summary>
        /// Gets an instance of <see cref="IDoAction{TInputs, TResult}"/> from the container.
        /// </summary>
        /// <typeparam name="TInputs">The type of input defined by the action.</typeparam>
        /// <typeparam name="TResult">The result type defined by the action.</typeparam>
        /// <param name="actionKey">A unique key used to identify a specific action.</param>
        /// <returns></returns>
        public virtual Task <IDoAction <TInputs, TResult> > GetAsync <TInputs, TResult>(string actionKey)
        {
            IDoAction <TInputs, TResult> returnValue = null;

            //
            // Get the decorator type being requested.
            //
            Type targetType = typeof(IDoAction <TInputs, TResult>);

            this.Logger.LogDebug($"Finding an IDoAction of type '{targetType.Name}' and action key of '{actionKey}'.");

            //
            // Get all decorators from the container of
            // type IDecorator<TItem>.
            //
            IEnumerable <IDoAction> items = this.ServiceProvider.GetRequiredService <IEnumerable <IDoAction> >();
            IDoAction doAction            = items.Where(t => t.ActionKey == actionKey).FirstOrDefault();

            //
            // Within the list, find the target decorator.
            //
            if (doAction != null)
            {
                if (targetType.IsInstanceOfType(doAction))
                {
                    this.Logger.LogDebug($"IDecorator of type '{targetType.Name}' and action key of '{actionKey}' was found.");
                    returnValue = (IDoAction <TInputs, TResult>)doAction;
                }
                else
                {
                    this.Logger.LogError($"IDecorator of type '{targetType.Name}' and action key of '{actionKey}' was NOT found. Throwing exception...");
                    throw new DoActionNotFoundException(typeof(TInputs), typeof(TResult), actionKey);
                }
            }
            else
            {
                this.Logger.LogError($"IDecorator of type '{targetType.Name}' and action key of '{actionKey}' was NOT found. Throwing exception...");
                throw new DoActionNotFoundException(typeof(TInputs), typeof(TResult), actionKey);
            }

            return(Task.FromResult(returnValue));
        }
コード例 #6
0
        /// <summary>
        /// Executes the controller method without the given parameter.
        /// </summary>
        /// <typeparam name="TInputs"></typeparam>
        /// <typeparam name="TResult">The type of object returned by the action.</typeparam>
        /// <param name="actionKey">The name of the action retrieved from the container.</param>
        /// <param name="inputs">The input parameter for the action.</param>
        /// <returns>An ActionResult encapsulating the expected return type.</returns>
        protected virtual async Task <ActionResult <TResult> > Do <TInputs, TResult>(TInputs inputs, [CallerMemberName] string actionKey = null)
        {
            ActionResult <TResult> returnValue = default;

            try
            {
                //
                // Log the method call.
                //
                this.LogMethodCall();

                //
                // Get the IDoAction
                //
                IDoAction <TInputs, TResult> action = null;

                try
                {
                    this.Logger.LogDebug($"Retrieving controller method action '{actionKey}'.");
                    action = await this.DoActionFactory.GetAsync <TInputs, TResult>(actionKey);

                    this.Logger.LogDebug($"Controller method action '{actionKey}' was successfully retrieved.");
                }
                catch (DoActionNotFoundException)
                {
                    //
                    // An implementation of this method was not found.
                    //
                    this.Logger.LogWarning($"Controller method action '{actionKey}' was not found in the container.");
                    returnValue = this.StatusCode(StatusCodes.Status501NotImplemented, this.OnCreateProblemDetail(DoActionResult.NotImplemented($"The method has not been implemented. This could be a configuration error or the service is still under development.")));
                    action      = null;
                }
                catch (Exception ex)
                {
                    //
                    // An implementation of this method was not found.
                    //
                    this.Logger.LogError(ex, $"Exception while retrieving do action.");
                    returnValue = this.StatusCode(StatusCodes.Status500InternalServerError, this.OnCreateProblemDetail(DoActionResult.InternalServerError("An unknown internal server error occurred.")));
                    action      = null;
                }

                if (action != null)
                {
                    using (ITryDisposable <IDoAction <TInputs, TResult> > disposable = new TryDisposable <IDoAction <TInputs, TResult> >(action))
                    {
                        //
                        // Perform the extra model validation step.
                        //
                        (bool modelResult, string errorMessage) = await action.ValidateModel(inputs);

                        if (modelResult)
                        {
                            //
                            // Execute the action.
                            //
                            this.Logger.LogDebug($"Executing controller method action '{actionKey}.TakeActionAsync()'.");
                            IControllerActionResult <TResult> result = await action.ExecuteActionAsync(inputs);

                            if (result.ResultDetails.Status == StatusCodes.Status200OK)
                            {
                                this.Logger.LogDebug($"Controller method action '{actionKey}.TakeActionAsync()' completed successfully.");
                                returnValue = this.Ok(result.Result);
                            }
                            else
                            {
                                this.Logger.LogDebug($"Controller method action '{actionKey}.TakeActionAsync()' completed with HTTP Status Code of {result.ResultDetails.Status}.");
                                this.Logger.LogDebug($"The action returned: '{result.ResultDetails.Detail}'.");

                                //
                                // Check if the instance is null.
                                //
                                if (result.ResultDetails.Instance == null)
                                {
                                    //
                                    // Add the request path.
                                    //
                                    result.ResultDetails.Instance = HttpContext.Request.Path;
                                }

                                returnValue = this.StatusCode(result.ResultDetails.Status.Value, this.OnCreateProblemDetail(result.ResultDetails));
                            }
                        }
                        else
                        {
                            //
                            // Model validation failed. Return a 400
                            //
                            ProblemDetails problemDetails = DoActionResult.BadRequest(errorMessage);
                            returnValue = this.BadRequest(this.OnCreateProblemDetail(problemDetails));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                //
                // Internal error.
                //
                this.Logger.LogError(ex, nameof(Do));
                returnValue = this.StatusCode(StatusCodes.Status500InternalServerError);
            }

            return(returnValue);
        }