Example #1
0
 public void can_find_value_in_an_expression_that_returns_a_dereferenced_value()
 {
     Assert.Equal(DateTime.MinValue, ValueExtractor.FindValueWithin(GetExpression(() => DateTime.MinValue)));
     Assert.Equal(decimal.MinValue, ValueExtractor.FindValueWithin(GetExpression(() => decimal.MinValue)));
     Assert.Equal(decimal.MaxValue, ValueExtractor.FindValueWithin(GetExpression(() => decimal.MaxValue)));
     Assert.Equal(decimal.MinusOne, ValueExtractor.FindValueWithin(GetExpression(() => decimal.MinusOne)));
 }
        public ConventionBasedCodingStyle Merge(ConventionBasedCodingStyle other)
        {
            AddTypes(other.types);

            Type.Merge(other.Type);
            TypeIsValue.Merge(other.TypeIsValue);
            TypeIsView.Merge(other.TypeIsView);
            IdExtractor.Merge(other.IdExtractor);
            ValueExtractor.Merge(other.ValueExtractor);
            Locator.Merge(other.Locator);
            Converters.Merge(other.Converters);
            StaticInstances.Merge(other.StaticInstances);
            Initializers.Merge(other.Initializers);
            Datas.Merge(other.Datas);
            Operations.Merge(other.Operations);

            DataFetchedEagerly.Merge(other.DataFetchedEagerly);

            ParameterIsOptional.Merge(other.ParameterIsOptional);
            ParameterDefaultValue.Merge(other.ParameterDefaultValue);

            Module.Merge(other.Module);
            TypeName.Merge(other.TypeName);
            DataName.Merge(other.DataName);
            OperationName.Merge(other.OperationName);
            ParameterName.Merge(other.ParameterName);

            TypeMarks.Merge(other.TypeMarks);
            InitializerMarks.Merge(other.InitializerMarks);
            DataMarks.Merge(other.DataMarks);
            OperationMarks.Merge(other.OperationMarks);
            ParameterMarks.Merge(other.ParameterMarks);

            return(this);
        }
Example #3
0
        public async Task GivenDataSourceForCode_ShouldParseAllEntryItems()
        {
            var data =
                "[10:54:44] :    [exec] 158>------ Build started: Project: blah x x x, Configuration: Release Win32 ------" + Environment.NewLine +
                "[10:54:44] :    [exec] Build Acceleration Console 8.0.1 (build 1867)" + Environment.NewLine +
                "[10:54:44] :    [exec] ========== Build: 35 succeeded, 0 failed, 5 up-to-date, 326 skipped ==========" + Environment.NewLine +
                "[10:54:44] :    [exec] ========== Rebuild All: 35 succeeded, 0 failed, 326 skipped ==========" + Environment.NewLine +
                "[10:54:44]W:    [NAnt output] BUILD FAILED - 8 non-fatal error(s), 15 warning(s)" + Environment.NewLine +
                "[10:53:29] :    [exec] 44> error : blah blah blah" + Environment.NewLine +
                "[10:53:29] :    [exec] 44>" + Environment.NewLine +
                "[19:07:17] :    [exec] 54>Time Elapsed 00:00:14.56" + Environment.NewLine +
                "[19:07:17] :    [exec] 27>Build FAILED." + Environment.NewLine +
                "[19:07:17] :    [exec] 27>Build succeeded." + Environment.NewLine +
                "bunch of noise";

            var dataService    = new DataService(data);
            var valueExtractor = new ValueExtractor(new DataDictionary());
            var parser         = new CodeParser(dataService, valueExtractor);

            await parser.Parse(1, 11, (update) =>
            {
            });

            var noise                        = parser.Noise;
            var solutionStart                = parser.SolutionStart;
            var solutionBuildSucceeded       = parser.SolutionBuildSucceeded;
            var solutionRebuildSucceeded     = parser.SolutionRebuildSucceeded;
            var projectDefinitions           = parser.ProjectDefinitions;
            var projectEmptyEntries          = parser.ProjectEmptyEntries;
            var projectBuildFailedEntries    = parser.ProjectBuildFailedEntries;
            var projectBuildSucceededEntries = parser.ProjectBuildSucceededEntries;
            var projectEntries               = parser.ProjectEntries;
            var projectEnd                   = parser.ProjectEndEntries;
        }
