Пример #1
0
        /// <summary>
        /// Executes the call method action
        /// </summary>
        /// <param name="action"></param>
        /// <param name="context"></param>
        public void Execute(CallMethodAction action, IExecutionContext context)
        {
            Console.WriteLine("Method {0} entered", action.MethodName);

            var routine = new MacroRoutine(1, context.MethodRegister.Get(action.MethodName).Actions);
            context.RoutineExecutor.Execute(routine, context.MethodRegister, context.CancellationToken, context.PauseToken);

            Console.WriteLine("Method {0} exited", action.MethodName);
        }
Пример #2
0
        /// <summary>
        /// Runs the macro
        /// </summary>
        /// <param name="repetitions"></param>
        /// <param name="actions"></param>
        /// <param name="register"></param>
        public void RunMacro(int repetitions, IList<IMacroAction> actions, IMacroMethodRegister register)
        {
            if (this._macroExecution != null)
            {
                if (this._pauseToken != null && this._pauseToken.PauseRequested)
                {
                    this.Pause();
                }

                return;
            }

            // Return if we're not ready to run
            if (this._window == null || !this.MacroEditor.Validate(actions, register)) return;

            // Create the routine and executor
            var routine = new MacroRoutine(repetitions, actions);
            var executor = new MacroRoutineExecutor(
                this._testMode
                ? (IMacroActionExecutor)new ConsoleMacroActionExecutor()
                : (IMacroActionExecutor)new WindowMacroActionExecutor(this._window)
            );

            // Wire-up callbacks
            executor.OnActionEnded += MacroExecution_OnActionEnded;
            executor.OnActionStarted += MacroExecution_OnActionStarted;
            executor.OnRepetitionEnded += MacroExecution_OnRepetitionEnded;
            executor.OnRepetitionStarted += MacroExecution_OnRepetitionStarted;

            // Create the cancellation and pause token
            this._cancellationToken = new CancellationTokenSource();
            this._pauseToken = new PauseToken();

            // Set the max value of progress
            prgIterationProgress.Minimum = 0;
            prgIterationProgress.Maximum = repetitions;

            // Start the execution
            this._macroExecution =
                executor.ExecuteAsync(routine, register, this._cancellationToken.Token, this._pauseToken)
                    .ContinueWith(MacroExecution_OnTaskEnded);

            // Refresh the UI
            this.RefreshUi();
        }