コード例 #1
0
ファイル: PSTraceSource.cs プロジェクト: nickchal/pash
 internal PSTraceSource(string fullName, string name, string description, bool traceHeaders)
 {
     if (string.IsNullOrEmpty(fullName))
     {
         throw new ArgumentNullException("fullName");
     }
     try
     {
         this.fullName = fullName;
         this.name = name;
         if (string.Equals(Environment.GetEnvironmentVariable("MshEnableTrace"), "True", StringComparison.OrdinalIgnoreCase))
         {
             string str2 = this.TraceSource.Attributes["Options"];
             if (str2 != null)
             {
                 this.flags = (PSTraceSourceOptions) Enum.Parse(typeof(PSTraceSourceOptions), str2, true);
             }
         }
         this.showHeaders = traceHeaders;
         this.description = description;
     }
     catch (XmlException)
     {
         this.flags = PSTraceSourceOptions.None;
     }
     catch (ConfigurationException)
     {
         this.flags = PSTraceSourceOptions.None;
     }
 }
コード例 #2
0
ファイル: PSTraceSource.cs プロジェクト: modulexcite/pash-1
        private static StringBuilder GetLinePrefix(PSTraceSourceOptions flag)
        {
            StringBuilder builder = new StringBuilder();

            builder.AppendFormat(Thread.CurrentThread.CurrentCulture, " {0,-11} ", new object[] { Enum.GetName(typeof(PSTraceSourceOptions), flag) });
            return(builder);
        }
コード例 #3
0
ファイル: PSTraceSource.cs プロジェクト: modulexcite/pash-1
 internal PSTraceSource(string fullName, string name, string description, bool traceHeaders)
 {
     if (string.IsNullOrEmpty(fullName))
     {
         throw new ArgumentNullException("fullName");
     }
     try
     {
         this.fullName = fullName;
         this.name     = name;
         if (string.Equals(Environment.GetEnvironmentVariable("MshEnableTrace"), "True", StringComparison.OrdinalIgnoreCase))
         {
             string str2 = this.TraceSource.Attributes["Options"];
             if (str2 != null)
             {
                 this.flags = (PSTraceSourceOptions)Enum.Parse(typeof(PSTraceSourceOptions), str2, true);
             }
         }
         this.showHeaders = traceHeaders;
         this.description = description;
     }
     catch (XmlException)
     {
         this.flags = PSTraceSourceOptions.None;
     }
     catch (ConfigurationException)
     {
         this.flags = PSTraceSourceOptions.None;
     }
 }
コード例 #4
0
ファイル: PSTraceSource.cs プロジェクト: mmoenfly/GitCook2021
        private static StringBuilder GetLinePrefix(PSTraceSourceOptions flag)
        {
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.AppendFormat((IFormatProvider)Thread.CurrentThread.CurrentCulture, " {0,-11} ", (object)Enum.GetName(typeof(PSTraceSourceOptions), (object)flag));
            return(stringBuilder);
        }
コード例 #5
0
ファイル: ScopeTracer.cs プロジェクト: mmoenfly/GitCook2021
 internal ScopeTracer(
     PSTraceSource tracer,
     PSTraceSourceOptions flag,
     string scopeOutputFormatter,
     string leavingScopeFormatter,
     string scopeName)
 {
     this._tracer = tracer;
     this.ScopeTracerHelper(flag, scopeOutputFormatter, leavingScopeFormatter, scopeName, "");
 }
コード例 #6
0
ファイル: ScopeTracer.cs プロジェクト: nickchal/pash
 internal ScopeTracer(PSTraceSource tracer, PSTraceSourceOptions flag, string scopeOutputFormatter, string leavingScopeFormatter, string scopeName, string format, params object[] args)
 {
     this._tracer = tracer;
     if (format != null)
     {
         this.ScopeTracerHelper(flag, scopeOutputFormatter, leavingScopeFormatter, scopeName, format, args);
     }
     else
     {
         this.ScopeTracerHelper(flag, scopeOutputFormatter, leavingScopeFormatter, scopeName, "", new object[0]);
     }
 }
