コード例 #1
0
        private static TraceSource CreateTraceSource(string sourceName)
        {
            // Create the trace source.  Whether or not it will actually
            // trace anything is a decision of the trace source, e.g. it
            // depends on the app.config file settings.

            TraceSource source = new TraceSource(sourceName);

            // If we're attached to the debugger, ensure that at least
            // warnings/errors are getting traced.

            if (source.Switch.Level == SourceLevels.Off
                &&
                AvTrace.IsDebuggerAttached())
            {
                // we need to assert as PT callers under a debugger can invoke this code path
                // with out having the needed permission to peform this action
                new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Assert(); // BlessedAssert
                try
                {
                    source.Switch.Level = SourceLevels.Warning;
                }
                finally
                {
                    SecurityPermission.RevertAssert();
                }
            }

            // returning source after reverting the assert to avoid
            // using exposed elements under the assert
            return(source);
        }
コード例 #2
0
        private string IdentifyNodeList(XmlNodeList nodeList)
        {
            if (nodeList == null)
            {
                return("<null>");
            }

            return(String.Format(TypeConverterHelper.InvariantEnglishUS, "{0} (hash={1} Count={2})",
                                 nodeList.GetType().Name, AvTrace.GetHashCodeHelper(nodeList), nodeList.Count));
        }
コード例 #3
0
        //------------------------------------------------------
        //
        //  Public Methods
        //
        //------------------------------------------------------

        /// <summary>
        /// Refresh TraceSources (re-read config file), creating if necessary.
        /// </summary>
        // Note: Better would be to separate enable from the Refresh method.
        public static void Refresh()
        {
            // Let AvTrace know that an explicit Refresh has been called.
            AvTrace.OnRefresh();

            // Re-read the .config files
            System.Diagnostics.Trace.Refresh();

            // Initialize any traces classes if needed
            if (TraceRefresh != null)
            {
                TraceRefresh();
            }
        }
コード例 #4
0
ファイル: CLRBindingWorker.cs プロジェクト: ash2005/z
 internal void ReportGetValueError(int k, object item, Exception ex)
 {
     if (TraceData.IsEnabled)
     {
         SourceValueInfo svi        = PW.GetSourceValueInfo(k);
         Type            type       = PW.GetType(k);
         string          parentName = (k > 0)? PW.GetSourceValueInfo(k - 1).name : String.Empty;
         TraceData.Trace(ParentBindingExpression.TraceLevel,
                         TraceData.CannotGetClrRawValue(
                             svi.propertyName, type.Name,
                             parentName, AvTrace.TypeName(item)),
                         ParentBindingExpression, ex);
     }
 }
コード例 #5
0
        //--------------------------------------------------------------------------
        // Internal Methods
        //--------------------------------------------------------------------------

        /// <summary>
        /// Will permit only internet zone permissions for TraceListeners and is
        /// safe to use inside of asserts for partial trust code.
        /// </summary>
        internal static void SafeWrite(
            BooleanSwitch boolSwitch, string format, params object[] args)
        {
            if (AvTrace.IsWpfTracingEnabledInRegistry())
            {
                System.Diagnostics.Trace.WriteLineIf(
                    boolSwitch.Enabled,
                    string.Format(
                        CultureInfo.CurrentCulture,
                        format,
                        args),
                    boolSwitch.DisplayName);
            }
        }
コード例 #6
0
ファイル: CLRBindingWorker.cs プロジェクト: ash2005/z
 internal void ReportSetValueError(int k, object item, object value, Exception ex)
 {
     if (TraceData.IsEnabled)
     {
         SourceValueInfo svi  = PW.GetSourceValueInfo(k);
         Type            type = PW.GetType(k);
         TraceData.Trace(TraceEventType.Error,
                         TraceData.CannotSetClrRawValue(
                             svi.propertyName, type.Name,
                             AvTrace.TypeName(item),
                             AvTrace.ToStringHelper(value),
                             AvTrace.TypeName(value)),
                         ParentBindingExpression, ex);
     }
 }
コード例 #7
0
 // Token: 0x06007485 RID: 29829 RVA: 0x002156DC File Offset: 0x002138DC
 internal void ReportGetValueError(int k, object item, Exception ex)
 {
     if (TraceData.IsEnabled)
     {
         SourceValueInfo sourceValueInfo = this.PW.GetSourceValueInfo(k);
         Type            type            = this.PW.GetType(k);
         string          text            = (k > 0) ? this.PW.GetSourceValueInfo(k - 1).name : string.Empty;
         TraceData.Trace(base.ParentBindingExpression.TraceLevel, TraceData.CannotGetClrRawValue(new object[]
         {
             sourceValueInfo.propertyName,
             type.Name,
             text,
             AvTrace.TypeName(item)
         }), base.ParentBindingExpression, ex);
     }
 }
