Пример #1
0
        private static Type LookUpType(string typeName)
        {
            Type       type       = null;
            StackTrace stackTrace = new StackTrace();
            Assembly   assembly   = null;

            foreach (StackFrame stackFrame in stackTrace.GetFrames())
            {
                Assembly assembly2 = stackFrame.GetMethod().DeclaringType.GetTypeInfo().Assembly;
                if (assembly2 != assembly)
                {
                    assembly = assembly2;
                    type     = assembly.GetType(typeName);
                    if (type == null)
                    {
                        type = FaultInjectionTrace.CheckReferencedAssemblies(assembly, typeName, 0);
                    }
                    if (type != null)
                    {
                        break;
                    }
                }
            }
            return(type);
        }
Пример #2
0
        private static object InvokeConstructorWithParams(Type targetType, string[] exceptionParameters)
        {
            object result = null;
            bool   flag   = false;

            try
            {
                result = ((targetType == typeof(string)) ? string.Empty : Activator.CreateInstance(targetType, exceptionParameters));
            }
            catch (MissingMethodException)
            {
                foreach (ConstructorInfo constructorInfo in targetType.GetTypeInfo().DeclaredConstructors)
                {
                    ParameterInfo[] parameters = constructorInfo.GetParameters();
                    if (parameters.Length == exceptionParameters.Length)
                    {
                        flag = true;
                        object[] array = new object[parameters.Length];
                        for (int i = 0; i < parameters.Length; i++)
                        {
                            array[i] = FaultInjectionTrace.StringToParameter(exceptionParameters[i], parameters[i].ParameterType);
                        }
                        result = constructorInfo.Invoke(array);
                        break;
                    }
                }
                if (!flag)
                {
                    throw new InvalidOperationException("Type Specified Does Not Have Any Constructors that match the parameters number: " + targetType.FullName);
                }
            }
            return(result);
        }
Пример #3
0
        private static object InvokeConstructor(Type targetType)
        {
            object result = null;
            bool   flag   = false;

            try
            {
                result = ((targetType == typeof(string)) ? string.Empty : Activator.CreateInstance(targetType));
            }
            catch (MissingMethodException)
            {
                using (IEnumerator <ConstructorInfo> enumerator = targetType.GetTypeInfo().DeclaredConstructors.GetEnumerator())
                {
                    if (enumerator.MoveNext())
                    {
                        ConstructorInfo constructorInfo = enumerator.Current;
                        flag = true;
                        ParameterInfo[] parameters = constructorInfo.GetParameters();
                        object[]        array      = new object[parameters.Length];
                        int             num        = 0;
                        foreach (ParameterInfo parameterInfo in parameters)
                        {
                            array[num] = FaultInjectionTrace.InvokeConstructor(parameterInfo.ParameterType);
                            num++;
                        }
                        result = constructorInfo.Invoke(array);
                    }
                }
                if (!flag)
                {
                    throw new InvalidOperationException("Type Specified Does Not Have Any Constructors : " + targetType.FullName);
                }
            }
            return(result);
        }
Пример #4
0
 private static void InjectException(Guid componentGuid, string exceptionTypeParams)
 {
     lock (ExTraceConfiguration.Instance.ExceptionInjection)
     {
         ExceptionInjectionCallback exceptionInjectionCallback;
         if (ExTraceConfiguration.Instance.ExceptionInjection.TryGetValue(componentGuid, out exceptionInjectionCallback))
         {
             Exception ex = exceptionInjectionCallback(exceptionTypeParams);
             if (ex == null)
             {
                 ex = FaultInjectionTrace.GenericExceptionCallback(exceptionTypeParams);
             }
             throw ex;
         }
     }
 }
Пример #5
0
        private static void InjectSync(uint lid, string tagIdentifier)
        {
            string name;
            string name2;

            FaultInjectionTrace.CreateSyncEventNames(lid, tagIdentifier, out name, out name2);
            try
            {
                using (EventWaitHandle eventWaitHandle = EventWaitHandle.OpenExisting(name))
                {
                    using (EventWaitHandle eventWaitHandle2 = EventWaitHandle.OpenExisting(name2))
                    {
                        eventWaitHandle.Reset();
                        eventWaitHandle2.Set();
                        eventWaitHandle.WaitOne();
                        eventWaitHandle2.Reset();
                    }
                }
            }
            catch
            {
            }
        }