Example #4
0
        public void Unbox_DataReader_Columns_with_Custom_Handlers(object input)
        {
            // Arrange
            ValueExtractor extractor = ValueExtractor.Create(config =>
            {
                config.UseHandler <bool>(
                    (obj, ctx) =>
                {
                    if (obj is bool b)
                    {
                        ctx.Result = b;
                        return;
                    }

                    if (obj is string s)
                    {
                        ctx.Result = s == "Y";
                        return;
                    }
                });
            });

            // Act
            bool result = extractor.Extract <bool>(input);

            // Assert
        }
        public void GivenRegexDefaultErrorEntry_ShouldExtractDefaultErrorEntryDetails()
        {
            var dataService    = new DataService("[11:57:05] : [Step 1/6] error: so here is an thing error");
            var dataDictionary = new DataDictionary();
            var valueExtractor = new ValueExtractor(dataDictionary);
            var defaultError   = EntryFactory.CreateDefaultErrorEntryFunc(1)(valueExtractor, dataService);

            Assert.Equal(EntryType.DefaultErrorEntry(), defaultError.EntryType);
            Assert.Equal(" so here is an thing error", defaultError.Error);
        }
        protected List <object> GetArgumentValue(T obj, MethodCallExpression wholeExpression, Expression methodExpression)
        {
            var visitor = new ValueExtractor <T, TMember>(obj, wholeExpression);

            visitor.Visit(methodExpression);

            var args = visitor.Arguments;

            return(args);
        }
Example #7
0
        public static StructValueStrings GetStructValueStrings(StructFieldsEx structFld, ClrHeap heap, ulong addr)
        {
            var cnt        = structFld._fields.Length;
            var structInfo = structFld._structFields;
            var vals       = new string[cnt];

            StructValueStrings[] structVals = null;
            for (int i = 0; i < cnt; ++i)
            {
                if (structInfo.IsAmbiguousKind(i))
                {
                    var fobj  = structFld._fields[i].GetValue(addr, true);
                    var faddr = (ulong)fobj;
                    var ftype = heap.GetObjectType(faddr);
                    if (ftype != null)
                    {
                        structFld._types[i] = ftype;
                        structInfo.SetKind(TypeExtractor.GetElementKind(ftype), i);
                    }
                }
                var fldType = structFld._types[i];
                var fld     = structFld._fields[i];
                var kind    = structFld._structFields.Kinds[i];
                Debug.Assert(fld != null);
                if (structFld._ex?[i] != null)
                {
                    if (structVals == null)
                    {
                        structVals = new StructValueStrings[cnt];
                    }

                    structVals[i] = GetStructValueStrings(structFld._ex[i], heap, fld.GetAddress(addr, true));
                }
                else if (fldType != null)
                {
                    var fobj  = fld.GetValue(addr, true);
                    var faddr = (ulong)fobj;
                    vals[i] = ValueExtractor.GetTypeValueString(heap, faddr, fldType, true, kind);
                }
                else
                {
                    if (TypeExtractor.IsKnownPrimitive(kind))
                    {
                        vals[i] = ValueExtractor.GetFieldValueString(heap, addr, true, fld, kind);
                    }
                    else
                    {
                        var fobj  = fld.GetAddress(addr, true);
                        var faddr = (ulong)fobj;
                        vals[i] = ValueExtractor.GetFieldValueString(heap, faddr, true, fld, kind);
                    }
                }
            }
            return(new StructValueStrings(vals, structVals));
        }
        public void GivenRegexSolutionStart_ShouldExtractSolutionStartDefinition()
        {
            var dataService        = new DataService("[10:54:44] :          [exec] Build Acceleration Console 8.0.1 (build 1867)");
            var dataDictionary     = new DataDictionary();
            var valueExtractor     = new ValueExtractor(dataDictionary);
            var solutionStartEntry = EntryFactory.CreateSolutionStartEntryFunc(1)(valueExtractor, dataService);

            Assert.Equal(EntryType.SolutionStart(), solutionStartEntry.EntryType);
            Assert.Equal("Build Acceleration Console", solutionStartEntry.SolutionStart);
            Assert.Equal(new TimeSpan(10, 54, 44), solutionStartEntry.Time);
        }
