Esempio n. 1
0
        /// <summary>
        /// </summary>
        static public string DescribeTarget(DependencyObject targetElement, DependencyProperty targetProperty)
        {
            AvTraceBuilder atb = new AvTraceBuilder(null);

            DescribeTarget(atb, targetElement, targetProperty);
            return(atb.ToString());
        }
Esempio n. 2
0
        /// <summary>
        /// </summary>
        static public string DescribeSourceObject(object o)
        {
            AvTraceBuilder atb = new AvTraceBuilder(null);

            DescribeSourceObject(atb, o);
            return(atb.ToString());
        }
Esempio n. 3
0
 /// <summary>
 /// </summary>
 static public string DescribeTarget(DependencyObject targetElement, DependencyProperty targetProperty)
 {
     AvTraceBuilder atb = new AvTraceBuilder(null);
     DescribeTarget(atb, targetElement, targetProperty);
     return atb.ToString();
 }
Esempio n. 4
0
 /// <summary>
 /// </summary>
 static public string DescribeSourceObject(object o)
 {
     AvTraceBuilder atb = new AvTraceBuilder(null);
     DescribeSourceObject(atb, o);
     return atb.ToString();
 }
Esempio n. 5
0
        //
        //  Trace an event
        //
        //  note: labels start at index 1, parameters start at index 0
        //

        public void Trace(TraceEventType type, int eventId, string message, string[] labels, object[] parameters)
        {
            // Don't bother building the string if this trace is going to be ignored.

            if (_traceSource == null ||
                !_traceSource.Switch.ShouldTrace(type))
            {
                return;
            }


            // Compose the trace string.

            AvTraceBuilder traceBuilder = new AvTraceBuilder(AntiFormat(message)); // Holds the format string
            ArrayList      arrayList    = new ArrayList();                         // Holds the combined labels & parameters arrays.

            int formatIndex = 0;

            if (parameters != null && labels != null && labels.Length > 0)
            {
                int i = 1, j = 0;
                for ( ; i < labels.Length && j < parameters.Length; i++, j++)
                {
                    // Append to the format string a "; {0} = '{1}'", where the index increments (e.g. the second iteration will
                    // produce {2} & {3}).

                    traceBuilder.Append("; {" + (formatIndex++).ToString() + "}='{" + (formatIndex++).ToString() + "}'");

                    // If this parameter is null, convert to "<null>"; otherwise, when a string.format is ultimately called
                    // it produces bad results.

                    if (parameters[j] == null)
                    {
                        parameters[j] = "<null>";
                    }

                    // Otherwise, if this is an interesting object, add the hash code and type to
                    // the format string explicitely.

                    else if (!SuppressGeneratedParameters &&
                             parameters[j].GetType() != typeof(string) &&
                             !(parameters[j] is ValueType) &&
                             !(parameters[j] is Type) &&
                             !(parameters[j] is DependencyProperty))
                    {
                        traceBuilder.Append("; " + labels[i].ToString() + ".HashCode='"
                                            + GetHashCodeHelper(parameters[j]).ToString() + "'");

                        traceBuilder.Append("; " + labels[i].ToString() + ".Type='"
                                            + GetTypeHelper(parameters[j]).ToString() + "'");
                    }


                    // Add the label & parameter to the combined list.
                    // (As an optimization, the generated classes could pre-allocate a thread-safe static array, to avoid
                    // this allocation and the ToArray allocation below.)

                    arrayList.Add(labels[i]);
                    arrayList.Add(parameters[j]);
                }

                // It's OK if we terminate because we have more lables than parameters;
                // this is used by traces to have out-values in the Stop message.

                if (TraceExtraMessages != null && j < parameters.Length)
                {
                    TraceExtraMessages(traceBuilder, parameters, j);
                }
            }

            // Send the trace

            _traceSource.TraceEvent(
                type,
                eventId,
                traceBuilder.ToString(),
                arrayList.ToArray());

            // When in the debugger, always flush the output, to guarantee that the
            // traces and other info (e.g. exceptions) get interleaved correctly.

            if (IsDebuggerAttached())
            {
                _traceSource.Flush();
            }
        }
Esempio n. 6
0
        //
        //  Trace an event
        //
        //  note: labels start at index 1, parameters start at index 0
        //

        public void Trace( TraceEventType type, int eventId, string message, string[] labels, object[] parameters )
        {
            // Don't bother building the string if this trace is going to be ignored.

            if( _traceSource == null
                || !_traceSource.Switch.ShouldTrace( type ))
            {
                return;
            }


            // Compose the trace string.

            AvTraceBuilder traceBuilder = new AvTraceBuilder(AntiFormat(message)); // Holds the format string
            ArrayList arrayList = new ArrayList(); // Holds the combined labels & parameters arrays.

            int formatIndex = 0;

            if (parameters != null && labels != null && labels.Length > 0)
            {
                int i = 1, j = 0;
                for( ; i < labels.Length && j < parameters.Length; i++, j++ )
                {
                    // Append to the format string a "; {0} = '{1}'", where the index increments (e.g. the second iteration will
                    // produce {2} & {3}).

                    traceBuilder.Append("; {" + (formatIndex++).ToString() + "}='{" + (formatIndex++).ToString() + "}'" );

                    // If this parameter is null, convert to "<null>"; otherwise, when a string.format is ultimately called
                    // it produces bad results.

                    if( parameters[j] == null )
                    {
                        parameters[j] = "<null>";
                    }

                    // Otherwise, if this is an interesting object, add the hash code and type to
                    // the format string explicitely.

                    else if( !SuppressGeneratedParameters
                             && parameters[j].GetType() != typeof(string)
                             && !(parameters[j] is ValueType)
                             && !(parameters[j] is Type)
                             && !(parameters[j] is DependencyProperty) )
                    {
                        traceBuilder.Append("; " + labels[i].ToString() + ".HashCode='"
                                                    + GetHashCodeHelper(parameters[j]).ToString() + "'" );

                        traceBuilder.Append("; " + labels[i].ToString() + ".Type='"
                                                    + GetTypeHelper(parameters[j]).ToString() + "'" );
                    }


                    // Add the label & parameter to the combined list.
                    // (As an optimization, the generated classes could pre-allocate a thread-safe static array, to avoid
                    // this allocation and the ToArray allocation below.)

                    arrayList.Add( labels[i] );
                    arrayList.Add( parameters[j] );


                }

                // It's OK if we terminate because we have more lables than parameters;
                // this is used by traces to have out-values in the Stop message.

                if( TraceExtraMessages != null && j < parameters.Length)
                {
                    TraceExtraMessages( traceBuilder, parameters, j );
                }

            }

            // Send the trace

            _traceSource.TraceEvent(
                type,
                eventId,
                traceBuilder.ToString(),
                arrayList.ToArray() );

            // When in the debugger, always flush the output, to guarantee that the
            // traces and other info (e.g. exceptions) get interleaved correctly.

            if( IsDebuggerAttached() )
            {
                _traceSource.Flush();
            }

        }