Exemplo n.º 1
0
        public IReleasable AddAction(string name, Action <Step> executeAction, Func <Step, bool> canExecuteAction)
        {
            if (executeAction == null)
            {
                throw new ArgumentNullException("executeAction");
            }
            if (canExecuteAction == null)
            {
                throw new ArgumentNullException("canExecuteAction");
            }

            var execute = new ExecuteAction(executeAction);

            myExecuteActions[name] = execute;
            var canExecute = new CanExecuteAction(canExecuteAction);

            myCanExecuteActions[name] = canExecute;

            Log.Debug("ActionRepository: Action '" + name + "' added (with CanExecute).");

            return(new ReleasableAction(() =>
            {
                ExecuteAction executeStored;
                if (myExecuteActions.TryGetValue(name, out executeStored) && executeStored == execute)
                {
                    myExecuteActions.Remove(name);
                }

                CanExecuteAction canExecuteStored;
                if (myCanExecuteActions.TryGetValue(name, out canExecuteStored) && canExecuteStored == canExecute)
                {
                    myCanExecuteActions.Remove(name);
                }
            }));
        }
 protected ResponseData Execute(ExecuteReponse response, ExecuteAction action)
 {
     try
     {
         return(response(action()));
     }
     catch (NoDataException ex)
     {
         return(NoDataResquest(ex.Message));
     }
     catch (ValidationException ex)
     {
         if (ex.ValidationErrorResponses is null)
         {
             return(ValidationErrorResquest(ex.Message));
         }
         else
         {
             return(ValidationErrorResquest(ex.ValidationErrorResponses));
         }
     }
     catch (NoPermissionException ex)
     {
         return(NoPermissionResquest(ex.Message));
     }
     catch (UnSuccessException ex)
     {
         return(UnSuccessResquest());
     }
     catch (Exception ex)
     {
         return(UnexpectedErrorResquest(ex.Message));
     }
 }
Exemplo n.º 3
0
 //Executes the action
 public virtual void Act(ExecuteAction action)
 {
     if (successor != null)
     {
         successor.Act(action);
     }
 }
Exemplo n.º 4
0
        public HttpResponseMessage RunCommand(string computer, [FromUri] string accessToken, [FromBody] CommandRequest command)
        {
            bool isAuth = CheckpointAuth.CheckCheckpointToken(accessToken);

            HttpResponseMessage response = new HttpResponseMessage();

            if (isAuth)
            {
                ExecutionResult result = new ExecutionResult();

                result = ExecuteAction.ExecuteCommand(computer,
                                                      command.commandToExecute);

                response = Request.CreateResponse(HttpStatusCode.OK, result);
            }
            else
            {
                ExecutionResult result = new ExecutionResult();

                result.commandExitCode = 403;
                result.resultError     = "Invalid token";

                response = Request.CreateResponse(HttpStatusCode.Forbidden, result);
            }

            return(response);
        }
Exemplo n.º 5
0
    void Start()
    {
        transform.localScale = new Vector3(0, 0, 1);

        if (type == Type.Bomb)
        {
            executeAction = BombAction;
            scoreToAdd    = 800;
        }
        else if (type == Type.Time)
        {
            executeAction = TimeAction;
            scoreToAdd    = 800;
        }
        else
        {
            executeAction = HealthAction;
            scoreToAdd    = 350;
        }

        if (timeOut > 0)
        {
            StartCoroutine(TimeOut());
        }
    }
Exemplo n.º 6
0
        public TurnOnOffScreen(Window window)
        {
            m_Window = window;
            WindowManagerFlags screenFlags = WindowManagerFlags.ShowWhenLocked | WindowManagerFlags.TurnScreenOn | WindowManagerFlags.KeepScreenOn | WindowManagerFlags.DismissKeyguard;

            m_TurnOff = new ExecuteAction(() =>
            {
                try
                {
                    m_Window.AddFlags(screenFlags);
                    var attributes = new WindowManagerLayoutParams();
                    attributes.CopyFrom(m_Window.Attributes);
                    attributes.ScreenBrightness = 0f;
                    m_Window.Attributes         = attributes;
                }
                catch
                {
                }
            });
            m_TurnOn = new ExecuteAction(() =>
            {
                try
                {
                    m_Window.ClearFlags(screenFlags);
                    var attributes = new WindowManagerLayoutParams();
                    attributes.CopyFrom(m_Window.Attributes);
                    attributes.ScreenBrightness = -1f;
                    m_Window.Attributes         = attributes;
                }
                catch
                {
                }
            });
        }
 public void Execute(object parameter)
 {
     if (ExecuteAction != null)
     {
         ExecuteAction.Invoke(parameter);
     }
 }
