Ejemplo n.º 1
0
        private async Task <ResponseBase> ExecuteAction(ActionHandlerBase actionHandler, ExecuteCommand command,
                                                        MethodInfo actionMethod, ExecutionContext executionContext)
        {
            logger.LogDebug("Execution of {actionHandlerName}.{actionName} started. ConnectionId: {connectionId}, ExecutionId: {executionId}", actionMethod.DeclaringType?.FullName,
                            actionMethod.Name, Connection.Id, executionContext.Id);

            object result = actionMethod.Invoke(actionHandler, GetParameters(actionMethod, command));

            if (result != null)
            {
                if (ActionHelper.HandleAsyncEnumerable(result, actionHandler.AsyncResult))
                {
                    result = null;
                }
                else
                {
                    result = await ActionHelper.HandleAsyncResult(result);
                }
            }

            logger.LogInformation("Executed {actionHandlerName}.{actionName}. ConnectionId: {connectionId}, ExecutionId: {executionId}", actionMethod.DeclaringType?.FullName, actionMethod.Name, Connection.Id, executionContext.Id);

            return(new ExecuteResponse()
            {
                ReferenceId = command.ReferenceId,
                Result = result
            });
        }
Ejemplo n.º 2
0
        private async Task <ResponseBase> ExecuteAction(ActionHandlerBase actionHandler, ExecuteCommand command,
                                                        MethodInfo actionMethod)
        {
            logger.LogInformation("Execution of " + actionMethod.DeclaringType?.FullName + "." + actionMethod.Name + " started");

            object result = actionMethod.Invoke(actionHandler, GetParameters(actionMethod, command));

            if (result != null)
            {
                if (ActionHelper.HandleAsyncEnumerable(result, actionHandler.AsyncResult))
                {
                    result = null;
                }
                else
                {
                    result = await ActionHelper.HandleAsyncResult(result);
                }
            }

            logger.LogInformation("Executed " + actionMethod.DeclaringType?.FullName + "." + actionMethod.Name);

            return(new ExecuteResponse()
            {
                ReferenceId = command.ReferenceId,
                Result = result
            });
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 处理
        /// </summary>
        public void Request(CRANE_ACTION_RECORD_X record)
        {
            try
            {
                HandlerProvider   handlerProvider = new HandlerProvider();
                ActionHandlerBase handler         = handlerProvider.GetHandler(record);
                if (handler != null)
                {
                    VisitorProvider visitorProvider = new VisitorProvider();
                    VisitorBase     visitor         = visitorProvider.GetVisitor(record);
                    handler.Handle(visitor);
                }
            }
            catch (Exception e)
            {
                log.WriteLog(E_ProcessLogType.Error, "物重处理异常。" + e.Message);
            }

            try
            {
                record.DEAL_SYMBOL = 2;
                CalculateWeightService.Instance.Update_CRANE_ACTION_RECORD_X(record);
            }
            catch (Exception e)
            {
                log.WriteLog(E_ProcessLogType.Error, "更新动作记录异常。" + e.Message);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 空包起吊
        /// </summary>
        /// <param name="record"></param>
        public override void EmptyHoist(ActionHandlerBase handler)
        {
            PosManager.UpdatePos_CCM_Hoist(Wst.NUM, handler.Record.CRA_ID.CRA_NUM, handler.Record.CRA_ID.CRA_NUM);
            PosManager.EndPos(handler.Record.CRA_ID.CRA_NUM, handler.Record.CRA_ID.CRA_NUM);

            InsertCCMOutWeightRecord(handler.Record);
        }
        /// <summary>
        /// 获取动作处理者
        /// </summary>
        /// <param name="record"></param>
        /// <returns></returns>
        public ActionHandlerBase GetHandler(CRANE_ACTION_RECORD_X record)
        {
            ActionHandlerBase handler = null;

            switch (record.ACTION_SYMBOL)
            {
            case 1:    //1空包起吊
                handler = new EmptyHoistHandler();
                break;

            case 2:    //2重包起吊
                handler = new FullHoistHandler();
                break;

            case 3:    //3空包放吊
                handler = new EmptyDropHandler();
                break;

            case 4:    //4重包放吊
                handler = new FullDropHandler();
                break;

            case 5:    //5兑物
                handler = new PourHandler();
                break;
            }
            if (handler != null)
            {
                handler.Record = record;
            }
            return(handler);
        }
Ejemplo n.º 6
0
        public static bool CanExecuteAction(this MethodInfo methodInfo, HttpInformation httpInformation,
                                            ActionHandlerBase actionHandler, IServiceProvider serviceProvider)
        {
            List <ActionAuthAttribute> authAttributes = methodInfo.GetCustomAttributes <ActionAuthAttribute>(false).ToList();

            return(HandleAuthAttributes(methodInfo.DeclaringType, authAttributes, httpInformation,
                                        SapphireAuthResource.OperationTypeEnum.Execute, actionHandler, serviceProvider));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 重包起吊
        /// </summary>
        /// <param name="record"></param>
        public override void FullHoist(ActionHandlerBase handler)
        {
            PosManager.UpdatePos(Wst.NUM, handler.Record.CRA_ID.CRA_NUM, handler.Record.CRA_ID.CRA_NUM);

            string ladle = LadleManager.MatchLadle(Wst.NUM, handler.Record.CRA_ID.CRA_NUM);

            InsertBofOutWeightRecord(handler.Record, ladle);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 获取数据类
        /// </summary>
        /// <typeparam name="TModel"></typeparam>
        /// <param name="handler"></param>
        /// <param name="maps"></param>
        /// <returns></returns>
        public static TModel GetModel <TModel>(
            this ActionHandlerBase <ActionEnum, GoalEnum> handler,
            IMaps <ActionEnum, GoalEnum> maps
            )
            where TModel : class, IModel
        {
            var mgr = maps.GetGameData <GameDataKeyEnum, AIModelMgr>(GameDataKeyEnum.AI_MODEL_MANAGER);

            return(mgr.GetModel <TModel>(handler.Label));
        }
Ejemplo n.º 9
0
 /// <summary>
 /// 兑物
 /// </summary>
 /// <param name="record"></param>
 public override void Pour(ActionHandlerBase handler)
 {
     if (handler.Record.WEIGHT < 40000 && handler.Record.WEIGHT > 5000)//废钢兑物
     {
         InsertScrapWeightRecord(handler.Record);
     }
     else if (handler.Record.WEIGHT < 200000 && handler.Record.WEIGHT > 40000)//铁水兑物
     {
         InsertHmlWeightRecord(handler.Record);
     }
 }
Ejemplo n.º 10
0
        private async Task <ResponseBase> GetActionDetails(ExecuteCommand command, HttpInformation context)
        {
            string[] actionParts = command?.Action.Split('.');

            if (actionParts == null || actionParts.Length != 2)
            {
                return(command.CreateExceptionResponse <ExecuteResponse>(
                           new FormatException("Wrong format of action name.")));
            }

            string actionHandlerName = actionParts[0];
            string actionName        = actionParts[1];

            Type actionHandlerType = actionMapper.GetHandler(actionHandlerName);

            if (actionHandlerType != null)
            {
                MethodInfo actionMethod = actionMapper.GetAction(actionName, actionHandlerType);

                if (actionMethod != null)
                {
                    ActionHandlerBase actionHandler = (ActionHandlerBase)serviceProvider.GetService(actionHandlerType);

                    if (actionHandler != null)
                    {
                        actionHandler.connection     = Connection;
                        actionHandler.executeCommand = command;

                        if (!actionHandlerType.CanExecuteAction(context, actionHandler, serviceProvider))
                        {
                            return(command.CreateExceptionResponse <ExecuteResponse>(
                                       new UnauthorizedException("User is not allowed to execute actions of this handler")));
                        }

                        if (!actionMethod.CanExecuteAction(context, actionHandler, serviceProvider))
                        {
                            return(command.CreateExceptionResponse <ExecuteResponse>(
                                       new UnauthorizedException("User is not allowed to execute action")));
                        }

                        return(await ExecuteAction(actionHandler, command, actionMethod));
                    }

                    return(command.CreateExceptionResponse <ExecuteResponse>(new HandlerNotFoundException()));
                }

                return(command.CreateExceptionResponse <ExecuteResponse>(new ActionNotFoundException()));
            }

            return(command.CreateExceptionResponse <ExecuteResponse>(new ActionHandlerNotFoundException()));
        }
Ejemplo n.º 11
0
        private async Task <ResponseBase> GetActionDetails(ExecuteCommand command, HttpInformation context)
        {
            string[] actionParts = command?.Action.Split('.');

            if (actionParts == null || actionParts.Length != 2)
            {
                return(command.CreateExceptionResponse <ExecuteResponse>("The format the action name was false."));
            }

            string actionHandlerName = actionParts[0];
            string actionName        = actionParts[1];

            Type actionHandlerType = actionMapper.GetHandler(actionHandlerName);

            if (actionHandlerType != null)
            {
                MethodInfo actionMethod = actionMapper.GetAction(actionName, actionHandlerType);

                if (actionMethod != null)
                {
                    ActionHandlerBase actionHandler = (ActionHandlerBase)serviceProvider.GetService(actionHandlerType);

                    if (actionHandler != null)
                    {
                        actionHandler.connection     = Connection;
                        actionHandler.executeCommand = command;

                        if (!actionHandlerType.CanExecuteAction(context, actionHandler, serviceProvider))
                        {
                            return(command.CreateExceptionResponse <ExecuteResponse>(
                                       "User is not allowed to execute actions of this handler."));
                        }

                        if (!actionMethod.CanExecuteAction(context, actionHandler, serviceProvider))
                        {
                            return(command.CreateExceptionResponse <ExecuteResponse>("User is not allowed to execute action."));
                        }

                        return(await ExecuteAction(actionHandler, command, actionMethod));
                    }

                    return(command.CreateExceptionResponse <ExecuteResponse>("No handler was found."));
                }

                return(command.CreateExceptionResponse <ExecuteResponse>("No action to execute was found."));
            }

            return(command.CreateExceptionResponse <ExecuteResponse>("No action handler type was matching"));
        }
Ejemplo n.º 12
0
        private async Task <ResponseBase> ExecuteAction(ActionHandlerBase actionHandler, ExecuteCommand command,
                                                        MethodInfo actionMethod)
        {
            logger.LogInformation("Execution of " + actionMethod.DeclaringType.FullName + "." + actionMethod.Name + " started");

            object result = actionMethod.Invoke(actionHandler, GetParameters(actionMethod, command));

            if (result != null)
            {
                try { result = await(dynamic) result; }
                catch (RuntimeBinderException) { /* Do nothing because result is not an awaitable and already contains the expected result */ }
            }

            logger.LogInformation("Executed " + actionMethod.DeclaringType.FullName + "." + actionMethod.Name);

            return(new ExecuteResponse()
            {
                ReferenceId = command.ReferenceId,
                Result = result
            });
        }
Ejemplo n.º 13
0
        private async Task <ResponseBase> GetActionDetails(ExecuteCommand command, HttpInformation context)
        {
            Type actionHandlerType = actionMapper.GetHandler(command);

            if (actionHandlerType != null)
            {
                MethodInfo actionMethod = actionMapper.GetAction(command, actionHandlerType);

                if (actionMethod != null)
                {
                    ActionHandlerBase actionHandler = (ActionHandlerBase)serviceProvider.GetService(actionHandlerType);

                    if (actionHandler != null)
                    {
                        actionHandler.connection     = Connection;
                        actionHandler.executeCommand = command;

                        if (!actionHandlerType.CanExecuteAction(context, actionHandler, serviceProvider))
                        {
                            return(command.CreateExceptionResponse <ExecuteResponse>(
                                       "User is not allowed to execute actions of this handler."));
                        }

                        if (!actionMethod.CanExecuteAction(context, actionHandler, serviceProvider))
                        {
                            return(command.CreateExceptionResponse <ExecuteResponse>("User is not allowed to execute action."));
                        }

                        return(await ExecuteAction(actionHandler, command, actionMethod));
                    }

                    return(command.CreateExceptionResponse <ExecuteResponse>("No handler was found."));
                }

                return(command.CreateExceptionResponse <ExecuteResponse>("No action to execute was found."));
            }

            return(command.CreateExceptionResponse <ExecuteResponse>("No action handler type was matching"));
        }
 /// <summary>
 /// 重包放吊
 /// </summary>
 /// <param name="record"></param>
 public override void FullDrop(ActionHandlerBase handler)
 {
 }
 /// <summary>
 /// 空包起吊
 /// </summary>
 /// <param name="record"></param>
 public override void EmptyHoist(ActionHandlerBase handler)
 {
 }
 /// <summary>
 /// 空包放吊
 /// </summary>
 /// <param name="record"></param>
 public override void EmptyDrop(ActionHandlerBase handler)
 {
 }
Ejemplo n.º 17
0
        /// <summary>
        /// 空包放吊
        /// </summary>
        /// <param name="record"></param>
        public override void EmptyDrop(ActionHandlerBase handler)
        {
            PosManager.StartPos(Wst.NUM, handler.Record.CRA_ID.CRA_NUM);

            InsertBofInWeightRecord(handler.Record);
        }
Ejemplo n.º 18
0
 public static bool CanExecuteAction(this Type type, HttpInformation httpInformation,
                                     ActionHandlerBase actionHandler, IServiceProvider serviceProvider)
 {
     return(HandleAuthAttributes(type.GetActionHandlerAttributesInfo().ActionAuthAttributes, httpInformation,
                                 SapphireAuthResource.OperationTypeEnum.Execute, actionHandler, serviceProvider));
 }
        /// <summary>
        /// 重包起吊
        /// </summary>
        /// <param name="record"></param>
        public override void FullHoist(ActionHandlerBase handler)
        {
            PosManager.UpdatePos(Wst.NUM, handler.Record.CRA_ID.CRA_NUM, handler.Record.CRA_ID.CRA_NUM);

            InsertRefineOutWeightRecord(handler.Record);
        }
Ejemplo n.º 20
0
 /// <summary>
 /// 重包起吊
 /// </summary>
 /// <param name="record"></param>
 public abstract void FullHoist(ActionHandlerBase handler);
Ejemplo n.º 21
0
 /// <summary>
 /// 空包放吊
 /// </summary>
 /// <param name="record"></param>
 public abstract void EmptyDrop(ActionHandlerBase handler);
Ejemplo n.º 22
0
 /// <summary>
 /// 空包起吊
 /// </summary>
 /// <param name="record"></param>
 public abstract void EmptyHoist(ActionHandlerBase handler);
Ejemplo n.º 23
0
 /// <summary>
 /// 空包起吊
 /// </summary>
 /// <param name="record"></param>
 public override void EmptyHoist(ActionHandlerBase handler)
 {
     PosManager.EndPos(Wst.NUM, handler.Record.CRA_ID.CRA_NUM);
 }
Ejemplo n.º 24
0
        /// <summary>
        /// 重包放吊
        /// </summary>
        /// <param name="record"></param>
        public override void FullDrop(ActionHandlerBase handler)
        {
            PosManager.UpdatePos(handler.Record.CRA_ID.CRA_NUM, Wst.NUM, handler.Record.CRA_ID.CRA_NUM);

            InsertBofInWeightRecord(handler.Record);
        }
 /// <summary>
 /// 重包起吊
 /// </summary>
 /// <param name="record"></param>
 public override void FullHoist(ActionHandlerBase handler)
 {
     PosManager.UpdatePos(handler.Record.CRA_ID.SPA_ID.NUM, (int)handler.Record.COORD_X,
                          (int)handler.Record.COORD_Y, handler.Record.CRA_ID.CRA_NUM, handler.Record.CRA_ID.CRA_NUM);
 }
 /// <summary>
 /// 重包起吊
 /// </summary>
 /// <param name="record"></param>
 public override void FullHoist(ActionHandlerBase handler)
 {
 }
 /// <summary>
 /// 兑物
 /// </summary>
 /// <param name="record"></param>
 public override void Pour(ActionHandlerBase handler)
 {
 }
Ejemplo n.º 28
0
 /// <summary>
 /// 重包放吊
 /// </summary>
 /// <param name="record"></param>
 public abstract void FullDrop(ActionHandlerBase handler);
Ejemplo n.º 29
0
 /// <summary>
 /// 兑物
 /// </summary>
 /// <param name="record"></param>
 public abstract void Pour(ActionHandlerBase handler);
Ejemplo n.º 30
0
 public static bool CanExecuteAction(this Type type, HttpInformation httpInformation,
                                     ActionHandlerBase actionHandler, IServiceProvider serviceProvider)
 {
     return(HandleAuthAttributes(type, type.GetCustomAttributes <ActionAuthAttribute>(false).ToList(), httpInformation,
                                 SapphireAuthResource.OperationTypeEnum.Execute, actionHandler, serviceProvider));
 }