Пример #6
0
        private static Type CheckReferencedAssemblies(Assembly assembly, string typeName, int depth)
        {
            Type type = null;

            foreach (AssemblyName assemblyRef in assembly.GetReferencedAssemblies())
            {
                Assembly assembly2 = Assembly.Load(assemblyRef);
                type = assembly2.GetType(typeName);
                if (type != null)
                {
                    break;
                }
                if (depth > 0)
                {
                    type = FaultInjectionTrace.CheckReferencedAssemblies(assembly2, typeName, depth--);
                    if (type != null)
                    {
                        break;
                    }
                }
            }
            return(type);
        }
Пример #7
0
        private static bool ValidateCondition <T>(string valueToCompareTo, ref T objectToCompare, InjectionComparisonOperator comparisonOperator)
        {
            bool result;

            try
            {
                T t = default(T);
                if (valueToCompareTo != null)
                {
                    FaultInjectionTrace.StringToValue <T>(valueToCompareTo, ref t);
                }
                string text = objectToCompare as string;
                switch (comparisonOperator)
                {
                case InjectionComparisonOperator.Skip:
                    result = true;
                    break;

                case InjectionComparisonOperator.Equals:
                    result = (Comparer <T> .Default.Compare(objectToCompare, t) == 0);
                    break;

                case InjectionComparisonOperator.NotEquals:
                    result = (Comparer <T> .Default.Compare(objectToCompare, t) != 0);
                    break;

                case InjectionComparisonOperator.GreaterThan:
                    result = (Comparer <T> .Default.Compare(objectToCompare, t) == 1);
                    break;

                case InjectionComparisonOperator.GreaterThanOrEqual:
                    result = (Comparer <T> .Default.Compare(objectToCompare, t) >= 0);
                    break;

                case InjectionComparisonOperator.LessThan:
                    result = (Comparer <T> .Default.Compare(objectToCompare, t) == -1);
                    break;

                case InjectionComparisonOperator.LessThanOrEqual:
                    result = (Comparer <T> .Default.Compare(objectToCompare, t) <= 0);
                    break;

                case InjectionComparisonOperator.Contains:
                    if (text != null)
                    {
                        result = text.Contains(valueToCompareTo);
                    }
                    else
                    {
                        result = false;
                    }
                    break;

                case InjectionComparisonOperator.NotContains:
                    if (text != null)
                    {
                        result = !text.Contains(valueToCompareTo);
                    }
                    else
                    {
                        result = false;
                    }
                    break;

                case InjectionComparisonOperator.IsNull:
                    result = (objectToCompare == null);
                    break;

                case InjectionComparisonOperator.IsNotNull:
                    result = (objectToCompare != null);
                    break;

                case InjectionComparisonOperator.PPM:
                {
                    int  num = FaultInjectionTrace.random.Next(1000000);
                    int  num2;
                    bool flag = int.TryParse((string)((object)t), out num2);
                    if (flag && num < num2)
                    {
                        result = true;
                    }
                    else
                    {
                        result = false;
                    }
                    break;
                }

                default:
                    result = false;
                    break;
                }
            }
            catch (Exception ex)
            {
                ExTraceGlobals.TracingTracer.TraceInformation <string>(63039, 0L, "ValidateCondition<T>: An exception occured while doing the comparison: {0}", ex.ToString());
                result = false;
            }
            return(result);
        }
