public static string GenTableAdapters(System.IO.Stream xmlStream, TypedDataSetGenerator.GenerateOption genOption, string customToolNamespace)
        {
            try
            {

                EnsureCustomDbProviders();
                var designSource = Activator.CreateInstance(assm.GetType("System.Data.Design.DesignDataSource"));
                designSource.Invoke("ReadXmlSchema",  xmlStream, string.Empty );
                var dataSourceGeneratorType = assm.GetType("System.Data.Design.TypedDataSourceCodeGenerator");
                //get the specific constructor
                var constructor = dataSourceGeneratorType.GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic,
                    null, CallingConventions.Any, new Type[0], new ParameterModifier[0]);
                var dataSourceGenerator = constructor.Invoke(null);

                var codeProvider = new Microsoft.CSharp.CSharpCodeProvider();
                dataSourceGenerator.SetInternalPropertyValue("CodeProvider", codeProvider);

                var codeCompileUnit = new CodeCompileUnit();
                var codeNamespace = new CodeNamespace(customToolNamespace);
                codeCompileUnit.Namespaces.Add(codeNamespace);

                dataSourceGenerator.InvokeInternal("GenerateDataSource",  designSource, codeCompileUnit, codeNamespace, customToolNamespace, genOption );
                var writer = new StringWriter();
                var adapterNameSpace = codeCompileUnit.Namespaces[1];
                codeProvider.GenerateCodeFromNamespace(adapterNameSpace, writer, new CodeGeneratorOptions());
                //codeProvider.GenerateCodeFromCompileUnit(codeCompileUnit, writer, options);
                var res = writer.ToString();
                return (string)res;
            }
            catch (Exception e)
            {

                return e.ToString();
            }
        }
        internal string GenerateTypedDataSet(XmlSchemaElement element, XmlSchemas schemas, CodeCompileUnit compileUnit, CodeNamespace mainNamespace, CodeDomProvider codeProvider)
        {
            if (element == null)
            {
                return(null);
            }
            if (this.importedTypes[element.SchemaType] != null)
            {
                return((string)this.importedTypes[element.SchemaType]);
            }
            IList list = schemas.GetSchemas(element.QualifiedName.Namespace);

            if (list.Count != 1)
            {
                return(null);
            }
            XmlSchema schema = list[0] as XmlSchema;

            if (schema == null)
            {
                return(null);
            }
            MemoryStream stream = new MemoryStream();

            schema.Write(stream);
            stream.Position = 0L;
            DesignDataSource designDS = new DesignDataSource();

            designDS.ReadXmlSchema(stream, null);
            stream.Close();
            string str = TypedDataSetGenerator.GenerateInternal(designDS, compileUnit, mainNamespace, codeProvider, this.dataSetGenerateOptions, null);

            this.importedTypes.Add(element.SchemaType, str);
            return(str);
        }
		protected TypedDataSetSchemaImporterExtension (TypedDataSetGenerator.GenerateOption dataSetGenerateOptions)
		{
		}
		protected TypedDataSetSchemaImporterExtension (TypedDataSetGenerator.GenerateOption dataSetGenerateOptions)
		{
			throw new NotImplementedException ();
		}
Beispiel #5
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
        }
 protected TypedDataSetSchemaImporterExtension(TypedDataSetGenerator.GenerateOption dataSetGenerateOptions)
 {
     this.importedTypes = new Hashtable();
     this.dataSetGenerateOptions = dataSetGenerateOptions;
 }