Exemplo n.º 1
0
        // Token: 0x060074CF RID: 29903 RVA: 0x00216970 File Offset: 0x00214B70
        private void ProcessRequest(object o)
        {
            AsyncDataRequest asyncDataRequest = (AsyncDataRequest)o;

            try
            {
                asyncDataRequest.Complete(asyncDataRequest.DoWork());
            }
            catch (Exception ex)
            {
                if (CriticalExceptions.IsCriticalApplicationException(ex))
                {
                    throw;
                }
                asyncDataRequest.Fail(ex);
            }
            catch
            {
                asyncDataRequest.Fail(new InvalidOperationException(SR.Get("NonCLSException", new object[]
                {
                    "processing an async data request"
                })));
            }
            object syncRoot = this._list.SyncRoot;

            lock (syncRoot)
            {
                this._list.Remove(asyncDataRequest);
            }
        }
Exemplo n.º 2
0
        object GetTypedParamValue(string param, Type type, bool throwOnError)
        {
            object value = null;

            if (type == typeof(string))
            {
                return(param);
            }

            TypeConverter tc = TypeDescriptor.GetConverter(type);

            if (tc != null && tc.CanConvertFrom(typeof(string)))
            {
                // PreSharp uses message numbers that the C# compiler doesn't know about.
                // Disable the C# complaints, per the PreSharp documentation.
                #pragma warning disable 1634, 1691

                // PreSharp complains about catching NullReference (and other) exceptions.
                // It doesn't recognize that IsCritical[Application]Exception() handles these correctly.
                #pragma warning disable 56500

                try
                {
                    value = tc.ConvertFromString(null, CultureInfo.InvariantCulture,
                                                 param);
                    // technically the converter can return null as a legitimate
                    // value.  In practice, this seems always to be a sign that
                    // the conversion didn't work (often because the converter
                    // reverts to the default behavior - returning null).  So
                    // we treat null as an "error", and keep trying for something
                    // better.  (See bug 861966)
                }
                // catch all exceptions.  We simply want to move on to the next
                // candidate indexer.
                catch (Exception ex)
                {
                    if (CriticalExceptions.IsCriticalApplicationException(ex) || throwOnError)
                    {
                        throw;
                    }
                }
                catch
                {
                    if (throwOnError)
                    {
                        throw;
                    }
                }

                #pragma warning restore 56500
                #pragma warning restore 1634, 1691
            }

            if (value == null && type.IsAssignableFrom(typeof(string)))
            {
                value = param;
            }
            return(value);
        }
Exemplo n.º 3
0
        // Token: 0x06001C5A RID: 7258 RVA: 0x000856C4 File Offset: 0x000838C4
        private object CreateObjectInstance(out Exception e)
        {
            object result = null;
            string text   = null;

            e = null;
            try
            {
                object[] array = new object[this._constructorParameters.Count];
                this._constructorParameters.CopyTo(array, 0);
                result = Activator.CreateInstance(this._objectType, BindingFlags.Default, null, array, CultureInfo.InvariantCulture);
                this.OnPropertyChanged("ObjectInstance");
            }
            catch (ArgumentException ex)
            {
                text = "Cannot create Context Affinity object.";
                e    = ex;
            }
            catch (COMException ex2)
            {
                text = "Marshaling issue detected.";
                e    = ex2;
            }
            catch (MissingMethodException ex3)
            {
                text = "Wrong parameters for constructor.";
                e    = ex3;
            }
            catch (Exception ex4)
            {
                if (CriticalExceptions.IsCriticalApplicationException(ex4))
                {
                    throw;
                }
                text = null;
                e    = ex4;
            }
            catch
            {
                text = null;
                e    = new InvalidOperationException(SR.Get("ObjectDataProviderNonCLSException", new object[]
                {
                    this._objectType.Name
                }));
            }
            if (e != null || text != null)
            {
                if (TraceData.IsEnabled)
                {
                    TraceData.Trace(TraceEventType.Error, TraceData.ObjDPCreateFailed, this._objectType.Name, text, e);
                }
                if (!this.IsAsynchronous && text == null)
                {
                    throw e;
                }
            }
            return(result);
        }