コード例 #7
0
ファイル: ScopeTracer.cs プロジェクト: modulexcite/pash-1
 internal ScopeTracer(PSTraceSource tracer, PSTraceSourceOptions flag, string scopeOutputFormatter, string leavingScopeFormatter, string scopeName, string format, params object[] args)
 {
     this._tracer = tracer;
     if (format != null)
     {
         this.ScopeTracerHelper(flag, scopeOutputFormatter, leavingScopeFormatter, scopeName, format, args);
     }
     else
     {
         this.ScopeTracerHelper(flag, scopeOutputFormatter, leavingScopeFormatter, scopeName, "", new object[0]);
     }
 }
コード例 #8
0
ファイル: ScopeTracer.cs プロジェクト: nickchal/pash
 internal void ScopeTracerHelper(PSTraceSourceOptions flag, string scopeOutputFormatter, string leavingScopeFormatter, string scopeName, string format, params object[] args)
 {
     this._flag = flag;
     this._scopeName = scopeName;
     this._leavingScopeFormatter = leavingScopeFormatter;
     StringBuilder builder = new StringBuilder();
     if (!string.IsNullOrEmpty(scopeOutputFormatter))
     {
         builder.AppendFormat(Thread.CurrentThread.CurrentCulture, scopeOutputFormatter, new object[] { this._scopeName });
     }
     if (!string.IsNullOrEmpty(format))
     {
         builder.AppendFormat(Thread.CurrentThread.CurrentCulture, format, args);
     }
     this._tracer.OutputLine(this._flag, builder.ToString(), new object[0]);
     PSTraceSource.ThreadIndentLevel++;
 }
コード例 #9
0
ファイル: ScopeTracer.cs プロジェクト: modulexcite/pash-1
        internal void ScopeTracerHelper(PSTraceSourceOptions flag, string scopeOutputFormatter, string leavingScopeFormatter, string scopeName, string format, params object[] args)
        {
            this._flag                  = flag;
            this._scopeName             = scopeName;
            this._leavingScopeFormatter = leavingScopeFormatter;
            StringBuilder builder = new StringBuilder();

            if (!string.IsNullOrEmpty(scopeOutputFormatter))
            {
                builder.AppendFormat(Thread.CurrentThread.CurrentCulture, scopeOutputFormatter, new object[] { this._scopeName });
            }
            if (!string.IsNullOrEmpty(format))
            {
                builder.AppendFormat(Thread.CurrentThread.CurrentCulture, format, args);
            }
            this._tracer.OutputLine(this._flag, builder.ToString(), new object[0]);
            PSTraceSource.ThreadIndentLevel++;
        }
コード例 #10
0
ファイル: PSTraceSource.cs プロジェクト: modulexcite/pash-1
 private void FormatOutputLine(PSTraceSourceOptions flag, string classFormatter, string format, params object[] args)
 {
     try
     {
         StringBuilder builder = new StringBuilder();
         if (classFormatter != null)
         {
             builder.Append(classFormatter);
         }
         if (format != null)
         {
             builder.AppendFormat(Thread.CurrentThread.CurrentCulture, format, args);
         }
         this.OutputLine(flag, builder.ToString(), new object[0]);
     }
     catch
     {
     }
 }
コード例 #11
0
ファイル: PSTraceSource.cs プロジェクト: mmoenfly/GitCook2021
 internal void OutputLine(PSTraceSourceOptions flag, string format, params object[] args)
 {
     if (this.alreadyTracing)
     {
         return;
     }
     this.alreadyTracing = true;
     try
     {
         StringBuilder lineBuilder = new StringBuilder();
         if (this.showHeaders)
         {
             lineBuilder.Append((object)PSTraceSource.GetLinePrefix(flag));
         }
         PSTraceSource.AddTab(ref lineBuilder);
         if (args != null && args.Length > 0)
         {
             for (int index = 0; index < args.Length; ++index)
             {
                 if (args[index] == null)
                 {
                     args[index] = (object)"null";
                 }
             }
             lineBuilder.AppendFormat((IFormatProvider)Thread.CurrentThread.CurrentCulture, format, args);
         }
         else
         {
             lineBuilder.Append(format);
         }
         this.TraceSource.TraceInformation(lineBuilder.ToString());
     }
     finally
     {
         this.alreadyTracing = false;
     }
 }
