public PSCmdletInfo(PSCmdletInfo other) { this.CmdletName = other.CmdletName; this.ParameterSets = new List <PSParameterSet>(other.ParameterSets); this.FieldParameterMapping = new Dictionary <string, string>(other.FieldParameterMapping); this.Options = new HashSet <string>(other.Options, StringComparer.OrdinalIgnoreCase); this.ImmutableParameters = new Dictionary <string, string>(other.ImmutableParameters, StringComparer.OrdinalIgnoreCase); }
public PSCmdletInfo(PSCmdletInfo other) { this.CmdletName = other.CmdletName; this.ParameterSets = new List<PSParameterSet>(other.ParameterSets); this.FieldParameterMapping = new Dictionary<string, string>(other.FieldParameterMapping); this.Options = new HashSet<string>(other.Options, StringComparer.OrdinalIgnoreCase); this.ImmutableParameters = new Dictionary<string, string>(other.ImmutableParameters, StringComparer.OrdinalIgnoreCase); }
public PSCommand(Envelope <PSRunspace, UserContext> runspace, ResourceType entityType, PSCmdletInfo cmdletInfo, CommandType commandType = (CommandType)1) { this.syncObject = new object(); this.runspace = runspace; this.cmdletInfo = cmdletInfo; this.entityType = entityType; this.parameters = new Dictionary <string, object>(); this.powerShell = null; this.timer = new PswsTimer(new ElapsedEventHandler(this.TimerCallback), DataServiceController.Current.Configuration.PowerShell.Quotas.MaxExecutionTime, false, false); this.commandType = commandType; }
public PSCommand(Envelope<PSRunspace, UserContext> runspace, ResourceType entityType, PSCmdletInfo cmdletInfo, CommandType commandType = (CommandType)1) { this.syncObject = new object(); this.runspace = runspace; this.cmdletInfo = cmdletInfo; this.entityType = entityType; this.parameters = new Dictionary<string, object>(); this.powerShell = null; this.timer = new PswsTimer(new ElapsedEventHandler(this.TimerCallback), DataServiceController.Current.Configuration.PowerShell.Quotas.MaxExecutionTime, false, false); this.commandType = commandType; }
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); } }
private static PSCmdletInfo ConstructMetadata(PSCmdletInfo cmdletInfo, Dictionary <string, CommandInfo> availableCmdlets) { CommandInfo commandInfo = null; if (availableCmdlets.TryGetValue(cmdletInfo.CmdletName, out commandInfo)) { List <string> strs = new List <string>(); foreach (KeyValuePair <string, string> fieldParameterMapping in cmdletInfo.FieldParameterMapping) { if (commandInfo.Parameters.ContainsKey(fieldParameterMapping.Value)) { continue; } strs.Add(fieldParameterMapping.Key); } List <string> strs1 = new List <string>(); foreach (string option in cmdletInfo.Options) { if (commandInfo.Parameters.ContainsKey(option)) { continue; } strs1.Add(option); } if (strs.Count != 0 || strs1.Count != 0) { PSCmdletInfo pSCmdletInfo = new PSCmdletInfo(cmdletInfo); foreach (string str in strs) { pSCmdletInfo.FieldParameterMapping.Remove(str); } foreach (string str1 in strs1) { pSCmdletInfo.Options.Remove(str1); } return(pSCmdletInfo); } else { return(cmdletInfo); } } else { return(cmdletInfo); } }
private static PSCmdletInfo ConstructMetadata(PSCmdletInfo cmdletInfo, Dictionary<string, CommandInfo> availableCmdlets) { CommandInfo commandInfo = null; if (availableCmdlets.TryGetValue(cmdletInfo.CmdletName, out commandInfo)) { List<string> strs = new List<string>(); foreach (KeyValuePair<string, string> fieldParameterMapping in cmdletInfo.FieldParameterMapping) { if (commandInfo.Parameters.ContainsKey(fieldParameterMapping.Value)) { continue; } strs.Add(fieldParameterMapping.Key); } List<string> strs1 = new List<string>(); foreach (string option in cmdletInfo.Options) { if (commandInfo.Parameters.ContainsKey(option)) { continue; } strs1.Add(option); } if (strs.Count != 0 || strs1.Count != 0) { PSCmdletInfo pSCmdletInfo = new PSCmdletInfo(cmdletInfo); foreach (string str in strs) { pSCmdletInfo.FieldParameterMapping.Remove(str); } foreach (string str1 in strs1) { pSCmdletInfo.Options.Remove(str1); } return pSCmdletInfo; } else { return cmdletInfo; } } else { return cmdletInfo; } }
private static void PopulateCmdletUrlOptions(ResourceType resourceType, PSCmdletInfo cmdletInfo, XElement urlOptionsRoot) { XElement firstNode = (XElement)urlOptionsRoot.FirstNode; while (firstNode != null) { if (string.Equals(firstNode.Name.LocalName, "ParameterName", StringComparison.OrdinalIgnoreCase)) { cmdletInfo.Options.Add(firstNode.Value); firstNode = (XElement)firstNode.NextNode; } else { object[] localName = new object[2]; localName[0] = "ParameterName"; localName[1] = firstNode.Name.LocalName; throw new MetadataException(ExceptionHelpers.GetExceptionMessage(Resources.InvalidXmlTag, localName)); } } }
private static void PopulateCmdletMandatoryParameters(ResourceType resourceType, PSCmdletInfo cmdletInfo, XElement mandatoryParamsRoot) { XElement firstNode = (XElement)mandatoryParamsRoot.FirstNode; while (firstNode != null) { if (string.Equals(firstNode.Name.LocalName, "ParameterValue", StringComparison.OrdinalIgnoreCase)) { string value = firstNode.GetUniqueElement("http://schemas.microsoft.com/powershell-web-services/2010/09", "ParameterName").Value; string str = firstNode.GetUniqueElement("http://schemas.microsoft.com/powershell-web-services/2010/09", "Value").Value; cmdletInfo.ImmutableParameters.Add(value, str); firstNode = (XElement)firstNode.NextNode; } else { object[] localName = new object[2]; localName[0] = "ParameterValue"; localName[1] = firstNode.Name.LocalName; throw new MetadataException(ExceptionHelpers.GetExceptionMessage(Resources.InvalidXmlTag, localName)); } } }
private static void PopulateCmdletFieldParameterMapping(ResourceType type, string xmlNodeName, PSCmdletInfo 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.Properties.FirstOrDefault<ResourceProperty>((ResourceProperty it) => it.Name == value) != null) { cmdletInfo.FieldParameterMapping.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)); } } }
private static void PopulateParameterSets(ResourceType resourceType, PSCmdletInfo cmdletInfo, XElement parameterSetsNodeRoot) { XNamespace xNamespace = "http://schemas.microsoft.com/powershell-web-services/2010/09"; XElement firstNode = (XElement)parameterSetsNodeRoot.FirstNode; while (firstNode != null) { PSParameterSet pSParameterSet = new PSParameterSet(firstNode.GetUniqueElement("http://schemas.microsoft.com/powershell-web-services/2010/09", "Name").Value); foreach (XElement xElement in firstNode.Elements(xNamespace + "Parameter")) { string value = xElement.GetUniqueElement("http://schemas.microsoft.com/powershell-web-services/2010/09", "Name").Value; XElement xElement1 = xElement.TryGetUniqueElement("http://schemas.microsoft.com/powershell-web-services/2010/09", "IsSwitch"); bool flag = false; if (xElement1 != null) { try { flag = (bool)TypeConverter.ConvertTo(xElement1.Value, typeof(bool)); } catch (InvalidCastException invalidCastException1) { InvalidCastException invalidCastException = invalidCastException1; object[] objArray = new object[1]; objArray[0] = xElement1.Value; throw new MetadataException(ExceptionHelpers.GetExceptionMessage(invalidCastException, Resources.InvalidSwitchParameterValue, objArray), invalidCastException); } } XElement xElement2 = xElement.TryGetUniqueElement("http://schemas.microsoft.com/powershell-web-services/2010/09", "IsMandatory"); bool flag1 = false; if (xElement2 != null) { try { flag1 = (bool)TypeConverter.ConvertTo(xElement2.Value, typeof(bool)); } catch (InvalidCastException invalidCastException3) { InvalidCastException invalidCastException2 = invalidCastException3; object[] value1 = new object[1]; value1[0] = xElement2.Value; throw new MetadataException(ExceptionHelpers.GetExceptionMessage(invalidCastException2, Resources.InvalidSwitchParameterValue, value1), invalidCastException2); } } string str = null; XElement xElement3 = xElement.TryGetUniqueElement("http://schemas.microsoft.com/powershell-web-services/2010/09", "Type"); if (xElement3 != null) { str = xElement3.Value; } pSParameterSet.Parameters.Add(value, new PSParameterInfo(flag, flag1, str)); } firstNode = (XElement)firstNode.NextNode; cmdletInfo.ParameterSets.Add(pSParameterSet); } try { cmdletInfo.ThrowIfInvalidState(resourceType); } catch (InvalidOperationException invalidOperationException1) { InvalidOperationException invalidOperationException = invalidOperationException1; object[] cmdletName = new object[2]; cmdletName[0] = cmdletInfo.CmdletName; cmdletName[1] = invalidOperationException.Message; throw new MetadataException(ExceptionHelpers.GetExceptionMessage(invalidOperationException, Resources.FieldOptionOrMandatoryParameterNotInParamset, cmdletName), invalidOperationException); } }