Example #9
0
        /// <summary>
        /// Map the data given in the StringData field of the payload using the DataBrowser
        /// </summary>
        public string MapStringData(string data)
        {
            string stringData = ValueExtractor.GetValueFromDataList("StringData", data);

            IDataBrowser        dataBrowser = DataBrowserFactory.CreateDataBrowser();
            IEnumerable <IPath> mappedPaths = dataBrowser.Map(stringData);

            string pathsString = string.Join(Environment.NewLine, mappedPaths.Select(p => p.DisplayPath));

            return("<ADL><PathData>" + pathsString + "</PathData></ADL>");
        }
        public void GivenRegexProjectEmptyEntry_ShouldExtractProjectEmptyEntryDefinition()
        {
            var dataService       = new DataService("[10:53:29] :            [exec] 44>");
            var dataDictionary    = new DataDictionary();
            var valueExtractor    = new ValueExtractor(dataDictionary);
            var projectEmptyEntry = EntryFactory.CreateProjectEmptyEntryFunc(1)(valueExtractor, dataService);

            Assert.Equal(EntryType.ProjectEmptyEntry(), projectEmptyEntry.EntryType);
            Assert.Equal((uint)44, projectEmptyEntry.ProjectId);
            Assert.Equal(new TimeSpan(10, 53, 29), projectEmptyEntry.Time);
        }
        public void GivenRegexStageSkippedEntry_ShouldExtractStageSkippedEntryDetails()
        {
            var dataService    = new DataService("[11:57:05] : [Step 1/6] Disabled build step this is Label  (here) is skipped");
            var dataDictionary = new DataDictionary();
            var valueExtractor = new ValueExtractor(dataDictionary);
            var stageSkipped   = EntryFactory.CreateStageSkippedEntryFunc(1)(valueExtractor, dataService);

            Assert.Equal(EntryType.StageSkippedType(), stageSkipped.EntryType);
            Assert.Equal((uint)1, stageSkipped.StageNo);
            Assert.Equal((uint)6, stageSkipped.StageCount);
            Assert.Equal("this is Label  (here)", stageSkipped.Label);
        }
        public void GivenRegexStageExitEntry_ShouldExtractStageExitEntryDetails()
        {
            var dataService    = new DataService("[19:07:17] :    [Step 4/4] Process exited with code 0");
            var dataDictionary = new DataDictionary();
            var valueExtractor = new ValueExtractor(dataDictionary);
            var stageExit      = EntryFactory.CreateStageExitEntryFunc(1)(valueExtractor, dataService);

            Assert.Equal(EntryType.StageExitType(), stageExit.EntryType);
            Assert.Equal((uint)4, stageExit.StageNo);
            Assert.Equal((uint)4, stageExit.StageCount);
            Assert.True(stageExit.Succeeded);
        }
        public void GivenRegexStageStartEntry_ShouldExtractStageStartEntryDetails()
        {
            var dataService    = new DataService("[19:07:17]W: Step 1/4: Clean up");
            var dataDictionary = new DataDictionary();
            var valueExtractor = new ValueExtractor(dataDictionary);
            var stageStart     = EntryFactory.CreateStageStartEntryFunc(1)(valueExtractor, dataService);

            Assert.Equal(EntryType.StageStartType(), stageStart.EntryType);
            Assert.Equal((uint)1, stageStart.StageNo);
            Assert.Equal((uint)4, stageStart.StageCount);
            Assert.Equal("Clean up", stageStart.StageLabel);
        }
        public void GivenRegexProjectEndBuildSucceededEntry_ShouldExtractProjectEndBuildSucceededEntryDefinition()
        {
            var dataService              = new DataService("[19:07:17] :       [exec] 54>Build succeeded.");
            var dataDictionary           = new DataDictionary();
            var valueExtractor           = new ValueExtractor(dataDictionary);
            var projectEndBuildSucceeded = EntryFactory.CreateProjectEndBuildSucceededEntryFunc(1)(valueExtractor, dataService);

            Assert.Equal(EntryType.ProjectBuildSucceededEntry(), projectEndBuildSucceeded.EntryType);
            Assert.Equal((uint)54, projectEndBuildSucceeded.Id);
            Assert.Equal("Build succeeded.", projectEndBuildSucceeded.BuildSucceeded);
            Assert.Equal(new TimeSpan(19, 07, 17), projectEndBuildSucceeded.Time);
        }
        public void GivenRegexProjectEndEntry_ShouldExtractProjectEndEntryDefinition()
        {
            var dataService     = new DataService("[19:07:17] :          [exec] 126>Time Elapsed 00:00:14.56");
            var dataDictionary  = new DataDictionary();
            var valueExtractor  = new ValueExtractor(dataDictionary);
            var projectEndEntry = EntryFactory.CreateProjectEndEntryFunc(1)(valueExtractor, dataService);

            Assert.Equal(EntryType.ProjectEndEntry(), projectEndEntry.EntryType);
            Assert.Equal((uint)126, projectEndEntry.Id);
            Assert.Equal(new TimeSpan(0, 0, 0, 14, 560), projectEndEntry.TimeElapsed);
            Assert.Equal(new TimeSpan(19, 07, 17), projectEndEntry.Time);
        }
