Execute() public static method

Scans the supplied (to a directory or assembly) for performance counters and adds/deletes/lists them depending on the .
public static Execute ( ScanMode mode, [ fullPath, bool executeAgain ) : void
mode ScanMode The mode.
fullPath [ The assemblies path.
executeAgain bool if set to execute's again on 64-bit OS.
return void
コード例 #1
0
ファイル: Program.cs プロジェクト: webappsuk/CoreLibraries
        private static void Main(string[] args)
        {
            Logger.AddLogger(
                (s, l) =>
                Console.WriteLine(
                    l == Level.Error || l == Level.Warning
                            ? string.Format("{0}: {1}", l.ToString(), s)
                            : s));
            // Parse options
            try
            {
                Options options = CommandLine.Parse <Options>();
                Debug.Assert(options != null);

                if (options.Help)
                {
                    return;
                }

                ScanMode mode;
                switch ((options.Mode ?? string.Empty).ToLower())
                {
                case "add":
                    mode = ScanMode.Add;
                    break;

                case "delete":
                    mode = ScanMode.Delete;
                    break;

                default:
                    mode = ScanMode.List;
                    break;
                }

                if (options.Path != null &&
                    options.Path.EndsWith("\""))
                {
                    options.Path = options.Path.Substring(0, options.Path.Length - 1);
                }

                Scan.Execute(
                    mode,
                    // ReSharper disable once AssignNullToNotNullAttribute - Let Execute throw
                    options.Path,
                    options.ExecuteAgain);
            }
            catch (CommandLineException commandLineException)
            {
                // ReSharper disable once PossibleNullReferenceException
                Logger.Add(Level.Error, commandLineException.ArgumentHelp.Message);
                Logger.Add(Level.High, commandLineException.ArgumentHelp.GetHelpText(Console.BufferWidth));
            }
            catch (Exception exception)
            {
                Logger.Add(Level.Error, "Fatal error occurred: {0}", exception.Message);
            }
        }
コード例 #2
0
        /// <summary>
        /// When overridden in a derived class, executes the task.
        /// </summary>
        /// <returns>true if the task successfully executed; otherwise, false.</returns>
        public override bool Execute()
        {
            Logger.AddLogger(
                (s, l) =>
            {
                s = "PerfSetup: " + s;
                Debug.Assert(Log != null);
                switch (l)
                {
                case Level.Low:
                    Log.LogMessage(MessageImportance.Low, s);
                    break;

                case Level.Normal:
                    Log.LogMessage(MessageImportance.Normal, s);
                    break;

                case Level.High:
                    Log.LogMessage(MessageImportance.High, s);
                    break;

                case Level.Warning:
                    Log.LogWarning(s);
                    break;

                case Level.Error:
                    Log.LogError(s);
                    break;
                }
            });

            if (string.IsNullOrWhiteSpace(Path))
            {
                Logger.Add(Level.Warning, "Not path supplied to PerfSetup");
            }
            try
            {
                Debug.Assert(Path != null);
                Scan.Execute(ScanMode.Add, Path, true);
                return(true);
            }
            catch (Exception e)
            {
                Logger.Add(Level.Error, e.Message);
                return(false);
            }
        }