/// <summary> /// Returns a new TypeParser object /// </summary> public static TypeParser GetParser(XsdGenerator generator, PropertyInfo property) { var propertyAtts = TypeParser.GetAttributes<ConfigurationPropertyAttribute>(property); var collectionAtts = TypeParser.GetAttributes<ConfigurationCollectionAttribute>(property); // this catches any collections which have their attribute on the property // that declares the use of the collection as opposed to on the collection class if (propertyAtts.Length > 0 && ( collectionAtts.Length > 0 || property.PropertyType.IsSubclassOf(typeof(ConfigurationElementCollection)))) { if (propertyAtts[0].IsDefaultCollection) { return new DefaultConfigurationCollectionParser(generator); } return new ConfigurationCollectionParser(generator); } if (propertyAtts.Length > 0) { if (property.PropertyType.IsSubclassOf(typeof(ConfigurationElement))) { return new ConfigurationElementParser(generator); } return new StandardTypeParser(generator); } throw new Exception( "Neither ConfigurationPropertyAttribute or ConfigurationCollectionAttribute were found in the type."); }
/// <summary> /// Returns a new TypeParser object /// </summary> public static TypeParser GetParser(XsdGenerator generator, PropertyInfo property) { var propertyAtts = TypeParser.GetAttributes <ConfigurationPropertyAttribute>(property); var collectionAtts = TypeParser.GetAttributes <ConfigurationCollectionAttribute>(property); // this catches any collections which have their attribute on the property // that declares the use of the collection as opposed to on the collection class if (propertyAtts.Length > 0 && ( collectionAtts.Length > 0 || property.PropertyType.IsSubclassOf(typeof(ConfigurationElementCollection)))) { if (propertyAtts[0].IsDefaultCollection) { return(new DefaultConfigurationCollectionParser(generator)); } return(new ConfigurationCollectionParser(generator)); } if (propertyAtts.Length > 0) { if (property.PropertyType.IsSubclassOf(typeof(ConfigurationElement))) { return(new ConfigurationElementParser(generator)); } return(new StandardTypeParser(generator)); } throw new Exception( "Neither ConfigurationPropertyAttribute or ConfigurationCollectionAttribute were found in the type."); }
public WsdlTemplateBase GetWsdlTemplate(XsdMetadata operations, string baseUri, bool optimizeForFlash, string rawUrl) { var xsd = new XsdGenerator { OperationTypes = operations.GetAllTypes(), OptimizeForFlash = optimizeForFlash, }.ToString(); var soapFormat = GetType().Name.StartsWith("Soap11", StringComparison.OrdinalIgnoreCase) ? Format.Soap11 : Format.Soap12; var wsdlTemplate = GetWsdlTemplate(); wsdlTemplate.Xsd = xsd; wsdlTemplate.ReplyOperationNames = operations.GetReplyOperationNames(soapFormat); wsdlTemplate.OneWayOperationNames = operations.GetOneWayOperationNames(soapFormat); if (rawUrl.ToLower().StartsWith(baseUri)) { wsdlTemplate.ReplyEndpointUri = rawUrl; wsdlTemplate.OneWayEndpointUri = rawUrl; } else { var suffix = soapFormat == Format.Soap11 ? "soap11" : "soap12"; wsdlTemplate.ReplyEndpointUri = baseUri + suffix; wsdlTemplate.OneWayEndpointUri = baseUri + suffix; } return(wsdlTemplate); }
public void Verify(string resourceName) { // build a standard configurationsection with properties (using the mock object) var enterpriseConfig = new EnterpriseConfig(); XmlHelper.UseAll = true; var configType = enterpriseConfig.GetType(); var generator = new XsdGenerator(configType); XmlSchema schema = generator.GenerateXsd(configType.FullName); var schemaXml = SchemaToString(schema); var schemas = new XmlSchemaSet(); schemas.Add("http://JFDI.Utils.XSDExtractor.UnitTests.ConfigurationClasses.EnterpriseConfig", XmlReader.Create(new StringReader(schemaXml))); schemas.CompilationSettings.EnableUpaCheck = true; schemas.Compile(); var assembly = Assembly.GetExecutingAssembly(); using (Stream stream = assembly.GetManifestResourceStream(resourceName)) { var doc = new XmlDocument(); doc.Load(stream); doc.Schemas.Add(schemas); Debug.WriteLine(doc.OuterXml); Debug.WriteLine("------------------"); doc.Validate(((sender, args) => { Debug.WriteLine("{0} {1}", args.Message, args.Severity); Assert.Fail(args.Message); })); } }
public WsdlTemplateBase GetWsdlTemplate(ServiceOperations operations, string baseUri, bool optimizeForFlash, bool includeAllTypesInAssembly, string rawUrl) { var xsd = new XsdGenerator { OperationTypes = operations.AllOperations.Types, OptimizeForFlash = optimizeForFlash, IncludeAllTypesInAssembly = includeAllTypesInAssembly, }.ToString(); var wsdlTemplate = GetWsdlTemplate(); wsdlTemplate.Xsd = xsd; wsdlTemplate.ReplyOperationNames = operations.ReplyOperations.Names; wsdlTemplate.OneWayOperationNames = operations.OneWayOperations.Names; if (rawUrl.ToLower().Contains("servicestack")) { //var qsPos = rawUrl.IndexOf('?'); //var urlWithoutQueryString = qsPos != -1 ? rawUrl.Substring(0, qsPos) : rawUrl; wsdlTemplate.ReplyEndpointUri = rawUrl; wsdlTemplate.OneWayEndpointUri = rawUrl; } else { wsdlTemplate.ReplyEndpointUri = baseUri + "SyncReply.svc"; wsdlTemplate.OneWayEndpointUri = baseUri + "AsyncOneWay.svc"; } return(wsdlTemplate); }
private static void Main(string[] args) { var options = new Options(); if (Parser.Default.ParseArguments(args, options) == false) { return; } Assembly inputAssembly; Type rootElementType; if (LoadInputAssembly(options.AssemblyFileName, out inputAssembly) == false || LoadRootElementType(inputAssembly, options.RootElementTypeName, out rootElementType) == false) { return; } var xsdGenerator = new XsdGenerator(new XmlWriterSettings { Indent = options.FormatOutput }); var xsdSchema = xsdGenerator.Generate(rootElementType, options.RootElementName); File.WriteAllText(options.OutputFileName, xsdSchema); }
public WsdlTemplateBase GetWsdlTemplate(ServiceOperations operations, string baseUri, bool optimizeForFlash, bool includeAllTypesInAssembly, string rawUrl) { var xsd = new XsdGenerator { OperationTypes = operations.AllOperations.Types, OptimizeForFlash = optimizeForFlash, IncludeAllTypesInAssembly = includeAllTypesInAssembly, }.ToString(); var wsdlTemplate = GetWsdlTemplate(); wsdlTemplate.Xsd = xsd; wsdlTemplate.ReplyOperationNames = operations.ReplyOperations.Names; wsdlTemplate.OneWayOperationNames = operations.OneWayOperations.Names; if (rawUrl.ToLower().StartsWith(baseUri)) { wsdlTemplate.ReplyEndpointUri = rawUrl; wsdlTemplate.OneWayEndpointUri = rawUrl; } else { wsdlTemplate.ReplyEndpointUri = baseUri + "SyncReply.svc"; wsdlTemplate.OneWayEndpointUri = baseUri + "AsyncOneWay.svc"; } return(wsdlTemplate); }
public GenerateDictionatyDialog(string dataSetFilePath) { this.Width = 600; this.Height = 440; var generator = new XsdGenerator(dataSetFilePath); this.Content = generator; }
public void Xsd_output_does_not_contain_xml_declaration() { var xsd = new XsdGenerator { OperationTypes = new[] { typeof(GetCustomer), typeof(GetCustomerResponse), typeof(GetCustomers), typeof(GetCustomersResponse), typeof(StoreCustomer) }, OptimizeForFlash = false, }.ToString(); Assert.That(!xsd.StartsWith("<?")); }
public void PrintGeneratedStubSchema() { var xsdGenerator = new XsdGenerator(new XmlWriterSettings { Indent = true }); var xsdSchema = xsdGenerator.Generate(typeof(LibrarySection), "library"); Console.WriteLine(xsdSchema); }
public void TestComplicatedConfigurationSection() { var generator = new XsdGenerator(typeof(AppSettingsSection)); var schema = generator.GenerateXsd("UnitTestRootElement"); var schemaXml = SchemaToString(schema); // load the schema into the document var doc = new XmlDocument(); doc.LoadXml(schemaXml); }
public void ShouldGenerateCorrectStubSchema() { var xsdGenerator = new XsdGenerator(new XmlWriterSettings { Indent = true }); var actualXsdSchema = xsdGenerator.Generate(typeof(LibrarySection), "library"); var expectedXsdSchema = File.ReadAllText(StubSchemaFileName); Assert.AreEqual(expectedXsdSchema, actualXsdSchema); }
public void Generate() // konstruktorVsfuggvenyPara namespaces imports { this.PrepareGeneration(); if (this.diagnostics.HasAnyErrors()) { return; } if (this.SingleFileWsdl) { this.SeparateXsdWsdl = false; } string xsdDirectory = Path.Combine(this.OutputDirectory, "xsd"); string wsdlDirectory = Path.Combine(this.OutputDirectory, "wsdl"); if (this.SeparateXsdWsdl) { Directory.CreateDirectory(xsdDirectory); } else { xsdDirectory = wsdlDirectory; } Directory.CreateDirectory(wsdlDirectory); var namespaces = this.Model.Symbols.OfType <Namespace>().Where(ns => ns.Uri != null).ToList(); foreach (var ns in namespaces) { if (ns.Uri != null) { if (!this.SingleFileWsdl) { string xsdFileName = Path.Combine(xsdDirectory, ns.FullName + ".xsd"); using (StreamWriter writer = new StreamWriter(xsdFileName)) { XsdGenerator xsdGen = new XsdGenerator(ns); writer.WriteLine(xsdGen.Generate(ns)); } } string wsdlFileName = Path.Combine(wsdlDirectory, ns.FullName + ".wsdl"); using (StreamWriter writer = new StreamWriter(wsdlFileName)) { WsdlGenerator wsdlGen = new WsdlGenerator(ns); wsdlGen.Properties.SingleFileWsdl = this.SingleFileWsdl; wsdlGen.Properties.SeparateXsdWsdl = this.SeparateXsdWsdl; writer.WriteLine(wsdlGen.Generate(ns)); } JavaEeGenerationHelper.GenerateJavaEe(ns, this.OutputDirectory); } } }
public static void Main() { var xsd = new XsdGenerator { OperationTypes = new[] { typeof(GetUsers), typeof(DeleteAllUsers), typeof(StoreNewUser), typeof(GetFactorial), typeof(GetFibonacciNumbers) }, OptimizeForFlash = false, }.ToString(); Console.WriteLine("xsd: " + xsd); }
public void GenerateTest() { String inputXml = @"<?xml version='1.0' encoding='UTF-8'?> <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note>"; String outputXml = "<?xml version=\"1.0\" encoding=\"utf-8\"?><xs:schema attributeFormDefault=\"unqualified\" elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\"><xs:element name=\"note\"><xs:complexType><xs:sequence><xs:element name=\"to\" type=\"xs:string\" /><xs:element name=\"from\" type=\"xs:string\" /><xs:element name=\"heading\" type=\"xs:string\" /><xs:element name=\"body\" type=\"xs:string\" /></xs:sequence></xs:complexType></xs:element></xs:schema>"; XsdGenerator generator = new XsdGenerator(); Assert.Equal(outputXml, generator.Generate(inputXml)); }
public void Xsd_output_does_not_contain_xml_declaration() { using (var appHost = new BasicAppHost().Init()) { var xsd = new XsdGenerator { OperationTypes = new[] { typeof(GetCustomer), typeof(GetCustomerResponse), typeof(GetCustomers), typeof(GetCustomersResponse), typeof(StoreCustomer) }, OptimizeForFlash = false, }.ToString(); Console.WriteLine(xsd); Assert.That(xsd.StartsWith("<xs:schema xmlns:tns=\"http://schemas.microsoft.com/2003/10/Serialization/\"")); } }
public void TestMultipleDefinitions() { // build a standard configurationsection with properties (using the mock object) var dm = Substitute.For<EnterpriseConfig>(); var enterpriseConfig = dm; var generator = new XsdGenerator(enterpriseConfig.GetType()); var schema = generator.GenerateXsd("UnitTestRootElement"); var schemaXml = SchemaToString(schema); // not sure why, but the add method throws an exception when called with // the schema object above, we have to serialize it and then add it // again - seems crazy but works. //compileSet.Add(schema); var compileSet = new XmlSchemaSet(); compileSet.Add(schema.TargetNamespace, new XmlTextReader(new StringReader(schemaXml))); compileSet.Compile(); }
public void TestXmlNSAttribute() { var generator = new XsdGenerator(typeof(ConfigurationWithXmlNSAttribute)); var schema = generator.GenerateXsd("UnitTestRootElement"); var schemaXml = SchemaToString(schema); // load the schema into the document var doc = new XmlDocument(); doc.LoadXml(schemaXml); // see if we can find the xmlns attribute var nsm = CreateNamespaceManager(doc); var xpath = new StringBuilder(); xpath.Append("//xs:schema/xs:complexType/xs:attribute[@name='xmlns']"); var attributeNode = doc.SelectSingleNode(xpath.ToString(), nsm); Assert.IsNull(attributeNode, "xmlns attribute was found"); }
public void TestMultipleDefinitions() { // build a standard configurationsection with properties (using the mock object) var dm = Substitute.For <EnterpriseConfig>(); var enterpriseConfig = dm; var generator = new XsdGenerator(enterpriseConfig.GetType()); var schema = generator.GenerateXsd("UnitTestRootElement"); var schemaXml = SchemaToString(schema); // not sure why, but the add method throws an exception when called with // the schema object above, we have to serialize it and then add it // again - seems crazy but works. //compileSet.Add(schema); var compileSet = new XmlSchemaSet(); compileSet.Add(schema.TargetNamespace, new XmlTextReader(new StringReader(schemaXml))); compileSet.Compile(); }
public void TestBlankConfig() { // build a standard configurationsection with properties (using the mock object) var dm = Substitute.For<ConfigurationSection>(); var cs = dm; var generator = new XsdGenerator(cs.GetType()); var schema = generator.GenerateXsd("UnitTestRootElement"); var schemaXml = SchemaToString(schema); // load the schema into the document var doc = new XmlDocument(); doc.LoadXml(schemaXml); // see if we can find the root element var nsm = CreateNamespaceManager(doc); var rootNode = doc.SelectSingleNode("//xs:element[@name='UnitTestRootElement']", nsm); Assert.IsNotNull(rootNode, "rootNode was null"); }
public void Generate() { this.PrepareGeneration(); if (this.diagnostics.HasAnyErrors()) { return; } if (this.SingleFileWsdl) { this.SeparateXsdWsdl = false; } string xsdDirectory = Path.Combine(this.OutputDirectory, "xsd"); string wsdlDirectory = Path.Combine(this.OutputDirectory, "wsdl"); if (this.SeparateXsdWsdl) { Directory.CreateDirectory(xsdDirectory); } else { xsdDirectory = wsdlDirectory; } Directory.CreateDirectory(wsdlDirectory); var namespaces = this.Model.Symbols.OfType <Namespace>().Where(ns => ns.Uri != null).ToList(); foreach (var ns in namespaces) { if (ns.Uri != null) { if (!this.SingleFileWsdl) { string xsdFileName = Path.Combine(xsdDirectory, ns.FullName + ".xsd"); XsdGenerator xsdGen = new XsdGenerator(ns); File.WriteAllText(xsdFileName, xsdGen.Generate(ns)); } string wsdlFileName = Path.Combine(wsdlDirectory, ns.FullName + ".wsdl"); WsdlGenerator wsdlGen = new WsdlGenerator(ns); wsdlGen.Properties.SingleFileWsdl = this.SingleFileWsdl; wsdlGen.Properties.SeparateXsdWsdl = this.SeparateXsdWsdl; File.WriteAllText(wsdlFileName, wsdlGen.Generate(ns)); } } }
public void TestBlankConfig() { // build a standard configurationsection with properties (using the mock object) var dm = Substitute.For <ConfigurationSection>(); var cs = dm; var generator = new XsdGenerator(cs.GetType()); var schema = generator.GenerateXsd("UnitTestRootElement"); var schemaXml = SchemaToString(schema); // load the schema into the document var doc = new XmlDocument(); doc.LoadXml(schemaXml); // see if we can find the root element var nsm = CreateNamespaceManager(doc); var rootNode = doc.SelectSingleNode("//xs:element[@name='UnitTestRootElement']", nsm); Assert.IsNotNull(rootNode, "rootNode was null"); }
public void TwoChildCollectionsNotRequiredConfig(string resourceName) { // build a standard configurationsection with properties (using the mock object) var configElement = new TwoChildCollectionsNotRequiredConfig(); XmlHelper.UseAll = true; var configType = configElement.GetType(); var generator = new XsdGenerator(configType); XmlSchema schema = generator.GenerateXsd(configType.FullName); var schemaXml = SchemaToString(schema); Debug.WriteLine(schemaXml); var schemas = new XmlSchemaSet(); schemas.Add(schema.TargetNamespace, XmlReader.Create(new StringReader(schemaXml))); schemas.CompilationSettings.EnableUpaCheck = true; schemas.Compile(); var assembly = Assembly.GetExecutingAssembly(); using (Stream stream = assembly.GetManifestResourceStream(resourceName)) { var doc = new XmlDocument(); doc.Load(stream); doc.Schemas.Add(schemas); Debug.WriteLine(doc.OuterXml); Debug.WriteLine("------------------"); doc.Validate(((sender, args) => { Debug.WriteLine("{0} {1}", args.Message, args.Severity); Assert.Fail(args.Message); })); } }
public void ShouldGenerateASchemaToValidateTestClassXml() { NetReflectorTypeTable table = new NetReflectorTypeTable(); table.Add(typeof(TestClass)); table.Add(typeof(TestInnerClass)); XsdGenerator generator = new XsdGenerator(table); XmlSchema schema = generator.Generate(true); // schema.Write(Console.Out); string xmlToValidate = TestClass.GetXml(DateTime.Today); // Console.Out.WriteLine("xmlToValidate = {0}", xmlToValidate); XmlValidatingReader reader = new XmlValidatingReader(new XmlTextReader(new StringReader(xmlToValidate))); reader.Schemas.Add(schema); reader.ValidationType = ValidationType.Schema; while (reader.Read()) { } }
static int Main(string[] args) { String inputXml = ""; // if nothing is being piped in, then exit if (!IsPipedInput()) { Console.WriteLine("Wrong number of arguments."); return((int)ExitCode.Error); } else { while (Console.In.Peek() != -1) { inputXml += Console.In.ReadLine(); } String xsd = new XsdGenerator().Generate(inputXml); Console.WriteLine(xsd); return((int)ExitCode.Success); } }
/// <summary> /// </summary> public ConfigurationElementParser(XsdGenerator generator) : base(generator) { }
public void Generate() { this.PrepareGeneration(); if (this.Diagnostics.HasErrors()) return; if (this.SingleFileWsdl) { this.SeparateXsdWsdl = false; } string xsdDirectory = Path.Combine(this.OutputDirectory, "xsd"); string wsdlDirectory = Path.Combine(this.OutputDirectory, "wsdl"); if (this.SeparateXsdWsdl) { Directory.CreateDirectory(xsdDirectory); } else { xsdDirectory = wsdlDirectory; } Directory.CreateDirectory(wsdlDirectory); var namespaces = this.Model.Instances.OfType<Namespace>().ToList(); foreach (var ns in namespaces) { if (ns.Uri != null) { if (!this.SingleFileWsdl) { string xsdFileName = Path.Combine(xsdDirectory, ns.FullName + ".xsd"); using (StreamWriter writer = new StreamWriter(xsdFileName)) { XsdGenerator xsdGen = new XsdGenerator(ns); writer.WriteLine(xsdGen.Generate(ns)); } } string wsdlFileName = Path.Combine(wsdlDirectory, ns.FullName + ".wsdl"); using (StreamWriter writer = new StreamWriter(wsdlFileName)) { WsdlGenerator wsdlGen = new WsdlGenerator(ns); wsdlGen.Properties.SingleFileWsdl = this.SingleFileWsdl; wsdlGen.Properties.SeparateXsdWsdl = this.SeparateXsdWsdl; writer.WriteLine(wsdlGen.Generate(ns)); } } } }
/// <summary> /// </summary> public StandardTypeParser(XsdGenerator generator) : base(generator) { }
/// <summary> /// Creates an instance of the <see cref="ConfigurationCollectionParser" /> class /// </summary> public ConfigurationCollectionParser(XsdGenerator generator) : base(generator) { }
public Test() { LoanRequestRequest e = new LoanRequestRequest() { AmmountRequested = 324234, Direccion = new Direccion { Carrera = "sdfsdf", Latitude = new Latitude { Longitud = 23123 } }, Id = 12, Type = LoanType.Car }; var x = CrossCutting.Utils.XmlHelper.SerializeObject(e); //var a = e.GetType(); //Activator.CreateInstance(a.AssemblyQualifiedName, a.q) //CrossCutting.Utils.XmlHelper.SerializeObject<> //using (var client = new WebClient()) //{ // Automation.DataAccess.Test testDataAccess = new Automation.DataAccess.Test(); // TestCase testCase = testDataAccess.GetTestCase(6); // XmlDocument xml = new XmlDocument(); // xml.LoadXml(testCase.Input); // //xml.FirstChild.Value.GetType(); // // read the raw SOAP request message from a file // //var data = File.ReadAllText(testCase.Input); // // the Content-Type needs to be set to XML // client.Headers.Add("Content-Type", "text/xml;charset=utf-8"); // // The SOAPAction header indicates which method you would like to invoke // // and could be seen in the WSDL: <soap:operation soapAction="..." /> element // client.Headers.Add("SOAPAction", "http://tempuri.org/ILoan/LoanRequest"); // var response = client.UploadString("http://localhost/Sofka.Automation.Dummy.Wcf/Loan.svc", testCase.Input); // Console.WriteLine(response); //} Provider.XsdGenerator asas = new XsdGenerator(); //Automation.DataAccess.Test testDataAccess = new Automation.DataAccess.Test(); //TestCase testCase = testDataAccess.GetTestCase(6); //client = new Provider.TestConnector //{ // Request = testCase.Input, // Url = "http://localhost/Sofka.Automation.Dummy.Wcf/Loan.svc", // WSServiceType = Provider.TestConnector.ServiceType.WCF, // WCFContractName = "ILoan", // WebMethod = "LoanRequest" //}; //client.BeginInvokeService(InvokeCompleted); //testDataAccess = new DataAccess.Test(); //loanClient = new LoanClient(); }
/// <summary> /// Creates an instance of the TypeParser object. CTOR is protected /// because only inheriting classes should be able to use this constructor /// </summary> protected TypeParser(XsdGenerator generator) { Generator = generator; }
/// <summary> /// Creates an instance of the <see cref="ConfigurationElementCollection" /> class /// </summary> public DefaultConfigurationCollectionParser(XsdGenerator generator) : base(generator) { }