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; }
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); } }
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); } }
public async Task Delay(int millsecond) { try { await Task.Delay(millsecond, AppEnvironment.GetInstance().CancelToken); } catch (TaskCanceledException) { throw; } catch (Exception ex) { await CommonUtil.HandleExceptionAsync(ex); } }
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); } }
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(); }
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(); }
private static int GetRelativeCoodinateY(int coordY) { return(( int )(coordY * (SystemParameters.PrimaryScreenHeight / AppEnvironment.GetInstance().DpiHeight) / COORDINATE_MAX)); }
private static int GetRelativeCoodinateX(int coordX) { return(( int )(coordX * (SystemParameters.PrimaryScreenWidth / AppEnvironment.GetInstance().DpiWidth) / COORDINATE_MAX)); }
private static int GetAbsoluteCoodinateY(int coordY) { return(( int )Math.Round(coordY * COORDINATE_MAX / (SystemParameters.PrimaryScreenHeight / AppEnvironment.GetInstance().DpiHeight), MidpointRounding.AwayFromZero)); }
public static bool CheckMode(ModeKind mode) { var currentMode = AppEnvironment.GetInstance().Mode; return((currentMode & mode) == mode); }