Exemplo n.º 4
0
        //------------------------------------------------------
        //
        //  Private methods
        //
        //------------------------------------------------------

        // Run a single request.  This method gets scheduled on a worker thread
        // from the process ThreadPool.
        void ProcessRequest(object o)
        {
            AsyncDataRequest request = (AsyncDataRequest)o;

            // PreSharp uses message numbers that the C# compiler doesn't know about.
            // Disable the C# complaints, per the PreSharp documentation.
#pragma warning disable 1634, 1691

            // PreSharp complains about catching NullReference (and other) exceptions.
            // In this case, these are precisely the ones we want to catch the most,
            // so that a failure on a worker thread doesn't affect the main thread.
#pragma warning disable 56500

            // run the request - this may take a while
            try
            {
                request.Complete(request.DoWork());
            }

            // Catch all exceptions.  There is no app code on the stack,
            // so the exception isn't actionable by the app.
            // Yet we don't want to crash the app.
            catch (Exception ex)
            {
                if (CriticalExceptions.IsCriticalApplicationException(ex))
                {
                    throw;
                }

                request.Fail(ex);
            }
            catch // non CLS compliant exception
            {
                request.Fail(new InvalidOperationException(SR.Get(SRID.NonCLSException, "processing an async data request")));
            }

#pragma warning restore 56500
#pragma warning restore 1634, 1691

            // remove the request from the list
            lock (_list.SyncRoot)
            {
                _list.Remove(request);
            }
        }
Exemplo n.º 5
0
        // Token: 0x06000962 RID: 2402 RVA: 0x00020E34 File Offset: 0x0001F034
        internal bool ConvertAndMatch(object state)
        {
            object obj  = this.Value;
            string text = obj as string;
            Type   type = (state != null) ? state.GetType() : null;

            if (text != null && type != null && type != typeof(string))
            {
                BindingValueCache bindingValueCache = this.BindingValueCache;
                Type   bindingValueType             = bindingValueCache.BindingValueType;
                object obj2 = bindingValueCache.ValueAsBindingValueType;
                if (type != bindingValueType)
                {
                    obj2 = obj;
                    TypeConverter converter = DefaultValueConverter.GetConverter(type);
                    if (converter != null && converter.CanConvertFrom(typeof(string)))
                    {
                        try
                        {
                            obj2 = converter.ConvertFromString(null, TypeConverterHelper.InvariantEnglishUS, text);
                        }
                        catch (Exception ex)
                        {
                            if (CriticalExceptions.IsCriticalApplicationException(ex))
                            {
                                throw;
                            }
                        }
                        catch
                        {
                        }
                    }
                    bindingValueCache      = new BindingValueCache(type, obj2);
                    this.BindingValueCache = bindingValueCache;
                }
                obj = obj2;
            }
            return(this.Match(state, obj));
        }
Exemplo n.º 6
0
        // Token: 0x060007C0 RID: 1984 RVA: 0x0001884C File Offset: 0x00016A4C
        private object GetTypedParamValue(string param, Type type, bool throwOnError)
        {
            object obj = null;

            if (type == typeof(string))
            {
                return(param);
            }
            TypeConverter converter = TypeDescriptor.GetConverter(type);

            if (converter != null && converter.CanConvertFrom(typeof(string)))
            {
                try
                {
                    obj = converter.ConvertFromString(null, CultureInfo.InvariantCulture, param);
                }
                catch (Exception ex)
                {
                    if (CriticalExceptions.IsCriticalApplicationException(ex) || throwOnError)
                    {
                        throw;
                    }
                }
                catch
                {
                    if (throwOnError)
                    {
                        throw;
                    }
                }
            }
            if (obj == null && type.IsAssignableFrom(typeof(string)))
            {
                obj = param;
            }
            return(obj);
        }
