Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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;
                            }
                        }
                    }
                }
            }
        }