private static ManifestMetadata ReadMetadata(XElement xElement) { var manifestMetadata = new ManifestMetadata(); manifestMetadata.DependencySets = new List<ManifestDependencySet>(); manifestMetadata.ReferenceSets = new List<ManifestReferenceSet>(); manifestMetadata.MinClientVersionString = xElement.GetOptionalAttributeValue("minClientVersion"); // we store all child elements under <metadata> so that we can easily check for required elements. var allElements = new HashSet<string>(); XNode node = xElement.FirstNode; while (node != null) { var element = node as XElement; if (element != null) { ReadMetadataValue(manifestMetadata, element, allElements); } node = node.NextNode; } // now check for required elements, which include <id>, <version>, <authors> and <description> foreach (var requiredElement in RequiredElements) { if (!allElements.Contains(requiredElement)) { throw new InvalidDataException( String.Format(CultureInfo.CurrentCulture, NuGetResources.Manifest_RequiredElementMissing, requiredElement)); } } return manifestMetadata; }
private static ManifestMetadata ReadMetadata(XElement xElement) { var manifestMetadata = new ManifestMetadata(); manifestMetadata.DependencySets = new List<ManifestDependencySet>(); manifestMetadata.ReferenceSets = new List<ManifestReferenceSet>(); manifestMetadata.MinClientVersionString = xElement.GetOptionalAttributeValue("minClientVersion"); XNode node = xElement.FirstNode; while (node != null) { var element = node as XElement; if (element != null) { ReadMetadataValue(manifestMetadata, element); } node = node.NextNode; } return manifestMetadata; }
/// <summary> /// Parse a Property from its XElement /// </summary> /// <param name="propertyElement">XElement to parse Property from</param> /// <returns>A memberProperty</returns> protected virtual MemberProperty ParseProperty(XElement propertyElement) { var name = propertyElement.GetRequiredAttributeValue("Name"); DataType dataType = this.ParsePropertyDataType(propertyElement); var memberProperty = new MemberProperty(name, dataType); if (propertyElement.GetOptionalAttributeValue("ConcurrencyMode", "None") == "Fixed") { memberProperty.Annotations.Add(new ConcurrencyTokenAnnotation()); } this.ParseAnnotations(memberProperty, propertyElement); return memberProperty; }
/// <summary> /// Parses a XElement that contains type information /// Accepts an element that is a CollectionType, RowType, ReferenceType, and TypeRef /// </summary> /// <param name="typeElement">XElement that contains a Type element</param> /// <returns>DataType represented by the XElement</returns> protected DataType ParseType(XElement typeElement) { if (typeElement.Name.LocalName == "CollectionType") { string elementTypeName = typeElement.GetOptionalAttributeValue("ElementType", null); if (elementTypeName != null) { bool isNullable = XmlConvert.ToBoolean(typeElement.GetOptionalAttributeValue("Nullable", "true")); DataType dataType = this.ParseType(elementTypeName, isNullable, typeElement.Attributes()); return DataTypes.CollectionType.WithElementDataType(dataType); } else { var elementType = typeElement.Elements().Single(e => this.IsXsdlNamespace(e.Name.NamespaceName)); return DataTypes.CollectionType.WithElementDataType(this.ParseType(elementType)); } } else if (typeElement.Name.LocalName == "RowType") { var row = new RowType(); foreach (var propertyElement in typeElement.Elements().Where(el => this.IsXsdlElement(el, "Property"))) { row.Properties.Add(this.ParseProperty(propertyElement)); } return DataTypes.RowType.WithDefinition(row); } else if (typeElement.Name.LocalName == "ReferenceType") { DataType dataType = this.ParseType(typeElement.GetRequiredAttributeValue("Type"), true, null); return DataTypes.ReferenceType.WithEntityType((dataType as EntityDataType).Definition); } else if (typeElement.Name.LocalName == "TypeRef") { bool isNullable = XmlConvert.ToBoolean(typeElement.GetOptionalAttributeValue("Nullable", "true")); DataType dataType = this.ParseType(typeElement.GetRequiredAttributeValue("Type"), isNullable, typeElement.Attributes()); return dataType; } else { throw new TaupoNotSupportedException("Unsupported data type element: " + typeElement.Name.LocalName); } }
/// <summary> /// Parses a function element /// </summary> /// <param name="functionElement">the XElement to represent a Function</param> /// <returns>the Function representation in entity data model</returns> protected virtual Function ParseFunction(XElement functionElement) { string name = functionElement.GetRequiredAttributeValue("Name"); var function = new Function(this.CurrentNamespace, name); string returnTypeName = functionElement.GetOptionalAttributeValue("ReturnType", null); if (returnTypeName != null) { bool isNullable = XmlConvert.ToBoolean(functionElement.GetOptionalAttributeValue("Nullable", "true")); function.ReturnType = this.ParseType(returnTypeName, isNullable, null); } var returnTypeElement = functionElement.Elements().SingleOrDefault(el => this.IsXsdlElement(el, "ReturnType")); if (returnTypeElement != null) { returnTypeName = returnTypeElement.GetOptionalAttributeValue("Type", null); bool isNullable = XmlConvert.ToBoolean(returnTypeElement.GetOptionalAttributeValue("Nullable", "true")); if (returnTypeName != null) { function.ReturnType = this.ParseType(returnTypeName, isNullable, returnTypeElement.Attributes()); } else { function.ReturnType = this.ParseType(returnTypeElement.Elements().Single(e => this.IsXsdlNamespace(e.Name.NamespaceName))); } } foreach (var parameterElement in functionElement.Elements().Where(el => this.IsXsdlElement(el, "Parameter"))) { function.Parameters.Add(this.ParseFunctionParameter(parameterElement)); } this.ParseAnnotations(function, functionElement); return function; }
/// <summary> /// Parses an entity container element in the csdl file. /// </summary> /// <param name="entityContainerElement">the entity container element to parse</param> /// <returns>the parsed entity container object in the entity model schema</returns> protected override EntityContainer ParseEntityContainer(XElement entityContainerElement) { var entityContainer = base.ParseEntityContainer(entityContainerElement); foreach (var functionImportElement in entityContainerElement.Elements().Where(el => this.IsXsdlElement(el, "FunctionImport"))) { entityContainer.Add(this.ParseFunctionImport(functionImportElement)); } string typeaccess = entityContainerElement.GetOptionalAttributeValue(EdmConstants.CodegenNamespace + "TypeAccess", null); if (typeaccess != null) { entityContainer.Annotations.Add(new TypeAccessModifierAnnotation(this.GetAccessModifier(typeaccess))); } return entityContainer; }
private RepositoryType GetRepositoryType(XElement packagesElement) { string repositoryAttributeValue = packagesElement.GetOptionalAttributeValue("repository"); switch (repositoryAttributeValue) { case "extension": return RepositoryType.Extension; case "registry": return RepositoryType.Registry; case "template": case null: return RepositoryType.Template; default: ShowErrorMessage(String.Format(VsResources.TemplateWizard_InvalidRepositoryAttribute, repositoryAttributeValue)); throw new WizardBackoutException(); } }
private string GetExtensionRepositoryPath(XElement packagesElement, object vsExtensionManager) { string repositoryId = packagesElement.GetOptionalAttributeValue("repositoryId"); if (repositoryId == null) { ShowErrorMessage(VsResources.TemplateWizard_MissingExtensionId); throw new WizardBackoutException(); } var extensionManagerShim = new ExtensionManagerShim(vsExtensionManager); string installPath; if (!extensionManagerShim.TryGetExtensionInstallPath(repositoryId, out installPath)) { ShowErrorMessage(String.Format(VsResources.TemplateWizard_InvalidExtensionId, repositoryId)); throw new WizardBackoutException(); } return Path.Combine(installPath, "Packages"); }
private FunctionImport ParseFunctionImport(XElement functionImportElement) { string functionImportName = functionImportElement.GetRequiredAttributeValue("Name"); var functionImport = new FunctionImport(functionImportName); bool isComposable = XmlConvert.ToBoolean(functionImportElement.GetOptionalAttributeValue("IsComposable", "false")); functionImport.IsComposable = isComposable; bool isBindable = XmlConvert.ToBoolean(functionImportElement.GetOptionalAttributeValue("IsBindable", "false")); functionImport.IsBindable = isBindable; bool isSideEffecting = XmlConvert.ToBoolean(functionImportElement.GetOptionalAttributeValue("IsSideEffecting", "true")); functionImport.IsSideEffecting = isSideEffecting; string entitySetPath = functionImportElement.GetOptionalAttributeValue("EntitySetPath", null); if (entitySetPath != null) { functionImport.Annotations.Add(new EntitySetPathAnnotation(entitySetPath)); } foreach (var parameterElement in functionImportElement.Elements().Where(el => this.IsXsdlElement(el, "Parameter"))) { functionImport.Parameters.Add(this.ParseFunctionParameter(parameterElement)); } string returnTypeName = functionImportElement.GetOptionalAttributeValue("ReturnType", null); if (returnTypeName != null) { bool isNullable = XmlConvert.ToBoolean(functionImportElement.GetOptionalAttributeValue("Nullable", "true")); var returnType = new FunctionImportReturnType(this.ParseType(returnTypeName, isNullable, null)); string entitySetName = functionImportElement.GetOptionalAttributeValue("EntitySet", null); if (entitySetName != null) { returnType.EntitySet = new EntitySetReference(entitySetName); } functionImport.Add(returnType); } foreach (var returnTypeElement in functionImportElement.Elements().Where(el => this.IsXsdlElement(el, "ReturnType"))) { var type = returnTypeElement.GetRequiredAttributeValue("Type"); var returnType = new FunctionImportReturnType(this.ParseType(type, true, null)); var entitySet = returnTypeElement.GetOptionalAttributeValue("EntitySet", null); if (entitySet != null) { returnType.EntitySet = new EntitySetReference(entitySet); } functionImport.ReturnTypes.Add(returnType); } string methodaccess = functionImportElement.GetOptionalAttributeValue(EdmConstants.CodegenNamespace + "MethodAccess", null); if (methodaccess != null) { functionImport.Annotations.Add(new MethodAccessModifierAnnotation(this.GetAccessModifier(methodaccess))); } this.ParseAnnotations(functionImport, functionImportElement); return functionImport; }
private NavigationProperty ParseNavigationProperty(XElement navigationPropertyElement) { var name = navigationPropertyElement.GetRequiredAttributeValue("Name"); string relationshipNamespace = this.ParseEdmTypeName(navigationPropertyElement.GetRequiredAttributeValue("Relationship"))[0]; string relationshipName = this.ParseEdmTypeName(navigationPropertyElement.GetRequiredAttributeValue("Relationship"))[1]; string fromRole = navigationPropertyElement.GetRequiredAttributeValue("FromRole"); string toRole = navigationPropertyElement.GetRequiredAttributeValue("ToRole"); var navProp = new NavigationProperty(name, new AssociationTypeReference(relationshipNamespace, relationshipName), fromRole, toRole); this.ParseAnnotations(navProp, navigationPropertyElement); string getteraccess = navigationPropertyElement.GetOptionalAttributeValue(EdmConstants.CodegenNamespace + "GetterAccess", null); string setteraccess = navigationPropertyElement.GetOptionalAttributeValue(EdmConstants.CodegenNamespace + "SetterAccess", null); if (getteraccess != null || setteraccess != null) { AccessModifier setter; AccessModifier getter; this.GetGetterAndSetterModifiers(getteraccess, setteraccess, out setter, out getter); navProp.Annotations.Add(new PropertyAccessModifierAnnotation(setter, getter)); } return navProp; }
private EnumMember ParseEnumMember(XElement memberElement) { string name = memberElement.GetRequiredAttributeValue("Name"); string valueString = memberElement.GetOptionalAttributeValue("Value", null); var member = new EnumMember(name, valueString); this.ParseAnnotations(member, memberElement); return member; }
private EnumType ParseEnumType(XElement enumTypeElement) { string name = enumTypeElement.GetRequiredAttributeValue("Name"); string underlyingTypeString = enumTypeElement.GetOptionalAttributeValue("UnderlyingType", null); Type underlyingType = null; if (underlyingTypeString != null) { string underlyingTypeName = this.ParseEdmTypeName(underlyingTypeString)[1]; underlyingType = Type.GetType("System." + underlyingTypeName); } var isFlagsString = enumTypeElement.Attribute("IsFlags"); var enumType = new EnumType(this.CurrentNamespace, name) { IsFlags = isFlagsString == null ? (bool?)null : bool.Parse(isFlagsString.Value), UnderlyingType = underlyingType }; foreach (var memberElement in enumTypeElement.Elements().Where(el => this.IsXsdlElement(el, "Member"))) { enumType.Members.Add(this.ParseEnumMember(memberElement)); } this.ParseAnnotations(enumType, enumTypeElement); return enumType; }
private void ParseNamedStructuralTypeAttributes(XElement typeElement, NamedStructuralType type) { type.IsAbstract = XmlConvert.ToBoolean(typeElement.GetOptionalAttributeValue("Abstract", "false")); type.IsOpen = XmlConvert.ToBoolean(typeElement.GetOptionalAttributeValue("OpenType", "false")); string baseTypeFullName = typeElement.GetOptionalAttributeValue("BaseType", null); if (baseTypeFullName != null) { string[] typeNameInfo = this.ParseEdmTypeName(baseTypeFullName); string baseTypeNamespace = typeNameInfo[0]; string baseTypeName = typeNameInfo[1]; ComplexType complexType = type as ComplexType; EntityType entityType = type as EntityType; if (complexType != null) { complexType.BaseType = new ComplexTypeReference(baseTypeNamespace, baseTypeName); } else { ExceptionUtilities.Assert(entityType != null, "{0} is neither Entity nor Complex, but {1}!", type.FullName, type.GetType()); entityType.BaseType = new EntityTypeReference(baseTypeNamespace, baseTypeName); } } string typeaccess = typeElement.GetOptionalAttributeValue(EdmConstants.CodegenNamespace + "TypeAccess", null); if (typeaccess != null) { type.Annotations.Add(new TypeAccessModifierAnnotation(this.GetAccessModifier(typeaccess))); } }
/// <summary> /// Parse a Property from its XElement /// </summary> /// <param name="propertyElement">XElement to parse Property from</param> /// <returns>A memberProperty</returns> protected override MemberProperty ParseProperty(XElement propertyElement) { MemberProperty memberProperty = base.ParseProperty(propertyElement); string defaultValueString = propertyElement.GetOptionalAttributeValue("DefaultValue", null); if (defaultValueString != null) { memberProperty.DefaultValue = this.ParseDefaultValueString(defaultValueString, memberProperty.PropertyType); } string getteraccess = propertyElement.GetOptionalAttributeValue(EdmConstants.CodegenNamespace + "GetterAccess", null); string setteraccess = propertyElement.GetOptionalAttributeValue(EdmConstants.CodegenNamespace + "SetterAccess", null); if (getteraccess != null || setteraccess != null) { AccessModifier setter; AccessModifier getter; this.GetGetterAndSetterModifiers(getteraccess, setteraccess, out setter, out getter); memberProperty.Annotations.Add(new PropertyAccessModifierAnnotation(setter, getter)); } string collectionKindString = propertyElement.GetOptionalAttributeValue("CollectionKind", null); if (collectionKindString != null) { CollectionKind kind = (CollectionKind)Enum.Parse(typeof(CollectionKind), collectionKindString, false); memberProperty.Annotations.Add(new CollectionKindAnnotation(kind)); } return memberProperty; }
/// <summary> /// Parses the property Element to determine the DataType of the Property /// </summary> /// <param name="propertyElement">Property Element used as input to find the DataType</param> /// <returns>DataType that is determined from the property element</returns> protected override DataType ParsePropertyDataType(XElement propertyElement) { bool isNullable = XmlConvert.ToBoolean(propertyElement.GetOptionalAttributeValue("Nullable", "true")); string parameterTypeName = propertyElement.GetOptionalAttributeValue("Type", null); if (parameterTypeName != null) { return this.ParseType(parameterTypeName, isNullable, propertyElement.Attributes()); } else { var parameterTypeElement = propertyElement.Elements().Single(e => this.IsXsdlNamespace(e.Name.NamespaceName)); return this.ParseType(parameterTypeElement); } }
private void SetupNamespaceAndAliases(XElement schemaElement) { string namespaceName = schemaElement.GetRequiredAttributeValue("Namespace"); string alias = schemaElement.GetOptionalAttributeValue("Alias", null); this.CurrentNamespace = namespaceName; this.alias2namespace = new Dictionary<string, string>(); if (alias != null) { this.alias2namespace.Add(alias, namespaceName); } foreach (var usingElement in schemaElement.Elements().Where(el => this.IsXsdlElement(el, "Using"))) { alias = usingElement.GetRequiredAttributeValue("Alias"); namespaceName = usingElement.GetRequiredAttributeValue("Namespace"); this.alias2namespace[alias] = namespaceName; } }
private string ElementToValue(XElement element, bool isPath) { if (element == null) { return null; } // Return the optional value which if not there will be null; string value = element.GetOptionalAttributeValue("value"); if (!isPath || String.IsNullOrEmpty(value)) { return value; } return _fileSystem.GetFullPath(ResolvePath(Path.GetDirectoryName(ConfigFilePath), value)); }
private string GetExtensionRepositoryPath(XElement packagesElement, object vsExtensionManager) { string repositoryId = packagesElement.GetOptionalAttributeValue("repositoryId"); if (repositoryId == null) { ShowErrorMessage(VsResources.TemplateWizard_MissingExtensionId); throw new WizardBackoutException(); } return _preinstalledPackageInstaller.GetExtensionRepositoryPath(repositoryId, vsExtensionManager, ThrowWizardBackoutError); }
public static NuspecDependency ReadFrom(XElement element) { var version = element.GetOptionalAttributeValue("version"); return new NuspecDependency(element.Attribute("id").Value, version); }
private string GetRegistryRepositoryPath(XElement packagesElement, IEnumerable<IRegistryKey> registryKeys) { string keyName = packagesElement.GetOptionalAttributeValue("keyName"); if (String.IsNullOrEmpty(keyName)) { ShowErrorMessage(VsResources.TemplateWizard_MissingRegistryKeyName); throw new WizardBackoutException(); } return _preinstalledPackageInstaller.GetRegistryRepositoryPath(keyName, registryKeys, ThrowWizardBackoutError); }
private string GetRegistryRepositoryPath(XElement packagesElement, IEnumerable<IRegistryKey> registryKeys) { string keyName = packagesElement.GetOptionalAttributeValue("keyName"); if (String.IsNullOrEmpty(keyName)) { ShowErrorMessage(VsResources.TemplateWizard_MissingRegistryKeyName); throw new WizardBackoutException(); } IRegistryKey repositoryKey = null; string repositoryValue = null; // When pulling the repository from the registry, use CurrentUser first, falling back onto LocalMachine registryKeys = registryKeys ?? new[] { new RegistryKeyWrapper(Microsoft.Win32.Registry.CurrentUser), new RegistryKeyWrapper(Microsoft.Win32.Registry.LocalMachine) }; // Find the first registry key that supplies the necessary subkey/value foreach (var registryKey in registryKeys) { repositoryKey = registryKey.OpenSubKey(RegistryKeyRoot); if (repositoryKey != null) { repositoryValue = repositoryKey.GetValue(keyName) as string; if (!String.IsNullOrEmpty(repositoryValue)) { break; } repositoryKey.Close(); } } if (repositoryKey == null) { ShowErrorMessage(String.Format(VsResources.TemplateWizard_RegistryKeyError, RegistryKeyRoot)); throw new WizardBackoutException(); } if (String.IsNullOrEmpty(repositoryValue)) { ShowErrorMessage(String.Format(VsResources.TemplateWizard_InvalidRegistryValue, keyName, RegistryKeyRoot)); throw new WizardBackoutException(); } // Ensure a trailing slash so that the path always gets read as a directory repositoryValue = PathUtility.EnsureTrailingSlash(repositoryValue); return Path.GetDirectoryName(repositoryValue); }
/// <summary> /// Parses a function element /// </summary> /// <param name="parameterElement">the function element in the schema file</param> /// <returns>the function parameter representation in the entity model schema</returns> protected FunctionParameter ParseFunctionParameter(XElement parameterElement) { string parameterName = parameterElement.GetRequiredAttributeValue("Name"); DataType parameterType; string parameterTypeName = parameterElement.GetOptionalAttributeValue("Type", null); bool isNullable = XmlConvert.ToBoolean(parameterElement.GetOptionalAttributeValue("Nullable", "true")); if (parameterTypeName != null) { parameterType = this.ParseType(parameterTypeName, isNullable, parameterElement.Attributes()); } else { var parameterTypeElement = parameterElement.Elements().Single(e => this.IsXsdlNamespace(e.Name.NamespaceName)); parameterType = this.ParseType(parameterTypeElement); } FunctionParameter parameter = new FunctionParameter() { Name = parameterName, DataType = parameterType, }; string parameterMode = parameterElement.GetOptionalAttributeValue("Mode", null); if (parameterMode != null) { parameter.Mode = (FunctionParameterMode)Enum.Parse(typeof(FunctionParameterMode), parameterMode, true); } this.ParseAnnotations(parameter, parameterElement); return parameter; }
private string ElementToValue(XElement element, bool isPath) { if (element == null) { return null; } // Return the optional value which if not there will be null; string value = element.GetOptionalAttributeValue("value"); if (!isPath || String.IsNullOrEmpty(value)) { return value; } // if value represents a path and relative to this file path was specified, // append location of file string configDirectory = Path.GetDirectoryName(ConfigFilePath); return _fileSystem.GetFullPath(Path.Combine(configDirectory, value)); }
private string GetRepositoryPath(XElement packagesElement, RepositoryType repositoryType, string vsTemplatePath, object vsExtensionManager) { switch (repositoryType) { case RepositoryType.Template: return Path.GetDirectoryName(vsTemplatePath); case RepositoryType.Extension: string repositoryId = packagesElement.GetOptionalAttributeValue("repositoryId"); if (repositoryId == null) { ShowErrorMessage(VsResources.TemplateWizard_MissingExtensionId); throw new WizardBackoutException(); } var extensionManagerShim = new ExtensionManagerShim(vsExtensionManager); string installPath; if (!extensionManagerShim.TryGetExtensionInstallPath(repositoryId, out installPath)) { ShowErrorMessage(String.Format(VsResources.TemplateWizard_InvalidExtensionId, repositoryId)); throw new WizardBackoutException(); } return Path.Combine(installPath, "Packages"); } // should not happen return null; }