Example #16
0
        public void can_find_value_in_an_expression_that_includes_a_lambda()
        {
            Expression <Func <int, bool> > expression = x => x % 2 == 0;
            var value = ValueExtractor.FindValueWithin(expression);

            Assert.NotNull(value);
            var castValue = Assert.IsType <Func <int, bool> >(value);

            Assert.True(castValue(0));
            Assert.False(castValue(1));
            Assert.True(castValue(2));
            Assert.False(castValue(3));
        }
        public void GivenRegexProjectDefinition_ShouldProduceProjectDefinition()
        {
            var dataService            = new DataService("[10:54:44] :          [exec] 158>------ Build started: Project: StarWinForms x x x, Configuration: Release Win32 ------");
            var dataDictionary         = new DataDictionary();
            var valueExtractor         = new ValueExtractor(dataDictionary);
            var projectDefinitionEntry = EntryFactory.CreateProjectDefinitionEntryFunc(1)(valueExtractor, dataService);

            Assert.Equal((uint)158, projectDefinitionEntry.Id);
            Assert.Equal("StarWinForms x x x", projectDefinitionEntry.Name);
            Assert.Equal(EntryType.ProjectDefinition(), projectDefinitionEntry.EntryType);
            Assert.Equal("Release Win32", projectDefinitionEntry.Configuration);
            Assert.Equal(new TimeSpan(10, 54, 44), projectDefinitionEntry.Time);
        }
Example #18
0
        public VisualizerData(object o, Config?config = null)
        {
            Config = config ?? new Config();
            if (!Config.Path.IsNullOrWhitespace())
            {
                o = ((Expression)ResolvePath(o, Config.Path) !).ExtractValue() !;
            }
            Source = Renderers.Invoke(Config.Formatter, o, Config.Language, out var pathSpans);

            var valueExtractor = new ValueExtractor();

            Root = new ExpressionNodeData(o, ("", ""), this, valueExtractor, pathSpans, false);
        }
        public void GivenRegexSolutionEndRebuildSucceeded_ShouldExtractSolutionRebuildSucceededDefinition()
        {
            var dataService    = new DataService("[10:54:44] :          [exec] ========== Rebuild All: 35 succeeded, 10 failed, 326 skipped ==========");
            var dataDictionary = new DataDictionary();
            var valueExtractor = new ValueExtractor(dataDictionary);
            var solutionRebuildSucceededEntry = EntryFactory.CreateSolutionEndRebuildSucceededEntryFunc(1)(valueExtractor, dataService);

            Assert.Equal(EntryType.SolutionEndRebuildSucceeded(), solutionRebuildSucceededEntry.EntryType);
            Assert.Equal((uint)35, solutionRebuildSucceededEntry.Succeeded);
            Assert.Equal((uint)10, solutionRebuildSucceededEntry.Failed);
            Assert.Equal((uint)326, solutionRebuildSucceededEntry.Skipped);
            Assert.Equal(new TimeSpan(10, 54, 44), solutionRebuildSucceededEntry.Time);
        }
Example #20
0
 public SessionImpl(
     Config aConfig,
     ClassMapLoader aLoader,
     SqlFactory aFactory,
     DBConnection aConnection,
     ValueExtractor aValueExtactor
     )
 {
     Config         = aConfig;
     Loader         = aLoader;
     Factory        = aFactory;
     QueryFactory   = aFactory.GetQueryFactory();
     Connetion      = aConnection;
     ValueExtractor = aValueExtactor;
 }
Example #21
0
 public void GetValues(List <ValueTuple <string, string> > vals)
 {
     if (_children != null)
     {
         for (int i = 0, icnt = _children.Length; i < icnt; ++i)
         {
             _children[i].GetValues(vals);
         }
     }
     else
     {
         string valStr = ValueExtractor.ValueToString(_value, _kind);
         vals.Add((_fieldName, valStr));
     }
 }
