private bool CreateConfigFile(string dllName, string hailMessage, string appName, int port, string fileName) { if (!dllName.Contains(".dll")) { dllName += ".dll"; } ConfigInformation info = new ConfigInformation(dllName, hailMessage, appName, port); if (fileName.Length == 0) { return(false); } using (StreamWriter sw = new StreamWriter(fileName + ".config", false)) { try { string xmlString = Serializer <GladNetXmlSerializer> .Instance.SerializeToString(info); sw.Write(xmlString); } catch (LoggableException e) { MessageBox.Show(this, "Encountered Error: " + e.Message + e.InnerException != null ? e.InnerException.Message : ""); return(false); } } MessageBox.Show(Owner, "Config file was successfully created in the root director named: " + fileNameText.Text + ".config", "Creation Result"); return(true); }
//DLLNAME APPNAME HAILMESSAGE PORT PIPEHANDLE public ServerProcess(string path, ConfigInformation info) { serverBroadcastingPipe = new AnonymousPipeServerStream(PipeDirection.Out, System.IO.HandleInheritability.Inheritable); serverStreamWriter = new StreamWriter(serverBroadcastingPipe); try { Config = info; string clientString = serverBroadcastingPipe.GetClientHandleAsString(); ApplicationProcess = Process.Start(new ProcessStartInfo() { Arguments = Config.DLLName + " " + Config.ApplicationName + " " + Config.HailMessage + " " + Config.Port.ToString() + " " + clientString, UseShellExecute = false, FileName = path }); UniqueProcessID = ApplicationProcess.Id; ApplicationProcess.EnableRaisingEvents = true; ApplicationProcess.Exited += new EventHandler(OnExit); } catch (NullReferenceException e) { MessageBox.Show(e.Message + " " + e.Data + e.StackTrace); } }
private void AddNewConfigToList(ConfigInformation config, string configFileName) { if (ConfigDictionary.ContainsKey(configFileName)) { MessageBox.Show(this, "You've already loaded this config file.", "Open Result"); } else { this.ConfigDictionary.Add(configFileName, config); this.configList.Clear(); foreach (var kp in ConfigDictionary) { configList.Items.Add(kp.Key); } } }
private void StartServer(string configKey) { //Should exist ConfigInformation info = this.ConfigDictionary[configKey]; ServerProcess sProcess = new ServerProcess("ServerLoader.exe", info); //Remove the sever process from the process list on exited. sProcess.OnExited += () => { StopServerProcess(sProcess); ServerProcess proc; ServerProcesses.TryRemove(sProcess.UniqueProcessID, out proc); this.UpdateProcessList(); sProcess.Dispose(); }; this.ServerProcesses.TryAdd(sProcess.UniqueProcessID, sProcess); this.UpdateProcessList(); }