|
From: <te...@us...> - 2006-10-04 01:42:31
|
Revision: 14
http://svn.sourceforge.net/hex/?rev=14&view=rev
Author: tewald
Date: 2006-10-03 14:43:19 -0700 (Tue, 03 Oct 2006)
Log Message:
-----------
Added noEmbed switch to hexsd.
Updated WSDL extension to get prototype behavior working.
Added test for WSDL extension, but it still needs work.
Modified Paths:
--------------
hexsdtools/trunk/HEXsd/CodeEmitter.cs
hexsdtools/trunk/HEXsd/Program.cs
hexsdtools/trunk/HEXsd/ProgramParameters.cs
hexsdtools/trunk/HEXsd/XmlToClrMapper.cs
hexsdtools/trunk/HEXsdWsdlExtensions/HEXsdWsdlExtensions.csproj
hexsdtools/trunk/HEXsdWsdlExtensions/SchemaExtensionReflector.cs
Added Paths:
-----------
hexsdtools/trunk/HEXsdWsdlExtensions/tests/
hexsdtools/trunk/HEXsdWsdlExtensions/tests/bin/
hexsdtools/trunk/HEXsdWsdlExtensions/tests/bin/urn.example.com.other.dll
hexsdtools/trunk/HEXsdWsdlExtensions/tests/bin/urn.example.org.test.dll
hexsdtools/trunk/HEXsdWsdlExtensions/tests/test.asmx
hexsdtools/trunk/HEXsdWsdlExtensions/tests/web.config
Modified: hexsdtools/trunk/HEXsd/CodeEmitter.cs
===================================================================
--- hexsdtools/trunk/HEXsd/CodeEmitter.cs 2006-10-02 18:52:52 UTC (rev 13)
+++ hexsdtools/trunk/HEXsd/CodeEmitter.cs 2006-10-03 21:43:19 UTC (rev 14)
@@ -49,15 +49,18 @@
// set assembly path and name
compilerParams.OutputAssembly = output;
- // add relevant resources to assembly
- SchemaEmbedder schemaEmbedder = new SchemaEmbedder(compilerParams);
- foreach (CodeNamespace ns in _unit.Namespaces)
+ // add relevant resources to assembly, unless /noEmbed was set
+ if (Program.Parameters.NoEmbed == false)
{
- foreach (XmlSchema schema in _schemas.Schemas)
+ SchemaEmbedder schemaEmbedder = new SchemaEmbedder(compilerParams);
+ foreach (CodeNamespace ns in _unit.Namespaces)
{
- if (ns.Name.Equals(Namespace.ConvertXmlNamespaceToClrNamespace(schema.TargetNamespace)))
+ foreach (XmlSchema schema in _schemas.Schemas)
{
- schemaEmbedder.EmbedSchemaAsResource(schema);
+ if (ns.Name.Equals(Namespace.ConvertXmlNamespaceToClrNamespace(schema.TargetNamespace)))
+ {
+ schemaEmbedder.EmbedSchemaAsResource(schema);
+ }
}
}
}
Modified: hexsdtools/trunk/HEXsd/Program.cs
===================================================================
--- hexsdtools/trunk/HEXsd/Program.cs 2006-10-02 18:52:52 UTC (rev 13)
+++ hexsdtools/trunk/HEXsd/Program.cs 2006-10-03 21:43:19 UTC (rev 14)
@@ -29,7 +29,7 @@
_parameters = new ProgramParameters();
if (!_parameters.ParseArgs(args))
{
- Usage();
+ _parameters.Usage();
return;
}
@@ -58,13 +58,6 @@
}
}
- private void Usage()
- {
- Console.WriteLine("xsd.exe /asm [/ref <list of dlls>] [/out <file>] <list of xsds>");
- Console.WriteLine("xsd.exe /cs [/ref <list of dlls>] [/out <file>] <list of xsds>");
- Console.WriteLine("xsd.exe /xsd [/out <file>] <list of dlls>");
- }
-
public static void Main(string[] args)
{
(s_current = new Program()).InstanceMain(args);
Modified: hexsdtools/trunk/HEXsd/ProgramParameters.cs
===================================================================
--- hexsdtools/trunk/HEXsd/ProgramParameters.cs 2006-10-02 18:52:52 UTC (rev 13)
+++ hexsdtools/trunk/HEXsd/ProgramParameters.cs 2006-10-03 21:43:19 UTC (rev 14)
@@ -12,16 +12,23 @@
internal class ProgramParameters
{
- private ProgramMode _mode = ProgramMode.Assembly;
+ private ProgramMode? _mode = null;
private string _output = null;
private List<string> _references = new List<string>();
private List<string> _input = new List<string>();
private bool _getException = false;
private bool _extraData = false;
+ private bool _noEmbed = false;
+ public bool NoEmbed
+ {
+ get { return _noEmbed; }
+ set { _noEmbed = value; }
+ }
+
internal ProgramMode Mode
{
- get { return _mode; }
+ get { return _mode.Value; }
}
internal string Output
@@ -58,7 +65,7 @@
bool result = true;
int index = 0;
- while (index < args.Length)
+ while (index < args.Length && result == true)
{
string arg = args[index];
@@ -66,15 +73,39 @@
{
if (arg.Equals(@"/assembly"))
{
- _mode = ProgramMode.Assembly;
+ if (_mode.HasValue)
+ {
+ Console.WriteLine("Error: Duplicate mode switch {0}", arg);
+ result = false;
+ }
+ else
+ {
+ _mode = ProgramMode.Assembly;
+ }
}
else if (arg.Equals(@"/cs"))
{
- _mode = ProgramMode.CSharp;
+ if (_mode.HasValue)
+ {
+ Console.WriteLine("Error: Duplicate mode switch {0}", arg);
+ result = false;
+ }
+ else
+ {
+ _mode = ProgramMode.CSharp;
+ }
}
else if (arg.Equals(@"/xsd"))
{
- _mode = ProgramMode.Xsd;
+ if (_mode.HasValue)
+ {
+ Console.WriteLine("Error: Duplicate mode switch {0}", arg);
+ result = false;
+ }
+ else
+ {
+ _mode = ProgramMode.Xsd;
+ }
}
else if (arg.Equals(@"/except"))
{
@@ -84,6 +115,10 @@
{
_extraData = true;
}
+ else if (arg.Equals(@"/noEmbed"))
+ {
+ _noEmbed = true;
+ }
else if (arg.Equals(@"/out"))
{
if (!args[index + 1].StartsWith(@"/"))
@@ -133,65 +168,27 @@
result = false;
}
+ if (result == true)
+ {
+ DefaultArgs();
+ }
+
return result;
}
- private bool ParseSwitch(int index, string[] args)
+ private void DefaultArgs()
{
- bool result = true;
-
- string arg = args[index];
-
- if (arg.Equals(@"/asm"))
+ if (_mode.HasValue == false)
{
_mode = ProgramMode.Assembly;
}
- else if (arg.Equals(@"/cs"))
- {
- _mode = ProgramMode.CSharp;
- }
- else if (arg.Equals(@"/xsd"))
- {
- _mode = ProgramMode.Xsd;
- }
- else if (arg.Equals(@"/out"))
- {
- // setting output file name
- string nextArg = args[index + 1];
- if (!nextArg.StartsWith(@"/"))
- {
- _output = nextArg;
- }
- else
- {
- Console.WriteLine("Error: Unexpected value for /out -> {0}", nextArg);
- result = false;
- }
- }
- else if (arg.Equals(@"/ref"))
- {
- // TBD add support for wildcards
-
- int offset = 1;
- while (args[index + offset].EndsWith(@".dll"))
- {
- _references.Add(args[index + offset]);
+ }
- offset = offset + 1;
- }
- if (offset == 1)
- {
- Console.WriteLine("Error: No reference assemblies following /ref");
- result = false;
- }
- }
- else
- {
- Console.WriteLine("Error: Unknown switch {0}", arg);
- result = false;
- }
-
- return result;
+ internal void Usage()
+ {
+ Console.WriteLine("hexsd.exe /assembly [/extra] [/noEmbed] [/except] [/ref <list of dlls>] [/out <file>] <list of xsds>");
+ Console.WriteLine("hexsd.exe /cs [/extra] [/noEmbed] [/except] [/ref <list of dlls>] [/out <file>] <list of xsds>");
+ Console.WriteLine("hexsd.exe /xsd [/out <file>] <list of dlls>");
}
}
}
Modified: hexsdtools/trunk/HEXsd/XmlToClrMapper.cs
===================================================================
--- hexsdtools/trunk/HEXsd/XmlToClrMapper.cs 2006-10-02 18:52:52 UTC (rev 13)
+++ hexsdtools/trunk/HEXsd/XmlToClrMapper.cs 2006-10-03 21:43:19 UTC (rev 14)
@@ -84,7 +84,7 @@
private Dictionary<string, string> CreateReferenceDictionary()
{
- Dictionary<string, string> result = new Dictionary<string, string>();
+ Dictionary<string, string> namespaceAssemblyDictionary = new Dictionary<string, string>();
foreach (string assemblyPath in Program.Parameters.References)
{
string fullAssemblyPath;
@@ -96,24 +96,70 @@
{
fullAssemblyPath = Path.Combine(Environment.CurrentDirectory, assemblyPath);
}
+
+ Assembly assembly = Assembly.LoadFile(fullAssemblyPath);
+ // check for desired attribute before recursing!
+ if (HasXsdNamespaceAttribute(assembly))
+ {
+ GetEmbeddedSchemaInfoRecursively(assembly, namespaceAssemblyDictionary);
+ }
+ }
+ return namespaceAssemblyDictionary;
+ }
- Assembly assembly = Assembly.LoadFile(fullAssemblyPath);
- object[] attribs = assembly.GetCustomAttributes(true);
- foreach (object attrib in attribs)
+ private void GetEmbeddedSchemaInfoRecursively(Assembly assembly,
+ Dictionary<string, string> namespaceAssemblyDictionary)
+ {
+ // extract schema info from given assembly
+ object[] attribs = assembly.GetCustomAttributes(true);
+ foreach (object attrib in attribs)
+ {
+ Type type = attrib.GetType();
+ if (type.Name.Equals("XsdNamespaceAttribute")
+ && type.Namespace.Equals("HEX.HEXsd.Internal"))
{
- Type type = attrib.GetType();
- if (type.Name.Equals("XsdNamespaceAttribute")
- && type.Namespace.Equals("HEX.HEXsd.Internal"))
+ // TBD how do we get XML namespace string?
+ PropertyInfo property = type.GetProperty("XmlNamespace", BindingFlags.NonPublic | BindingFlags.GetProperty | BindingFlags.Instance);
+ MethodInfo getter = property.GetGetMethod(true);
+ string xmlNamespace = (string) getter.Invoke(attrib, null);
+ if (namespaceAssemblyDictionary.ContainsKey(xmlNamespace))
{
- // TBD how do we get XML namespace string?
- PropertyInfo property = type.GetProperty("XmlNamespace", BindingFlags.NonPublic | BindingFlags.GetProperty | BindingFlags.Instance);
- MethodInfo getter = property.GetGetMethod(true);
- string xmlNamespace = (string) getter.Invoke(attrib, null);
- result.Add(xmlNamespace, assemblyPath);
+ Console.WriteLine("Duplicate definition of schema for namespace {0}", xmlNamespace);
}
+ else
+ {
+ namespaceAssemblyDictionary.Add(xmlNamespace, assembly.Location);
+ }
}
}
+
+ foreach (AssemblyName assemblyName in assembly.GetReferencedAssemblies())
+ {
+ Assembly referencedAssembly = Assembly.Load(assemblyName);
+ // check for desired attribute before recursing!
+ if (HasXsdNamespaceAttribute(referencedAssembly))
+ {
+ GetEmbeddedSchemaInfoRecursively(referencedAssembly, namespaceAssemblyDictionary);
+ }
+ }
+ }
+
+ // TBD remove duplicate code
+ private bool HasXsdNamespaceAttribute(Assembly assembly)
+ {
+ bool result = false;
+ object[] attribs = assembly.GetCustomAttributes(true);
+ foreach (object attrib in attribs)
+ {
+ Type type = attrib.GetType();
+ if (type.Name.Equals("XsdNamespaceAttribute")
+ && type.Namespace.Equals("HEX.HEXsd.Internal"))
+ {
+ result = true;
+ break;
+ }
+ }
return result;
}
Modified: hexsdtools/trunk/HEXsdWsdlExtensions/HEXsdWsdlExtensions.csproj
===================================================================
--- hexsdtools/trunk/HEXsdWsdlExtensions/HEXsdWsdlExtensions.csproj 2006-10-02 18:52:52 UTC (rev 13)
+++ hexsdtools/trunk/HEXsdWsdlExtensions/HEXsdWsdlExtensions.csproj 2006-10-03 21:43:19 UTC (rev 14)
@@ -42,6 +42,24 @@
<Compile Include="SchemaExtensionReflector.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
+ <ItemGroup>
+ <Content Include="bin\Debug\HEX.HEXsdWsdlExtensions.dll" />
+ <Content Include="tests\bin\urn.example.com.other.dll">
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+ </Content>
+ <Content Include="tests\bin\urn.example.org.test.dll">
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+ </Content>
+ <Content Include="tests\test.asmx">
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+ <SubType>Component</SubType>
+ </Content>
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="tests\web.config">
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+ </None>
+ </ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Modified: hexsdtools/trunk/HEXsdWsdlExtensions/SchemaExtensionReflector.cs
===================================================================
--- hexsdtools/trunk/HEXsdWsdlExtensions/SchemaExtensionReflector.cs 2006-10-02 18:52:52 UTC (rev 13)
+++ hexsdtools/trunk/HEXsdWsdlExtensions/SchemaExtensionReflector.cs 2006-10-03 21:43:19 UTC (rev 14)
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Text;
@@ -17,6 +18,11 @@
private int? _totalMethodCount;
private int _methodCount = 1;
+ public override void ReflectDescription()
+ {
+ base.ReflectDescription();
+ }
+
public override void ReflectMethod()
{
if (!_totalMethodCount.HasValue)
@@ -62,10 +68,10 @@
private Dictionary<string, XmlSchema> GetEmbeddedSchemas(Assembly assembly)
{
Dictionary<string, XmlSchema> embeddedSchemas = new Dictionary<string, XmlSchema>();
- if (HasXsdNamespaceAttribute(assembly))
- {
+ //if (HasXsdNamespaceAttribute(assembly))
+ //{
GetEmbeddedSchemasRecursively(assembly, embeddedSchemas);
- }
+ //}
return embeddedSchemas;
}
@@ -79,7 +85,14 @@
{
// TBD add event handler
XmlSchema schema = XmlSchema.Read(stm, null);
- embeddedSchemas.Add(schema.TargetNamespace, schema);
+ foreach (XmlSchemaExternal external in schema.Includes)
+ {
+ external.SchemaLocation = null;
+ }
+ if (!embeddedSchemas.ContainsKey(schema.TargetNamespace))
+ {
+ embeddedSchemas.Add(schema.TargetNamespace, schema);
+ }
}
}
}
Added: hexsdtools/trunk/HEXsdWsdlExtensions/tests/bin/urn.example.com.other.dll
===================================================================
(Binary files differ)
Property changes on: hexsdtools/trunk/HEXsdWsdlExtensions/tests/bin/urn.example.com.other.dll
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: hexsdtools/trunk/HEXsdWsdlExtensions/tests/bin/urn.example.org.test.dll
===================================================================
(Binary files differ)
Property changes on: hexsdtools/trunk/HEXsdWsdlExtensions/tests/bin/urn.example.org.test.dll
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: hexsdtools/trunk/HEXsdWsdlExtensions/tests/test.asmx
===================================================================
--- hexsdtools/trunk/HEXsdWsdlExtensions/tests/test.asmx (rev 0)
+++ hexsdtools/trunk/HEXsdWsdlExtensions/tests/test.asmx 2006-10-03 21:43:19 UTC (rev 14)
@@ -0,0 +1,17 @@
+<%@ WebService Class="Test" Language="C#" %>
+<%@ Assembly Name="urn.example.org.test" %>
+
+using System;
+using System.Web;
+using System.Web.Services;
+
+using Urn.Example.Org.Test;
+
+[WebService]
+public class Test : WebService
+{
+ [WebMethod]
+ public void ProcessPerson(PersonType pt)
+ {
+ }
+}
\ No newline at end of file
Added: hexsdtools/trunk/HEXsdWsdlExtensions/tests/web.config
===================================================================
--- hexsdtools/trunk/HEXsdWsdlExtensions/tests/web.config (rev 0)
+++ hexsdtools/trunk/HEXsdWsdlExtensions/tests/web.config 2006-10-03 21:43:19 UTC (rev 14)
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<configuration>
+
+ <system.web>
+ <webServices>
+ <soapExtensionReflectorTypes>
+ <add type="HEX.HEXsdWsdlExtensions.SchemaExtensionReflector, HEX.HEXsdWsdlExtensions"/>
+ </soapExtensionReflectorTypes>
+ </webServices>
+ </system.web>
+
+</configuration>
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|