Exemplo n.º 7
0
        object InvokeMethodOnInstance(out Exception e)
        {
            object data  = null;
            string error = null;    // string that describes known error

            e = null;

            Debug.Assert(_objectType != null);

            object[] parameters = new object[_methodParameters.Count];
            _methodParameters.CopyTo(parameters, 0);

            // PreSharp uses message numbers that the C# compiler doesn't know about.
            // Disable the C# complaints, per the PreSharp documentation.
            #pragma warning disable 1634, 1691

            // PreSharp complains about catching NullReference (and other) exceptions.
            // It doesn't recognize that IsCritical[Application]Exception() handles these correctly.
            #pragma warning disable 56500

            try
            {
                data = _objectType.InvokeMember(MethodName,
                                                s_invokeMethodFlags, null, _objectInstance, parameters,
                                                System.Globalization.CultureInfo.InvariantCulture);
            }
            catch (ArgumentException ae)
            {
                error = "Parameter array contains a string that is a null reference.";
                e     = ae;
            }
            catch (MethodAccessException mae)
            {
                error = "The specified member is a class initializer.";
                e     = mae;
            }
            catch (MissingMethodException mme)
            {
                error = "No method was found with matching parameter signature.";
                e     = mme;
            }
            catch (TargetException te)
            {
                error = "The specified member cannot be invoked on target.";
                e     = te;
            }
            catch (AmbiguousMatchException ame)
            {
                error = "More than one method matches the binding criteria.";
                e     = ame;
            }
            // Catch all exceptions.  When there is no app code on the stack,
            // the exception isn't actionable by the app.
            // Yet we don't want to crash the app.
            catch (Exception ex)
            {
                if (CriticalExceptions.IsCriticalApplicationException(ex))
                {
                    throw;
                }
                error = null;   // indicate unknown error
                e     = ex;
            }
            catch             //FXCop Fix: CatchNonClsCompliantExceptionsInGeneralHandlers
            {
                error = null; // indicate unknown error
                e     = new InvalidOperationException(SR.Get(SRID.ObjectDataProviderNonCLSExceptionInvoke, MethodName, _objectType.Name));
            }

            #pragma warning restore 56500
            #pragma warning restore 1634, 1691

            if (e != null || error != null)
            {
                // report known errors through TraceData (instead of throwing exceptions)
                if (TraceData.IsEnabled)
                {
                    TraceData.Trace(TraceEventType.Error, TraceData.ObjDPInvokeFailed, MethodName, _objectType.Name, error, e);
                }

                // in async mode we pass all exceptions to main thread;
                // in [....] mode we don't handle unknown exceptions.
                if (!IsAsynchronous && error == null)
                {
                    throw e;
                }
            }

            return(data);
        }
