Exemple #1
0
        private void LogWindowCommand_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            // Force update of script interface
            LogWindowButton.Focus();

            LogDialog = new LogWindow {
                Owner = this
            };
            LogDialog.Show();
        }
Exemple #2
0
        private void LogWindowCommand_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            // Force update of script interface
            LogWindowButton.Focus();

            // Reset TaskBar progress state when build is not running
            if (Engine.WorkingEngine == null)
            {
                Global.MainViewModel.TaskBarProgressState = TaskbarItemProgressState.None;
            }

            // If last build ended with issue, show build log instead of system log
            int selectedTabIndex = Global.MainViewModel.BuildEndedWithIssue ? 1 : 0;

            Global.MainViewModel.BuildEndedWithIssue = false;

            LogDialog = new LogWindow(selectedTabIndex)
            {
                Owner = this
            };
            LogDialog.Show();
        }
Exemple #3
0
        private async void ProjectBuildStartCommand_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            // Force update of script interface
            ProjectBuildStartButton.Focus();

            if (!Engine.TryEnterLock())
            {
                return;
            }
            try
            {
                // Get current project
                Project p = Model.CurMainTree.Script.Project;

                Model.BuildTreeItems.Clear();
                ProjectTreeItemModel treeRoot = MainViewModel.PopulateOneTreeItem(p.MainScript, null, null);
                MainViewModel.ScriptListToTreeViewModel(p, p.ActiveScripts, false, treeRoot);
                Model.BuildTreeItems.Add(treeRoot);
                Model.CurBuildTree = null;

                EngineState s = new EngineState(p, Logger, Model);
                s.SetOptions(Global.Setting);
                s.SetCompat(p.Compat);

                Engine.WorkingEngine = new Engine(s);

                // Build Start, Switch to Build View
                Model.SwitchNormalBuildInterface = false;

                // Turn on progress ring
                Model.WorkInProgress = true;

                // Set StatusBar Text
                using (CancellationTokenSource ct = new CancellationTokenSource())
                {
                    Task printStatus = MainViewModel.PrintBuildElapsedStatus($"Building {p.ProjectName}...", s, ct.Token);

                    // Run
                    int buildId = await Engine.WorkingEngine.Run($"Project {p.ProjectName}");

#if DEBUG
                    Logger.ExportBuildLog(LogExportType.Text, Path.Combine(s.BaseDir, "LogDebugDump.txt"), buildId, new BuildLogOptions
                    {
                        IncludeComments = true,
                        IncludeMacros   = true,
                        ShowLogFlags    = true,
                    });
#endif

                    // Cancel and wait until PrintBuildElapsedStatus stops
                    ct.Cancel();
                    await printStatus;
                }

                // Turn off progress ring
                Model.WorkInProgress = false;

                // Build ended, Switch to Normal View
                Model.SwitchNormalBuildInterface = true;
                Model.BuildTreeItems.Clear();
                Model.DisplayScript(Model.CurMainTree.Script);

                // Report elapsed time
                string reason = s.RunResultReport();
                if (reason != null)
                {
                    Model.StatusBarText = $"{p.ProjectName} build stopped by {reason}. ({s.Elapsed:h\\:mm\\:ss})";
                }
                else
                {
                    Model.StatusBarText = $"{p.ProjectName} build finished. ({s.Elapsed:h\\:mm\\:ss})";
                }

                if (Global.Setting.General.ShowLogAfterBuild && LogWindow.Count == 0)
                { // Open BuildLogWindow
                    LogDialog = new LogWindow(1);
                    LogDialog.Show();
                }
            }
            finally
            {
                Engine.WorkingEngine = null;
                Engine.ExitLock();
                CommandManager.InvalidateRequerySuggested();
            }
        }
Exemple #4
0
        private async void ScriptRunCommand_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            // Force update of script interface
            ScriptRunButton.Focus();

            Script sc = Model.CurMainTree.Script;

            if (!sc.Sections.ContainsKey(ScriptSection.Names.Process))
            {
                Model.StatusBarText = $"Section [Process] does not exist in {sc.Title}";
                return;
            }

            if (Engine.TryEnterLock())
            { // Engine is not running, so we can start new engine
                try
                {
                    Model.BuildTreeItems.Clear();
                    ProjectTreeItemModel rootItem = MainViewModel.PopulateOneTreeItem(sc, null, null);
                    Model.BuildTreeItems.Add(rootItem);
                    Model.CurBuildTree = null;

                    EngineState s = new EngineState(sc.Project, Logger, Model, EngineMode.RunMainAndOne, sc);
                    s.SetOptions(Global.Setting);
                    s.SetCompat(sc.Project.Compat);

                    Engine.WorkingEngine = new Engine(s);

                    // Switch to Build View
                    Model.SwitchNormalBuildInterface = false;

                    TimeSpan t;
                    using (CancellationTokenSource ct = new CancellationTokenSource())
                    {
                        Task printStatus = MainViewModel.PrintBuildElapsedStatus($"Running {sc.Title}...", s, ct.Token);
                        // Run
                        int buildId = await Engine.WorkingEngine.Run($"{sc.Title} - Run");

#if DEBUG
                        Logger.ExportBuildLog(LogExportType.Text, Path.Combine(s.BaseDir, "LogDebugDump.txt"), buildId, new BuildLogOptions
                        {
                            IncludeComments = true,
                            IncludeMacros   = true,
                            ShowLogFlags    = true,
                        });
#endif

                        // Cancel and Wait until PrintBuildElapsedStatus stops
                        // Report elapsed time
                        t = s.Elapsed;

                        ct.Cancel();
                        await printStatus;
                    }

                    Model.StatusBarText = $"{sc.Title} processed in {t:h\\:mm\\:ss}";

                    // Build Ended, Switch to Normal View
                    Model.SwitchNormalBuildInterface = true;
                    Model.BuildTreeItems.Clear();
                    Model.DisplayScript(Model.CurMainTree.Script);

                    if (Global.Setting.General.ShowLogAfterBuild && LogWindow.Count == 0)
                    { // Open BuildLogWindow
                        LogDialog = new LogWindow(1);
                        LogDialog.Show();
                    }
                }
                finally
                {
                    Engine.WorkingEngine = null;
                    Engine.ExitLock();
                }
            }
            else // Stop Build
            {
                // Request engine to stop the build.
                ForceStopBuild();
            }
        }