private static ViewDefinition GetView(MshExpressionFactory expressionFactory, TypeInfoDataBase db, Type mainControlType, Collection <string> typeNames, string viewName) { TypeMatch match = new TypeMatch(expressionFactory, db, typeNames); foreach (ViewDefinition definition in db.viewDefinitionsSection.viewDefinitionList) { if ((definition == null) || (mainControlType != definition.mainControl.GetType())) { ActiveTracer.WriteLine("NOT MATCH {0} NAME: {1}", new object[] { ControlBase.GetControlShapeName(definition.mainControl), (definition != null) ? definition.name : string.Empty }); } else if (IsOutOfBandView(definition)) { ActiveTracer.WriteLine("NOT MATCH OutOfBand {0} NAME: {1}", new object[] { ControlBase.GetControlShapeName(definition.mainControl), definition.name }); } else if (definition.appliesTo == null) { ActiveTracer.WriteLine("NOT MATCH {0} NAME: {1} No applicable types", new object[] { ControlBase.GetControlShapeName(definition.mainControl), definition.name }); } else if ((viewName != null) && !string.Equals(definition.name, viewName, StringComparison.OrdinalIgnoreCase)) { ActiveTracer.WriteLine("NOT MATCH {0} NAME: {1}", new object[] { ControlBase.GetControlShapeName(definition.mainControl), definition.name }); } else { try { TypeMatch.SetTracer(ActiveTracer); if (match.PerfectMatch(new TypeMatchItem(definition, definition.appliesTo))) { TraceHelper(definition, true); return(definition); } } finally { TypeMatch.ResetTracer(); } TraceHelper(definition, false); } } ViewDefinition bestMatch = GetBestMatch(match); if (bestMatch == null) { Collection <string> collection = Deserializer.MaskDeserializationPrefix(typeNames); if (collection != null) { bestMatch = GetView(expressionFactory, db, mainControlType, collection, viewName); } } return(bestMatch); }
private static void TraceHelper(ViewDefinition vd, bool isMatched) { if ((ActiveTracer.Options & PSTraceSourceOptions.WriteLine) != PSTraceSourceOptions.None) { foreach (TypeOrGroupReference reference in vd.appliesTo.referenceList) { StringBuilder builder = new StringBuilder(); TypeReference reference2 = reference as TypeReference; builder.Append(isMatched ? "MATCH FOUND" : "NOT MATCH"); if (reference2 != null) { builder.AppendFormat(CultureInfo.InvariantCulture, " {0} NAME: {1} TYPE: {2}", new object[] { ControlBase.GetControlShapeName(vd.mainControl), vd.name, reference2.name }); } else { TypeGroupReference reference3 = reference as TypeGroupReference; builder.AppendFormat(CultureInfo.InvariantCulture, " {0} NAME: {1} GROUP: {2}", new object[] { ControlBase.GetControlShapeName(vd.mainControl), vd.name, reference3.name }); } ActiveTracer.WriteLine(builder.ToString(), new object[0]); } } }