Exemplo n.º 8
0
        private void SaveDepth(DbTransaction transaction, ExecuteAction executeAction, bool checkTimestamp)
        {
            switch (executeAction)
            {
            case ExecuteAction.Insert:
                if (IsSelfDeleted)
                {
                    break;
                }
                InsertSelf(transaction);
                foreach (KeyValuePair <Type, List <IBusiness> > kvp in _details)
                {
                    foreach (IBusiness item in kvp.Value)
                    {
                        ((IRefinedBusiness)item).SaveDepth(transaction, ExecuteAction.Insert, checkTimestamp);
                    }
                }
                break;

            case ExecuteAction.Delete:
                if (IsNew)
                {
                    break;
                }
                foreach (KeyValuePair <Type, List <IBusiness> > kvp in _details)
                {
                    foreach (IBusiness item in kvp.Value)
                    {
                        ((IRefinedBusiness)item).SaveDepth(transaction, ExecuteAction.Delete, checkTimestamp);
                    }
                }
                DeleteSelf(transaction, true);
                break;

            case ExecuteAction.Update:
                foreach (KeyValuePair <Type, List <IBusiness> > kvp in _details)
                {
                    foreach (IBusiness item in kvp.Value)
                    {
                        if (item.IsNew)
                        {
                            ((IRefinedBusiness)item).SaveDepth(transaction, ExecuteAction.Insert, checkTimestamp);
                        }
                        else if (IsSelfDeleted)
                        {
                            ((IRefinedBusiness)item).SaveDepth(transaction, ExecuteAction.Delete, checkTimestamp);
                        }
                        else
                        {
                            ((IRefinedBusiness)item).SaveDepth(transaction, ExecuteAction.Update, checkTimestamp);
                        }
                    }
                }
                if (IsSelfDirty)
                {
                    UpdateSelf(transaction, GetDirtValues(), checkTimestamp);
                }
                break;
            }
        }
Exemplo n.º 9
0
 /** called by the agent infra arch to perform an action in the environment */
 public void Act(string agName, ExecuteAction action)
 {
     if (running)
     {
         userEnv.ScheduleAction(agName, action.GetActionTerm(), action);
     }
 }
Exemplo n.º 10
0
        public Result Execute(ExprNode node)
        {
            if ((node == null) || (node.Expression == null))
            {
                return(new Result(string.Empty));
            }
            IExecutor start    = this.CreateExecutor(node);
            IExecutor executor = start;

            this.Push(executor);
            while (executor != null)
            {
                ExecuteAction result = executor.Execute(this);
                if (result == ExecuteAction.End)
                {
                    this.Pop();
                }
                else if (result == ExecuteAction.Exit)
                {
                    return(start.Result);
                }
                executor = this.Top;
            }

            return(start.Result);
        }
Exemplo n.º 11
0
        /// <summary>
        /// 添加根节点。
        /// </summary>
        /// <param name="action"></param>
        /// <param name="checker"></param>
        /// <returns></returns>
        public ActionPair AddRoot(ExecuteAction action, CheckActionState checker)
        {
            var root = new ActionPair(action, checker);

            _head.AddDefaultChild(root);
            return(root);
        }
Exemplo n.º 12
0
 public override void Release(RDGObjectPool ObjectPool)
 {
     Clear();
     ExecuteFunc = null;
     ObjectPool.Release(this);
     ObjectPool.Release(PassData);
 }
Exemplo n.º 13
0
        public IReleasable AddAction(string name, Action <Step> executeAction)
        {
            if (executeAction == null)
            {
                throw new ArgumentNullException("executeAction");
            }

            var execute = new ExecuteAction(executeAction);

            if (myExecuteActions.ContainsKey(name))
            {
                Log.Warn($"Action with name '{name}' already exists. Will be overwritten!");
            }

            myExecuteActions[name] = execute;

            Log.Debug("ActionRepository: Action '" + name + "' added.");

            return(new ReleasableAction(() =>
            {
                ExecuteAction executeStored;
                if (myExecuteActions.TryGetValue(name, out executeStored) && executeStored == execute)
                {
                    myExecuteActions.Remove(name);
                }
            }));
        }
Exemplo n.º 14
0
 public void Execute(object parameter)
 {
     if (ExecuteAction == null)
     {
         return;
     }
     ExecuteAction.Invoke(parameter);
 }