コード例 #8
0
        private static TraceSource CreateTraceSource(string sourceName)
        {
            // Create the trace source.  Whether or not it will actually
            // trace anything is a decision of the trace source, e.g. it
            // depends on the app.config file settings.

            TraceSource source = new TraceSource(sourceName);

            // If we're attached to the debugger, ensure that at least
            // warnings/errors are getting traced.

            if (source.Switch.Level == SourceLevels.Off
                &&
                AvTrace.IsDebuggerAttached())
            {
                source.Switch.Level = SourceLevels.Warning;
            }

            // returning source after reverting the assert to avoid
            // using exposed elements under the assert
            return(source);
        }
コード例 #9
0
        //------------------------------------------------------
        //
        //  Private API
        //
        //------------------------------------------------------

        private object ConvertHelper(object o, Type destinationType, DependencyObject targetElement, CultureInfo culture, bool isForward)
        {
            object value                  = DependencyProperty.UnsetValue;
            bool   needAssignment         = (isForward ? !_shouldConvertTo : !_shouldConvertFrom);
            NotSupportedException savedEx = null;

            if (!needAssignment)
            {
                value = TryParse(o, destinationType, culture);

                if (value == DependencyProperty.UnsetValue)
                {
                    ValueConverterContext ctx = Engine.ValueConverterContext;

                    // The fixed VCContext object is usually available for re-use.
                    // In the rare cases when a second conversion is requested while
                    // a previous conversion is still in progress, we allocate a temporary
                    // context object to handle the re-entrant request.
                    if (ctx.IsInUse)
                    {
                        ctx = new ValueConverterContext();
                    }

                    try
                    {
                        ctx.SetTargetElement(targetElement);
                        if (isForward)
                        {
                            value = _typeConverter.ConvertTo(ctx, culture, o, destinationType);
                        }
                        else
                        {
                            value = _typeConverter.ConvertFrom(ctx, culture, o);
                        }
                    }
                    catch (NotSupportedException ex)
                    {
                        needAssignment = true;
                        savedEx        = ex;
                    }
                    finally
                    {
                        ctx.SetTargetElement(null);
                    }
                }
            }

            if (needAssignment &&
                ((o != null && destinationType.IsAssignableFrom(o.GetType())) ||
                 (o == null && !destinationType.IsValueType)))
            {
                value          = o;
                needAssignment = false;
            }

            if (TraceData.IsEnabled)
            {
                if ((culture != null) && (savedEx != null))
                {
                    TraceData.Trace(TraceEventType.Error,
                                    TraceData.DefaultValueConverterFailedForCulture(
                                        AvTrace.ToStringHelper(o),
                                        AvTrace.TypeName(o),
                                        destinationType.ToString(),
                                        culture),
                                    savedEx);
                }
                else if (needAssignment)
                {
                    TraceData.Trace(TraceEventType.Error,
                                    TraceData.DefaultValueConverterFailed(
                                        AvTrace.ToStringHelper(o),
                                        AvTrace.TypeName(o),
                                        destinationType.ToString()),
                                    savedEx);
                }
            }

            if (needAssignment && savedEx != null)
            {
                throw savedEx;
            }

            return(value);
        }