Example #22
0
        public void ContextualHandler_Throws_InvalidCastException_If_No_Result_Assigned()
        {
            // Arrange
            ValueExtractor extractor = ValueExtractor.Create(config =>
            {
                config.UseHandler <string>(
                    (obj, ctx) =>
                {
                });
            });

            // Act
            TestDelegate test = () => extractor.Extract <string>("");

            // Assert
            Assert.That(test, Throws.TypeOf <InvalidCastException>());
        }
Example #23
0
        internal InsertUpdateQuery(PropertyBinder aBinder, T aData, bool isNullBind, ValueExtractor anExtractor)
            : base(aBinder)
        {
            ValueBinder valuebinder = Database.Current.Factory.GetValueBinder();

            aBinder.BindProperty <T>(

                delegate(PropertyMap aMap)
            {
                valuebinder.BindValue(query.GetStatement(), aMap, aData, isNullBind);
            },
                delegate(IdentityMap aMap)
            {
                setIdentity(aMap.GetColumn());
            },
                delegate(PropertyMap aMap, MemberInfo[] aParentsMembers)
            {
                var field = anExtractor.GetValue(aData, aParentsMembers);
                valuebinder.BindValue(query.GetStatement(), aMap, field, isNullBind);
            });
        }
Example #24
0
 internal virtual object Extract(object o)
 {
     return(ValueExtractor.Extract(o));
 }
Example #25
0
 internal UpdateQuery(PropertyBinder aBinder, T aData, bool isNullBind, ValueExtractor anExtractor)
     : base(aBinder, aData, isNullBind, anExtractor)
 {
 }
 IValueExtractor ICodingStyle.GetValueExtractor(IType type) => ValueExtractor.Get(type);
Example #27
0
 public ModelCriteriaImpl(SqlFactory aFactory, PropertyBinder aBinder, ValueExtractor anExtractor)
 {
     propertyBinder = aBinder;
     extractor      = anExtractor;
     factory        = aFactory;
 }
Example #28
0
 public TemplateBinder()
 {
     PropertyBinder    = Database.Current.Factory.GetInstance <PropertyBinder>();
     ValueExtractor    = Database.Current.Factory.GetInstance <ValueExtractor>();
     CacheBinderHelper = new CacheBinderHelper <T>();
 }
Example #29
0
 public QueryFactoryImpl(PropertyBinder aBinder, ValueExtractor aValueExtrator)
 {
     Binder         = aBinder;
     ValueExtractor = aValueExtrator;
 }
Example #30
-1
        public void GetValue(ClrHeap heap, ulong address, Queue <ValueTuple <TypeValue, ulong> > que)
        {
            que.Clear();
            que.Enqueue((this, address));
            while (que.Count > 0)
            {
                (TypeValue val, ulong addr) = que.Dequeue();
                if (val._type == null)
                {
                    ClrType clrType = heap.GetObjectType(addr);
                    if (clrType == null)
                    {
                        continue;
                    }
                    val._type = clrType;
                    val._kind = TypeExtractor.GetElementKind(clrType);
                    val.SetValue(addr);
                }
                if (val._children != null)
                {
                    for (int i = 0, icnt = val._children.Length; i < icnt; ++i)
                    {
                        TypeValue fldVal = val._children[i];

                        if (fldVal._fieldName != null && fldVal._field == null)
                        {
                            ClrInstanceField f = val._type.GetFieldByName(fldVal._fieldName);
                            if (f == null)
                            {
                                continue;
                            }
                            fldVal._field = f;
                            fldVal._type  = f.Type;
                            fldVal._kind  = TypeExtractor.GetElementKind(f.Type);
                        }
                        object v = ValueExtractor.GetFieldValue(heap, addr, fldVal._type.IsValueClass, fldVal._field, fldVal._kind);
                        ulong  a = (v is ulong) ? (ulong)v : Constants.InvalidAddress;
                        fldVal.SetValue(v);
                        que.Enqueue((val._children[i], (ulong)val._value));
                    }
                }
                else
                {
                    if (val._fieldName != null && val._field == null)
                    {
                        ClrInstanceField f = val._type.GetFieldByName(val._fieldName);
                        val._field = f;
                        val._type  = f.Type;
                        val._kind  = TypeExtractor.GetElementKind(f.Type);
                    }
                    object v = ValueExtractor.GetFieldValue(heap, addr, val._type.IsValueClass, val._field, val._kind);
                    val.SetValue(v);
                }
            }
        }