private DSLinqQueryProvider(Microsoft.Management.Odata.Schema.Schema schema, ResourceType root, UserContext userContext, string membershipId, DataServiceQueryProvider.ResultSetCollection resultSets) { this.schema = schema; this.initialResourceRoot = new DataServiceQueryProvider.ResultSet(root); this.initialQueryable = this.initialResourceRoot.AsQueryable <DSResource>(); this.resultSets = resultSets; this.userContext = userContext; this.membershipId = membershipId; }
public void Build(Microsoft.Management.Odata.Schema.Schema logicalSchema, Microsoft.Management.Odata.Schema.Schema userSchema, UserContext userContext, string membershipId) { Envelope <PSRunspace, UserContext> envelope = this.runspaceStore.Borrow(userContext, membershipId); using (envelope) { this.Build(logicalSchema, userSchema, envelope.Item.Runspace); } }
internal void Build(Microsoft.Management.Odata.Schema.Schema logicalSchema, Microsoft.Management.Odata.Schema.Schema userSchema, Runspace runspace) { HashSet <string> strs = null; Dictionary <string, CommandInfo> strs1 = null; PSSchemaBuilder.GetCommands(runspace, out strs, out strs1); List <PSSchemaBuilder.EntityDataForSchemaBuilding> entityDataForSchemaBuildings = this.CreateEntityDataForSchemaBuilding(logicalSchema, strs); this.AddEntitiesToSchema(logicalSchema, userSchema, entityDataForSchemaBuildings, strs1); userSchema.PopulateAllRelevantResourceTypes(logicalSchema); }
public void Build(Microsoft.Management.Odata.Schema.Schema logicalSchema, Microsoft.Management.Odata.Schema.Schema userSchema, UserContext userContext, string membershipId) { ResourceSet resourceSet = null; if (logicalSchema.ResourceSets.TryGetValue("CommandInvocations", out resourceSet)) { string str = "PowerShell.CommandInvocation"; userSchema.AddEntity(str, true, logicalSchema); userSchema.EntityMetadataDictionary.Add(str, logicalSchema.EntityMetadataDictionary[str]); userSchema.PopulateAllRelevantResourceTypes(logicalSchema); } }
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 void PopulateAssociationType(Schema schema, List<ResourceType> entityResources, ClassDeclaration classDeclaration) { Schema.AssociationType item = schema.AssociationTypes[SchemaLoader.TransformCimNameToCsdl(classDeclaration.Name.FullName, true)]; if (classDeclaration.Properties.Count == 2) { Schema.AssociationEnd associationEnd = SchemaLoader.CreateAssociationEnd(classDeclaration.Name.FullName, classDeclaration.Properties.ElementAt<PropertyDeclaration>(0), entityResources); Schema.AssociationEnd associationEnd1 = SchemaLoader.CreateAssociationEnd(classDeclaration.Name.FullName, classDeclaration.Properties.ElementAt<PropertyDeclaration>(1), entityResources); item.AddEnds(associationEnd, associationEnd1); return; } else { object[] fullName = new object[1]; fullName[0] = classDeclaration.Name.FullName; string str = string.Format(CultureInfo.CurrentCulture, Resources.AssociationEndCount, fullName); throw new MetadataException(str); } }
private static void PopulateInvocationEntityMetadata(Schema schema) { GIEntityMetadata gIEntityMetadatum = new GIEntityMetadata(); schema.EntityMetadataDictionary.Add(SchemaLoader.TransformCimNameToCsdl("PowerShell_CommandInvocation", true), gIEntityMetadatum); }
private List <PSSchemaBuilder.EntityDataForSchemaBuilding> CreateEntityDataForSchemaBuilding(Microsoft.Management.Odata.Schema.Schema logicalSchema, HashSet <string> initialSessionCommands) { IEnumerable <PSSchemaBuilder.EntityDataForSchemaBuilding> entityDataForSchemaBuildings = null; List <PSSchemaBuilder.EntityDataForSchemaBuilding> entityDataForSchemaBuildings1 = new List <PSSchemaBuilder.EntityDataForSchemaBuilding>(); foreach (string key in logicalSchema.EntityMetadataDictionary.Keys) { if (logicalSchema.EntityMetadataDictionary[key].MgmtSystem != ManagementSystemType.PowerShell) { continue; } PSSchemaBuilder.EntityDataForSchemaBuilding entityDataForSchemaBuilding = new PSSchemaBuilder.EntityDataForSchemaBuilding(key); PSEntityMetadata item = (PSEntityMetadata)logicalSchema.EntityMetadataDictionary[key]; entityDataForSchemaBuilding.Commands = this.FindSupportedCommands(item, initialSessionCommands); entityDataForSchemaBuilding.ReferenceSetCommands = this.FindSupportedReferenceCommands(item, initialSessionCommands); entityDataForSchemaBuildings1.Add(entityDataForSchemaBuilding); } foreach (PSSchemaBuilder.EntityDataForSchemaBuilding entityDataForSchemaBuilding1 in entityDataForSchemaBuildings1) { if (!entityDataForSchemaBuilding1.Commands.Contains(CommandType.Read)) { continue; } entityDataForSchemaBuilding1.IncludeEntitySet = true; entityDataForSchemaBuilding1.IncludeInSchema = true; new HashSet <ResourceType>(); ResourceType resourceType = logicalSchema.ResourceTypes[entityDataForSchemaBuilding1.EntityName]; HashSet <ResourceType> family = resourceType.GetFamily(); List <PSSchemaBuilder.EntityDataForSchemaBuilding> entityDataForSchemaBuildings2 = entityDataForSchemaBuildings1; HashSet <ResourceType> resourceTypes = family; Func <PSSchemaBuilder.EntityDataForSchemaBuilding, string> func = (PSSchemaBuilder.EntityDataForSchemaBuilding entityStat) => entityStat.EntityName; Func <ResourceType, string> func1 = (ResourceType res) => res.FullName; entityDataForSchemaBuildings = entityDataForSchemaBuildings2.Join <PSSchemaBuilder.EntityDataForSchemaBuilding, ResourceType, string, PSSchemaBuilder.EntityDataForSchemaBuilding>(resourceTypes, func, func1, (PSSchemaBuilder.EntityDataForSchemaBuilding entityStat, ResourceType res) => entityStat); IEnumerator <PSSchemaBuilder.EntityDataForSchemaBuilding> enumerator = entityDataForSchemaBuildings.GetEnumerator(); using (enumerator) { while (enumerator.MoveNext()) { PSSchemaBuilder.EntityDataForSchemaBuilding entityDataForSchemaBuilding2 = entityDataForSchemaBuilding1; entityDataForSchemaBuilding2.IncludeInSchema = true; } } } return(entityDataForSchemaBuildings1); }
internal void PopulateAllRelevantResourceTypes(Schema other) { Action<ResourceType> action = null; Func<ResourceType, bool> func = null; Action<ResourceType> action1 = null; Func<ResourceType, bool> func1 = null; foreach (ResourceType list in this.ResourceTypes.Values.ToList<ResourceType>()) { HashSet<ResourceType> allDependencies = list.GetAllDependencies(); if (allDependencies != null) { HashSet<ResourceType> resourceTypes = allDependencies; if (func == null) { func = (ResourceType item) => !this.ResourceTypes.ContainsKey(item.FullName); } List<ResourceType> list1 = resourceTypes.Where<ResourceType>(func).ToList<ResourceType>(); if (action == null) { action = (ResourceType item) => this.ResourceTypes.Add(item.FullName, item); } list1.ForEach(action); } HashSet<ResourceType> derivedTypes = list.GetDerivedTypes(); if (derivedTypes == null) { continue; } HashSet<ResourceType> resourceTypes1 = derivedTypes; if (func1 == null) { func1 = (ResourceType item) => !this.ResourceTypes.ContainsKey(item.FullName); } List<ResourceType> list2 = resourceTypes1.Where<ResourceType>(func1).ToList<ResourceType>(); if (action1 == null) { action1 = (ResourceType item) => this.ResourceTypes.Add(item.FullName, item); } list2.ForEach(action1); } }
public void AddEnds(Schema.AssociationEnd end1, Schema.AssociationEnd end2) { if (this.Ends.Count == 0) { this.Ends.Add(end1); this.Ends.Add(end2); return; } else { throw new NotImplementedException(ExceptionHelpers.GetExceptionMessage(Resources.AssociationMoreThanTwoEndNotSupported, new object[0])); } }
public DataContext(Microsoft.Management.Odata.Schema.Schema userSchema, UserContext userContext, string membershipId) { this.UserSchema = userSchema; this.UserContext = userContext; this.MembershipId = membershipId; }
internal void AddResourceSetReferenceProperty(ResourceType sourceType, string name, ResourceType targetType, Schema.AssociationType assocType) { ResourceProperty resourcePropertyWithDescription = new ResourcePropertyWithDescription(name, ResourcePropertyKind.ResourceSetReference, targetType); resourcePropertyWithDescription.CanReflectOnInstanceTypeProperty = false; resourcePropertyWithDescription.CustomState = new ReferenceCustomState(true); resourcePropertyWithDescription.GetReferenceCustomState().AssociationType = assocType; sourceType.AddProperty(resourcePropertyWithDescription); }
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); } }
internal void AddToSchema(Schema schema, MofSpecificationSet mof, XElement resources) { this.VerifyQualifierNames(mof); this.VerifyClassNames(mof); HashSet<MofProduction> mofProductions = new HashSet<MofProduction>(); foreach (XElement xElement in resources.Elements()) { mof.GetClosureOfClass(mofProductions, xElement.GetUniqueElement("http://schemas.microsoft.com/powershell-web-services/2010/09", "Class").Value); } List<ResourceType> resourceTypes = new List<ResourceType>(); List<ResourceType> resourceTypes1 = new List<ResourceType>(); HashSet<MofProduction> mofProductions1 = mofProductions; foreach (MofProduction mofProduction in mofProductions1.Where<MofProduction>((MofProduction item) => item is ClassDeclaration)) { SchemaLoader.CreateResourceType(mofProduction as ClassDeclaration, mofProductions, schema, resourceTypes, resourceTypes1); } foreach (MofProduction mofProduction1 in mofProductions) { ClassDeclaration classDeclaration = mofProduction1 as ClassDeclaration; if (classDeclaration == null) { continue; } SchemaLoader.ClassCategory category = classDeclaration.GetCategory(); switch (category) { case SchemaLoader.ClassCategory.Complex: { SchemaLoader.PopulateComplexType(schema, resourceTypes, classDeclaration); continue; } case SchemaLoader.ClassCategory.Entity: { SchemaLoader.PopulateEntityType(schema, resourceTypes, resourceTypes1, classDeclaration); continue; } case SchemaLoader.ClassCategory.Association: { SchemaLoader.PopulateAssociationType(schema, resourceTypes1, classDeclaration); continue; } } throw new NotImplementedException(string.Concat("class category ", classDeclaration.GetCategory())); } foreach (XElement xElement1 in resources.Elements()) { string value = xElement1.GetUniqueElement("http://schemas.microsoft.com/powershell-web-services/2010/09", "RelativeUrl").Value; string str = xElement1.GetUniqueElement("http://schemas.microsoft.com/powershell-web-services/2010/09", "Class").Value; ResourceType resourceType = resourceTypes1.Find((ResourceType item) => item.FullName == SchemaLoader.TransformCimNameToCsdl(str, true)); if (resourceType != null) { schema.AddResourceSet(value, resourceType); } else { object[] csdl = new object[1]; csdl[0] = SchemaLoader.TransformCimNameToCsdl(str, true); throw new ArgumentException(ExceptionHelpers.GetExceptionMessage(Resources.EntityTypeResourceNotFound, csdl)); } } foreach (MofProduction mofProduction2 in mofProductions) { if (mofProduction2 as ClassDeclaration == null || (mofProduction2 as ClassDeclaration).GetCategory () != SchemaLoader.ClassCategory.Entity) { continue; } SchemaLoader.AddReferenceProperties(schema, resourceTypes1, mofProduction2 as ClassDeclaration, mofProductions); } foreach (Schema.AssociationType associationType in schema.AssociationTypes.Values) { associationType.CreateWcfType(schema.ResourceSets); } }
private static void AddReferenceProperties(Schema schema, List<ResourceType> entityResources, ClassDeclaration classDeclaration, HashSet<MofProduction> mof) { ResourceType resourceType = schema.ResourceTypes[SchemaLoader.TransformCimNameToCsdl(classDeclaration.Name.FullName, true)]; foreach (PropertyDeclaration property in classDeclaration.Properties) { Func<ResourceProperty, bool> func = null; Func<MofProduction, bool> func1 = null; Qualifier qualifier = property.GetQualifier("AssociationClass"); Qualifier qualifier1 = property.GetQualifier("ToEnd"); if (property.IsReferenceType()) { if (qualifier == null || qualifier1 == null) { SchemaLoader.ThrowPropertyMetadataException(classDeclaration.Name.FullName, property.Name, Resources.RefWithoutAssociationQual); } if (qualifier.Parameter == null || qualifier.Parameter as string == null) { SchemaLoader.ThrowPropertyMetadataException(classDeclaration.Name.FullName, property.Name, Resources.AssociationQualWithoutParm); } string parameter = qualifier.Parameter as string; Schema.AssociationType associationType = null; if (!schema.AssociationTypes.TryGetValue(SchemaLoader.TransformCimNameToCsdl(parameter, true), out associationType)) { object[] objArray = new object[1]; objArray[0] = qualifier.Parameter as string; string str = string.Format(CultureInfo.CurrentCulture, Resources.MissingAssociationType, objArray); SchemaLoader.ThrowPropertyMetadataException(classDeclaration.Name.FullName, property.Name, str); } ResourceType referencedResourceType = SchemaLoader.GetReferencedResourceType(property, classDeclaration.Name.FullName, entityResources); Schema.AssociationEnd associationEnd = associationType.Ends.FirstOrDefault<Schema.AssociationEnd>((Schema.AssociationEnd it) => string.Equals(it.Name, qualifier.Parameter as string, StringComparison.Ordinal)); if (associationEnd == null) { SchemaLoader.ThrowPropertyMetadataException(classDeclaration.Name.FullName, property.Name, Resources.MissingAssociationEnd); } if (associationEnd.Type != referencedResourceType) { object[] cim = new object[2]; cim[0] = SchemaLoader.TransformCsdlNameToCim(referencedResourceType.FullName); cim[1] = SchemaLoader.TransformCsdlNameToCim(associationEnd.Type.FullName); string str1 = string.Format(CultureInfo.CurrentCulture, Resources.WrongAssocEndDataType, cim); SchemaLoader.ThrowPropertyMetadataException(classDeclaration.Name.FullName, property.Name, str1); } if (property.DataType.Type != DataTypeType.ObjectReference) { schema.AddResourceSetReferenceProperty(resourceType, property.Name, referencedResourceType, associationType); } else { HashSet<MofProduction> mofProductions = mof; if (func1 == null) { func1 = (MofProduction item) => item.GetFullClassName() == SchemaLoader.TransformCsdlNameToCim(classDeclaration.Name.FullName); /* TODO: not sure of classDeclaration here */ } ClassDeclaration classDeclaration1 = mofProductions.First<MofProduction>(func1) as ClassDeclaration; object explicitDefaultValue = null; if (referencedResourceType.KeyProperties.Count == 1) { string name = referencedResourceType.KeyProperties.First<ResourceProperty>().Name; PropertyDeclaration propertyDeclaration = classDeclaration1.GetProperty(name, mof); explicitDefaultValue = TypeSystem.GetExplicitDefaultValue(SchemaLoader.GetClrType(propertyDeclaration)); } schema.AddResourceReferenceProperty(resourceType, property.Name, referencedResourceType, associationType, explicitDefaultValue); } Schema.AssociationEnd associationEnd1 = associationType.Ends.First<Schema.AssociationEnd>((Schema.AssociationEnd it) => !string.Equals(it.Name, qualifier1.Parameter as string)); Schema.AssociationEnd associationEnd2 = associationEnd1; ReadOnlyCollection<ResourceProperty> properties = resourceType.Properties; if (func == null) { func = (ResourceProperty it) => string.Equals(it.Name, property.Name); } associationEnd2.Property = properties.First<ResourceProperty>(func); } else { if (qualifier == null && qualifier1 == null) { continue; } SchemaLoader.ThrowPropertyMetadataException(classDeclaration.Name.FullName, property.Name, Resources.AssociationQualWithoutRef); } } }
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; }
private static void CreateResourceType(ClassDeclaration c, HashSet<MofProduction> mof, Schema schema, List<ResourceType> complexTypeResources, List<ResourceType> entityResources) { Func<MofProduction, bool> func = null; if (!SchemaLoader.IsTypeDefined(c, complexTypeResources, entityResources, schema.AssociationTypes)) { if (!c.IsClassAndSuperclassesContainsLoop(mof)) { SchemaLoader.ClassCategory category = c.GetCategory(); ResourceType resourceType = null; if (c.SuperclassName != null) { HashSet<MofProduction> mofProductions = mof; if (func == null) { func = (MofProduction item) => string.Equals(c.SuperclassName.FullName, item.GetFullClassName(), StringComparison.Ordinal); } ClassDeclaration classDeclaration = mofProductions.FirstOrDefault<MofProduction>(func) as ClassDeclaration; if (classDeclaration != null) { SchemaLoader.ClassCategory classCategory = classDeclaration.GetCategory(); if (category == classCategory) { if (!SchemaLoader.IsTypeDefined(classDeclaration, complexTypeResources, entityResources, schema.AssociationTypes)) { SchemaLoader.CreateResourceType(classDeclaration, mof, schema, complexTypeResources, entityResources); } if (!schema.ResourceTypes.TryGetValue(SchemaLoader.TransformCimNameToCsdl(classDeclaration.Name.FullName, true), out resourceType)) { object[] fullName = new object[2]; fullName[0] = classDeclaration.Name.FullName; fullName[1] = c.Name.FullName; throw new MetadataException(ExceptionHelpers.GetExceptionMessage(Resources.BaseClassNotFound, fullName)); } } else { object[] superclassName = new object[2]; superclassName[0] = c.Name.FullName; superclassName[1] = c.SuperclassName; throw new MetadataException(ExceptionHelpers.GetExceptionMessage(Resources.CrossCategoryDerivation, superclassName)); } } else { object[] objArray = new object[2]; objArray[0] = c.Name.FullName; objArray[1] = c.SuperclassName; throw new MetadataException(ExceptionHelpers.GetExceptionMessage(Resources.MissingBaseClass, objArray)); } } SchemaLoader.ClassCategory category1 = c.GetCategory(); switch (category1) { case SchemaLoader.ClassCategory.Complex: { complexTypeResources.Add(schema.AddResourceType(c.Name.Identifier, ResourceTypeKind.ComplexType, SchemaLoader.TransformCimNameToCsdl(c.Name.Schema, false), resourceType, null)); return; } case SchemaLoader.ClassCategory.Entity: { entityResources.Add(schema.AddResourceType(c.Name.Identifier, ResourceTypeKind.EntityType, SchemaLoader.TransformCimNameToCsdl(c.Name.Schema, false), resourceType, null)); return; } case SchemaLoader.ClassCategory.Association: { schema.AddAssociationType(SchemaLoader.TransformCimNameToCsdl(c.Name.Identifier, false), SchemaLoader.TransformCimNameToCsdl(c.Name.Schema, false)); return; } } throw new NotImplementedException(string.Concat("class category ", c.GetCategory())); } else { object[] identifier = new object[1]; identifier[0] = c.Name.Identifier; throw new MetadataException(ExceptionHelpers.GetExceptionMessage(Resources.BaseClassesNotPresentOrRecursive, identifier)); } } else { return; } }
private static void PopulateComplexType(Schema schema, List<ResourceType> complexTypeResources, ClassDeclaration classDeclaration) { ResourceType resourceType = complexTypeResources.Find((ResourceType item) => item.FullName == SchemaLoader.TransformCimNameToCsdl(classDeclaration.Name.FullName, true)); if (resourceType != null) { foreach (PropertyDeclaration property in classDeclaration.Properties) { bool qualifier = property.GetQualifier("Key") != null; bool flag = property.GetQualifier("Etag") != null; bool flag1 = SchemaLoader.IsNullableProperty(property); Qualifier qualifier1 = property.GetQualifier("EmbeddedInstance"); if (qualifier) { SchemaLoader.ThrowPropertyMetadataException(classDeclaration.Name.FullName, property.Name, Resources.ComplexTypeSpecifiesKeyProperty); } if (flag) { SchemaLoader.ThrowPropertyMetadataException(classDeclaration.Name.FullName, property.Name, Resources.ComplexTypeSpecifiesEtagProperty); } Type clrType = SchemaLoader.CheckForPrimitiveEmbeddedType(qualifier1, flag1); if (qualifier1 == null || clrType != null) { bool flag2 = property.DataType.IsArray(); if (clrType == null) { clrType = SchemaLoader.GetClrType(property); } object defaultValue = TypeSystem.GetDefaultValue(clrType); if (flag2) { schema.AddPrimitiveCollectionProperty(resourceType, property.Name, clrType, defaultValue); } else { schema.AddPrimitiveProperty(resourceType, property.Name, clrType, flag, defaultValue); } } else { bool flag3 = property.DataType.IsArray(); string csdl = SchemaLoader.TransformCimNameToCsdl(qualifier1.Parameter as string, true); ResourceType resourceType1 = complexTypeResources.Find((ResourceType item) => item.FullName == csdl); if (resourceType1 != null) { if (flag3) { schema.AddComplexCollectionProperty(resourceType, property.Name, resourceType1); } else { schema.AddComplexProperty(resourceType, property.Name, resourceType1); } } else { object[] objArray = new object[1]; objArray[0] = csdl; throw new ArgumentException(ExceptionHelpers.GetExceptionMessage(Resources.ComplexTypeResourceNotFound, objArray)); } } } return; } else { object[] csdl1 = new object[1]; csdl1[0] = SchemaLoader.TransformCimNameToCsdl(classDeclaration.Name.FullName, true); throw new ArgumentException(ExceptionHelpers.GetExceptionMessage(Resources.ComplexTypeResourceNotFound, csdl1)); } }
public void AddEntity(string entityName, bool includeEntitySet, Schema other) { this.ResourceTypes.Add(entityName, other.ResourceTypes[entityName]); if (includeEntitySet) { foreach (string key in other.ResourceSets.Keys) { if (other.ResourceSets[key].ResourceType.FullName != entityName) { continue; } this.ResourceSets.Add(key, other.ResourceSets[key]); } } }
internal static IQueryable CreateQuery(Microsoft.Management.Odata.Schema.Schema schema, ResourceType type, UserContext userContext, string membershipId, DataServiceQueryProvider.ResultSetCollection resultSets) { DSLinqQueryProvider dSLinqQueryProvider = new DSLinqQueryProvider(schema, type, userContext, membershipId, resultSets); return(dSLinqQueryProvider.CreateRootQuery()); }