예제 #1
0
		private HashSet<ClassName> GetDerivedClasses(ClassDeclaration classDecl)
		{
			IEnumerable<ClassDeclaration> classDeclarations = this.ClassDeclarations.Values.Where<ClassDeclaration>((ClassDeclaration item) => item.SuperclassName == classDecl.Name);
			return new HashSet<ClassName>(classDeclarations.Select<ClassDeclaration, ClassName>((ClassDeclaration item) => item.Name));
		}
예제 #2
0
        private HashSet <ClassName> GetDerivedClasses(ClassDeclaration classDecl)
        {
            IEnumerable <ClassDeclaration> classDeclarations = this.ClassDeclarations.Values.Where <ClassDeclaration>((ClassDeclaration item) => item.SuperclassName == classDecl.Name);

            return(new HashSet <ClassName>(classDeclarations.Select <ClassDeclaration, ClassName>((ClassDeclaration item) => item.Name)));
        }
예제 #3
0
		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));
			}
		}
예제 #4
0
		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);
			}
		}
예제 #5
0
		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);
				}
			}
		}
예제 #6
0
		private static bool IsTypeDefined(ClassDeclaration c, List<ResourceType> complexTypeResources, List<ResourceType> entityResources, Dictionary<string, Schema.AssociationType> associationResources)
		{
			Func<ResourceType, bool> func = null;
			Func<ResourceType, bool> func1 = null;
			SchemaLoader.ClassCategory category = c.GetCategory();
			switch (category)
			{
				case SchemaLoader.ClassCategory.Complex:
				{
					object obj = null;
					List<ResourceType> resourceTypes = complexTypeResources;
					if (func1 == null)
					{
						func1 = (ResourceType it) => string.Equals(it.FullName, SchemaLoader.TransformCimNameToCsdl(c.Name.FullName, true));
					}
					return obj != resourceTypes.FirstOrDefault<ResourceType>(func1);
				}
				case SchemaLoader.ClassCategory.Entity:
				{
					object obj1 = null;
					List<ResourceType> resourceTypes1 = entityResources;
					if (func == null)
					{
						func = (ResourceType it) => string.Equals(it.FullName, SchemaLoader.TransformCimNameToCsdl(c.Name.FullName, true));
					}
					return obj1 != resourceTypes1.FirstOrDefault<ResourceType>(func);
				}
				case SchemaLoader.ClassCategory.Association:
				{
					return associationResources.Keys.Contains<string>(SchemaLoader.TransformCimNameToCsdl(c.Name.FullName, true));
				}
			}
			throw new NotImplementedException(string.Concat("class category ", c.GetCategory()));
		}
예제 #7
0
		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;
			}
		}