public static void Main(string[] args) { MenuContainer container; Menu mainMenu = new Menu("Main menu"); Menu subMenu = new Menu("Sub menu"); Menu subSubMenu = new Menu("sub sub Menu"); IStep turnOnStep = new StepContainer(TurnOn, "Turning On", "Error turning on", "Turned on sucesfully"); IStep turnOffStep = new StepContainer(TurnOff, "Turning Off", "Error turning off"); subSubMenu.AddItem(new ItemWithCheckBoxStep("Turned on", false, "Device", new CheckBoxStep(turnOnStep, turnOffStep), OnTurnOnChanged)); subSubMenu.AddItem(new MonoBrickQuestion()); subSubMenu.AddItem(new ItemWithBrickInfo()); subMenu.AddItem(subSubMenu); subMenu.AddItem(new ItemWithCharacterInput("Name", "Enter Name", "Anders", OnNameChanged, false, true, true)); subMenu.AddItem(new ItemWithNumericInput("Age", 29, OnAgeChanged, 0, 100)); subMenu.AddItem(new ItemWithCheckBox("Loves C#", true, OnCheckedChanged)); mainMenu.AddItem(subMenu); mainMenu.AddItem(new ItemWithProgramList("Programs")); container = new MenuContainer(mainMenu); container.Show(true); }
static bool ShowUpdatesDialogs() { if (WiFiDevice.IsLinkUp()) { var step = new StepContainer( delegate() { try{ return(UpdateAvailable()); } catch { return(false); } }, "Checking server", "No software updates available", "Software update available. Visit monobrick.dk"); var dialog = new ProgressDialog("Updates", step); dialog.Show(); } else { var dialog = new InfoDialog("WiFi device is not pressent", true); dialog.Show(); } return(false); }
private StepBuilder AddStep(string id, StepTypeEnum stepType) { if (_steps.ContainsKey(id)) { throw new ArgumentException($"Step with id={id} already exists"); } var container = new StepContainer(new StepBuilder(this, id), stepType); _steps[id] = container; return(container.Builder); }
static void Main(string[] args) { var step = new StepContainer(StartWebserver, "Starting server", "Failed to start"); Dialog dialog = new ProgressDialog("Webserver", step); if (dialog.Show()) { dialog = new InfoDialog("Press enter to stop", "Webserver"); dialog.Show(); StopWebserver(); } }
static bool ShowWebServerMenu() { List <IMenuItem> items = new List <IMenuItem> (); var portItem = new MenuItemWithNumericInput("Port", settings.WebServerSettings.Port, 1, ushort.MaxValue); portItem.OnValueChanged += delegate(int value) { new Thread(delegate() { settings.WebServerSettings.Port = value; settings.Save(); }).Start(); }; var startItem = new MenuItemWithCheckBox("Start server", WebServer.IsRunning(), delegate(bool running) { bool isRunning = running; if (running) { var step = new StepContainer( delegate() { WebServer.StopAll(); System.Threading.Thread.Sleep(2000); return(true); }, "Stopping", "Failed to stop"); var dialog = new ProgressDialog("Web Server", step); dialog.Show(); isRunning = WebServer.IsRunning(); } else { var step1 = new StepContainer(() => { return(WebServer.StartFastCGI()); }, "Init CGI Server", "Failed to start CGI Server"); var step2 = new StepContainer(() => { return(WebServer.StartLighttpd()); }, "Initializing", "Failed to start server"); var step3 = new StepContainer(() => { return(WebServer.LoadPage()); }, "Loading page", "Failed to load page"); var stepDialog = new StepDialog("Web Server", new List <IStep> { step1, step2, step3 }, "Webserver started"); isRunning = stepDialog.Show(); } return(isRunning); } ); //items.Add(portItem); items.Add(startItem); //Show the menu Menu m = new Menu("Web Server", items); m.Show(); return(false); }
static bool ShowWebServerMenu() { List <IMenuItem> items = new List <IMenuItem> (); var portItem = new MenuItemWithNumericInput("Port", settings.WebServerSettings.Port, 1, ushort.MaxValue); portItem.OnValueChanged += delegate(int value) { new Thread(delegate() { settings.WebServerSettings.Port = value; settings.Save(); }).Start(); }; var startItem = new MenuItemWithCheckBox("Start server", Webserver.Instance.IsRunning, delegate(bool running) { bool isRunning = running; if (running) { var step = new StepContainer( delegate() { Webserver.Instance.Stop(); return(true); }, "Stopping", "Failed to stop"); var dialog = new ProgressDialog("Web Server", step); dialog.Show(); isRunning = Webserver.Instance.IsRunning; } else { var step1 = new StepContainer(() => { Webserver.Instance.Start(portItem.Value); return(true); }, "Starting REST", "Failed To Start REST"); var step2 = new StepContainer(() => { return(Webserver.Instance.LoadPage()); }, "Loading Webpage", "Failed to load page"); var stepDialog = new StepDialog("Web Server", new List <IStep> { step1, step2 }, "Webserver started"); isRunning = stepDialog.Show(); } return(isRunning); } ); //items.Add(portItem); items.Add(startItem); //Show the menu Menu m = new Menu("Web Server", items); m.Show(); return(false); }
public static bool TurnCheckBoxOnOff(bool isChecked) { if (isChecked) { var step = new StepContainer(DummyStep, "Turning off", "Failed to turn off"); var progressDialog = new ProgressDialog("Information", step); progressDialog.Show(); return(false); } else { var dialog = new InfoDialog("Turning On", true); dialog.Show(); return(true); } }
static bool ShowProgramOptions(string programFolder) { string fileName = ""; try { fileName = Directory.EnumerateFiles(programFolder, "*.exe").First(); } catch { var info = new InfoDialog(programFolder + "is not executable", true, "Program"); info.Show(); Directory.Delete(programFolder, true); updateProgramList = true; return(true); } var dialog = new SelectDialog <string> (new string[] { "Run Program", "Debug Program", "Run In AOT", "AOT Compile", "Delete Program", }, "Options", true); dialog.Show(); if (!dialog.EscPressed) { Action programAction = null; switch (dialog.GetSelectionIndex()) { case 0: Lcd.Instance.Clear(); Lcd.Instance.DrawBitmap(monoLogo, new Point((int)(Lcd.Width - monoLogo.Width) / 2, 5)); Rectangle textRect = new Rectangle(new Point(0, Lcd.Height - (int)Font.SmallFont.maxHeight - 2), new Point(Lcd.Width, Lcd.Height - 2)); Lcd.Instance.WriteTextBox(Font.SmallFont, textRect, "Running...", true, Lcd.Alignment.Center); Lcd.Instance.Update(); programAction = () => RunAndWaitForProgram(fileName, ExecutionMode.Normal); break; case 1: programAction = () => RunAndWaitForProgram(fileName, ExecutionMode.Debug); break; case 2: if (!AOTHelper.IsFileCompiled(fileName)) { if (AOTCompileAndShowDialog(programFolder)) { programAction = () => RunAndWaitForProgram(fileName, ExecutionMode.AOT); } } else { programAction = () => RunAndWaitForProgram(fileName, ExecutionMode.AOT); } break; case 3: if (AOTHelper.IsFileCompiled(fileName)) { var questionDialog = new QuestionDialog("Progran already compiled. Recompile?", "AOT recompile"); if (questionDialog.Show()) { AOTCompileAndShowDialog(programFolder); } } else { AOTCompileAndShowDialog(programFolder); } break; case 4: var question = new QuestionDialog("Are you sure?", "Delete"); if (question.Show()) { var step = new StepContainer(() => { Directory.Delete(programFolder, true); return(true); }, "Deleting ", "Error deleting program"); var progressDialog = new ProgressDialog("Program", step); progressDialog.Show(); updateProgramList = true; } break; } if (programAction != null) { Console.WriteLine("Starting application"); programAction(); Console.WriteLine("Done running application"); } return(updateProgramList); } return(false); }
static bool ShowUpdatesDialogs() { if (WiFiDevice.IsLinkUp()) { bool newImage = false; bool newFirmwareApp = false; bool newAddin = false; VersionInfo versionInfo = null; var step = new StepContainer( delegate() { try { versionInfo = VersionHelper.AvailableVersions(); newImage = versionInfo.Image != VersionHelper.CurrentImageVersion(); newFirmwareApp = versionInfo.Fimrware != firmwareVersion; string addInVersion = VersionHelper.CurrentAddInVersion(); if (addInVersion != null) { newAddin = versionInfo.AddIn != VersionHelper.CurrentAddInVersion(); } } catch { return(false); } return(true); }, "Checking server", "Failed to check for Updates"); var dialog = new ProgressDialog("Updates", step); dialog.Show(); if (newImage) { var visitWebsiteDialog = new InfoDialog("New image available. Download it at monobrick.dk", true); visitWebsiteDialog.Show(); } else { if (newFirmwareApp) { var updateQuestion = new QuestionDialog("New firmware available. Update?", "New Fiwmware"); if (updateQuestion.Show()) { var updateHelper = new UpdateHelper(versionInfo.Fimrware); List <IStep> steps = new List <IStep> (); steps.Add(new StepContainer(updateHelper.DownloadFirmware, "Downloading...", "Failed to download files")); steps.Add(new StepContainer(updateHelper.UpdateBootFile, "Updating system", "Failed to update boot file")); var updateDialog = new StepDialog("Updating", steps); if (updateDialog.Show()) { for (int seconds = 10; seconds > 0; seconds--) { var rebootDialog = new InfoDialog("Update completed. Rebooting in " + seconds, false); rebootDialog.Show(); System.Threading.Thread.Sleep(1000); } ProcessHelper.RunAndWaitForProcess("/sbin/shutdown", "-h now"); Thread.Sleep(120000); var whyAreYouHereDialog = new InfoDialog("Cut the power", false, "Reboot failed"); whyAreYouHereDialog.Show(); new ManualResetEvent(false).WaitOne(); } } } else { if (newAddin) { var visitWebsiteDialog = new InfoDialog("New Xamarin Add-in. Download it at monobrick.dk", true); visitWebsiteDialog.Show(); } else { var noUpdateDialog = new InfoDialog("No updates available", true); noUpdateDialog.Show(); } } } } else { var dialog = new InfoDialog("WiFi device is not pressent", true); dialog.Show(); } return(false); }
static bool ShowWiFiMenu() { List <IMenuItem> items = new List <IMenuItem> (); var ssidItem = new MenuItemWithCharacterInput("SSID", "Enter SSID", settings.WiFiSettings.SSID); ssidItem.OnDialogExit += delegate(string text) { new Thread(delegate() { settings.WiFiSettings.SSID = text; settings.Save(); }).Start(); }; var passwordItem = new MenuItemWithCharacterInput("Password", "Password", settings.WiFiSettings.Password, true); passwordItem.OnDialogExit += delegate(string text) { new Thread(delegate() { settings.WiFiSettings.Password = text; settings.Save(); }).Start(); }; var encryptionItem = new MenuItemWithOptions <string>("Encryption", new string[] { "None", "WPA/2" }, settings.WiFiSettings.Encryption ? 1 : 0); encryptionItem.OnOptionChanged += delegate(string newOpstion) { new Thread(delegate() { if (newOpstion == "None") { settings.WiFiSettings.Encryption = false; } else { settings.WiFiSettings.Encryption = true; } settings.Save(); }).Start(); }; var connectItem = new MenuItemWithCheckBox("Connect", WiFiDevice.IsLinkUp(), delegate(bool WiFiOn) { bool isOn = WiFiOn; var createFileStep = new StepContainer ( delegate() { WriteWpaSupplicantConfiguration(settings.WiFiSettings.SSID, settings.WiFiSettings.Password, settings.WiFiSettings.Encryption); return(true); }, "Creating file", "Error creating WPA file" ); var progressDialog = new ProgressDialog("WiFi", createFileStep); progressDialog.Show(); if (WiFiOn) { var turnOffStep = new StepContainer( delegate() { WiFiDevice.TurnOff(); return(true); }, "Turning Off", "Error turning off WiFi", "WiFi Disabled"); var dialog = new ProgressDialog("WiFi", turnOffStep); dialog.Show(); isOn = false; } else { var turnOnStep = new StepContainer( delegate() { return(WiFiDevice.TurnOn(60000)); }, "Connecting", "Failed to connect"); Dialog dialog = new ProgressDialog("WiFi", turnOnStep); if (dialog.Show()) { if (settings.WiFiSettings.ConnectAtStartUp == false) { var question = new QuestionDialog("Do you want to connect at start-up?", "Settings"); if (question.Show()) { new Thread(delegate() { settings.WiFiSettings.ConnectAtStartUp = true; settings.Save(); }).Start(); } } dialog = new InfoDialog("Connected Successfully " + WiFiDevice.GetIpAddress(), true, "WiFi"); dialog.Show(); isOn = true; } else { isOn = false; } } return(isOn); } ); items.Add(ssidItem); items.Add(passwordItem); items.Add(encryptionItem); items.Add(connectItem); //Show the menu Menu m = new Menu("WiFi Connection", items); m.Show(); return(false); }
private static List <MoveWay> AStarSolve(int[] baseOrder, int[] currentOrder) { Step rootNode = new Step(0, baseOrder, currentOrder); Console.Write(new string('\n', 50)); if (currentOrder.SequenceEqual(baseOrder)) { return(null); } StepContainer aStarList = new StepContainer(); StepContainer AddedNodes = new StepContainer(); aStarList.Add(rootNode); List <long> time1 = new List <long>(); List <long> time2 = new List <long>(); Stopwatch w = Stopwatch.StartNew(); int FScore = 0; for (;;) { time1.Add(w.ElapsedMilliseconds); w = Stopwatch.StartNew(); Step bestNodeRoot = aStarList.GetBestAndDeleteNode; NodeTickEvent(null, null); NodeDepthEvent(bestNodeRoot.GetNodeDepth(), null); AddedNodes.Add(bestNodeRoot.GetLast()); time2.Add(w.ElapsedMilliseconds); w = Stopwatch.StartNew(); for (int i = 0; i < 4; i++) { Step newStep = bestNodeRoot.GetLast().Move((MoveWay)i); if (newStep.IsMoved && !AddedNodes.ContainsNode(newStep)) { aStarList.Add(bestNodeRoot.Clone().Add(newStep)); //OutputDebugString($"{"Move "+((MoveWay)i),-18} f({newStep.FScore})=g({newStep.GScore})+h({newStep.FScore-newStep.GScore})"); } else { OutputDebugString($"{"Cannot move " + (MoveWay) i,-18}"); } } //OutputDebugString(new string('-',30)); if (aStarList.IsCompleted()) { break; } } Console.WriteLine("Solve hardness"); Console.WriteLine(time1.Average() / time2.Average()); return(aStarList.GetCompletedRoot().GetSolve().Select(a => a).Reverse().ToList()); }
static bool ShowProgramOptions(ProgramInformation program) { var dialog = new SelectDialog <string> (new string[] { "Run Program", "Run In AOT", "AOT Compile", "Delete Program", }, "Options", true); dialog.Show(); if (!dialog.EscPressed) { Action programAction = null; switch (dialog.GetSelectionIndex()) { case 0: Lcd.Instance.Clear(); Lcd.Instance.DrawBitmap(monoLogo, new Point((int)(Lcd.Width - monoLogo.Width) / 2, 5)); Rectangle textRect = new Rectangle(new Point(0, Lcd.Height - (int)Font.SmallFont.maxHeight - 2), new Point(Lcd.Width, Lcd.Height - 2)); Lcd.Instance.WriteTextBox(Font.SmallFont, textRect, "Running...", true, Lcd.Alignment.Center); Lcd.Instance.Update(); programAction = () => ProgramManager.Instance.StartProgram(program, false); break; case 1: if (!program.IsAOTCompiled) { if (AOTCompileAndShowDialog(program)) { programAction = () => ProgramManager.Instance.StartProgram(program, true); } } else { programAction = () => ProgramManager.Instance.StartProgram(program, true); } break; case 3: if (program.IsAOTCompiled) { var questionDialog = new QuestionDialog("Progran already compiled. Recompile?", "AOT recompile"); if (questionDialog.Show()) { AOTCompileAndShowDialog(program); } } else { AOTCompileAndShowDialog(program); } break; case 4: var question = new QuestionDialog("Are you sure?", "Delete"); if (question.Show()) { var step = new StepContainer(() => { ProgramManager.Instance.DeleteProgram(program); return(true); }, "Deleting ", "Error deleting program"); var progressDialog = new ProgressDialog("Program", step); progressDialog.Show(); updateProgramList = true; } break; } if (programAction != null) { Console.WriteLine("Starting application"); programAction(); Console.WriteLine("Done running application"); } return(updateProgramList); } return(false); }
void InitializeComponent() { SetStyle(ControlStyles.Selectable, false); // the wizard itself can't receive keyboard focus SuspendLayout(); Size = DefaultSize; buttonContainer = new Panel(); // create a panel to hold the buttons buttonContainer.Size = new Size(Width, 38); buttonContainer.Location = new Point(0, Height-buttonContainer.Height); buttonContainer.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; buttonContainer.Name = "buttonContainer"; buttonContainer.TabIndex = 1000; // the tabindex starts at 1000 so the buttons hopefully come last in the tab order buttonContainer.Paint += delegate(object sender, PaintEventArgs e) { OnPaintButtonContainer(e); }; btnBack = new Button(); btnBack.Size = new Size(75, 23); btnBack.Location = new Point(219, (buttonContainer.Height - btnBack.Height + 1) / 2); // center it vertically btnBack.Anchor = AnchorStyles.Right | AnchorStyles.Bottom; btnBack.Text = "< &Back"; btnBack.Name = "btnBack"; btnBack.TabIndex = 1001; btnBack.Click += delegate { OnBackButtonClicked(new CancelEventArgs()); }; btnNext = new Button(); btnNext.Location = new Point(btnBack.Right, btnBack.Top); btnNext.Size = btnBack.Size; btnNext.Anchor = btnBack.Anchor; btnNext.Text = "&Next >"; btnNext.Name = "btnNext"; btnNext.TabIndex = 1002; btnNext.Click += delegate { CancelEventArgs e = new CancelEventArgs(); if(IsFinishStep) OnFinishButtonClicked(e); else OnNextButtonClicked(e); }; btnCancel = new Button(); btnCancel.Location = new Point(btnNext.Right + 7, btnBack.Top); btnCancel.Size = btnBack.Size; btnCancel.Anchor = btnBack.Anchor; btnCancel.Text = "Cancel"; btnCancel.Name = "btnCancel"; btnCancel.TabIndex = 1003; btnCancel.Click += delegate { OnCancelButtonClicked(new CancelEventArgs()); }; btnHelp = new Button(); btnHelp.Location = new Point(btnCancel.Right + 7, btnBack.Top); btnHelp.Size = btnBack.Size; btnHelp.Anchor = btnBack.Anchor; btnHelp.Text = "Help"; btnHelp.Name = "btnHelp"; btnHelp.TabIndex = 1004; btnHelp.Click += delegate { OnHelpButtonClicked(EventArgs.Empty); }; stepContainer = new StepContainer(this); stepContainer.Size = new Size(Width, Height-buttonContainer.Height); stepContainer.Location = new Point(); stepContainer.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top; stepContainer.TabIndex = 0; buttonContainer.Controls.AddRange(new Control[] { btnBack, btnNext, btnCancel, btnHelp }); Controls.AddRange(new Control[] { stepContainer, buttonContainer }); ResumeLayout(); }