Exemplo n.º 15
0
 public async void Execute(object parameter)
 {
     if (CanExecute(parameter))
     {
         ExecuteAction?.Invoke(parameter);
         await ExecuteAsync(parameter);
     }
 }
 public void Refresh(ActionHolder actionHolder, IAlgorithmContext algoContext)
 {
     ActionHolder     = actionHolder;
     AlgorithmContext = algoContext;
     _action          = (ExecuteAction)actionHolder.Action;
     action1View.Refresh(_action.MasterActionHolder, algoContext);
     action2View.Refresh(_action.InputValue, algoContext);
     Action2EqualizeToAction1();
 }
Exemplo n.º 17
0
        /// <summary>
        /// Execute command
        /// </summary>
        public DebugCommandStatus Execute(string[] args)
        {
            if (ExecuteAction == null)
            {
                return(DebugCommandStatus.ACTION_IS_NULL_ERROR);
            }

            return(ExecuteAction.Invoke(this, args));
        }
Exemplo n.º 18
0
 public CreateProductHttpAction(GetAction get, ExecuteAction execute, RevertAction revert, PostProductRequest createProductRequest) : base(get, execute, revert)
 {
     CreateRequest = createProductRequest;
     GetRequest    = new GetProductRequest {
         ExternalIdentifier = createProductRequest.ExternalIdentifier
     };
     DeleteRequest = new DeleteProductRequest {
         ExternalIdentifier = createProductRequest.ExternalIdentifier
     };
 }
Exemplo n.º 19
0
 /// <summary>
 /// 操作根实体对象之前
 /// </summary>
 /// <param name="executeAction">执行动作</param>
 /// <param name="tag">标记</param>
 protected override void OnKernelOperating(ExecuteAction executeAction, out object tag)
 {
     tag = executeAction == ExecuteAction.Update
         ? new
     {
         ProjectManager = Kernel.ProjectManager,
         DevelopManager = Kernel.DevelopManager
     }
         : null;
 }
Exemplo n.º 20
0
 public void Execute(object parameter)
 {
     if (parameter == null)
     {
         ExecuteAction?.Invoke();
     }
     else
     {
         ExecuteActionArg?.Invoke(parameter);
     }
 }
 /// <summary>
 /// 操作根实体对象之后
 /// </summary>
 /// <param name="executeAction">执行动作</param>
 /// <param name="tag">标记</param>
 protected override void OnKernelOperated(ExecuteAction executeAction, object tag)
 {
     if (executeAction == ExecuteAction.Insert)
     {
         Send(Kernel);
     }
     else
     {
         Send(Kernel, Kernel.PrimaryKey.ToString());
     }
 }
Exemplo n.º 22
0
        /// <summary>
        /// Reads the next set of actions from the given stream, then sends them to the
        /// ExecuteAction utility to be executed.
        /// </summary>
        /// <param name="clientStream"></param>
        private void ReadAndExecuteNextActions(BTDataIO clientStream)
        {
            List <string> sentAction = clientStream.Read();

            if (sentAction.Count > 0) // TODO greater than 0
            {
                foreach (string action in sentAction)
                {
                    ExecuteAction.Execute(action);
                }
            }
        }
Exemplo n.º 23
0
        /** called by the user implementation of the environment when the action was executed */
        public void ActionExecuted(string agName, Structure actTerm, bool success, object infraData)
        {
            ExecuteAction action = (ExecuteAction)infraData;

            action.SetResult(success);
            CentralisedAgArch ag = masRunner.GetAg(agName);

            if (ag != null) // the agent may was killed
            {
                ag.ActionExecuted(action);
            }
        }
Exemplo n.º 24
0
        public void Execute(object parameter)
        {
            if (ExecuteAction is null)
            {
                return;
            }

            if (ConvertToType(parameter, out var convertedValue))
            {
                ExecuteAction?.Invoke(convertedValue);
            }
        }
