Exemplo n.º 1
0
		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;
		}
Exemplo n.º 2
0
		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);
			}
		}