protected override Result RunCommand(RhinoDoc doc, RunMode mode) { if (!(RhinoApp.GetPlugInObject("Grasshopper") is GH_RhinoScriptInterface Grasshopper)) { return(Result.Cancel); } GetOption go = null; while (true) { var port = new OptionInteger(Port, 1024, 65535); var toggle = new OptionToggle(ShowEditor, "Hide", "Show"); var debugger = new OptionToggle(Debug, "Off", "On"); go = new GetOption(); go.SetCommandPrompt("Noah Server"); go.AddOption("Connect"); go.AddOption("Stop"); go.AddOption("Observer"); go.AddOptionInteger("Port", ref port); go.AddOptionToggle("Editor", ref toggle); go.AddOptionToggle("Debug", ref debugger); go.AddOption("Workspace"); GetResult result = go.Get(); if (result != GetResult.Option) { break; } ShowEditor = toggle.CurrentValue; Debug = debugger.CurrentValue; string whereToGo = go.Option().EnglishName; if (whereToGo == "Connect") { if (Port == 0) { RhinoApp.WriteLine("Please set Port you want to connect!"); continue; } if (WorkDir == null) { RhinoApp.WriteLine("Noah can not work without workspace!"); continue; } if (Client == null) { try { Grasshopper.DisableBanner(); if (!Grasshopper.IsEditorLoaded()) { Grasshopper.LoadEditor(); } Client = new NoahClient(Port, WorkDir); Client.InfoEvent += Client_MessageEvent; Client.ErrorEvent += Client_ErrorEvent; Client.WarningEvent += Client_WarningEvent; Client.DebugEvent += Client_DebugEvent; } catch (Exception ex) { RhinoApp.WriteLine("Error: " + ex.Message); } Client.Connect(); } else { Client.Reconnect(); } if (Debug) { try { if (Logger == null) { Panels.OpenPanel(LoggerPanel.PanelId); } Logger = Panels.GetPanel <LoggerPanel>(doc); } catch (Exception ex) { RhinoApp.WriteLine("Error: " + ex.Message); } } if (ShowEditor) { Grasshopper.ShowEditor(); } break; } if (whereToGo == "Stop") { if (Port == 0) { continue; } if (Client != null) { Client.Close(); } break; } if (whereToGo == "Workspace") { RhinoGet.GetString("Noah Workspace", false, ref WorkDir); } if (whereToGo == "Observer") { if (Port == 0) { RhinoApp.WriteLine("Server connecting need a port!"); continue; } Process.Start("http://localhost:" + Port + "/data/center"); break; } if (whereToGo == "Port") { Port = port.CurrentValue; RhinoApp.WriteLine("Port is set to " + Port.ToString()); continue; } } return(Result.Nothing); }