コード例 #10
0
        // Token: 0x06001C2E RID: 7214 RVA: 0x000844B0 File Offset: 0x000826B0
        private bool ConvertProposedValueImpl(object value, out object result)
        {
            DependencyObject targetElement = base.TargetElement;

            if (targetElement == null)
            {
                result = DependencyProperty.UnsetValue;
                return(false);
            }
            result = this.GetValuesForChildBindings(value);
            if (base.IsDetached)
            {
                return(false);
            }
            if (result == DependencyProperty.UnsetValue)
            {
                base.SetStatus(BindingStatusInternal.UpdateSourceError);
                return(false);
            }
            object[] array = (object[])result;
            if (array == null)
            {
                if (TraceData.IsEnabled)
                {
                    TraceData.Trace(TraceEventType.Error, TraceData.BadMultiConverterForUpdate(new object[]
                    {
                        this.Converter.GetType().Name,
                        AvTrace.ToStringHelper(value),
                        AvTrace.TypeName(value)
                    }), this);
                }
                result = DependencyProperty.UnsetValue;
                return(false);
            }
            if (TraceData.IsExtendedTraceEnabled(this, TraceDataLevel.Transfer))
            {
                for (int i = 0; i < array.Length; i++)
                {
                    TraceData.Trace(TraceEventType.Warning, TraceData.UserConvertBackMulti(new object[]
                    {
                        TraceData.Identify(this),
                        i,
                        TraceData.Identify(array[i])
                    }));
                }
            }
            int num = this.MutableBindingExpressions.Count;

            if (array.Length != num && TraceData.IsEnabled)
            {
                TraceData.Trace(TraceEventType.Information, TraceData.MultiValueConverterMismatch, new object[]
                {
                    this.Converter.GetType().Name,
                    num,
                    array.Length,
                    TraceData.DescribeTarget(targetElement, base.TargetProperty)
                });
            }
            if (array.Length < num)
            {
                num = array.Length;
            }
            bool result2 = true;

            for (int j = 0; j < num; j++)
            {
                value = array[j];
                if (value != Binding.DoNothing && value != DependencyProperty.UnsetValue)
                {
                    BindingExpressionBase bindingExpressionBase = this.MutableBindingExpressions[j];
                    bindingExpressionBase.SetValue(targetElement, base.TargetProperty, value);
                    value = bindingExpressionBase.GetRawProposedValue();
                    if (!bindingExpressionBase.Validate(value, ValidationStep.RawProposedValue))
                    {
                        value = DependencyProperty.UnsetValue;
                    }
                    value = bindingExpressionBase.ConvertProposedValue(value);
                }
                else if (value == DependencyProperty.UnsetValue && TraceData.IsEnabled)
                {
                    TraceData.Trace(TraceEventType.Information, TraceData.UnsetValueInMultiBindingExpressionUpdate(new object[]
                    {
                        this.Converter.GetType().Name,
                        AvTrace.ToStringHelper(value),
                        j,
                        this._tempTypes[j]
                    }), this);
                }
                if (value == DependencyProperty.UnsetValue)
                {
                    result2 = false;
                }
                array[j] = value;
            }
            Array.Clear(this._tempTypes, 0, this._tempTypes.Length);
            result = array;
            return(result2);
        }
コード例 #11
0
        // Token: 0x060074D8 RID: 29912 RVA: 0x00216DAC File Offset: 0x00214FAC
        private object ConvertHelper(object o, Type destinationType, DependencyObject targetElement, CultureInfo culture, bool isForward)
        {
            object obj  = DependencyProperty.UnsetValue;
            bool   flag = isForward ? (!this._shouldConvertTo) : (!this._shouldConvertFrom);
            NotSupportedException ex = null;

            if (!flag)
            {
                obj = DefaultValueConverter.TryParse(o, destinationType, culture);
                if (obj == DependencyProperty.UnsetValue)
                {
                    ValueConverterContext valueConverterContext = this.Engine.ValueConverterContext;
                    if (valueConverterContext.IsInUse)
                    {
                        valueConverterContext = new ValueConverterContext();
                    }
                    try
                    {
                        valueConverterContext.SetTargetElement(targetElement);
                        if (isForward)
                        {
                            obj = this._typeConverter.ConvertTo(valueConverterContext, culture, o, destinationType);
                        }
                        else
                        {
                            obj = this._typeConverter.ConvertFrom(valueConverterContext, culture, o);
                        }
                    }
                    catch (NotSupportedException ex2)
                    {
                        flag = true;
                        ex   = ex2;
                    }
                    finally
                    {
                        valueConverterContext.SetTargetElement(null);
                    }
                }
            }
            if (flag && ((o != null && destinationType.IsAssignableFrom(o.GetType())) || (o == null && !destinationType.IsValueType)))
            {
                obj  = o;
                flag = false;
            }
            if (TraceData.IsEnabled)
            {
                if (culture != null && ex != null)
                {
                    TraceData.Trace(TraceEventType.Error, TraceData.DefaultValueConverterFailedForCulture(new object[]
                    {
                        AvTrace.ToStringHelper(o),
                        AvTrace.TypeName(o),
                        destinationType.ToString(),
                        culture
                    }), ex);
                }
                else if (flag)
                {
                    TraceData.Trace(TraceEventType.Error, TraceData.DefaultValueConverterFailed(new object[]
                    {
                        AvTrace.ToStringHelper(o),
                        AvTrace.TypeName(o),
                        destinationType.ToString()
                    }), ex);
                }
            }
            if (flag && ex != null)
            {
                throw ex;
            }
            return(obj);
        }