예제 #1
0
        protected virtual ExecuteResult OnExecute(IExecuteContext executionContext, TraceInfo traceInfo)
        {
            _ = executionContext ?? throw new ArgumentNullException(nameof(executionContext));
            _ = traceInfo ?? throw new ArgumentNullException(nameof(traceInfo));
            IActionContext actionContext = null;

            try
            {
                //1 resolve action name
                var actionName = this.OnResolveActionName(executionContext.ActionFullName);
                traceInfo.ActionName = actionName;
                //2 get runtime info
                var runtimeInfo = this.OnGetActionRuntime(actionName);
                traceInfo.ActionRuntime = runtimeInfo;
                //3 prepare package
                this.OnPrepareAction(actionName, runtimeInfo);
                //4 get meta info
                var metaInfo = this.OnGetActionMeta(actionName);
                traceInfo.ActionMeta = metaInfo;
                //5 resolve action factory
                var actionFactory = this.OnResolveActionFactory(metaInfo);
                //6 create action context
                actionContext = this.OnCreateActionContext(executionContext, actionName, runtimeInfo, metaInfo);

                //7 check premission
                this.OnCheckPremission(actionContext);
                //8 valid inputs
                this.OnValidInputs(actionContext);
                //9 create action instance
                var actionInstance = this.OnCreateActionInstance(actionFactory, actionContext);
                //10 run action
                var result = OnRunAction(actionInstance, executionContext, actionContext);
                //11 valid output
                this.OnValidOutput(actionContext, result);
                return(ExecuteResult.FromResult(result, actionContext.Logger.ToString()));
            }
            catch (Exception ex)
            {
                return(ExecuteResult.FromError(ex, actionContext?.Logger?.ToString()));
            }
        }