Exemple #1
0
        private void btnLoadDocumentXML_Click(object sender, EventArgs e)
        {
            this.lblFileSizeXML.Text = "Deserializing the XML file";
            AbortRequested           = false;
            ObjectEnabling(false);

            MassiveReadXML = ObjectXMLSerializer <SerializableDictionary <int, SerializableDictionary <int, string> > > .LoadDocumentFormat(this.lblFileNameXML.Text);

            this.lblFileSizeXML.Text = "Comparing deserialized XML file content against original";
            this.lblFileSizeXML.Refresh();
            if (!CompareMassiveXMLs())
            {
                MessageBox.Show("The XML deserialized object does not match the original.");
            }
            MassiveReadXML           = null;
            this.lblFileSizeXML.Text = "Deserializing the XML GZ file";
            this.lblFileSizeXML.Refresh();
            MassiveReadXML = ObjectXMLSerializer <SerializableDictionary <int, SerializableDictionary <int, string> > > .LoadCompressedDocumentFormat(this.lblFileNameXML.Text + ".gz");

            this.lblFileSizeXML.Text = "Comparing deserialized XML GZ file content against original";
            this.lblFileSizeXML.Refresh();
            if (!CompareMassiveXMLs())
            {
                MessageBox.Show("The XML GZ deserialized object does not match the original.");
            }
            this.lblFileSizeXML.Text = "Forcing garbage collection";
            this.lblFileSizeXML.Refresh();
            MassiveReadXML           = null;
            this.lblFileSizeXML.Text = "Idle";
            ObjectEnabling(true);
        }
        public void LoadFromFile()
        {
            try
            {
                cs = ObjectXMLSerializer <WeedKillerConfigSet> .LoadDocumentFormat(_ConfigurationFilePath);

                this.lvwConfigSet.Items.Clear();
                foreach (WeedKillerConfig c in cs.ConfigSet)
                {
                    ListViewItem i = new ListViewItem(c.Description);
                    i.Tag   = c;
                    i.Group = new ListViewGroup("Configuration Set");
                    this.lvwConfigSet.Items.Add(i);
                    AdjustListViewItemColor(this.lvwConfigSet.Items.Count - 1);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(string.Format("Error loading configuration from file: {0}", e.Message), "Can't load file", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            this.Text = Path.GetFileNameWithoutExtension(_ConfigurationFilePath);
            this.lvwConfigSet.Sort();
        }
Exemple #3
0
        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);
        }
Exemple #4
0
 static void ParseArguments(string[] args)
 {
     foreach (string s in args)
     {
         // switch
         if (s.Substring(0, 1) == "/")
         {
             if (s.Length == 1)
             {
                 throw new Exception("Incomplete switch");
             }
             string[] sx = s.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
             if (sx.Length > 2)
             {
                 throw new Exception(string.Format("Invalid switch: {0}", s));
             }
             sx[0] = sx[0].ToLower();
             if ((sx[0] == "/test" || sx[0] == "/t") && sx.Length == 1)
             {
                 TestingMode = true;
             }
             else if ((sx[0] == "/short" || sx[0] == "/s") && sx.Length == 1)
             {
                 ShortForm    = true;
                 LoggingLevel = 0;
             }
             else if ((sx[0] == "/counts" || sx[0] == "/c") && sx.Length == 1)
             {
                 IncludeStats = true;
             }
             else if ((sx[0] == "/logging_level" || sx[0] == "/l") && sx.Length == 2)
             {
                 if (!ShortForm)
                 {
                     if (int.TryParse(sx[1], out LoggingLevel))
                     {
                         if (LoggingLevel < 0 || LoggingLevel > 3)
                         {
                             throw new ArgumentException(string.Format("Invalid logging level: {0}.  Value must be 0 through 3", sx[1]));
                         }
                     }
                     else
                     {
                         throw new ArgumentException(string.Format("Invalid logging level specifier: {0}", sx[1]));
                     }
                 }
             }
             else if ((sx[0] == "/permission+" || sx[0] == "/p+") && sx.Length == 2)
             {
                 SetPermissions = true;
                 if (RemovePermissions)
                 {
                     throw new ArgumentException("Only /p+ or /p- can be specified: not both");
                 }
                 NTaccount = sx[1];
             }
             else if ((sx[0] == "/permission-" || sx[0] == "/p-") && sx.Length == 2)
             {
                 RemovePermissions = true;
                 if (SetPermissions)
                 {
                     throw new ArgumentException("Only /p+ or /p- can be specified: not both");
                 }
                 NTaccount = sx[1];
             }
             else
             {
                 throw new ArgumentException(string.Format("Unrecognized switch: {0}", s));
             }
         }
         else // the configuration object, saved as a file.
         {
             if (s.IndexOfAny(new char[] { '*', '?' }) < 0 && !File.Exists(s))
             {
                 throw new ArgumentException(string.Format("Configuration file does not exist: {0}", s));
             }
             string DirPart  = Path.GetDirectoryName(s);
             string FilePart = Path.GetFileName(s);
             foreach (string FileName in Directory.GetFiles(Path.GetDirectoryName(string.IsNullOrEmpty(DirPart) ? "." : DirPart), Path.GetFileName(FilePart), SearchOption.TopDirectoryOnly))
             {
                 try
                 {
                     config = ObjectXMLSerializer <BOG.WeedKiller.WeedKillerConfigSet> .LoadDocumentFormat(FileName);
                 }
                 catch (Exception ex)
                 {
                     throw new ArgumentException(string.Format("error reading content from configuration file: {0}", FileName), ex);
                 }
                 ConfigFiles.Add(FileName);
             }
         }
     }
 }