Пример #1
0
        public override void GenerateCode(AssemblyBuilder assemblyBuilder)
        {
            // Get the namespace that we will use
            string ns = Util.GetNamespaceFromVirtualPath(VirtualPathObject);

            ServiceDescription sd;

            // Load the wsdl file
            using (Stream stream = VirtualPathObject.OpenFile()) {
                try {
                    sd = ServiceDescription.Read(stream);
                }
                catch (InvalidOperationException e) {
                    // It can throw an InvalidOperationException, with the relevant
                    // XmlException as the inner exception.  If so, throw that instead.
                    XmlException xmlException = e.InnerException as XmlException;
                    if (xmlException != null)
                    {
                        throw xmlException;
                    }
                    throw;
                }
            }

            ServiceDescriptionImporter importer = new ServiceDescriptionImporter();

#if !FEATURE_PAL
            importer.CodeGenerator = assemblyBuilder.CodeDomProvider;

            importer.CodeGenerationOptions = CodeGenerationOptions.GenerateProperties |
                                             CodeGenerationOptions.GenerateNewAsync | CodeGenerationOptions.GenerateOldAsync;
#endif // !FEATURE_PAL
            importer.ServiceDescriptions.Add(sd);

            CodeCompileUnit codeCompileUnit = new CodeCompileUnit();

            CodeNamespace codeNamespace = new CodeNamespace(ns);
            codeCompileUnit.Namespaces.Add(codeNamespace);

            // Create the code compile unit
            importer.Import(codeNamespace, codeCompileUnit);

            // Add the CodeCompileUnit to the compilation
            assemblyBuilder.AddCodeCompileUnit(this, codeCompileUnit);
        }
Пример #2
0
        public override void GenerateCode(AssemblyBuilder assemblyBuilder)
        {
#if !FEATURE_PAL // FEATURE_PAL does not support System.Data.Design
            // Get the namespace that we will use
            string ns = Util.GetNamespaceFromVirtualPath(VirtualPathObject);

            // We need to use XmlDocument to parse the xsd file is order to open it with the
            // correct encoding (VSWhidbey 566286)
            XmlDocument doc = new XmlDocument();
            using (Stream stream = OpenStream()) {
                doc.Load(stream);
            }
            String content = doc.OuterXml;

            // Generate a CodeCompileUnit from the dataset
            CodeCompileUnit codeCompileUnit = new CodeCompileUnit();

            CodeNamespace codeNamespace = new CodeNamespace(ns);
            codeCompileUnit.Namespaces.Add(codeNamespace);

            // Devdiv 18365, Dev10

            bool isVer35OrAbove = CompilationUtil.IsCompilerVersion35OrAbove(assemblyBuilder.CodeDomProvider.GetType());

            if (isVer35OrAbove)
            {
                TypedDataSetGenerator.GenerateOption generateOptions = TypedDataSetGenerator.GenerateOption.None;
                generateOptions |= TypedDataSetGenerator.GenerateOption.HierarchicalUpdate;
                generateOptions |= TypedDataSetGenerator.GenerateOption.LinqOverTypedDatasets;
                Hashtable customDBProviders = null;
                TypedDataSetGenerator.Generate(content, codeCompileUnit, codeNamespace, assemblyBuilder.CodeDomProvider, customDBProviders, generateOptions);
            }
            else
            {
                TypedDataSetGenerator.Generate(content, codeCompileUnit, codeNamespace, assemblyBuilder.CodeDomProvider);
            }

            // Add all the assembly references needed by the generated code
            if (TypedDataSetGenerator.ReferencedAssemblies != null)
            {
                var isVer35 = CompilationUtil.IsCompilerVersion35(assemblyBuilder.CodeDomProvider.GetType());
                foreach (Assembly a in TypedDataSetGenerator.ReferencedAssemblies)
                {
                    if (isVer35)
                    {
                        var aName = a.GetName();
                        if (aName.Name == "System.Data.DataSetExtensions")
                        {
                            // Dev10

                            aName.Version = new Version(3, 5, 0, 0);
                            CompilationSection.RecordAssembly(aName.FullName, a);
                        }
                    }
                    assemblyBuilder.AddAssemblyReference(a);
                }
            }


            // Add the CodeCompileUnit to the compilation
            assemblyBuilder.AddCodeCompileUnit(this, codeCompileUnit);
#else // !FEATURE_PAL
            throw new NotImplementedException("System.Data.Design - ROTORTODO");
#endif // !FEATURE_PAL
        }