private int ComputeBestMatch(AppliesTo appliesTo, PSObject currentObject) { int num1 = -1; foreach (TypeOrGroupReference reference in appliesTo.referenceList) { MshExpression ex = (MshExpression)null; if (reference.conditionToken != null) { ex = this._expressionFactory.CreateFromExpressionToken(reference.conditionToken); } int num2 = -1; if (reference is TypeReference typeReference) { num2 = this.MatchTypeIndex(typeReference.name, currentObject, ex); } else { TypeGroupDefinition groupDefinition = DisplayDataQuery.FindGroupDefinition(this._db, (reference as TypeGroupReference).name); if (groupDefinition != null) { num2 = this.ComputeBestMatchInGroup(groupDefinition, currentObject, ex); } } if (num2 == 0) { return(num2); } if (num1 == -1 || num1 < num2) { num1 = num2; } } return(num1); }
/// <summary> /// given an appliesTo list, it finds all the types that are contained (following type /// group references) /// </summary> /// <param name="db">database to use</param> /// <param name="appliesTo">object to lookup</param> /// <returns></returns> internal static AppliesTo GetAllApplicableTypes(TypeInfoDataBase db, AppliesTo appliesTo) { Hashtable allTypes = new Hashtable(StringComparer.OrdinalIgnoreCase); foreach (TypeOrGroupReference r in appliesTo.referenceList) { // if it is a type reference, just add the type name TypeReference tr = r as TypeReference; if (tr != null) { if (!allTypes.ContainsKey(tr.name)) { allTypes.Add(tr.name, null); } } else { // check if we have a type group reference TypeGroupReference tgr = r as TypeGroupReference; if (tgr == null) { continue; } // find the type group definition the reference points to TypeGroupDefinition tgd = FindGroupDefinition(db, tgr.name); if (tgd == null) { continue; } // we found the group, go over it foreach (TypeReference x in tgd.typeReferenceList) { if (!allTypes.ContainsKey(x.name)) { allTypes.Add(x.name, null); } } } } AppliesTo retVal = new AppliesTo(); foreach (DictionaryEntry x in allTypes) { retVal.AddAppliesToType(x.Key as string); } return(retVal); }
private AppliesTo LoadAppliesToSection(System.Xml.XmlNode appliesToNode, bool allowSelectionCondition) { using (base.StackFrame(appliesToNode)) { AppliesTo to = new AppliesTo(); foreach (System.Xml.XmlNode node in appliesToNode.ChildNodes) { using (base.StackFrame(node)) { if (base.MatchNodeName(node, "SelectionSetName")) { TypeGroupReference item = this.LoadTypeGroupReference(node); if (item == null) { return null; } to.referenceList.Add(item); } else if (base.MatchNodeName(node, "TypeName")) { TypeReference reference2 = this.LoadTypeReference(node); if (reference2 == null) { return null; } to.referenceList.Add(reference2); } else if (allowSelectionCondition && base.MatchNodeName(node, "SelectionCondition")) { TypeOrGroupReference reference3 = this.LoadSelectionConditionNode(node); if (reference3 == null) { return null; } to.referenceList.Add(reference3); } else { base.ProcessUnknownNode(node); } } } if (to.referenceList.Count == 0) { base.ReportError(StringUtil.Format(FormatAndOutXmlLoadingStrings.EmptyAppliesTo, base.ComputeCurrentXPath(), base.FilePath)); return null; } return to; } }
private int ComputeBestMatch(AppliesTo appliesTo, PSObject currentObject) { int best = BestMatchIndexUndefined; foreach (TypeOrGroupReference r in appliesTo.referenceList) { PSPropertyExpression ex = null; if (r.conditionToken != null) { ex = _expressionFactory.CreateFromExpressionToken(r.conditionToken); } int currentMatch = BestMatchIndexUndefined; TypeReference tr = r as TypeReference; if (tr != null) { // we have a type currentMatch = MatchTypeIndex(tr.name, currentObject, ex); } else { // we have a type group reference TypeGroupReference tgr = r as TypeGroupReference; // find the type group definition the reference points to TypeGroupDefinition tgd = DisplayDataQuery.FindGroupDefinition(_db, tgr.name); if (tgd != null) { // we found the group, see if the group has the type currentMatch = ComputeBestMatchInGroup(tgd, currentObject, ex); } } if (currentMatch == BestMatchIndexPerfect) { return(currentMatch); } if (best == BestMatchIndexUndefined || best < currentMatch) { best = currentMatch; } } return(best); }
internal static AppliesTo GetAllApplicableTypes(TypeInfoDataBase db, AppliesTo appliesTo) { Hashtable hashtable = new Hashtable(StringComparer.OrdinalIgnoreCase); foreach (TypeOrGroupReference reference in appliesTo.referenceList) { TypeReference reference2 = reference as TypeReference; if (reference2 != null) { if (!hashtable.ContainsKey(reference2.name)) { hashtable.Add(reference2.name, null); } } else { TypeGroupReference reference3 = reference as TypeGroupReference; if (reference3 != null) { TypeGroupDefinition definition = FindGroupDefinition(db, reference3.name); if (definition != null) { foreach (TypeReference reference4 in definition.typeReferenceList) { if (!hashtable.ContainsKey(reference4.name)) { hashtable.Add(reference4.name, null); } } } } } } AppliesTo to = new AppliesTo(); foreach (DictionaryEntry entry in hashtable) { to.AddAppliesToType(entry.Key as string); } return(to); }
internal static AppliesTo GetAllApplicableTypes(TypeInfoDataBase db, AppliesTo appliesTo) { Hashtable hashtable = new Hashtable(StringComparer.OrdinalIgnoreCase); foreach (TypeOrGroupReference reference in appliesTo.referenceList) { TypeReference reference2 = reference as TypeReference; if (reference2 != null) { if (!hashtable.ContainsKey(reference2.name)) { hashtable.Add(reference2.name, null); } } else { TypeGroupReference reference3 = reference as TypeGroupReference; if (reference3 != null) { TypeGroupDefinition definition = FindGroupDefinition(db, reference3.name); if (definition != null) { foreach (TypeReference reference4 in definition.typeReferenceList) { if (!hashtable.ContainsKey(reference4.name)) { hashtable.Add(reference4.name, null); } } } } } } AppliesTo to = new AppliesTo(); foreach (DictionaryEntry entry in hashtable) { to.AddAppliesToType(entry.Key as string); } return to; }
internal static AppliesTo GetAllApplicableTypes( TypeInfoDataBase db, AppliesTo appliesTo) { Hashtable hashtable = new Hashtable((IEqualityComparer)StringComparer.OrdinalIgnoreCase); foreach (TypeOrGroupReference reference in appliesTo.referenceList) { if (reference is TypeReference typeReference) { if (!hashtable.ContainsKey((object)typeReference.name)) { hashtable.Add((object)typeReference.name, (object)null); } } else if (reference is TypeGroupReference typeGroupReference) { TypeGroupDefinition groupDefinition = DisplayDataQuery.FindGroupDefinition(db, typeGroupReference.name); if (groupDefinition != null) { foreach (TypeReference typeReference in groupDefinition.typeReferenceList) { if (!hashtable.ContainsKey((object)typeReference.name)) { hashtable.Add((object)typeReference.name, (object)null); } } } } } AppliesTo appliesTo1 = new AppliesTo(); foreach (DictionaryEntry dictionaryEntry in hashtable) { appliesTo1.AddAppliesToType(dictionaryEntry.Key as string); } return(appliesTo1); }
private int ComputeBestMatch(AppliesTo appliesTo, PSObject currentObject) { int num = -1; foreach (TypeOrGroupReference reference in appliesTo.referenceList) { MshExpression ex = null; if (reference.conditionToken != null) { ex = this._expressionFactory.CreateFromExpressionToken(reference.conditionToken); } int num2 = -1; TypeReference reference2 = reference as TypeReference; if (reference2 != null) { num2 = this.MatchTypeIndex(reference2.name, currentObject, ex); } else { TypeGroupReference reference3 = reference as TypeGroupReference; TypeGroupDefinition tgd = DisplayDataQuery.FindGroupDefinition(this._db, reference3.name); if (tgd != null) { num2 = this.ComputeBestMatchInGroup(tgd, currentObject, ex); } } if (num2 == 0) { return(num2); } if ((num == -1) || (num < num2)) { num = num2; } } return(num); }
private int ComputeBestMatch(AppliesTo appliesTo, PSObject currentObject) { int num = -1; foreach (TypeOrGroupReference reference in appliesTo.referenceList) { MshExpression ex = null; if (reference.conditionToken != null) { ex = this._expressionFactory.CreateFromExpressionToken(reference.conditionToken); } int num2 = -1; TypeReference reference2 = reference as TypeReference; if (reference2 != null) { num2 = this.MatchTypeIndex(reference2.name, currentObject, ex); } else { TypeGroupReference reference3 = reference as TypeGroupReference; TypeGroupDefinition tgd = DisplayDataQuery.FindGroupDefinition(this._db, reference3.name); if (tgd != null) { num2 = this.ComputeBestMatchInGroup(tgd, currentObject, ex); } } if (num2 == 0) { return num2; } if ((num == -1) || (num < num2)) { num = num2; } } return num; }
private ViewDefinition LoadViewFromObjectModle(string typeName, FormatViewDefinition formatView, int viewIndex) { TypeReference reference = new TypeReference { name = typeName }; AppliesTo to = new AppliesTo { referenceList = { reference } }; ViewDefinition definition = new ViewDefinition { appliesTo = to, name = formatView.Name }; PSControl control = formatView.Control; if (control is TableControl) { TableControl table = control as TableControl; definition.mainControl = this.LoadTableControlFromObjectModel(table, viewIndex, typeName); } else if (control is ListControl) { ListControl list = control as ListControl; definition.mainControl = this.LoadListControlFromObjectModel(list, viewIndex, typeName); } else if (control is WideControl) { WideControl wide = control as WideControl; definition.mainControl = this.LoadWideControlFromObjectModel(wide, viewIndex, typeName); } if (definition.mainControl == null) { return null; } return definition; }
private AppliesTo LoadAppliesToSection(XmlNode appliesToNode, bool allowSelectionCondition) { using (this.StackFrame(appliesToNode)) { AppliesTo appliesTo = new AppliesTo(); // expect: type ref, group ref, or nothing foreach (XmlNode n in appliesToNode.ChildNodes) { using (this.StackFrame(n)) { if (MatchNodeName(n, XmlTags.SelectionSetNameNode)) { TypeGroupReference tgr = LoadTypeGroupReference(n); if (tgr != null) { appliesTo.referenceList.Add(tgr); } else { return null; } } else if (MatchNodeName(n, XmlTags.TypeNameNode)) { TypeReference tr = LoadTypeReference(n); if (tr != null) { appliesTo.referenceList.Add(tr); } else { return null; } } else if (allowSelectionCondition && MatchNodeName(n, XmlTags.SelectionConditionNode)) { TypeOrGroupReference tgr = LoadSelectionConditionNode(n); if (tgr != null) { appliesTo.referenceList.Add(tgr); } else { return null; } } else { this.ProcessUnknownNode(n); } } // using } if (appliesTo.referenceList.Count == 0) { // we do not accept an empty list //Error at XPath {0} in file {1}: No type or condition is specified for applying the view. this.ReportError(StringUtil.Format(FormatAndOutXmlLoadingStrings.EmptyAppliesTo, ComputeCurrentXPath(), FilePath)); return null; } return appliesTo; } }
internal TypeMatchItem(object obj, AppliesTo a, PSObject currentObject) { this._item = obj; this._appliesTo = a; this._currentObject = currentObject; }
private AppliesTo LoadAppliesToSectionFromObjectModel(List<string> selectedBy) { AppliesTo to = new AppliesTo(); foreach (string str in selectedBy) { if (string.IsNullOrEmpty(str)) { return null; } TypeReference item = new TypeReference { name = str }; to.referenceList.Add(item); } return to; }
internal NonscalarTypeHeader(OutGridViewCommand parentCmd, PSObject input) : base(parentCmd) { TableView tableView = new TableView(); tableView.Initialize(parentCmd.expressionFactory, parentCmd.typeInfoDataBase); ViewDefinition definition = DisplayDataQuery.GetViewByShapeAndType(parentCmd.expressionFactory, parentCmd.typeInfoDataBase, FormatShape.Table, input.TypeNames, null); if (definition != null) { parentCmd.windowProxy.AddColumnsAndItem(input, tableView, (TableControlBody) definition.mainControl); this.appliesTo = definition.appliesTo; } else { parentCmd.windowProxy.AddColumnsAndItem(input, tableView); this.appliesTo = new AppliesTo(); int num = 0; foreach (string str in input.TypeNames) { if ((num > 0) && (str.Equals(typeof(object).FullName, StringComparison.OrdinalIgnoreCase) || str.Equals(typeof(MarshalByRefObject).FullName, StringComparison.OrdinalIgnoreCase))) { break; } this.appliesTo.AddAppliesToType(str); num++; } } }
internal TypeMatchItem(object obj, AppliesTo a) { this._item = obj; this._appliesTo = a; }
internal TypeMatchItem(object obj, AppliesTo a) { Item = obj; AppliesTo = a; }
internal TypeMatchItem(object obj, AppliesTo a, PSObject currentObject) { Item = obj; AppliesTo = a; CurrentObject = currentObject; }
/// <summary> /// Load the view into a ViewDefinition /// </summary> /// <param name="typeNames">the TypeName tag under SelectedBy tag</param> /// <param name="formatView"></param> /// <param name="viewIndex"></param> /// <returns></returns> private ViewDefinition LoadViewFromObjectModel(List<string> typeNames, FormatViewDefinition formatView, int viewIndex) { // Get AppliesTo information AppliesTo appliesTo = new AppliesTo(); foreach (var typename in typeNames) { TypeReference tr = new TypeReference { name = typename }; appliesTo.referenceList.Add(tr); } // Set AppliesTo and Name in the view ViewDefinition view = new ViewDefinition(); view.appliesTo = appliesTo; view.name = formatView.Name; var firstTypeName = typeNames[0]; PSControl control = formatView.Control; if (control is TableControl) { var tableControl = control as TableControl; view.mainControl = LoadTableControlFromObjectModel(tableControl, viewIndex, firstTypeName); } else if (control is ListControl) { var listControl = control as ListControl; view.mainControl = LoadListControlFromObjectModel(listControl, viewIndex, firstTypeName); } else if (control is WideControl) { var wideControl = control as WideControl; view.mainControl = LoadWideControlFromObjectModel(wideControl, viewIndex, firstTypeName); } else { view.mainControl = LoadCustomControlFromObjectModel((CustomControl)control, viewIndex, firstTypeName); } // Check if the PSControl is successfully loaded if (view.mainControl == null) { return null; } view.outOfBand = control.OutOfBand; if (control.GroupBy != null) { view.groupBy = new GroupBy { startGroup = new StartGroup { expression = LoadExpressionFromObjectModel(control.GroupBy.Expression, viewIndex, firstTypeName) } }; if (control.GroupBy.Label != null) { view.groupBy.startGroup.labelTextToken = new TextToken { text = control.GroupBy.Label }; } if (control.GroupBy.CustomControl != null) { view.groupBy.startGroup.control = LoadCustomControlFromObjectModel(control.GroupBy.CustomControl, viewIndex, firstTypeName); } } return view; }
/// <summary> /// Load EntrySelectedBy (TypeName) into AppliesTo /// </summary> /// <returns></returns> private AppliesTo LoadAppliesToSectionFromObjectModel(List<string> selectedBy, List<DisplayEntry> condition) { AppliesTo appliesTo = new AppliesTo(); if (selectedBy != null) { foreach (string type in selectedBy) { if (String.IsNullOrEmpty(type)) return null; TypeReference tr = new TypeReference { name = type }; appliesTo.referenceList.Add(tr); } } if (condition != null) { foreach (var cond in condition) { // TODO } } return appliesTo; }
internal NonscalarTypeHeader(OutGridViewCommand parentCmd, PSObject input) : base(parentCmd) { // Prepare a table view. TableView tableView = new TableView(); tableView.Initialize(parentCmd._expressionFactory, parentCmd._typeInfoDataBase); // Request a view definition from the type database. ViewDefinition viewDefinition = DisplayDataQuery.GetViewByShapeAndType(parentCmd._expressionFactory, parentCmd._typeInfoDataBase, FormatShape.Table, input.TypeNames, null); if (viewDefinition != null) { // Create a header using a view definition provided by the types database. parentCmd._windowProxy.AddColumnsAndItem(input, tableView, (TableControlBody)viewDefinition.mainControl); // Remember all type names and type groups the current view applies to. _appliesTo = viewDefinition.appliesTo; } else { // Create a header using only the input object's properties. parentCmd._windowProxy.AddColumnsAndItem(input, tableView); _appliesTo = new AppliesTo(); // Add all type names except for Object and MarshalByRefObject types because they are too generic. // Leave the Object type name if it is the only type name. int index = 0; foreach (string typeName in input.TypeNames) { if (index > 0 && (typeName.Equals(typeof(Object).FullName, StringComparison.OrdinalIgnoreCase) || typeName.Equals(typeof(MarshalByRefObject).FullName, StringComparison.OrdinalIgnoreCase))) { break; } _appliesTo.AddAppliesToType(typeName); index++; } } }
private int ComputeBestMatch(AppliesTo appliesTo, PSObject currentObject) { int best = BestMatchIndexUndefined; foreach (TypeOrGroupReference r in appliesTo.referenceList) { MshExpression ex = null; if (r.conditionToken != null) { ex = _expressionFactory.CreateFromExpressionToken(r.conditionToken); } int currentMatch = BestMatchIndexUndefined; TypeReference tr = r as TypeReference; if (tr != null) { // we have a type currentMatch = MatchTypeIndex(tr.name, currentObject, ex); } else { // we have a type group reference TypeGroupReference tgr = r as TypeGroupReference; // find the type group definition the reference points to TypeGroupDefinition tgd = DisplayDataQuery.FindGroupDefinition(_db, tgr.name); if (tgd != null) { // we found the group, see if the group has the type currentMatch = ComputeBestMatchInGroup(tgd, currentObject, ex); } } if (currentMatch == BestMatchIndexPerfect) return currentMatch; if (best == BestMatchIndexUndefined || best < currentMatch) { best = currentMatch; } } return best; }
/// <summary> /// given an appliesTo list, it finds all the types that are contained (following type /// group references) /// </summary> /// <param name="db">database to use</param> /// <param name="appliesTo">object to lookup</param> /// <returns></returns> internal static AppliesTo GetAllApplicableTypes(TypeInfoDataBase db, AppliesTo appliesTo) { Hashtable allTypes = new Hashtable(StringComparer.OrdinalIgnoreCase); foreach (TypeOrGroupReference r in appliesTo.referenceList) { // if it is a type reference, just add the type name TypeReference tr = r as TypeReference; if (tr != null) { if (!allTypes.ContainsKey(tr.name)) allTypes.Add(tr.name, null); } else { // check if we have a type group reference TypeGroupReference tgr = r as TypeGroupReference; if (tgr == null) continue; // find the type group definition the reference points to TypeGroupDefinition tgd = FindGroupDefinition(db, tgr.name); if (tgd == null) continue; // we found the group, go over it foreach (TypeReference x in tgd.typeReferenceList) { if (!allTypes.ContainsKey(x.name)) allTypes.Add(x.name, null); } } } AppliesTo retVal = new AppliesTo(); foreach (DictionaryEntry x in allTypes) { retVal.AddAppliesToType(x.Key as string); } return retVal; }