コード例 #12
0
ファイル: PSTraceSource.cs プロジェクト: modulexcite/pash-1
 internal void OutputLine(PSTraceSourceOptions flag, string format, params object[] args)
 {
     if (!this.alreadyTracing)
     {
         this.alreadyTracing = true;
         try
         {
             StringBuilder lineBuilder = new StringBuilder();
             if (this.showHeaders)
             {
                 lineBuilder.Append(GetLinePrefix(flag));
             }
             AddTab(ref lineBuilder);
             if ((args != null) && (args.Length > 0))
             {
                 for (int i = 0; i < args.Length; i++)
                 {
                     if (args[i] == null)
                     {
                         args[i] = "null";
                     }
                 }
                 lineBuilder.AppendFormat(Thread.CurrentThread.CurrentCulture, format, args);
             }
             else
             {
                 lineBuilder.Append(format);
             }
             this.TraceSource.TraceInformation(lineBuilder.ToString());
         }
         finally
         {
             this.alreadyTracing = false;
         }
     }
 }
コード例 #13
0
        /// <summary>
        /// Helper for the ScopeTracer constructor
        /// </summary>
        /// 
        /// <param name="flag">
        /// The flag that caused this line of tracing to be traced.
        /// </param>
        /// 
        /// <param name="scopeOutputFormatter">
        /// This format string is used to determine the
        /// general output format for the scope. For instance,
        /// TraceMethod would probably provide a formatter similar
        /// to "Entering: {0}: {1}" where {0} is the name of the
        /// method and {1} is the additional formatted info provided.
        /// </param>
        /// 
        /// <param name="leavingScopeFormatter">
        /// The format string used to determine the general output
        /// format for the scope when the Dispose method is called.
        /// </param>
        /// 
        /// <param name="scopeName">
        /// The name of the scope being entered
        /// </param>
        /// 
        /// <param name="format">
        /// The format of any additional arguments which will be appended
        /// to the "Entering" line of trace output
        /// </param>
        /// 
        /// <param name="args">
        /// Arguments to the format string.
        /// </param>
        /// 
        internal void ScopeTracerHelper(
            PSTraceSourceOptions flag,
            string scopeOutputFormatter,
            string leavingScopeFormatter,
            string scopeName,
            string format,
            params object[] args)
        {
            // Store the flags, scopeName, and the leavingScopeFormatter
            // so that it can be used in the Dispose method

            _flag = flag;
            _scopeName = scopeName;
            _leavingScopeFormatter = leavingScopeFormatter;

            // Format the string for output

            StringBuilder output = new StringBuilder();

            if (!String.IsNullOrEmpty(scopeOutputFormatter))
            {
                output.AppendFormat(
                    CultureInfo.CurrentCulture,
                    scopeOutputFormatter,
                    _scopeName);
            }

            if (!String.IsNullOrEmpty(format))
            {
                output.AppendFormat(
                    CultureInfo.CurrentCulture,
                    format,
                    args);
            }

            // Now write the trace

            _tracer.OutputLine(_flag, output.ToString());

            // Increment the current thread indent level

            PSTraceSource.ThreadIndentLevel++;
        }
コード例 #14
0
        /// <summary>
        /// Constructor that traces the scope name
        /// and raises the indent level in thread
        /// local storage.
        /// </summary>
        /// 
        /// <param name="tracer">
        /// The trace object that is to be used for output
        /// </param>
        /// 
        /// <param name="flag">
        /// The PSTraceSourceOptions that is causing the scope object to 
        /// be created.
        /// </param>
        /// 
        /// <param name="scopeOutputFormatter">
        /// This format string is used to determine the
        /// general output format for the scope. For instance,
        /// TraceMethod would probably provide a formatter similar
        /// to "Entering: {0}: {1}" where {0} is the name of the
        /// method and {1} is the additional formatted info provided.
        /// </param>
        /// 
        /// <param name="leavingScopeFormatter">
        /// The format string used to determine the general output
        /// format for the scope when the Dispose method is called.
        /// </param>
        /// 
        /// <param name="scopeName">
        /// The name of the scope that is being traced
        /// </param>
        /// 
        /// <param name="format">
        /// The format of any additional arguments which will be appended
        /// to the line of trace output
        /// </param>
        /// 
        /// <param name="args">
        /// Arguments to the format string.
        /// </param>
        /// 
        internal ScopeTracer(
            PSTraceSource tracer,
            PSTraceSourceOptions flag,
            string scopeOutputFormatter,
            string leavingScopeFormatter,
            string scopeName,
            string format,
            params object[] args)
        {
            _tracer = tracer;

            // Call the helper

            if (format != null)
            {
                ScopeTracerHelper(
                    flag,
                    scopeOutputFormatter,
                    leavingScopeFormatter,
                    scopeName,
                    format,
                    args);
            }
            else
            {
                ScopeTracerHelper(
                    flag,
                    scopeOutputFormatter,
                    leavingScopeFormatter,
                    scopeName,
                    "");
            }
        }
