private void AddEntitiesToSchema(Microsoft.Management.Odata.Schema.Schema logicalSchema, Microsoft.Management.Odata.Schema.Schema userSchema, List <PSSchemaBuilder.EntityDataForSchemaBuilding> entityDataCollection, Dictionary <string, CommandInfo> sessionCmdlets) { foreach (PSSchemaBuilder.EntityDataForSchemaBuilding referenceSetCommand in entityDataCollection) { if (!referenceSetCommand.IncludeInSchema) { continue; } userSchema.AddEntity(referenceSetCommand.EntityName, referenceSetCommand.IncludeEntitySet, logicalSchema); PSEntityMetadata pSEntityMetadatum = new PSEntityMetadata(); PSEntityMetadata item = (PSEntityMetadata)logicalSchema.EntityMetadataDictionary[referenceSetCommand.EntityName]; foreach (CommandType command in referenceSetCommand.Commands) { PSCmdletInfo pSCmdletInfo = item.Cmdlets[command]; pSEntityMetadatum.Cmdlets.Add(command, PSSchemaBuilder.ConstructMetadata(pSCmdletInfo, sessionCmdlets)); } Dictionary <string, PSSchemaBuilder.EntityDataForSchemaBuilding.ReferencePropertyData> .Enumerator enumerator = referenceSetCommand.ReferenceSetCommands.GetEnumerator(); try { while (enumerator.MoveNext()) { KeyValuePair <string, PSSchemaBuilder.EntityDataForSchemaBuilding.ReferencePropertyData> keyValuePair = enumerator.Current; PSReferenceSetCmdletInfo pSReferenceSetCmdletInfo = null; PSReferenceSetCmdletInfo item1 = null; PSReferenceSetCmdletInfo pSReferenceSetCmdletInfo1 = null; if (keyValuePair.Value.IncludeAdd) { pSReferenceSetCmdletInfo = item.CmdletsForReferenceSets[keyValuePair.Key].Cmdlets[CommandType.AddReference]; } if (keyValuePair.Value.IncludeRemove) { item1 = item.CmdletsForReferenceSets[keyValuePair.Key].Cmdlets[CommandType.RemoveReference]; } if (keyValuePair.Value.IncludeGet) { pSReferenceSetCmdletInfo1 = item.CmdletsForReferenceSets[keyValuePair.Key].Cmdlets[CommandType.GetReference]; } PSEntityMetadata.ReferenceSetCmdlets referenceSetCmdlet = new PSEntityMetadata.ReferenceSetCmdlets(item.CmdletsForReferenceSets[keyValuePair.Key].PropertyType, pSReferenceSetCmdletInfo, item1, pSReferenceSetCmdletInfo1, keyValuePair.Value.GetHidden); pSEntityMetadatum.CmdletsForReferenceSets[keyValuePair.Key] = referenceSetCmdlet; } } finally { enumerator.Dispose(); } userSchema.EntityMetadataDictionary.Add(referenceSetCommand.EntityName, pSEntityMetadatum); } }
internal Dictionary <string, PSSchemaBuilder.EntityDataForSchemaBuilding.ReferencePropertyData> FindSupportedReferenceCommands(PSEntityMetadata entityMetadata, HashSet <string> initialSessionCommands) { string str; Dictionary <string, PSSchemaBuilder.EntityDataForSchemaBuilding.ReferencePropertyData> strs = new Dictionary <string, PSSchemaBuilder.EntityDataForSchemaBuilding.ReferencePropertyData>(); foreach (KeyValuePair <string, PSEntityMetadata.ReferenceSetCmdlets> cmdletsForReferenceSet in entityMetadata.CmdletsForReferenceSets) { Func <string, bool> func = null; Func <string, bool> func1 = null; Func <string, bool> func2 = null; PSSchemaBuilder.EntityDataForSchemaBuilding.ReferencePropertyData referencePropertyDatum = new PSSchemaBuilder.EntityDataForSchemaBuilding.ReferencePropertyData(); PSReferenceSetCmdletInfo pSReferenceSetCmdletInfo = null; if (cmdletsForReferenceSet.Value.Cmdlets.TryGetValue(CommandType.AddReference, out pSReferenceSetCmdletInfo)) { HashSet <string> strs1 = initialSessionCommands; if (func == null) { func = (string item) => string.Equals(item, pSReferenceSetCmdletInfo.CmdletName, StringComparison.OrdinalIgnoreCase); } str = strs1.FirstOrDefault <string>(func); referencePropertyDatum.IncludeAdd = str != null; } if (cmdletsForReferenceSet.Value.Cmdlets.TryGetValue(CommandType.RemoveReference, out pSReferenceSetCmdletInfo)) { HashSet <string> strs2 = initialSessionCommands; if (func1 == null) { func1 = (string item) => string.Equals(item, pSReferenceSetCmdletInfo.CmdletName, StringComparison.OrdinalIgnoreCase); } str = strs2.FirstOrDefault <string>(func1); referencePropertyDatum.IncludeRemove = str != null; } if (cmdletsForReferenceSet.Value.Cmdlets.TryGetValue(CommandType.GetReference, out pSReferenceSetCmdletInfo)) { HashSet <string> strs3 = initialSessionCommands; if (func2 == null) { func2 = (string item) => string.Equals(item, pSReferenceSetCmdletInfo.CmdletName, StringComparison.OrdinalIgnoreCase); } str = strs3.FirstOrDefault <string>(func2); referencePropertyDatum.IncludeGet = true; referencePropertyDatum.GetHidden = str == null; } strs.Add(cmdletsForReferenceSet.Key, referencePropertyDatum); } return(strs); }
public ReferenceSetCmdlets(PSEntityMetadata.ReferenceSetCmdlets.ReferencePropertyType propertyType, PSReferenceSetCmdletInfo addRefCmdlet, PSReferenceSetCmdletInfo removeRefCmdlet, PSReferenceSetCmdletInfo getRefCmdlet = null, bool getRefHidden = false) { this.Cmdlets = new Dictionary<CommandType, PSReferenceSetCmdletInfo>(); this.PropertyType = propertyType; if (addRefCmdlet != null) { this.Cmdlets.Add(CommandType.AddReference, addRefCmdlet); } if (removeRefCmdlet != null) { this.Cmdlets.Add(CommandType.RemoveReference, removeRefCmdlet); } if (getRefCmdlet != null) { this.Cmdlets.Add(CommandType.GetReference, getRefCmdlet); this.GetRefHidden = getRefHidden; } }
public IReferenceSetCommand GetReferenceSetCommand(CommandType commandType, UserContext userContext, ResourceProperty property, EntityMetadata entityMetadata, string membershipId, ResourceType resourceType) { Envelope <PSRunspace, UserContext> envelope = this.runspaceStore.Borrow(userContext, membershipId); PSReferenceSetCmdletInfo item = null; try { item = ((PSEntityMetadata)entityMetadata).CmdletsForReferenceSets[property.Name].Cmdlets[commandType]; } catch (KeyNotFoundException keyNotFoundException) { Tracer tracer = new Tracer(); tracer.DebugMessage(string.Concat("GetCommand cannot find commandType: ", commandType.ToString())); object[] fullName = new object[3]; fullName[0] = property.ResourceType.FullName; fullName[1] = property.Name; fullName[2] = commandType.ToString(); string str = string.Format(CultureInfo.CurrentCulture, Resources.PropertyDoesNotHaveCommand, fullName); throw new InvalidOperationException(str); } return(new PSReferenceCommand(envelope, resourceType, item)); }
public ReferenceSetCmdlets(PSEntityMetadata.ReferenceSetCmdlets.ReferencePropertyType propertyType, PSReferenceSetCmdletInfo addRefCmdlet, PSReferenceSetCmdletInfo removeRefCmdlet, PSReferenceSetCmdletInfo getRefCmdlet = null, bool getRefHidden = false) { this.Cmdlets = new Dictionary <CommandType, PSReferenceSetCmdletInfo>(); this.PropertyType = propertyType; if (addRefCmdlet != null) { this.Cmdlets.Add(CommandType.AddReference, addRefCmdlet); } if (removeRefCmdlet != null) { this.Cmdlets.Add(CommandType.RemoveReference, removeRefCmdlet); } if (getRefCmdlet != null) { this.Cmdlets.Add(CommandType.GetReference, getRefCmdlet); this.GetRefHidden = getRefHidden; } }
public void AddCmdletsForReference(string property, PSEntityMetadata.ReferenceSetCmdlets.ReferencePropertyType propertyType, PSReferenceSetCmdletInfo addRefCmdlet, PSReferenceSetCmdletInfo removeRefCmdlet, PSReferenceSetCmdletInfo getRefCmdlet = null) { this.CmdletsForReferenceSets.Add(property, new PSEntityMetadata.ReferenceSetCmdlets(propertyType, addRefCmdlet, removeRefCmdlet, getRefCmdlet, false)); }
public PSReferenceCommand(Envelope <PSRunspace, UserContext> runspace, ResourceType entityType, PSReferenceSetCmdletInfo referenceCmdletInfo) : base(runspace, entityType, referenceCmdletInfo, (CommandType)1) { this.referenceCmdletInfo = referenceCmdletInfo; }
private static PSReferenceSetCmdletInfo CreateRefSetCmdlet(ResourceType otherResourceType, ResourceType type, XElement element) { XElement uniqueElement = element.GetUniqueElement("http://schemas.microsoft.com/powershell-web-services/2010/09", "Cmdlet"); XElement xElement = element.GetUniqueElement("http://schemas.microsoft.com/powershell-web-services/2010/09", "ParameterForThisObject"); XElement uniqueElement1 = element.GetUniqueElement("http://schemas.microsoft.com/powershell-web-services/2010/09", "ParameterForReferredObject"); PSReferenceSetCmdletInfo pSReferenceSetCmdletInfo = new PSReferenceSetCmdletInfo(uniqueElement.Value); PSParameterSet pSParameterSet = new PSParameterSet("Default"); foreach (XElement xElement1 in xElement.Nodes()) { XElement uniqueElement2 = xElement1.GetUniqueElement("http://schemas.microsoft.com/powershell-web-services/2010/09", "ParameterName"); pSParameterSet.Parameters.Add(uniqueElement2.Value); } foreach (XElement xElement2 in uniqueElement1.Nodes()) { XElement uniqueElement3 = xElement2.GetUniqueElement("http://schemas.microsoft.com/powershell-web-services/2010/09", "ParameterName"); pSParameterSet.Parameters.Add(uniqueElement3.Value); } pSReferenceSetCmdletInfo.ParameterSets.Add(pSParameterSet); SchemaLoader.PopulateReferringFieldParameterMapping(type, "ParameterForThisObject", pSReferenceSetCmdletInfo, xElement); SchemaLoader.PopulateReferredFieldParameterMapping(otherResourceType, "ParameterForReferredObject", pSReferenceSetCmdletInfo, uniqueElement1); XElement xElement3 = element.TryGetUniqueElement("http://schemas.microsoft.com/powershell-web-services/2010/09", "Options"); if (xElement3 != null) { foreach (XElement xElement4 in xElement3.Nodes()) { pSParameterSet.Parameters.Add(xElement4.Value); } SchemaLoader.PopulateCmdletUrlOptions(type, pSReferenceSetCmdletInfo, xElement3); } return pSReferenceSetCmdletInfo; }
private static void PopulateReferringFieldParameterMapping(ResourceType type, string xmlNodeName, PSReferenceSetCmdletInfo cmdletInfo, XElement fieldParameterMappingRoot) { XElement firstNode = (XElement)fieldParameterMappingRoot.FirstNode; while (firstNode != null) { string value = firstNode.GetUniqueElement("http://schemas.microsoft.com/powershell-web-services/2010/09", "FieldName").Value; string str = firstNode.GetUniqueElement("http://schemas.microsoft.com/powershell-web-services/2010/09", "ParameterName").Value; if (type.KeyProperties.FirstOrDefault<ResourceProperty>((ResourceProperty it) => it.Name == value) != null) { cmdletInfo.ReferringObjectParameterMapping.Add(value, str); firstNode = (XElement)firstNode.NextNode; } else { object[] name = new object[3]; name[0] = type.Name; name[1] = xmlNodeName; name[2] = value; throw new MetadataException(ExceptionHelpers.GetExceptionMessage(Resources.InvalidFieldInParameterMapping, name)); } } }
public PSReferenceCommand(Envelope<PSRunspace, UserContext> runspace, ResourceType entityType, PSReferenceSetCmdletInfo referenceCmdletInfo) : base(runspace, entityType, referenceCmdletInfo, (CommandType)1) { this.referenceCmdletInfo = referenceCmdletInfo; }