예제 #1
0
파일: XmlHelpers.cs 프로젝트: nickchal/pash
		public static void InsertResourceMapping(this XDocument primaryMapping, XDocument secondaryMapping)
		{
			XElement uniqueElement = primaryMapping.GetUniqueElement("http://schemas.microsoft.com/powershell-web-services/2010/09", "Resources");
			XElement xElement = secondaryMapping.GetUniqueElement("http://schemas.microsoft.com/powershell-web-services/2010/09", "Resources");
			foreach (XElement xElement1 in xElement.Elements())
			{
				uniqueElement.AddFirst(xElement1);
			}
			uniqueElement = primaryMapping.GetUniqueElement("http://schemas.microsoft.com/powershell-web-services/2010/09", "ClassImplementations");
			xElement = secondaryMapping.GetUniqueElement("http://schemas.microsoft.com/powershell-web-services/2010/09", "ClassImplementations");
			foreach (XElement xElement2 in xElement.Elements())
			{
				uniqueElement.AddFirst(xElement2);
			}
		}
예제 #2
0
		internal Schema LoadSchema(List<MofSpecification> mofs, XDocument dispatch, bool allowInvoke = false)
		{
			string value = dispatch.GetUniqueElement("http://schemas.microsoft.com/powershell-web-services/2010/09", "SchemaNamespace").Value;
			string str = dispatch.GetUniqueElement("http://schemas.microsoft.com/powershell-web-services/2010/09", "ContainerName").Value;
			Schema schema = new Schema(str, value);
			if (allowInvoke)
			{
				string str1 = Encoding.ASCII.GetString(Resources.genericInvoke);
				MofSpecification mofSpecification = MofFileParser.ParseMofFile(str1.AsEnumerable<char>(), "(command invocation types)");
				mofs.Add(mofSpecification);
				XDocument xDocument = this.XDocumentFromString(Encoding.ASCII.GetString(Resources.GenericInvokeMapping));
				dispatch.InsertResourceMapping(xDocument);
			}
			XElement uniqueElement = dispatch.GetUniqueElement("http://schemas.microsoft.com/powershell-web-services/2010/09", "Resources");
			this.AddToSchema(schema, new MofSpecificationSet(mofs.ToArray()), uniqueElement);
			schema.FreezeSchema();
			try
			{
				foreach (ResourceType property in schema.ResourceTypes.Values)
				{
					IEnumerator<ResourceProperty> enumerator = property.Properties.GetEnumerator();
					using (enumerator)
					{
						while (enumerator.MoveNext())
						{
							//property;
						}
					}
				}
			}
			catch (InvalidOperationException invalidOperationException1)
			{
				InvalidOperationException invalidOperationException = invalidOperationException1;
				throw new MetadataException(ExceptionHelpers.GetExceptionMessage(invalidOperationException.Message, new object[0]), invalidOperationException);
			}
			if (allowInvoke)
			{
				SchemaLoader.PopulateInvocationEntityMetadata(schema);
			}
			SchemaLoader.PopulateResourceMetadata(schema, dispatch);
			schema.Trace("New schema loaded in memory ");
			return schema;
		}
예제 #3
0
		private static void PopulateResourceMetadata(Schema schema, XDocument dispatchXml)
		{
			XElement uniqueElement = dispatchXml.GetUniqueElement("http://schemas.microsoft.com/powershell-web-services/2010/09", "ClassImplementations");
			foreach (XElement xElement in uniqueElement.Elements())
			{
				string value = xElement.GetUniqueElement("http://schemas.microsoft.com/powershell-web-services/2010/09", "Name").Value;
				ResourceType resourceType = null;
				if (schema.ResourceTypes.TryGetValue(SchemaLoader.TransformCimNameToCsdl(value, true), out resourceType))
				{
					XElement xElement1 = xElement.TryGetUniqueElement("http://schemas.microsoft.com/powershell-web-services/2010/09", "ClrType");
					if (xElement1 != null)
					{
						resourceType.SetClrTypeStr(xElement1.Value);
					}
					XElement xElement2 = xElement.TryGetUniqueElement("http://schemas.microsoft.com/powershell-web-services/2010/09", "RenamedFields");
					if (xElement2 != null)
					{
						foreach (XElement xElement3 in xElement2.Elements())
						{
							string str = xElement3.GetUniqueElement("http://schemas.microsoft.com/powershell-web-services/2010/09", "SchemaProperty").Value;
							string value1 = xElement3.GetUniqueElement("http://schemas.microsoft.com/powershell-web-services/2010/09", "PowerShellProperty").Value;
							ResourceProperty resourceProperty = resourceType.Properties.FirstOrDefault<ResourceProperty>((ResourceProperty it) => string.Equals(str, it.Name, StringComparison.Ordinal));
							if (resourceProperty != null)
							{
								resourceProperty.GetCustomState().PsProperty = value1;
							}
							else
							{
								object[] objArray = new object[2];
								objArray[0] = value;
								objArray[1] = str;
								throw new MetadataException(ExceptionHelpers.GetExceptionMessage(Resources.InvalidRenamedProperty, objArray));
							}
						}
					}
					schema.ResourceTypes.Values.Where<ResourceType>((ResourceType item) => item.BaseType == resourceType).ToList<ResourceType>().ForEach((ResourceType item) => resourceType.AddDerivedType(item));
					if (resourceType.ResourceTypeKind != ResourceTypeKind.EntityType)
					{
						continue;
					}
					PSEntityMetadata pSEntityMetadatum = new PSEntityMetadata();
					XElement uniqueElement1 = xElement.GetUniqueElement("http://schemas.microsoft.com/powershell-web-services/2010/09", "CmdletImplementation");
					SchemaLoader.PopulateCmdletInformation(resourceType, Microsoft.Management.Odata.Core.CommandType.Read, uniqueElement1, "Query", pSEntityMetadatum);
					SchemaLoader.PopulateCmdletInformation(resourceType, Microsoft.Management.Odata.Core.CommandType.Create, uniqueElement1, "Create", pSEntityMetadatum);
					SchemaLoader.PopulateCmdletInformation(resourceType, Microsoft.Management.Odata.Core.CommandType.Update, uniqueElement1, "Update", pSEntityMetadatum);
					SchemaLoader.PopulateCmdletInformation(resourceType, Microsoft.Management.Odata.Core.CommandType.Delete, uniqueElement1, "Delete", pSEntityMetadatum);
					SchemaLoader.PopulateCmdletReferenceSetInfo(resourceType, uniqueElement1, pSEntityMetadatum);
					schema.EntityMetadataDictionary.Add(SchemaLoader.TransformCimNameToCsdl(value, true), pSEntityMetadatum);
				}
				else
				{
					object[] objArray1 = new object[1];
					objArray1[0] = value;
					throw new MetadataException(ExceptionHelpers.GetExceptionMessage(Resources.MappingClassNotFound, objArray1));
				}
			}
			foreach (ResourceType resourceType1 in schema.ResourceTypes.Values)
			{
				if (resourceType1.ResourceTypeKind != ResourceTypeKind.EntityType)
				{
					continue;
				}
				if (!schema.EntityMetadataDictionary.ContainsKey(resourceType1.FullName))
				{
					schema.EntityMetadataDictionary.Add(resourceType1.FullName, new PSEntityMetadata());
				}
				if (schema.EntityMetadataDictionary[resourceType1.FullName] as PSEntityMetadata == null)
				{
					continue;
				}
				SchemaLoader.UpdateEntityPropertyMetadata(schema.EntityMetadataDictionary[resourceType1.FullName] as PSEntityMetadata, resourceType1);
			}
		}