コード例 #15
0
        /// <summary>
        /// Constructor that traces the scope name
        /// and raises the indent level in thread
        /// local storage.
        /// </summary>
        /// 
        /// <param name="tracer">
        /// The trace object that is to be used for output
        /// </param>
        /// 
        /// <param name="flag">
        /// The PSTraceSourceOptions that is causing the scope object to 
        /// be created.
        /// </param>
        /// 
        /// <param name="scopeOutputFormatter">
        /// This format string is used to determine the
        /// general output format for the scope. For instance,
        /// TraceMethod would probably provide a formatter similar
        /// to "Entering: {0}: {1}" where {0} is the name of the
        /// method and {1} is the additional formatted info provided.
        /// </param>
        /// 
        /// <param name="leavingScopeFormatter">
        /// The format string used to determine the general output
        /// format for the scope when the Dispose method is called.
        /// </param>
        /// 
        /// <param name="scopeName">
        /// The name of the scope that is being traced
        /// </param>
        /// 
        internal ScopeTracer(
            PSTraceSource tracer,
            PSTraceSourceOptions flag,
            string scopeOutputFormatter,
            string leavingScopeFormatter,
            string scopeName)
        {
            _tracer = tracer;

            // Call the helper

            ScopeTracerHelper(
                flag,
                scopeOutputFormatter,
                leavingScopeFormatter,
                scopeName,
                "");
        }
コード例 #16
0
        /// <summary>
        /// Composes a line of trace output and then writes it
        /// </summary>
        /// 
        /// <param name="flag">
        /// The flag that caused the line to be traced
        /// </param>
        /// 
        /// <param name="format">
        /// The string to write with format symbols if necessary
        /// </param>
        /// 
        /// <param name="args">
        /// Arguments to the format string
        /// </param>
        /// 
        /// <remarks>
        /// The line is composed by prefixing the process name, thread ID,
        /// and tick count. Then the indenting is added. Then the
        /// specified string is formatted. Finally the finished string
        /// is output using the Trace class.
        /// </remarks>
        internal void OutputLine(
            PSTraceSourceOptions flag,
            string format,
            params object[] args)
        {
            // if already tracing something for this current TraceSource,
            // dont trace again. This will block cyclic-loops from happening.
            if (_alreadyTracing)
            {
                return;
            }

            _alreadyTracing = true;
            try
            {
                Diagnostics.Assert(
                    format != null,
                    "The format string should not be null");

                StringBuilder lineBuilder = new StringBuilder();

                if (ShowHeaders)
                {
                    // Get the line prefix string which includes things
                    // like App name, clock tick, thread ID, etc.

                    lineBuilder.Append(GetLinePrefix(flag));
                }

                // Add the spaces for the indent

                AddTab(ref lineBuilder);

                if (args != null && args.Length > 0)
                {
                    for (int index = 0; index < args.Length; ++index)
                    {
                        if (args[index] == null)
                        {
                            args[index] = "null";
                        }
                    }

                    lineBuilder.AppendFormat(
                        CultureInfo.CurrentCulture,
                        format,
                        args);
                }
                else
                {
                    lineBuilder.Append(format);
                }

                this.TraceSource.TraceInformation(lineBuilder.ToString());
            }
            finally
            {
                // reset tracing for the current trace source..
                // so future traces can go through.
                _alreadyTracing = false;
            }
        }
