public ManagerMDI(string[] args) { InitializeComponent(); LocalFileList.Columns.Add("Timestamp", Type.GetType("System.DateTime")); LocalFileList.Columns.Add("FileName", Type.GetType("System.String")); BOG.Framework.AssemblyVersion a = new BOG.Framework.AssemblyVersion(System.Reflection.Assembly.GetEntryAssembly()); _ExecutablePath = a.FullPath.Substring(0, a.FullPath.Length - a.Name.Length); _HelpURL = Path.Combine(_ExecutablePath, "WeedKillerHelp.htm"); _ConfigurationPath = Path.Combine(Path.Combine(System.Environment.GetEnvironmentVariable("APPDATA"), "Bits of Genius"), "Weed Killer Manager"); _ConfigurationFile = Path.Combine(_ConfigurationPath, "usersettings.xml"); _DefaultConfigurationFile = Path.Combine(_ExecutablePath, "default_usersettings.xml"); _StorageFolder = Environment.GetFolderPath(Environment.SpecialFolder.Personal); try { if (!File.Exists(_ConfigurationFile) && File.Exists(_DefaultConfigurationFile)) { File.Copy(_DefaultConfigurationFile, _ConfigurationFile); } } catch { } _AppSettings = new SettingsDictionary(_ConfigurationFile); _AppSettings.LoadSettings(); LoadOptions(); string FileName = string.Empty; for (int i = 0; i < 100 && (FileName = (string)_AppSettings.GetSetting(string.Format("Recovery{0:0#}", i), string.Empty)) != string.Empty; i++) { if (File.Exists(FileName)) { string NewFileName = string.Empty; // a file which was previously saved, but was not current at the time of closing. if (FileName.Length >= 13 && FileName.Substring(FileName.Length - 13, 13).ToLower() == ".recovery.wkconf") { NewFileName = FileName.Substring(0, FileName.Length - 13); } OpenFile(FileName); Application.DoEvents(); SetEditor ChildForm = (SetEditor)this.MdiChildren[this.MdiChildren.GetUpperBound(0)]; ChildForm.ConfigurationFilePath = NewFileName; ChildForm.Saved = false; ChildForm.Text = ChildForm.ConfigurationFilePath == string.Empty ? "Untitled" : Path.GetFileNameWithoutExtension(NewFileName); File.Delete(FileName); } _AppSettings.DeleteSetting(string.Format("Recovery{0:0#}", i)); } _AppSettings.SaveSettings(); // If the command line is not empty, treat each argument as a configuration file, // and open the file. This allows files to be opened from the explorer extension // "Open" for (int Index = 0; args != null && Index < args.Length; Index++) { if (args[Index].IndexOfAny(new char[] { '*', '?' }) < 0 && !File.Exists(args[Index])) { MessageBox.Show(string.Format("Non-existent file specific on command line: {0}", args[Index]), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { foreach (string ThisFileName in Directory.GetFiles(Path.GetDirectoryName(args[Index]), Path.GetFileName(args[Index]), SearchOption.TopDirectoryOnly)) { OpenFile(ThisFileName); if (this.MdiChildren.Length > 0) { Application.DoEvents(); SetEditor ChildForm = (SetEditor)this.MdiChildren[this.MdiChildren.GetUpperBound(0)]; if (ChildForm.ConfigurationFilePath == ThisFileName) { ChildForm.Saved = true; ChildForm.Text = Path.GetFileNameWithoutExtension(ThisFileName); } } } } } LoadMRU(); AdjustMenu(); this.toolStripStatusLabel.Text = "Ready"; }
static void Main(string[] args) { System.Environment.ExitCode = 1; AssemblyVersion av = new BOG.Framework.AssemblyVersion(System.Reflection.Assembly.GetExecutingAssembly()); Console.WriteLine("{0} -- v{1}, {2}\r\n(c) 2009-2015, John J Schultz, usage restricted to terms of the Microsoft Public License\r\nProject page: http://www.sourceforge.net/projects/weedkiller\r\n", av.Name, av.Version, av.BuildDate); try { ParseArguments(args); } catch (Exception e) { Console.WriteLine(DetailedException.WithMachineContent(ref e)); System.Environment.ExitCode = 0; } if (System.Environment.ExitCode == 1) { try { string ServerName = System.Environment.GetEnvironmentVariable("COMPUTERNAME"); foreach (string ConfigFile in ConfigFiles) { Console.WriteLine(); Console.WriteLine("========================================================================"); Console.WriteLine("config file: {0}", ConfigFile); config = ObjectXMLSerializer <BOG.WeedKiller.WeedKillerConfigSet> .LoadDocumentFormat(ConfigFile); Console.WriteLine(" created: {0:F}", config.Created); Console.WriteLine(" updated: {0:F}", config.Updated); Console.WriteLine(" servers: {0}", config.ExecutionServer.Length == 0 ? "{any}" : config.ExecutionServer); if (config.ConfigSet.Count == 0) { Console.WriteLine(); Console.WriteLine("?? There are no entries in this configuration file ??"); } else if (config.ExecutionServer.Length > 0 && ("," + config.ExecutionServer.ToLower() + ",").IndexOf(ServerName.ToLower()) == -1) { Console.WriteLine(); Console.WriteLine("This configuration set can not run on this server {0}: skipping the file.", ServerName); } else { Console.WriteLine("========================================================================"); foreach (WeedKillerConfig parameters in config.ConfigSet) { string OriginalRoot = parameters.RootFolder; // preservers the <SERVER> placeholder, if present parameters.TestOnly |= TestingMode; if (!parameters.Enabled) { Console.WriteLine(); Console.WriteLine(".. skipping disabled process: {0}", parameters.Description); } else { // The foreach will only execute once if Server List is empty, or the <SERVER> placeholder is not present. foreach (string servername in parameters.ServerList.Split(new char[] { ',', '|', ' ' }, StringSplitOptions.None)) { if (parameters.ServerList != string.Empty && (OriginalRoot.IndexOf("<SERVER>") > -1 || OriginalRoot.IndexOf("<server>") > -1) && servername.Trim() == string.Empty) { continue; } Console.WriteLine("\r\n-- Process: {0}", parameters.Description); if (parameters.ServerList != string.Empty && (OriginalRoot.IndexOf("<SERVER>") > -1 || OriginalRoot.IndexOf("<server>") > -1)) { Console.WriteLine(); Console.WriteLine("-- Server: {0}", servername); parameters.RootFolder = OriginalRoot.Replace("<SERVER>", servername.Trim()); if (parameters.RootFolder == OriginalRoot) { parameters.RootFolder = OriginalRoot.Replace("<server>", servername.Trim()); } } WeedKiller worker = new WeedKiller(); try { worker.WeedKillerEvent += new WeedKillerEventHandler(WeedKillerEventProcessor); worker.KillWeeds(parameters); } catch (Exception e) { Console.WriteLine(DetailedException.WithMachineContent(ref e)); } finally { try { worker.WeedKillerEvent -= new WeedKillerEventHandler(WeedKillerEventProcessor); } finally { } } } } } } } } catch (Exception e) { Console.WriteLine(DetailedException.WithMachineContent(ref e)); System.Environment.ExitCode = 0; } } #if DEBUG Console.WriteLine("\r\nExit Code: {0}", System.Environment.ExitCode); Console.WriteLine("Code execution complete... press ENTER"); Console.ReadLine(); #endif System.Environment.Exit(System.Environment.ExitCode); }
private void EstablishListener() { if (System.Configuration.ConfigurationManager.AppSettings["BabbleOn.LowPort"] != null) { if (int.TryParse(System.Configuration.ConfigurationManager.AppSettings["BabbleOn.LowPort"], out _LowListenPort) == false) { throw new Exception("The value for AppSettings key \"BabbleOn.LowPort\" does not contain a valid integer value."); } if (_LowListenPort < 1 || _LowListenPort >= 65535) { throw new Exception("The port number in AppSettings key \"BabbleOn.LowPort\" is not in the range 1 < x < 65535"); } if (int.TryParse(System.Configuration.ConfigurationManager.AppSettings["BabbleOn.HighPort"], out _HighListenPort) == false) { throw new Exception("The value for AppSettings key \"BabbleOn.HighPort\" does not contain a valid integer value."); } if (_HighListenPort < 1 || _HighListenPort >= 65535) { throw new Exception("The port number in AppSettings key \"BabbleOn.HighPort\" is not in the range 1 < x < 65535"); } if (_LowListenPort > _HighListenPort) { int t = _LowListenPort; _LowListenPort = _HighListenPort; _HighListenPort = t; } } for (_ListeningPort = _LowListenPort; _ListeningPort <= _HighListenPort; _ListeningPort++) { try { this.MyTcpListener = new TcpListener(IPAddress.Any, _ListeningPort); this.MyTcpListener.ExclusiveAddressUse = true; this.MyTcpListener.Start(); this.MyTcpListener.Stop(); this.MyListenThread = new Thread(new ThreadStart(ListenForClients)); this.MyListenThread.Start(); Running = true; break; } catch (SocketException) { // this is the only error we trap and ignore. } } if (Running == false) { throw new Exception(string.Format( "BabbleOn was not able to find an available port for the listener in the range {0} .. {1}", _LowListenPort, _HighListenPort)); } AssemblyVersion a = new AssemblyVersion(true); System.Diagnostics.Process p = System.Diagnostics.Process.GetCurrentProcess(); // build a signal string, which is $/App Signature/Process ID/Base Priority/MaxConnections/$ // E.g. // $/MyDomain.MyApp.MyService/2380/80/5/$ // This is used by the BabbleFinder app to build a list of available babble channels, when it is not // given a specific port to connect to. _appSignature = string.Format( "#APP: $/{0}/{1}/{2}/{3}/{4:u}/$\r\n", a.Name, p.Id, p.BasePriority, _MaxListeners, StartTime); }