コード例 #1
0
        public void Reset()
        {
            lock (locker)
            {
                commandQueue.Clear();
            }

            if (runningMacro)
            {
                runningMacro = false;
                for (int i = 0; i < startingExtruderTemps.Count; i++)
                {
                    PrinterConnectionAndCommunication.Instance.SetTargetExtruderTemperature(i, startingExtruderTemps[i]);
                }

                if (ActiveSliceSettings.Instance.GetValue <bool>(SettingsKey.has_heated_bed))
                {
                    PrinterConnectionAndCommunication.Instance.TargetBedTemperature = startingBedTemp;
                }
            }
            waitingForUserInput = false;
            timeHaveBeenWaiting.Reset();
            maxTimeToWaitForOk = 0;
            UiThread.RunOnIdle(() => WizardWindow.Close("Macro"));
        }
コード例 #2
0
        private void CloseWizard()
        {
            if (_wizardWindow.DataContext is WizardViewModel viewModel)
            {
                viewModel.RequestCancel -= ViewModel_RequestCancel;
                viewModel.RequestClose  -= ViewModel_RequestClose;
                viewModel.Dispose();
            }

            _wizardWindow.Close();
        }
コード例 #3
0
        public void RunStarted(object automationObject, Dictionary <string, string> replacementsDictionary, WizardRunKind runKind, object[] customParams)
        {
            // Store a copy of the replacements dictionary, used later for deleting the project if it was cancelled
            _replacementsDictionary = replacementsDictionary;
            string projectName          = replacementsDictionary["$projectname$"];
            string destinationDirectory = replacementsDictionary["$destinationdirectory$"];

            #region VSTemplate Parsing for NuGet Packages
            // Parse the VSTemplate for nuget package entries, this is the only way AFAIK to make them optional but at the detriment of them having to be downloaded
            // instead of locally available in the VSIX...
            if (customParams.Length > 0)
            {
                var vsTemplate = XDocument.Load((string)customParams[0]);
                IEnumerable <XElement> parsedPackages = vsTemplate.Descendants().Where(x => x.Name.LocalName == "package");

                foreach (XElement parsedPackage in parsedPackages)
                {
                    _nugetPackages.Add(parsedPackage.Attribute("id").Value);
                }
            }
            #endregion

            try
            {
                // Create a new instance of the WizardWindow
                wizardWindow = new WizardWindow();

                if (wizardWindow.ShowDialog().Value == true)
                {
                    // Set up the paths we need for the configuration. & should automatically be escaped with &amp;
                    bannerlordDirectory = wizardWindow.BannerlordDirectory;
                    bannerlordExe       = bannerlordDirectory + @"\bin\Win64_Shipping_Client\Bannerlord.exe";
                    createSubModule     = wizardWindow.IncludeSubModule;
                    createReadme        = wizardWindow.IncludeReadme;
                    addHarmony          = wizardWindow.IncludeHarmony;
                    useLauncherMods     = wizardWindow.UseLauncherMods;

                    // Parse the Bannerlord Launcher to find what modules were last used
                    StringBuilder argumentString = new StringBuilder();
                    List <string> moduleList     = wizardWindow.LauncherMods;

                    if (moduleList != null && moduleList.Count >= 1 && useLauncherMods)
                    {
                        argumentString.Append("/singleplayer _MODULES_*");
                        foreach (string module in moduleList)
                        {
                            argumentString.Append($"{module}*");
                        }
                        argumentString.Append($"{replacementsDictionary["$safeprojectname$"]}*_MODULES_");
                    }
                    else
                    {
                        argumentString.Append($"/singleplayer _MODULES_*Native*SandBoxCore*SandBox*StoryMode*CustomBattle*{replacementsDictionary["$safeprojectname$"]}*_MODULES_");
                    }

                    // Add our custom replacements to the dictionary
                    replacementsDictionary.Add("$BannerlordDirectory$", bannerlordDirectory);
                    replacementsDictionary.Add("$BannerlordExecutable$", bannerlordExe);
                    replacementsDictionary.Add("$BannerlordDebugArgs$", argumentString.ToString());

                    // We should be done now, close the window
                    wizardWindow.Close();
                }
                else
                {
                    // The user clicked cancel or closed the window, throw the exception
                    wizardWindow.Close();
                    throw new WizardBackoutException();
                }
            } catch (Exception ex) {
                if (ex.GetType().IsAssignableFrom(typeof(WizardBackoutException)) || ex.GetType().IsAssignableFrom(typeof(WizardCancelledException)))
                {
                    // Project folder would still have been created, clean it up if the user decided to back out
                    string projectFolder = Path.GetFullPath(Path.Combine(destinationDirectory, @"..\"));

                    if (Directory.Exists(projectFolder))
                    {
                        Directory.Delete(projectFolder, true);
                    }
                    else
                    {
                        Directory.Delete(destinationDirectory, true);
                    }
                    throw;
                }
                else
                {
                    MessageBox.Show($"An error has occurred!\n\nError Message:\n{ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        }
コード例 #4
0
        public override string ReadLine()
        {
            string lineToSend = null;

            if (waitingForUserInput)
            {
                lineToSend = "";
                Thread.Sleep(100);

                if (timeHaveBeenWaiting.IsRunning &&
                    timeHaveBeenWaiting.Elapsed.TotalSeconds > maxTimeToWaitForOk)
                {
                    if (commandsToRepeat.Count > 0)
                    {
                        // We timed out without the user responding. Cancel the operation.
                        Reset();
                    }
                    else
                    {
                        // everything normal continue after time waited
                        Continue();
                    }
                }

                if (maxTimeToWaitForOk > 0 &&
                    timeHaveBeenWaiting.Elapsed.TotalSeconds < maxTimeToWaitForOk &&
                    commandsToRepeat.Count > 0)
                {
                    lineToSend = commandsToRepeat[repeatCommandIndex % commandsToRepeat.Count];
                    repeatCommandIndex++;
                }
            }
            else
            {
                // lock queue
                lock (locker)
                {
                    if (commandQueue.Count > 0)
                    {
                        lineToSend = commandQueue[0];
                        lineToSend = GCodeProcessing.ReplaceMacroValues(lineToSend);
                        commandQueue.RemoveAt(0);
                    }
                }

                if (lineToSend != null)
                {
                    if (lineToSend.StartsWith(MacroPrefix) && lineToSend.TrimEnd().EndsWith(")"))
                    {
                        if (!runningMacro)
                        {
                            runningMacro = true;
                            int extruderCount = ActiveSliceSettings.Instance.GetValue <int>(SettingsKey.extruder_count);
                            for (int i = 0; i < extruderCount; i++)
                            {
                                startingExtruderTemps.Add(PrinterConnectionAndCommunication.Instance.GetTargetExtruderTemperature(i));
                            }

                            if (ActiveSliceSettings.Instance.GetValue <bool>(SettingsKey.has_heated_bed))
                            {
                                startingBedTemp = PrinterConnectionAndCommunication.Instance.TargetBedTemperature;
                            }
                        }
                        int    parensAfterCommand = lineToSend.IndexOf('(', MacroPrefix.Length);
                        string command            = "";
                        if (parensAfterCommand > 0)
                        {
                            command = lineToSend.Substring(MacroPrefix.Length, parensAfterCommand - MacroPrefix.Length);
                        }

                        RunningMacroPage.MacroCommandData macroData = new RunningMacroPage.MacroCommandData();

                        string value = "";
                        if (TryGetAfterString(lineToSend, "title", out value))
                        {
                            macroData.title = value;
                        }
                        if (TryGetAfterString(lineToSend, "expire", out value))
                        {
                            double.TryParse(value, out macroData.expireTime);
                            maxTimeToWaitForOk = macroData.expireTime;
                        }
                        if (TryGetAfterString(lineToSend, "count_down", out value))
                        {
                            double.TryParse(value, out macroData.countDown);
                        }
                        if (TryGetAfterString(lineToSend, "image", out value))
                        {
                            macroData.image = LoadImageAsset(value);
                        }
                        if (TryGetAfterString(lineToSend, "wait_ok", out value))
                        {
                            macroData.waitOk = value == "true";
                        }
                        if (TryGetAfterString(lineToSend, "repeat_gcode", out value))
                        {
                            foreach (string line in value.Split('|'))
                            {
                                commandsToRepeat.Add(line);
                            }
                        }

                        switch (command)
                        {
                        case "choose_material":
                            waitingForUserInput            = true;
                            macroData.showMaterialSelector = true;
                            macroData.waitOk = true;
                            UiThread.RunOnIdle(() => RunningMacroPage.Show(macroData));
                            break;

                        case "close":
                            runningMacro = false;
                            UiThread.RunOnIdle(() => WizardWindow.Close("Macro"));
                            break;

                        case "ding":
                            MatterControlApplication.Instance.PlaySound("timer-done.wav");
                            break;

                        case "show_message":
                            waitingForUserInput = macroData.waitOk | macroData.expireTime > 0;
                            UiThread.RunOnIdle(() => RunningMacroPage.Show(macroData));
                            break;

                        default:
                            // Don't know the command. Print to terminal log?
                            break;
                        }
                    }
                }
                else
                {
                    lineToSend = base.ReadLine();
                }
            }

            return(lineToSend);
        }
コード例 #5
0
        public RunningMacroPage(MacroCommandData macroData)
            : base("Cancel", macroData.title)
        {
            //TextWidget syncingText = new TextWidget(message, textColor: ActiveTheme.Instance.PrimaryTextColor);
            //contentRow.AddChild(syncingText);

            cancelButton.Click += (s, e) =>
            {
                PrinterConnectionAndCommunication.Instance.MacroCancel();
            };

            if (macroData.showMaterialSelector)
            {
                int extruderIndex    = 0;
                var materialSelector = new PresetSelectorWidget(string.Format($"{"Material".Localize()} {extruderIndex + 1}"), RGBA_Bytes.Transparent, NamedSettingsLayers.Material, extruderIndex);
                materialSelector.BackgroundColor = RGBA_Bytes.Transparent;
                materialSelector.Margin          = new BorderDouble(0, 0, 0, 15);
                contentRow.AddChild(materialSelector);
            }

            PrinterConnectionAndCommunication.Instance.WroteLine.RegisterEvent(LookForTempRequest, ref unregisterEvents);

            if (macroData.waitOk | macroData.expireTime > 0)
            {
                Button okButton = textImageButtonFactory.Generate("Continue".Localize());

                okButton.Click += (s, e) =>
                {
                    PrinterConnectionAndCommunication.Instance.MacroContinue();
                    UiThread.RunOnIdle(() => WizardWindow?.Close());
                };

                footerRow.AddChild(okButton);
            }

            if (macroData.image != null)
            {
                var imageWidget = new ImageWidget(macroData.image)
                {
                    HAnchor = HAnchor.ParentCenter,
                    Margin  = new BorderDouble(5, 15),
                };

                contentRow.AddChild(imageWidget);
            }

            var holder = new FlowLayoutWidget();

            progressBar = new ProgressBar((int)(150 * GuiWidget.DeviceScale), (int)(15 * GuiWidget.DeviceScale))
            {
                FillColor       = ActiveTheme.Instance.PrimaryAccentColor,
                BorderColor     = ActiveTheme.Instance.PrimaryTextColor,
                BackgroundColor = RGBA_Bytes.White,
                Margin          = new BorderDouble(3, 0, 0, 10),
            };
            progressBarText = new TextWidget("", pointSize: 10, textColor: ActiveTheme.Instance.PrimaryTextColor)
            {
                AutoExpandBoundsToText = true,
                Margin = new BorderDouble(5, 0, 0, 0),
            };
            holder.AddChild(progressBar);
            holder.AddChild(progressBarText);
            contentRow.AddChild(holder);
            progressBar.Visible = false;

            if (macroData.countDown > 0)
            {
                timeToWaitMs = (long)(macroData.countDown * 1000);
                startTimeMs  = UiThread.CurrentTimerMs;
                UiThread.RunOnIdle(CountDownTime);
            }

            footerRow.AddChild(new HorizontalSpacer());
            footerRow.AddChild(cancelButton);
        }
コード例 #6
0
        public ShowAuthPanel()
        {
            WrappedTextWidget userSignInPromptLabel = new WrappedTextWidget("Sign in to access your cloud printer profiles.\n\nOnce signed in you will be able to access:".Localize())
            {
                TextColor = ActiveTheme.Instance.PrimaryTextColor,
            };

            contentRow.AddChild(userSignInPromptLabel);

            AddBulletPointAndDescription(contentRow,
                                         "Cloud Library".Localize(),
                                         "Save your designs to the cloud and access them from anywhere in the world. You can also share them any time with with anyone you want.".Localize());
            AddBulletPointAndDescription(contentRow,
                                         "Cloud Printer Profiles".Localize(),
                                         "Create your machine settings once, and have them available anywhere you want to print. All your changes appear on all your devices.".Localize());
            AddBulletPointAndDescription(contentRow,
                                         "Remote Monitoring".Localize(),
                                         "Check on your prints from anywhere. With cloud monitoring, you have access to your printer no matter where you go.".Localize());

            contentRow.AddChild(new VerticalSpacer());

            CheckBox rememberChoice = new CheckBox("Don't remind me again".Localize(), ActiveTheme.Instance.PrimaryTextColor);

            contentRow.AddChild(rememberChoice);
            rememberChoice.CheckedStateChanged += (s, e) =>
            {
                ApplicationSettings.Instance.set(ApplicationSettingsKey.SuppressAuthPanel, rememberChoice.Checked.ToString());
            };

            var skipButton = textImageButtonFactory.Generate("Skip".Localize());

            skipButton.Name   = "Connection Wizard Skip Sign In Button";
            skipButton.Click += (sender, e) =>
            {
                if (!ProfileManager.Instance.ActiveProfiles.Any())
                {
                    UiThread.RunOnIdle(WizardWindow.ChangeToPage <SetupStepMakeModelName>);
                }
                else
                {
                    UiThread.RunOnIdle(WizardWindow.Close);
                }
            };

            var createAccountButton = textImageButtonFactory.Generate("Create Account".Localize());

            createAccountButton.Name   = "Create Account From Connection Wizard Button";
            createAccountButton.Margin = new Agg.BorderDouble(right: 5);
            createAccountButton.Click += (s, e) =>
            {
                UiThread.RunOnIdle(() =>
                {
                    WizardWindow.Close();
                    WizardWindow.ChangeToAccountCreate();
                });
            };

            var signInButton = textImageButtonFactory.Generate("Sign In".Localize());

            signInButton.Name   = "Sign In From Connection Wizard Button";
            signInButton.Click += (s, e) =>
            {
                UiThread.RunOnIdle(() =>
                {
                    WizardWindow.Close();
                    WizardWindow.ShowAuthDialog?.Invoke();
                });
            };

            footerRow.AddChild(skipButton);
            footerRow.AddChild(new HorizontalSpacer());
            footerRow.AddChild(createAccountButton);
            footerRow.AddChild(signInButton);
        }