public void ShouldGetValidUriFromPartsWithNoFilePath() { XmlSchemaElementMoniker uri = new XmlSchemaElementMoniker(XmlSchemaFileNoPath, ElementName); Assert.AreEqual<string>(XmlSchemaFileNoPath, uri.XmlSchemaPath); Assert.AreEqual<string>(ElementName, uri.ElementName); }
public virtual CodeGenerationResults Generate(IArtifactLink link) { Guard.ArgumentNotNull(link, "link"); CodeGenerationResults content = new CodeGenerationResults(); try { XmlSchemaTypeGenerator generator = new XmlSchemaTypeGenerator(UseXmlSerializer(link), GetNamespace(link)); string xsdMoniker = Utility.GetData <string>(link, ElementDataKey); string xmlSchemaSource = XmlSchemaUtility.GetXmlSchemaSource(xsdMoniker, link); if (!string.IsNullOrEmpty(xmlSchemaSource)) { CodeCompileUnit unit = generator.GenerateCodeCompileUnit(xmlSchemaSource); string element = new XmlSchemaElementMoniker(xsdMoniker).ElementName; UpdateUnit(unit, element, link); ThrowOnNoTypes(unit.Namespaces, element); this.assemblyReferences = GetAssemblyReferences(link, unit.ReferencedAssemblies); CodeDomProvider provider = GetCodeDomProvider(link); GenerateCode(unit, provider, content, link.ItemPath); } } catch (Exception exception) { LogErrors(exception); } return(content); }
public void ShouldGetValidElementFromUriTypeFormat() { XmlSchemaElementMoniker uri = new XmlSchemaElementMoniker("xsd:String"); Assert.IsNull(uri.ElementName); Assert.AreEqual <string>("String", uri.XmlSchemaPath); }
public void ShouldGetValidUriFromElementType() { XmlSchemaElementMoniker uri = new XmlSchemaElementMoniker("String", null); Assert.IsNull(uri.ElementName); Assert.AreEqual <string>("xsd:String", uri.ToString()); }
public void ShouldGetValidUriFromPartsWithNoFilePath() { XmlSchemaElementMoniker uri = new XmlSchemaElementMoniker(XmlSchemaFileNoPath, ElementName); Assert.AreEqual <string>(XmlSchemaFileNoPath, uri.XmlSchemaPath); Assert.AreEqual <string>(ElementName, uri.ElementName); }
public void ShouldGetValidElementFromUriSpecialTypeFormat() { XmlSchemaElementMoniker uri = new XmlSchemaElementMoniker("xsd:Nullable<int>"); Assert.IsNull(uri.ElementName); Assert.AreEqual <string>("Nullable<int>", uri.XmlSchemaPath); }
private void trvHierarchy_AfterSelect(object sender, TreeViewEventArgs e) { this.XsdElementUri = null; if (e.Node.Tag is ProjectItem) { ProjectItem projectItem = e.Node.Tag as ProjectItem; if (!projectItem.Kind.Equals(Constants.vsProjectItemKindPhysicalFolder, StringComparison.OrdinalIgnoreCase)) { Cursor currentCursor = this.Cursor; this.Cursor = Cursors.WaitCursor; LoadXsdElementsHierarchy(e.Node); this.Cursor = currentCursor; } } else if (e.Node is XsdElementNode) { ProjectItem parent = e.Node.Parent.Tag as ProjectItem; this.XsdElementUri = new XmlSchemaElementMoniker(DteHelper2.BuildPath(parent), e.Node.Text); } if (SelectionChanged != null) { SelectionChanged(this, EventArgs.Empty); } }
public void ShouldGetValidUriFromPartsWithSpaces() { XmlSchemaElementMoniker uri = new XmlSchemaElementMoniker(XmlSchemaFilePath, ElementName); Assert.AreEqual<string>(XmlSchemaFilePath, uri.XmlSchemaPath); Assert.AreEqual<string>(ElementName, uri.ElementName); Assert.AreEqual<string>(XmlSchemaElementMonikerFileFormat, uri.ToString()); }
public void ShouldGetValidUriFromPartsWithSpaces() { XmlSchemaElementMoniker uri = new XmlSchemaElementMoniker(XmlSchemaFilePath, ElementName); Assert.AreEqual <string>(XmlSchemaFilePath, uri.XmlSchemaPath); Assert.AreEqual <string>(ElementName, uri.ElementName); Assert.AreEqual <string>(XmlSchemaElementMonikerFileFormat, uri.ToString()); }
/// <summary> /// Gets the XML schema source. /// </summary> /// <param name="xsdMoniker">The XSD moniker.</param> /// <param name="link">The link.</param> /// <returns></returns> public static string GetXmlSchemaSource(string xsdMoniker, IArtifactLink link) { Guard.ArgumentNotNullOrEmptyString(xsdMoniker, "xsdMoniker"); Guard.ArgumentNotNull(link, "link"); IResourceResolver resolver = (link as IResourceResolver) ?? new XmlSchemaResourceResolver(link); XmlSchemaElementMoniker uri = new XmlSchemaElementMoniker(xsdMoniker); return(uri.ElementName != null ? resolver.GetResourcePath(uri.XmlSchemaPath) : null); }
/// <summary> /// Gets the type of the base types from referenced. /// </summary> /// <param name="xsdMoniker">The XSD moniker.</param> /// <param name="link">The link.</param> /// <returns></returns> public static IList <string> GetBaseTypesFromReferencedType(string xsdMoniker, IArtifactLink link) { Guard.ArgumentNotNullOrEmptyString(xsdMoniker, "xsdMoniker"); Guard.ArgumentNotNull(link, "link"); IList <string> types = new List <string>(); string xmlSchemaSource = GetXmlSchemaSource(xsdMoniker, link); string element = new XmlSchemaElementMoniker(xsdMoniker).ElementName; // try first with DC serializer XmlSchemaTypeGenerator generator = new XmlSchemaTypeGenerator(false); CodeCompileUnit unit; try { unit = generator.GenerateCodeCompileUnit(xmlSchemaSource); } catch (InvalidSerializerException) { // now try with Xml serializer generator = new XmlSchemaTypeGenerator(true); unit = generator.GenerateCodeCompileUnit(xmlSchemaSource); } foreach (CodeNamespace ns in unit.Namespaces) { foreach (CodeTypeDeclaration codeType in ns.Types) { if (codeType.Name.Equals(element, StringComparison.OrdinalIgnoreCase)) { CollectNestedTypes(codeType, types, unit, ns.Types, link); return(types); } } } return(types); }
public void ShouldGetValidUriFromElementType() { XmlSchemaElementMoniker uri = new XmlSchemaElementMoniker("String", null); Assert.IsNull(uri.ElementName); Assert.AreEqual<string>("xsd:String", uri.ToString()); }
public void ShouldGetValidElementFromUriTypeFormat() { XmlSchemaElementMoniker uri = new XmlSchemaElementMoniker("xsd:String"); Assert.IsNull(uri.ElementName); Assert.AreEqual<string>("String", uri.XmlSchemaPath); }
public void ShouldGetValidElementFromUriSpecialTypeFormat() { XmlSchemaElementMoniker uri = new XmlSchemaElementMoniker("xsd:Nullable<int>"); Assert.IsNull(uri.ElementName); Assert.AreEqual<string>("Nullable<int>", uri.XmlSchemaPath); }
protected override void DoValidate(string objectToValidate, object currentTarget, string key, ValidationResults validationResults) { if (string.IsNullOrEmpty(objectToValidate)) { return; } ModelElement mel = currentTarget as ModelElement; if (mel == null || (!(mel is XsdMessage) && !(mel is XsdElementFault))) { return; } XmlSchemaElementMoniker elementUri = new XmlSchemaElementMoniker(objectToValidate); // It's a primite type if (string.IsNullOrEmpty(elementUri.ElementName)) { return; } string fileName = Path.GetFileName(elementUri.XmlSchemaPath); string fullPath = GetXsdFullPath(mel, elementUri.XmlSchemaPath); string melName = string.Empty; DomainClassInfo.TryGetName(mel, out melName); if (string.IsNullOrEmpty(fullPath)) { this.LogValidationResult(validationResults, string.Format(CultureInfo.CurrentUICulture, this.invalidFilePathMessage, melName, fileName, schemaDirectory), currentTarget, key); return; } XmlSchemaTypeGenerator generator = new XmlSchemaTypeGenerator(IsXmlSerializer(mel)); CodeCompileUnit unit = null; try { unit = generator.GenerateCodeCompileUnit(fullPath); } catch (InvalidDataContractException exception) { this.LogValidationResult(validationResults, exception.Message, currentTarget, key); return; } catch (InvalidSerializerException serializationException) { if (!IsXmlSerializer(mel)) { this.LogValidationResult(validationResults, string.Format(CultureInfo.CurrentUICulture, this.notCompliantWithDataContractSerializerMessage + ". " + serializationException.Message, fileName), currentTarget, key); return; } } foreach (CodeNamespace ns in unit.Namespaces) { foreach (CodeTypeDeclaration codeType in ns.Types) { if (codeType.Name.Equals(elementUri.ElementName, StringComparison.Ordinal)) { return; } } } this.LogValidationResult(validationResults, string.Format(CultureInfo.CurrentUICulture, this.MessageTemplate, melName, elementUri.ElementName, fileName), currentTarget, key); }