Пример #8
0
        public void TraceTest <T>(uint lid, ref T objectToChange)
        {
            string text = ExTraceConfiguration.Instance.ComponentInjection();

            ExTraceGlobals.TracingTracer.TraceDebug <uint, string>(35221, (long)((ulong)lid), "TraceTest called for LID:{0}, TagIdentifier:'{1}'.", lid, text);
            if (base.IsTraceEnabled(TraceType.FaultInjection))
            {
                if (ExTraceConfiguration.DisableAllTraces != null && ExTraceConfiguration.DisableAllTraces.Contains(this.category))
                {
                    ExTraceGlobals.TracingTracer.TraceDebug <Guid>(56316L, "Component: {0} has all traces temporary disabled for this thread.", this.category);
                    return;
                }
                ExTraceGlobals.TracingTracer.TraceDebug <Guid, uint, string>(51605, (long)((ulong)lid), "FI tracing is enabled for category:{0}, lid:{1}, tagIdentifier:'{2}'.", this.category, lid, text);
                FaultInjectionTagComponentConfig faultInjectionTagComponentConfig = null;
                if (ExTraceConfiguration.Instance.FaultInjectionConfiguration.TryGetValue(this.category, out faultInjectionTagComponentConfig))
                {
                    FaultInjectionComponentConfig faultInjectionComponentConfig = null;
                    if (faultInjectionTagComponentConfig.TryGetValue(text, out faultInjectionComponentConfig) || faultInjectionTagComponentConfig.TryGetValue(string.Empty, out faultInjectionComponentConfig))
                    {
                        ExTraceGlobals.TracingTracer.TraceDebug <string>(33320, (long)((ulong)lid), "Tracing found for tag identifier:'{0}'", text);
                        if (ExTraceConfiguration.DisabledLids != null && ExTraceConfiguration.DisabledLids.Contains(lid))
                        {
                            ExTraceGlobals.TracingTracer.TraceDebug <uint>(43932, (long)((ulong)lid), "LID:{0} is temporary disabled for this thread.", lid);
                            return;
                        }
                        FaultInjectionPointConfig faultInjectionPointConfig = null;
                        if (faultInjectionComponentConfig.TryGetValue(lid, out faultInjectionPointConfig))
                        {
                            ExTraceGlobals.TracingTracer.TraceDebug <FaultInjectionType, uint>(45461, (long)((ulong)lid), "Tracing found for a configuration of type:{0} for lid:{1}", faultInjectionPointConfig.Type, lid);
                            string valueToCompareTo = null;
                            InjectionComparisonOperator comparisonOperator = InjectionComparisonOperator.Skip;
                            List <string> expectedCallStack = null;
                            switch (faultInjectionPointConfig.Type)
                            {
                            case FaultInjectionType.None:
                                break;

                            case FaultInjectionType.Sync:
                            {
                                int condition = FaultInjectionTrace.GetCondition(faultInjectionPointConfig.Parameters, out comparisonOperator, out valueToCompareTo);
                                if (condition < faultInjectionPointConfig.Parameters.Count)
                                {
                                    expectedCallStack = faultInjectionPointConfig.Parameters.GetRange(condition, faultInjectionPointConfig.Parameters.Count - condition);
                                }
                                if (FaultInjectionTrace.ValidateCondition <T>(valueToCompareTo, ref objectToChange, comparisonOperator) && FaultInjectionTrace.ValidateCallStack(lid, expectedCallStack))
                                {
                                    ExTraceGlobals.TracingTracer.TraceInformation <uint>(59951, (long)((ulong)lid), "FI.Sync[lid:{0}]", lid);
                                    FaultInjectionTrace.InjectSync(lid, text);
                                    return;
                                }
                                break;
                            }

                            case FaultInjectionType.Exception:
                                if (faultInjectionPointConfig.Parameters != null && 0 < faultInjectionPointConfig.Parameters.Count)
                                {
                                    int condition2 = FaultInjectionTrace.GetCondition(faultInjectionPointConfig.Parameters, out comparisonOperator, out valueToCompareTo);
                                    if (condition2 < faultInjectionPointConfig.Parameters.Count)
                                    {
                                        string text2 = faultInjectionPointConfig.Parameters[condition2];
                                        if (condition2 + 1 < faultInjectionPointConfig.Parameters.Count)
                                        {
                                            expectedCallStack = faultInjectionPointConfig.Parameters.GetRange(condition2 + 1, faultInjectionPointConfig.Parameters.Count - condition2 - 1);
                                        }
                                        if (FaultInjectionTrace.ValidateCondition <T>(valueToCompareTo, ref objectToChange, comparisonOperator) && FaultInjectionTrace.ValidateCallStack(lid, expectedCallStack))
                                        {
                                            this.EnsureExceptionInjectionCallbackExists();
                                            ExTraceGlobals.TracingTracer.TraceInformation <uint, string>(43567, (long)((ulong)lid), "FI.Exception[lid:{0}] {1}", lid, text2);
                                            FaultInjectionTrace.InjectException(this.category, text2);
                                            return;
                                        }
                                    }
                                }
                                break;

                            case FaultInjectionType.Investigate:
                                ExTraceGlobals.TracingTracer.TraceInformation <StackTrace>(53653, 0L, "Tracing FaultInjectionType.Investigate with stack trace: {0}", new StackTrace());
                                return;

                            case FaultInjectionType.ChangeValue:
                                if (faultInjectionPointConfig.Parameters != null && 0 < faultInjectionPointConfig.Parameters.Count)
                                {
                                    int    condition3 = FaultInjectionTrace.GetCondition(faultInjectionPointConfig.Parameters, out comparisonOperator, out valueToCompareTo);
                                    string text3      = null;
                                    if (condition3 < faultInjectionPointConfig.Parameters.Count)
                                    {
                                        text3 = faultInjectionPointConfig.Parameters[condition3];
                                    }
                                    if (string.IsNullOrEmpty(text3))
                                    {
                                        throw new InvalidOperationException("Expected non-null and non-empty string: string.IsNullOrEmpty(valueToChangeTo)");
                                    }
                                    if (condition3 + 1 < faultInjectionPointConfig.Parameters.Count)
                                    {
                                        expectedCallStack = faultInjectionPointConfig.Parameters.GetRange(1, faultInjectionPointConfig.Parameters.Count - 1);
                                    }
                                    object obj = null;
                                    if (FaultInjectionTrace.ValidateCondition <object>(valueToCompareTo, ref obj, comparisonOperator) && FaultInjectionTrace.ValidateCallStack(lid, expectedCallStack))
                                    {
                                        ExTraceGlobals.TracingTracer.TraceInformation <uint, T, string>(55855, (long)((ulong)lid), "FI.ChangeValue[lid:{0}] {1} => {2}", lid, objectToChange, text3);
                                        FaultInjectionTrace.StringToValue <T>(text3, ref objectToChange);
                                    }
                                }
                                break;

                            default:
                                return;
                            }
                        }
                    }
                }
            }
        }