Exemplo n.º 25
0
 internal bool IsHandlerRegistered(object target, MethodInfo methodInfo)
 {
     if (ExecuteAction != null)
     {
         foreach (Delegate dlg in ExecuteAction.GetInvocationList())
         {
             if (dlg.Target == target && dlg.Method == methodInfo)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Exemplo n.º 26
0
        public void Execute(Object parameter)
        {
            if (ExecuteAction is not null)
            {
                ExecuteAction.Invoke();
                return;
            }

            if (ExecuteActionWithParameter is not null)
            {
                ExecuteActionWithParameter.Invoke(parameter);
                return;
            }
        }
Exemplo n.º 27
0
        /// <summary>
        /// Initializes a new instance of the <see cref="V8ActionHandlerFunction"/> class.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="action">The action.</param>
        /// <exception cref="System.ArgumentNullException">
        /// name
        /// or
        /// action
        /// </exception>
        public V8ActionHandlerFunction(string name, ExecuteAction action)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentNullException("name");
            }

            if (action == null)
            {
                throw new ArgumentNullException("action");
            }

            Name   = name;
            Action = action;
        }
Exemplo n.º 28
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DelegateJob" /> class.
        /// </summary>
        /// <param name="id">The ID of the job.</param>
        /// <param name="execAction">An action for a <see cref="DelegateJob.OnExecute(IJobExecutionContext)" /> method.</param>
        /// <param name="canExecuteAction">An action for a <see cref="DelegateJob.OnCanExecute(DateTimeOffset, ref bool)" /> method.</param>
        /// <param name="isThreadSafe">Job schould work thread safe or not.</param>
        /// <param name="syncRoot">The object for thread safe operations.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="execAction" />, <paramref name="canExecuteAction" /> and/or <paramref name="syncRoot" /> are <see langword="null" />.
        /// </exception>
        public DelegateJob(Guid id, ExecuteAction execAction, CanExecuteAction canExecuteAction, bool isThreadSafe, object syncRoot)
            : base(id, false)
        {
            if (execAction == null)
            {
                throw new ArgumentNullException("execAction");
            }

            if (canExecuteAction == null)
            {
                throw new ArgumentNullException("canExecuteAction");
            }

            this._EXECUTE_ACTION     = execAction;
            this._CAN_EXECUTE_ACTION = canExecuteAction;
        }
Exemplo n.º 29
0
        public virtual void Execute(string uri, string json, ExecuteAction action)
        {
            HttpClient client = GetClient();

            client.BaseAddress = new Uri(BaseAddress);
            var stringContent = new StringContent(json, Encoding.UTF8, "application/json");

            if (action == ExecuteAction.Post)
            {
                var postTask = client.PostAsync(uri, stringContent).Result;
            }
            else
            {
                var postTask = client.PutAsync(uri, stringContent).Result;
            }
        }
Exemplo n.º 30
0
        public ExecuteAction SelectAction(List <ExecuteAction> actList)
        {
            //synchronized(actList) {
            IEnumerator <ExecuteAction> i = actList.GetEnumerator();

            while (i.MoveNext())
            {
                ExecuteAction a = i.Current;
                if (!a.GetIntention().IsSuspended())
                {
                    i.Dispose();
                    return(a);
                }
            }
            //}
            return(null);
        }
        // <summary>
        //     Creates an EntityDesignerCommand which can be executed from a context menu in the designer
        // </summary>
        // <param name="name">The name of the command, and the label text that will appear in the designer's context menu</param>
        // <param name="executeAction">A simple Action that will get passed in the EntityDesignerSelection and the selected XElement</param>
        // <param name="canExecuteFunction">Delegate which accepts an EntityDesignerSelection and will return a Tuple where the first boolean corresponds to whether the command is shown, and the second corresponds to whether the command is enabled</param>
        // <param name="isRefactoringCommand">Specifies whether this command is a refactoring operation, in which case it may be placed separately in the resulting context menu</param>
        internal EntityDesignerCommand(
            string name,
            ExecuteAction executeAction,
            CanExecuteFunction canExecuteFunction = null,
            bool isRefactoringCommand = false)
        {
            if (name == null)
            {
                throw new ArgumentException("name should not be null");
            }
            if (executeAction == null)
            {
                throw new ArgumentException("executeAction should not be null");
            }

            Name = name;
            _execute = executeAction;
            _canExecute = canExecuteFunction;
            IsRefactoringCommand = isRefactoringCommand;
        }
 public string Execute(ExecuteAction action, string param = "")
 {
     RestRequest restRequest = null;
     switch (action)
     {
         case ExecuteAction.Get:
         case ExecuteAction.GetCache:
             restRequest = new RestRequest(this.a_restUrl + action.ToString(), param, "GET");
             break;
         case ExecuteAction.AwakeThread:
         case ExecuteAction.Clear:
         case ExecuteAction.GetByGuid:
         case ExecuteAction.GetByFilter:
             restRequest = new RestRequest(this.a_restUrl + action.ToString(), param, "POST");
             break;
         default:
             break;
     }
     return restRequest.Execute();
 }