Пример #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));
        }
Пример #2
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();
        }