コード例 #1
0
ファイル: SetTester.cs プロジェクト: rambotech/BOG.Weedkiller
        private void BackgroundWorkerStarts()
        {
            BackgroundWorkerIsProcessing = true;
            OriginalText = this.btnLaunch.Text;
            workset      = _c;
            this.lblWaitMessage.Refresh();

            workset.TestOnly = this.chkForceTestMode.Checked ? true : workset.TestOnly;

            this.btnLaunch.Enabled = false;
            this.btnLaunch.Text    = "Processing...";
            this.txtResults.Text   = string.Format("Start Time: {0:F}\r\n\r\n", DateTime.Now);
            FileEventResults.Clear();
            this.dgvFileResults.Rows.Clear();
            this.chkForceTestMode.Enabled     = false;
            this.chkStopAfter.Enabled         = false;
            this.tbarStopAfter.Enabled        = false;
            this.cbxlEventsOfInterest.Enabled = false;
            this.btnAdjustColorBG.Enabled     = false;
            this.btnAdjustColorFG.Enabled     = false;
            this.btnClearAll.Enabled          = false;
            this.btnInvertAll.Enabled         = false;
            this.btnSelectAll.Enabled         = false;
            this.cbxTemplateName.Enabled      = false;
            this.btnSaveTemplate.Enabled      = false;
            this.btnDropTemplate.Enabled      = false;
            this.Refresh();

            string OriginalRoot = workset.RootFolder;

            if (!workset.Enabled)
            {
                AppendToScrollingTextbox(ref this.txtResults, "*** WARNING: The process is set to disabled... forcing test mode to on.\r\n");
                workset.TestOnly = true;
            }

            AppendToScrollingTextbox(ref this.txtResults, string.Format("\r\n-- Process: {0}\r\n", workset.Description));

            worker         = new WeedKiller();
            ItemEventCount = 0;
        }
コード例 #2
0
        private void btnApply_Click(object sender, EventArgs e)
        {
            if (this.txtNTAccount.Text.Trim().Length == 0)
            {
                MessageBox.Show("Please enter the name of the account", "No account specified", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            this.btnApply.Enabled = false;
            this.txtResults.Text  = "Applying permission changes...";
            this.Refresh();

            WeedKiller worker = new WeedKiller();

            try
            {
                worker.WeedKillerEvent += new WeedKillerEventHandler(WeedKillerEventProcessor);
                foreach (WeedKillerConfig w in cs.ConfigSet)
                {
                    AppendToScrollingTextbox(ref this.txtResults, "\r\n--> " + w.Description);
                    worker.KillWeeds(w);
                }
            }
            catch (Exception ex)
            {
                AppendToScrollingTextbox(ref this.txtResults, "\r\n" + DetailedException.WithMachineContent(ref ex));
            }
            finally
            {
                try
                {
                    worker.WeedKillerEvent -= new WeedKillerEventHandler(WeedKillerEventProcessor);
                }
                finally
                {
                }
            }
            this.btnApply.Enabled = true;
        }
コード例 #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);
        }
コード例 #4
0
        public void DoWork()
        {
            WeedKillerConfig config = new WeedKillerConfig();

            config.Description = "not needed in local applications";
            config.Enabled     = true;
            config.RootFolder  = Environment.GetFolderPath(Environment.SpecialFolder.Cookies);

            // for regular expressions
            config.FilePattern            = @"domain_.+\.cookie"; // would match the pattern domain_*.cookie
            config.FilePattern_Evaluation = WeedKillerConfig.ExpressionEvaluation.RegularExpression;
            // for legacy wildcard patterns
            config.FilePattern            = @"domain_*.cookie"; // would match the pattern domain_*.cookie
            config.FilePattern_Evaluation = WeedKillerConfig.ExpressionEvaluation.Wildcards;

            // for regular expressions
            config.SubFolderPattern       = ".+";
            config.FilePattern_Evaluation = WeedKillerConfig.ExpressionEvaluation.RegularExpression;
            // for legacy wildcard patterns
            config.SubFolderPattern       = "*.*";
            config.FilePattern_Evaluation = WeedKillerConfig.ExpressionEvaluation.Wildcards;

            config.FileEval       = WeedKillerConfig.FileDateEvaluation.Created;
            config.AgeMetric      = 30;
            config.AgeMeasureUnit = WeedKillerConfig.AgeUnitOfMeasure.Days;
            config.ServerList     = string.Empty;

            config.Aggressive            = true;
            config.IgnoreZeroLength      = false;
            config.MinimumRetentionCount = 1;
            config.MaximumRetentionCount = 2000;
            config.RecurseSubFolders     = true;
            config.SubFoldersOnly        = false;
            config.RemoveEmptyFolders    = false;
            config.TestOnly = true;

            WeedKiller worker = new WeedKiller();

            try
            {
                if (WantEvents)
                {
                    worker.WeedKillerEvent += new WeedKillerEventHandler(WeedKillerEventProcessor);
                }
                worker.KillWeeds(config);
            }
            catch
            {
                // handle your exception here.
            }
            finally
            {
                try
                {
                    if (WantEvents)
                    {
                        worker.WeedKillerEvent -= new WeedKillerEventHandler(WeedKillerEventProcessor);
                    }
                }
                finally
                {
                }
            }
        }