Пример #9
0
        private static Exception GenericExceptionCallback(string exceptionTypeNameParams)
        {
            Exception ex = null;

            if (exceptionTypeNameParams != null)
            {
                Regex  regex     = new Regex("([A-Za-z.]+)(?:\\((?:(?:((?:[0-9]+)|(?:'[A-Za-z0-9,.?:;!@_ ]*')))[, ]*)+\\))*");
                char[] trimChars = new char[]
                {
                    '\''
                };
                string   text  = string.Empty;
                string[] array = new string[0];
                if (regex.IsMatch(exceptionTypeNameParams))
                {
                    using (IEnumerator enumerator = regex.Matches(exceptionTypeNameParams).GetEnumerator())
                    {
                        while (enumerator.MoveNext())
                        {
                            object obj   = enumerator.Current;
                            Match  match = (Match)obj;
                            if (match.Groups.Count == 3)
                            {
                                text = match.Groups[1].Value;
                                if (match.Groups[1].Captures.Count > 0)
                                {
                                    array = new string[match.Groups[2].Captures.Count];
                                    int num = 0;
                                    foreach (object obj2 in match.Groups[2].Captures)
                                    {
                                        Capture capture = (Capture)obj2;
                                        array[num] = capture.Value.Trim(trimChars);
                                        num++;
                                    }
                                }
                            }
                        }
                        goto IL_157;
                    }
                    goto IL_146;
IL_157:
                    Type targetType = FaultInjectionTrace.LookUpType(text);
                    if (text == null)
                    {
                        throw new InvalidOperationException("No Type Exists In Current Calling Assembly Or Referenced Assemblies With The Name : " + exceptionTypeNameParams);
                    }
                    if (array.Length == 0)
                    {
                        ex = (FaultInjectionTrace.InvokeConstructor(targetType) as Exception);
                    }
                    else
                    {
                        ex = (FaultInjectionTrace.InvokeConstructorWithParams(targetType, array) as Exception);
                    }
                    if (ex == null)
                    {
                        throw new InvalidOperationException("Type Name Specified For The Exception Callback Is Not A Valid Exception Type : " + exceptionTypeNameParams);
                    }
                    return(ex);
                }
IL_146:
                throw new InvalidOperationException("The exception string is not valid. ExceptionTypeNameParams: " + exceptionTypeNameParams);
            }
            return(ex);
        }