Exemplo n.º 8
0
        object CreateObjectInstance(out Exception e)
        {
            object instance = null;
            string error    = null; // string that describes known error

            e = null;

            // PreSharp uses message numbers that the C# compiler doesn't know about.
            // Disable the C# complaints, per the PreSharp documentation.
            #pragma warning disable 1634, 1691

            // PreSharp complains about catching NullReference (and other) exceptions.
            // It doesn't recognize that IsCritical[Application]Exception() handles these correctly.
            #pragma warning disable 56500

            Debug.Assert(_objectType != null);

            try
            {
                object[] parameters = new object[_constructorParameters.Count];
                _constructorParameters.CopyTo(parameters, 0);
                instance = Activator.CreateInstance(_objectType, 0, null, parameters,
                                                    System.Globalization.CultureInfo.InvariantCulture);
                OnPropertyChanged(s_instance);
            }
            catch (ArgumentException ae)
            {
                // this may fire when trying to create Context Affinity objects
                error = "Cannot create Context Affinity object.";
                e     = ae;
            }
            catch (System.Runtime.InteropServices.COMException ce)
            {
                // this may fire due to marshalling issues
                error = "Marshaling issue detected.";
                e     = ce;
            }
            catch (System.MissingMethodException mme)
            {
                // this may be due to setting parameters to a non parameter
                // only class contructor
                error = "Wrong parameters for constructor.";
                e     = mme;
            }
            // Catch all exceptions.  When there is no app code on the stack,
            // the exception isn't actionable by the app.
            // Yet we don't want to crash the app.
            catch (Exception ex)
            {
                if (CriticalExceptions.IsCriticalApplicationException(ex))
                {
                    throw;
                }
                error = null;   // indicate unknown error
                e     = ex;
            }
            catch             // non CLS compliant exception
            {
                error = null; // indicate unknown error
                e     = new InvalidOperationException(SR.Get(SRID.ObjectDataProviderNonCLSException, _objectType.Name));
            }

            #pragma warning restore 56500
            #pragma warning restore 1634, 1691

            if (e != null || error != null)
            {
                // report known errors through TraceData (instead of throwing exceptions)
                if (TraceData.IsEnabled)
                {
                    TraceData.Trace(TraceEventType.Error, TraceData.ObjDPCreateFailed, _objectType.Name, error, e);
                }

                // in async mode we pass all exceptions to main thread;
                // in [....] mode we don't handle unknown exceptions.
                if (!IsAsynchronous && error == null)
                {
                    throw e;
                }
            }

            return(instance);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Validate is called when Data binding is updating
        /// </summary>
        public override ValidationResult Validate(object value, CultureInfo cultureInfo)
        {
            // This rule is called during the CommittedValue step, so the value is the
            // owner of the rule collection - either a BindingGroup or an individual
            // binding expression.
            BindingGroup      bindingGroup;
            BindingExpression bindingExpr;

            if ((bindingGroup = value as BindingGroup) != null)
            {
                // in a BindingGroup, check the item-level IDataErrorInfo for each
                // source item in the group
                IList items = bindingGroup.Items;
                for (int i = items.Count - 1; i >= 0; --i)
                {
                    IDataErrorInfo idei = items[i] as IDataErrorInfo;
                    if (idei != null)
                    {
                        string error = idei.Error;
                        if (!String.IsNullOrEmpty(error))
                        {
                            return(new ValidationResult(false, error));
                        }
                    }
                }
            }
            else if ((bindingExpr = value as BindingExpression) != null)
            {
                // in a binding, check the error info for the binding's source
                // property
                IDataErrorInfo idei = bindingExpr.SourceItem as IDataErrorInfo;
                string         name = (idei != null) ? bindingExpr.SourcePropertyName : null;

                if (!String.IsNullOrEmpty(name))
                {
                    // get the data error information, if any, by calling idie[name].
                    // We do this in a paranoid way, even though indexers with
                    // string-valued arguments are not supposed to throw exceptions.

                    // PreSharp uses message numbers that the C# compiler doesn't know about.
                    // Disable the C# complaints, per the PreSharp documentation.
                    #pragma warning disable 1634, 1691

                    // PreSharp complains about catching NullReference (and other) exceptions.
                    // It doesn't recognize that IsCritical[Application]Exception() handles these correctly.
                    #pragma warning disable 56500

                    string error;
                    try
                    {
                        error = idei[name];
                    }
                    catch (Exception ex)
                    {
                        if (CriticalExceptions.IsCriticalApplicationException(ex))
                        {
                            throw;
                        }

                        error = null;

                        if (TraceData.IsEnabled)
                        {
                            TraceData.TraceAndNotify(TraceEventType.Error,
                                                     TraceData.DataErrorInfoFailed(
                                                         name,
                                                         idei.GetType().FullName,
                                                         ex.GetType().FullName,
                                                         ex.Message),
                                                     bindingExpr);
                        }
                    }
                    #pragma warning restore 56500
                    #pragma warning restore 1634, 1691

                    if (!String.IsNullOrEmpty(error))
                    {
                        return(new ValidationResult(false, error));
                    }
                }
            }
            else
            {
                throw new InvalidOperationException(SR.Get(SRID.ValidationRule_UnexpectedValue, this, value));
            }

            return(ValidationResult.ValidResult);
        }
Exemplo n.º 10
0
        /// <summary>Performs validation checks on a value.</summary>
        /// <param name="value">The value to check.</param>
        /// <param name="cultureInfo">The culture to use in this rule.</param>
        /// <returns>The result of the validation.</returns>
        // Token: 0x060044E3 RID: 17635 RVA: 0x001385D4 File Offset: 0x001367D4
        public override ValidationResult Validate(object value, CultureInfo cultureInfo)
        {
            BindingGroup bindingGroup;

            if ((bindingGroup = (value as BindingGroup)) != null)
            {
                IList items = bindingGroup.Items;
                for (int i = items.Count - 1; i >= 0; i--)
                {
                    IDataErrorInfo dataErrorInfo = items[i] as IDataErrorInfo;
                    if (dataErrorInfo != null)
                    {
                        string error = dataErrorInfo.Error;
                        if (!string.IsNullOrEmpty(error))
                        {
                            return(new ValidationResult(false, error));
                        }
                    }
                }
            }
            else
            {
                BindingExpression bindingExpression;
                if ((bindingExpression = (value as BindingExpression)) == null)
                {
                    throw new InvalidOperationException(SR.Get("ValidationRule_UnexpectedValue", new object[]
                    {
                        this,
                        value
                    }));
                }
                IDataErrorInfo dataErrorInfo2 = bindingExpression.SourceItem as IDataErrorInfo;
                string         text           = (dataErrorInfo2 != null) ? bindingExpression.SourcePropertyName : null;
                if (!string.IsNullOrEmpty(text))
                {
                    string text2;
                    try
                    {
                        text2 = dataErrorInfo2[text];
                    }
                    catch (Exception ex)
                    {
                        if (CriticalExceptions.IsCriticalApplicationException(ex))
                        {
                            throw;
                        }
                        text2 = null;
                        if (TraceData.IsEnabled)
                        {
                            TraceData.Trace(TraceEventType.Error, TraceData.DataErrorInfoFailed(new object[]
                            {
                                text,
                                dataErrorInfo2.GetType().FullName,
                                ex.GetType().FullName,
                                ex.Message
                            }), bindingExpression);
                        }
                    }
                    if (!string.IsNullOrEmpty(text2))
                    {
                        return(new ValidationResult(false, text2));
                    }
                }
            }
            return(ValidationResult.ValidResult);
        }
Exemplo n.º 11
0
        // Token: 0x06001C5B RID: 7259 RVA: 0x000857F4 File Offset: 0x000839F4
        private object InvokeMethodOnInstance(out Exception e)
        {
            object result = null;
            string text   = null;

            e = null;
            object[] array = new object[this._methodParameters.Count];
            this._methodParameters.CopyTo(array, 0);
            try
            {
                result = this._objectType.InvokeMember(this.MethodName, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy | BindingFlags.InvokeMethod | BindingFlags.OptionalParamBinding, null, this._objectInstance, array, CultureInfo.InvariantCulture);
            }
            catch (ArgumentException ex)
            {
                text = "Parameter array contains a string that is a null reference.";
                e    = ex;
            }
            catch (MethodAccessException ex2)
            {
                text = "The specified member is a class initializer.";
                e    = ex2;
            }
            catch (MissingMethodException ex3)
            {
                text = "No method was found with matching parameter signature.";
                e    = ex3;
            }
            catch (TargetException ex4)
            {
                text = "The specified member cannot be invoked on target.";
                e    = ex4;
            }
            catch (AmbiguousMatchException ex5)
            {
                text = "More than one method matches the binding criteria.";
                e    = ex5;
            }
            catch (Exception ex6)
            {
                if (CriticalExceptions.IsCriticalApplicationException(ex6))
                {
                    throw;
                }
                text = null;
                e    = ex6;
            }
            catch
            {
                text = null;
                e    = new InvalidOperationException(SR.Get("ObjectDataProviderNonCLSExceptionInvoke", new object[]
                {
                    this.MethodName,
                    this._objectType.Name
                }));
            }
            if (e != null || text != null)
            {
                if (TraceData.IsEnabled)
                {
                    TraceData.Trace(TraceEventType.Error, TraceData.ObjDPInvokeFailed, new object[]
                    {
                        this.MethodName,
                        this._objectType.Name,
                        text,
                        e
                    });
                }
                if (!this.IsAsynchronous && text == null)
                {
                    throw e;
                }
            }
            return(result);
        }