예제 #1
0
        private async Task PlayCmd_ExecuteAsync()
        {
            if (!File.Exists(scriptPath))
            {
                ErrorMessage = "[File Error]" + Environment.NewLine + "'" + scriptPath + "' is not found.";
                return;
            }

            ErrorMessage = "";

            try {
                buttonState.IsPlaying = true;
                cancelTokenSrc        = new CancellationTokenSource();
                AppEnvironment.GetInstance().CancelToken = cancelTokenSrc.Token;

                WinDispacher?.Invoke(new Action(CommandManager.InvalidateRequerySuggested));
                await ScriptExecuter.ExecuteAsync(ScriptPath);
            }
            catch (CompilationErrorException ex) {
                ErrorMessage = "[Compile Error]" + Environment.NewLine + ex.Message;
            }
            catch (TaskCanceledException) {
                ErrorMessage = "[Message]Script was cancelled.";
            }
            catch (Exception) {
                throw;
            }

            buttonState.IsPlaying = false;
            WinDispacher?.Invoke(new Action(CommandManager.InvalidateRequerySuggested));
        }
        public MainWindow()
        {
            DataContext = userModel;
            InitializeComponent();

            AppEnvironment.GetInstance().DpiSetting();
            userModel.WinDispacher = Application.Current.Dispatcher;
        }
예제 #3
0
        private async Task SendKeyInput(KeyInput[] keyInput)
        {
            if (CommonUtil.CheckMode(ModeKind.CreateLog))
            {
                await Logger.WriteKeyInputAsync(keyInput);
            }

            if (!CommonUtil.CheckMode(ModeKind.MouseOnly))
            {
                await Task.Run(() => SendInputWrapper.SendKeyInput(keyInput), AppEnvironment.GetInstance().CancelToken);
            }
        }
예제 #4
0
 public async Task WrileUserCustomLog(Dictionary <string, string> userCustomDic)
 {
     try {
         await Task.Run(() => Logger.WriteUserCustomAsync(userCustomDic), AppEnvironment.GetInstance().CancelToken);
     }
     catch (TaskCanceledException) {
         throw;
     }
     catch (Exception ex) {
         await CommonUtil.HandleExceptionAsync(ex);
     }
 }
예제 #5
0
 public async Task Delay(int millsecond)
 {
     try {
         await Task.Delay(millsecond, AppEnvironment.GetInstance().CancelToken);
     }
     catch (TaskCanceledException) {
         throw;
     }
     catch (Exception ex) {
         await CommonUtil.HandleExceptionAsync(ex);
     }
 }
예제 #6
0
 public async Task SetMode(byte mode)
 {
     try {
         await Task.Run(() => {
             AppEnvironment.GetInstance().Mode = ( ModeKind )mode;
         }, AppEnvironment.GetInstance().CancelToken);
     }
     catch (TaskCanceledException) {
         throw;
     }
     catch (Exception ex) {
         await CommonUtil.HandleExceptionAsync(ex);
     }
 }
예제 #7
0
        private static void ProcessException(Exception ex)
        {
            if (AppEnvironment.GetInstance().IsConsoleMode)
            {
                WriteToConsole(ex.ToString());
            }
            else
            {
                MessageBox.Show(ex.ToString(), "Error");
            }

            // for executing destructor of hook
            GC.Collect();
        }
예제 #8
0
        private async void Application_StartupAsync(object sender, StartupEventArgs e)
        {
            try {
                // when no arguments are specified, execute main window
                if (e.Args.Length == 0)
                {
                    AppEnvironment.GetInstance().IsConsoleMode = false;
                    var window = new MainWindow();
                    window.Show();
                    return;
                }
                else if (e.Args.Length >= 2)
                {
                    Usage();
                }

                Regex scriptArgPattern = new Regex("-script=(?<scriptPath>.+)");
                Match argsChacker      = scriptArgPattern.Match(e.Args[0]);

                if (argsChacker.Success)
                {
                    string filePath = argsChacker.Groups["scriptPath"].Value;
                    if (File.Exists(filePath))
                    {
                        AppEnvironment.GetInstance().DpiSetting();
                        await ScriptExecuter.ExecuteAsync(filePath);
                    }
                    else
                    {
                        CommonUtil.WriteToConsole("[File Error]" + Environment.NewLine + "'" + filePath + "' is not found.");
                    }
                }
                else
                {
                    Usage();
                }
            }
            catch (CompilationErrorException ex) {
                CommonUtil.WriteToConsole("[Compile Error]" + Environment.NewLine + ex.Message);
            }
            catch (Exception ex) {
                CommonUtil.HandleException(ex);
            }

            Current.Shutdown();
        }
예제 #9
0
 private static int GetRelativeCoodinateY(int coordY)
 {
     return(( int )(coordY * (SystemParameters.PrimaryScreenHeight / AppEnvironment.GetInstance().DpiHeight) / COORDINATE_MAX));
 }
예제 #10
0
 private static int GetRelativeCoodinateX(int coordX)
 {
     return(( int )(coordX * (SystemParameters.PrimaryScreenWidth / AppEnvironment.GetInstance().DpiWidth) / COORDINATE_MAX));
 }
예제 #11
0
 private static int GetAbsoluteCoodinateY(int coordY)
 {
     return(( int )Math.Round(coordY * COORDINATE_MAX /
                              (SystemParameters.PrimaryScreenHeight / AppEnvironment.GetInstance().DpiHeight), MidpointRounding.AwayFromZero));
 }
예제 #12
0
        public static bool CheckMode(ModeKind mode)
        {
            var currentMode = AppEnvironment.GetInstance().Mode;

            return((currentMode & mode) == mode);
        }