コード例 #17
0
        private static StringBuilder GetLinePrefix(PSTraceSourceOptions flag)
        {
            StringBuilder prefixBuilder = new StringBuilder();

            // Add the flag that caused this line to be traced

            prefixBuilder.AppendFormat(
                CultureInfo.CurrentCulture,
                " {0,-11} ",
                Enum.GetName(typeof(PSTraceSourceOptions), flag));
            return prefixBuilder;
        }
コード例 #18
0
        /// <summary>
        /// Formats the specified text and then traces it
        /// </summary>
        /// 
        /// <param name="flag">
        /// The flag that met the criteria to have this line traced.
        /// </param>
        /// 
        /// <param name="classFormatter">
        /// This is the trace class formatter. For instance,
        /// TraceError has a formatter like "ERROR: {0}"
        /// </param>
        /// 
        /// <param name="format">
        /// Additional format string
        /// </param>
        /// 
        /// <param name="args">
        /// Arguments for the additional format string
        /// </param>
        /// 
        private void FormatOutputLine(
            PSTraceSourceOptions flag,
            string classFormatter,
            string format,
            params object[] args)
        {
            try
            {
                // First format the class format string and the
                // user provided format string together

                StringBuilder output = new StringBuilder();

                if (classFormatter != null)
                {
                    output.Append(classFormatter);
                }

                if (format != null)
                {
                    output.AppendFormat(
                        CultureInfo.CurrentCulture,
                        format,
                        args);
                }

                // finally trace the output

                OutputLine(flag, output.ToString());
            }
            catch
            {
                // Eat all exceptions

                // Do not assert here because exceptions can be
                // raised while a thread is shutting down during
                // normal operation.
            }
        }
コード例 #19
0
ファイル: ScopeTracer.cs プロジェクト: nickchal/pash
 internal ScopeTracer(PSTraceSource tracer, PSTraceSourceOptions flag, string scopeOutputFormatter, string leavingScopeFormatter, string scopeName)
 {
     this._tracer = tracer;
     this.ScopeTracerHelper(flag, scopeOutputFormatter, leavingScopeFormatter, scopeName, "", new object[0]);
 }
コード例 #20
0
ファイル: PSTraceSource.cs プロジェクト: nickchal/pash
 private void FormatOutputLine(PSTraceSourceOptions flag, string classFormatter, string format, params object[] args)
 {
     try
     {
         StringBuilder builder = new StringBuilder();
         if (classFormatter != null)
         {
             builder.Append(classFormatter);
         }
         if (format != null)
         {
             builder.AppendFormat(Thread.CurrentThread.CurrentCulture, format, args);
         }
         this.OutputLine(flag, builder.ToString(), new object[0]);
     }
     catch
     {
     }
 }
コード例 #21
0
ファイル: PSTraceSource.cs プロジェクト: nickchal/pash
 internal void OutputLine(PSTraceSourceOptions flag, string format, params object[] args)
 {
     if (!this.alreadyTracing)
     {
         this.alreadyTracing = true;
         try
         {
             StringBuilder lineBuilder = new StringBuilder();
             if (this.showHeaders)
             {
                 lineBuilder.Append(GetLinePrefix(flag));
             }
             AddTab(ref lineBuilder);
             if ((args != null) && (args.Length > 0))
             {
                 for (int i = 0; i < args.Length; i++)
                 {
                     if (args[i] == null)
                     {
                         args[i] = "null";
                     }
                 }
                 lineBuilder.AppendFormat(Thread.CurrentThread.CurrentCulture, format, args);
             }
             else
             {
                 lineBuilder.Append(format);
             }
             this.TraceSource.TraceInformation(lineBuilder.ToString());
         }
         finally
         {
             this.alreadyTracing = false;
         }
     }
 }
コード例 #22
0
ファイル: PSTraceSource.cs プロジェクト: nickchal/pash
 private static StringBuilder GetLinePrefix(PSTraceSourceOptions flag)
 {
     StringBuilder builder = new StringBuilder();
     builder.AppendFormat(Thread.CurrentThread.CurrentCulture, " {0,-11} ", new object[] { Enum.GetName(typeof(PSTraceSourceOptions), flag) });
     return builder;
 }