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);
        }
        internal CodeTypeDeclaration GenerateAdapterManager(DesignDataSource dataSource, CodeTypeDeclaration dataSourceClass)
        {
            TypeAttributes @public = TypeAttributes.Public;

            foreach (DesignTable table in dataSource.DesignTables)
            {
                if ((table.DataAccessorModifier & TypeAttributes.Public) != TypeAttributes.Public)
                {
                    @public = table.DataAccessorModifier;
                }
            }
            CodeTypeDeclaration dataComponentClass = CodeGenHelper.Class("TableAdapterManager", true, @public);

            dataComponentClass.Comments.Add(CodeGenHelper.Comment("TableAdapterManager is used to coordinate TableAdapters in the dataset to enable Hierarchical Update scenarios", true));
            dataComponentClass.BaseTypes.Add(CodeGenHelper.GlobalType(typeof(Component)));
            dataComponentClass.CustomAttributes.Add(CodeGenHelper.AttributeDecl("System.ComponentModel.DesignerCategoryAttribute", CodeGenHelper.Str("code")));
            dataComponentClass.CustomAttributes.Add(CodeGenHelper.AttributeDecl("System.ComponentModel.ToolboxItem", CodeGenHelper.Primitive(true)));
            dataComponentClass.CustomAttributes.Add(CodeGenHelper.AttributeDecl("System.ComponentModel.DesignerAttribute", CodeGenHelper.Str("Microsoft.VSDesigner.DataSource.Design.TableAdapterManagerDesigner, Microsoft.VSDesigner, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")));
            dataComponentClass.CustomAttributes.Add(CodeGenHelper.AttributeDecl(typeof(HelpKeywordAttribute).FullName, CodeGenHelper.Str("vs.data.TableAdapterManager")));
            new TableAdapterManagerMethodGenerator(this.dataSourceGenerator, dataSource, dataSourceClass).AddEverything(dataComponentClass);
            try
            {
                CodeGenerator.ValidateIdentifiers(dataComponentClass);
            }
            catch (Exception)
            {
            }
            return(dataComponentClass);
        }
 internal void GenerateMemberNames(DesignDataSource dataSource, ArrayList problemList)
 {
     if ((dataSource == null) || (codeProvider == null))
     {
         throw new InternalException("DesignDataSource or/and CodeDomProvider parameters are null.");
     }
     InitLookupIdentifiers();
     this.dataSourceHandler = new DataSourceNameHandler();
     this.dataSourceHandler.GenerateMemberNames(dataSource, codeProvider, this.languageCaseInsensitive, problemList);
     foreach (DesignTable table in dataSource.DesignTables)
     {
         new DataTableNameHandler().GenerateMemberNames(table, codeProvider, this.languageCaseInsensitive, problemList);
         new DataComponentNameHandler().GenerateMemberNames(table, codeProvider, this.languageCaseInsensitive, problemList);
     }
     if ((dataSource.Sources != null) && (dataSource.Sources.Count > 0))
     {
         DesignTable designTable = new DesignTable {
             TableType                       = TableType.RadTable,
             DataAccessorName                = dataSource.FunctionsComponentName,
             UserDataComponentName           = dataSource.UserFunctionsComponentName,
             GeneratorDataComponentClassName = dataSource.GeneratorFunctionsComponentClassName
         };
         foreach (Source source in dataSource.Sources)
         {
             designTable.Sources.Add(source);
         }
         new DataComponentNameHandler {
             GlobalSources = true
         }.GenerateMemberNames(designTable, codeProvider, this.languageCaseInsensitive, problemList);
         dataSource.GeneratorFunctionsComponentClassName = designTable.GeneratorDataComponentClassName;
     }
 }
 internal CodeTypeDeclaration GenerateAdapterManager(DesignDataSource dataSource, CodeTypeDeclaration dataSourceClass)
 {
     TypeAttributes @public = TypeAttributes.Public;
     foreach (DesignTable table in dataSource.DesignTables)
     {
         if ((table.DataAccessorModifier & TypeAttributes.Public) != TypeAttributes.Public)
         {
             @public = table.DataAccessorModifier;
         }
     }
     CodeTypeDeclaration dataComponentClass = CodeGenHelper.Class("TableAdapterManager", true, @public);
     dataComponentClass.Comments.Add(CodeGenHelper.Comment("TableAdapterManager is used to coordinate TableAdapters in the dataset to enable Hierarchical Update scenarios", true));
     dataComponentClass.BaseTypes.Add(CodeGenHelper.GlobalType(typeof(Component)));
     dataComponentClass.CustomAttributes.Add(CodeGenHelper.AttributeDecl("System.ComponentModel.DesignerCategoryAttribute", CodeGenHelper.Str("code")));
     dataComponentClass.CustomAttributes.Add(CodeGenHelper.AttributeDecl("System.ComponentModel.ToolboxItem", CodeGenHelper.Primitive(true)));
     dataComponentClass.CustomAttributes.Add(CodeGenHelper.AttributeDecl("System.ComponentModel.DesignerAttribute", CodeGenHelper.Str("Microsoft.VSDesigner.DataSource.Design.TableAdapterManagerDesigner, Microsoft.VSDesigner, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")));
     dataComponentClass.CustomAttributes.Add(CodeGenHelper.AttributeDecl(typeof(HelpKeywordAttribute).FullName, CodeGenHelper.Str("vs.data.TableAdapterManager")));
     new TableAdapterManagerMethodGenerator(this.dataSourceGenerator, dataSource, dataSourceClass).AddEverything(dataComponentClass);
     try
     {
         CodeGenerator.ValidateIdentifiers(dataComponentClass);
     }
     catch (Exception)
     {
     }
     return dataComponentClass;
 }
 internal void GenerateMemberNames(DesignDataSource dataSource, ArrayList problemList)
 {
     if ((dataSource == null) || (codeProvider == null))
     {
         throw new InternalException("DesignDataSource or/and CodeDomProvider parameters are null.");
     }
     InitLookupIdentifiers();
     this.dataSourceHandler = new DataSourceNameHandler();
     this.dataSourceHandler.GenerateMemberNames(dataSource, codeProvider, this.languageCaseInsensitive, problemList);
     foreach (DesignTable table in dataSource.DesignTables)
     {
         new DataTableNameHandler().GenerateMemberNames(table, codeProvider, this.languageCaseInsensitive, problemList);
         new DataComponentNameHandler().GenerateMemberNames(table, codeProvider, this.languageCaseInsensitive, problemList);
     }
     if ((dataSource.Sources != null) && (dataSource.Sources.Count > 0))
     {
         DesignTable designTable = new DesignTable {
             TableType = TableType.RadTable,
             DataAccessorName = dataSource.FunctionsComponentName,
             UserDataComponentName = dataSource.UserFunctionsComponentName,
             GeneratorDataComponentClassName = dataSource.GeneratorFunctionsComponentClassName
         };
         foreach (Source source in dataSource.Sources)
         {
             designTable.Sources.Add(source);
         }
         new DataComponentNameHandler { GlobalSources = true }.GenerateMemberNames(designTable, codeProvider, this.languageCaseInsensitive, problemList);
         dataSource.GeneratorFunctionsComponentClassName = designTable.GeneratorDataComponentClassName;
     }
 }
 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;
 }
        private CodeTypeDeclaration CreateDataSourceDeclaration(DesignDataSource dtDataSource)
        {
            if (dtDataSource.Name == null)
            {
                throw new DataSourceGeneratorException("DataSource name cannot be null.");
            }
            new NameHandler(this.codeProvider).GenerateMemberNames(dtDataSource, this.problemList);
            CodeTypeDeclaration dataSourceClass = CodeGenHelper.Class(dtDataSource.GeneratorDataSetName, true, dtDataSource.Modifier);

            dataSourceClass.BaseTypes.Add(CodeGenHelper.GlobalType(typeof(DataSet)));
            dataSourceClass.CustomAttributes.Add(CodeGenHelper.AttributeDecl("System.Serializable"));
            dataSourceClass.CustomAttributes.Add(CodeGenHelper.AttributeDecl("System.ComponentModel.DesignerCategoryAttribute", CodeGenHelper.Str("code")));
            dataSourceClass.CustomAttributes.Add(CodeGenHelper.AttributeDecl("System.ComponentModel.ToolboxItem", CodeGenHelper.Primitive(true)));
            dataSourceClass.CustomAttributes.Add(CodeGenHelper.AttributeDecl(typeof(XmlSchemaProviderAttribute).FullName, CodeGenHelper.Primitive("GetTypedDataSetSchema")));
            dataSourceClass.CustomAttributes.Add(CodeGenHelper.AttributeDecl(typeof(XmlRootAttribute).FullName, CodeGenHelper.Primitive(dtDataSource.GeneratorDataSetName)));
            dataSourceClass.CustomAttributes.Add(CodeGenHelper.AttributeDecl(typeof(HelpKeywordAttribute).FullName, CodeGenHelper.Str("vs.data.DataSet")));
            dataSourceClass.Comments.Add(CodeGenHelper.Comment("Represents a strongly typed in-memory cache of data.", true));
            this.tableHandler    = new TypedTableHandler(this, dtDataSource.DesignTables);
            this.relationHandler = new System.Data.Design.RelationHandler(this, dtDataSource.DesignRelations);
            this.rowHandler      = new TypedRowHandler(this, dtDataSource.DesignTables);
            DatasetMethodGenerator generator = new DatasetMethodGenerator(this, dtDataSource);

            this.tableHandler.AddPrivateVars(dataSourceClass);
            this.tableHandler.AddTableProperties(dataSourceClass);
            this.relationHandler.AddPrivateVars(dataSourceClass);
            generator.AddMethods(dataSourceClass);
            this.rowHandler.AddTypedRowEventHandlers(dataSourceClass);
            this.tableHandler.AddTableClasses(dataSourceClass);
            this.rowHandler.AddTypedRows(dataSourceClass);
            this.rowHandler.AddTypedRowEventArgs(dataSourceClass);
            return(dataSourceClass);
        }
 private CodeTypeDeclaration CreateDataSourceDeclaration(DesignDataSource dtDataSource)
 {
     if (dtDataSource.Name == null)
     {
         throw new DataSourceGeneratorException("DataSource name cannot be null.");
     }
     new NameHandler(this.codeProvider).GenerateMemberNames(dtDataSource, this.problemList);
     CodeTypeDeclaration dataSourceClass = CodeGenHelper.Class(dtDataSource.GeneratorDataSetName, true, dtDataSource.Modifier);
     dataSourceClass.BaseTypes.Add(CodeGenHelper.GlobalType(typeof(DataSet)));
     dataSourceClass.CustomAttributes.Add(CodeGenHelper.AttributeDecl("System.Serializable"));
     dataSourceClass.CustomAttributes.Add(CodeGenHelper.AttributeDecl("System.ComponentModel.DesignerCategoryAttribute", CodeGenHelper.Str("code")));
     dataSourceClass.CustomAttributes.Add(CodeGenHelper.AttributeDecl("System.ComponentModel.ToolboxItem", CodeGenHelper.Primitive(true)));
     dataSourceClass.CustomAttributes.Add(CodeGenHelper.AttributeDecl(typeof(XmlSchemaProviderAttribute).FullName, CodeGenHelper.Primitive("GetTypedDataSetSchema")));
     dataSourceClass.CustomAttributes.Add(CodeGenHelper.AttributeDecl(typeof(XmlRootAttribute).FullName, CodeGenHelper.Primitive(dtDataSource.GeneratorDataSetName)));
     dataSourceClass.CustomAttributes.Add(CodeGenHelper.AttributeDecl(typeof(HelpKeywordAttribute).FullName, CodeGenHelper.Str("vs.data.DataSet")));
     dataSourceClass.Comments.Add(CodeGenHelper.Comment("Represents a strongly typed in-memory cache of data.", true));
     this.tableHandler = new TypedTableHandler(this, dtDataSource.DesignTables);
     this.relationHandler = new System.Data.Design.RelationHandler(this, dtDataSource.DesignRelations);
     this.rowHandler = new TypedRowHandler(this, dtDataSource.DesignTables);
     DatasetMethodGenerator generator = new DatasetMethodGenerator(this, dtDataSource);
     this.tableHandler.AddPrivateVars(dataSourceClass);
     this.tableHandler.AddTableProperties(dataSourceClass);
     this.relationHandler.AddPrivateVars(dataSourceClass);
     generator.AddMethods(dataSourceClass);
     this.rowHandler.AddTypedRowEventHandlers(dataSourceClass);
     this.tableHandler.AddTableClasses(dataSourceClass);
     this.rowHandler.AddTypedRows(dataSourceClass);
     this.rowHandler.AddTypedRowEventArgs(dataSourceClass);
     return dataSourceClass;
 }
Example #9
0
        public static string Generate(string inputFileContent, CodeCompileUnit compileUnit, CodeNamespace mainNamespace, CodeDomProvider codeProvider, GenerateOption option, string dataSetNamespace, string basePath)
        {
            if ((inputFileContent == null) || (inputFileContent.Length == 0))
            {
                throw new ArgumentException(System.Design.SR.GetString("CG_DataSetGeneratorFail_InputFileEmpty"));
            }
            if (mainNamespace == null)
            {
                throw new ArgumentException(System.Design.SR.GetString("CG_DataSetGeneratorFail_CodeNamespaceNull"));
            }
            if (codeProvider == null)
            {
                throw new ArgumentNullException("codeProvider");
            }
            StringReader     textReader = new StringReader(inputFileContent);
            DesignDataSource designDS   = new DesignDataSource();

            try
            {
                designDS.ReadXmlSchema(textReader, basePath);
            }
            catch (Exception exception)
            {
                throw new Exception(System.Design.SR.GetString("CG_DataSetGeneratorFail_UnableToConvertToDataSet", new object[] { CreateExceptionMessage(exception) }), exception);
            }
            return(GenerateInternal(designDS, compileUnit, mainNamespace, codeProvider, option, dataSetNamespace));
        }
Example #10
0
        public static string GetProviderName(string inputFileContent, string tableName)
        {
            if ((inputFileContent == null) || (inputFileContent.Length == 0))
            {
                throw new ArgumentException(System.Design.SR.GetString("CG_DataSetGeneratorFail_InputFileEmpty"));
            }
            StringReader     textReader = new StringReader(inputFileContent);
            DesignDataSource source     = new DesignDataSource();

            try
            {
                source.ReadXmlSchema(textReader, null);
            }
            catch (Exception exception)
            {
                throw new Exception(System.Design.SR.GetString("CG_DataSetGeneratorFail_UnableToConvertToDataSet", new object[] { CreateExceptionMessage(exception) }), exception);
            }
            if ((tableName == null) || (tableName.Length == 0))
            {
                if (source.DefaultConnection != null)
                {
                    return(source.DefaultConnection.Provider);
                }
            }
            else
            {
                DesignTable table = source.DesignTables[tableName];
                if (table != null)
                {
                    return(table.Connection.Provider);
                }
            }
            return(null);
        }
Example #11
0
        internal static string GenerateInternal(DesignDataSource designDS, CodeCompileUnit compileUnit, CodeNamespace mainNamespace, CodeDomProvider codeProvider, GenerateOption generateOption, string dataSetNamespace)
        {
            if (StringUtil.Empty(designDS.Name))
            {
                designDS.Name = "DataSet1";
            }
            try
            {
                TypedDataSourceCodeGenerator generator = new TypedDataSourceCodeGenerator {
                    CodeProvider            = codeProvider,
                    GenerateSingleNamespace = false
                };
                if (mainNamespace == null)
                {
                    mainNamespace = new CodeNamespace();
                }
                if (compileUnit == null)
                {
                    compileUnit = new CodeCompileUnit();
                    compileUnit.Namespaces.Add(mainNamespace);
                }
                generator.GenerateDataSource(designDS, compileUnit, mainNamespace, dataSetNamespace, generateOption);
                foreach (string str in imports)
                {
                    mainNamespace.Imports.Add(new CodeNamespaceImport(str));
                }
            }
            catch (Exception exception)
            {
                throw new Exception(System.Design.SR.GetString("CG_DataSetGeneratorFail_FailToGenerateCode", new object[] { CreateExceptionMessage(exception) }), exception);
            }
            ArrayList list = new ArrayList(fixedReferences);

            list.AddRange(TypedDataSourceCodeGenerator.GetProviderAssemblies(designDS));
            if ((generateOption & GenerateOption.LinqOverTypedDatasets) == GenerateOption.LinqOverTypedDatasets)
            {
                Assembly entityAssembly = EntityAssembly;
                if (entityAssembly != null)
                {
                    list.Add(entityAssembly);
                }
            }
            referencedAssemblies = (Assembly[])list.ToArray(typeof(Assembly));
            foreach (Assembly assembly2 in referencedAssemblies)
            {
                compileUnit.ReferencedAssemblies.Add(assembly2.GetName().Name + ".dll");
            }
            return(designDS.GeneratorDataSetName);
        }
        public void SetMethodSourceContent(string methodSourceContent)
        {
            DesignDataSource source     = new DesignDataSource();
            StringReader     textReader = new StringReader(methodSourceContent);

            source.ReadXmlSchema(textReader, null);
            if ((source.Sources == null) || (source.Sources.Count != 1))
            {
                throw new InternalException("Unexpected number of sources in deserialized DataSource.");
            }
            IEnumerator enumerator = source.Sources.GetEnumerator();

            enumerator.MoveNext();
            this.methodSource = (DbSource)enumerator.Current;
        }
Example #13
0
        public void SetDesignTableContent(string designTableContent)
        {
            DesignDataSource designDataSource = new DesignDataSource();
            StringReader     textReader       = new StringReader(designTableContent);

            designDataSource.ReadXmlSchema(textReader, null);

            if (designDataSource.DesignTables == null || designDataSource.DesignTables.Count != 1)
            {
                throw new InternalException("Unexpected number of sources in deserialized DataSource.");
            }

            IEnumerator enumerator = designDataSource.DesignTables.GetEnumerator();

            enumerator.MoveNext();
            this.designTable = (DesignTable)enumerator.Current;
        }
Example #14
0
        private DesignRelation FindCorrespondingDesignRelation(DesignTable designTable, DataRelation relation)
        {
            DesignDataSource owner = designTable.Owner;

            if (owner == null)
            {
                throw new InternalException("Unable to find DataSource for table.");
            }
            foreach (DesignRelation relation2 in owner.DesignRelations)
            {
                if (((relation2.DataRelation != null) && StringUtil.EqualValue(relation2.DataRelation.ChildTable.TableName, relation.ChildTable.TableName)) && (StringUtil.EqualValue(relation2.DataRelation.ParentTable.TableName, relation.ParentTable.TableName) && StringUtil.EqualValue(relation2.Name, relation.RelationName)))
                {
                    return(relation2);
                }
            }
            return(null);
        }
        internal static ArrayList GetProviderAssemblies(DesignDataSource designDS)
        {
            ArrayList list = new ArrayList();

            foreach (IDesignConnection connection in designDS.DesignConnections)
            {
                IDbConnection connection2 = connection.CreateEmptyDbConnection();
                if (connection2 != null)
                {
                    Assembly item = connection2.GetType().Assembly;
                    if (!list.Contains(item))
                    {
                        list.Add(item);
                    }
                }
            }
            return(list);
        }
Example #16
0
 internal void ProcessMemberNames(DesignDataSource dataSource)
 {
     this.ProcessDataSourceName(dataSource);
     if (dataSource.DesignTables != null)
     {
         foreach (DesignTable table in dataSource.DesignTables)
         {
             this.ProcessTableRelatedNames(table);
         }
     }
     if (dataSource.DesignRelations != null)
     {
         foreach (DesignRelation relation in dataSource.DesignRelations)
         {
             this.ProcessRelationRelatedNames(relation);
         }
     }
 }
 internal void ProcessMemberNames(DesignDataSource dataSource)
 {
     this.ProcessDataSourceName(dataSource);
     if (dataSource.DesignTables != null)
     {
         foreach (DesignTable table in dataSource.DesignTables)
         {
             this.ProcessTableRelatedNames(table);
         }
     }
     if (dataSource.DesignRelations != null)
     {
         foreach (DesignRelation relation in dataSource.DesignRelations)
         {
             this.ProcessRelationRelatedNames(relation);
         }
     }
 }
Example #18
0
 internal void ProcessDataSourceName(DesignDataSource dataSource)
 {
     if (StringUtil.Empty(dataSource.Name))
     {
         throw new DataSourceGeneratorException(System.Design.SR.GetString("CG_EmptyDSName"));
     }
     if (!StringUtil.EqualValue(dataSource.Name, dataSource.UserDataSetName, this.languageCaseInsensitive) || StringUtil.Empty(dataSource.GeneratorDataSetName))
     {
         dataSource.GeneratorDataSetName = NameHandler.FixIdName(dataSource.Name);
     }
     else
     {
         dataSource.GeneratorDataSetName = this.validator.GenerateIdName(dataSource.GeneratorDataSetName);
     }
     dataSource.UserDataSetName = dataSource.Name;
     if (!StringUtil.EqualValue(NameHandler.FixIdName(dataSource.Name), dataSource.GeneratorDataSetName))
     {
         dataSource.NamingPropertyNames.Add(DesignDataSource.EXTPROPNAME_USER_DATASETNAME);
         dataSource.NamingPropertyNames.Add(DesignDataSource.EXTPROPNAME_GENERATOR_DATASETNAME);
     }
 }
 internal void ProcessDataSourceName(DesignDataSource dataSource)
 {
     if (StringUtil.Empty(dataSource.Name))
     {
         throw new DataSourceGeneratorException(System.Design.SR.GetString("CG_EmptyDSName"));
     }
     if (!StringUtil.EqualValue(dataSource.Name, dataSource.UserDataSetName, this.languageCaseInsensitive) || StringUtil.Empty(dataSource.GeneratorDataSetName))
     {
         dataSource.GeneratorDataSetName = NameHandler.FixIdName(dataSource.Name);
     }
     else
     {
         dataSource.GeneratorDataSetName = this.validator.GenerateIdName(dataSource.GeneratorDataSetName);
     }
     dataSource.UserDataSetName = dataSource.Name;
     if (!StringUtil.EqualValue(NameHandler.FixIdName(dataSource.Name), dataSource.GeneratorDataSetName))
     {
         dataSource.NamingPropertyNames.Add(DesignDataSource.EXTPROPNAME_USER_DATASETNAME);
         dataSource.NamingPropertyNames.Add(DesignDataSource.EXTPROPNAME_GENERATOR_DATASETNAME);
     }
 }
 internal void GenerateMemberNames(DesignDataSource dataSource, CodeDomProvider codeProvider, bool languageCaseInsensitive, ArrayList problemList)
 {
     this.languageCaseInsensitive = languageCaseInsensitive;
     this.validator = new MemberNameValidator(new string[] { tablesPropertyName, relationsPropertyName }, codeProvider, this.languageCaseInsensitive);
     this.ProcessMemberNames(dataSource);
 }
 internal DatasetMethodGenerator(TypedDataSourceCodeGenerator codeGenerator, DesignDataSource dataSource)
 {
     this.codeGenerator = codeGenerator;
     this.dataSource = dataSource;
     this.dataSet = dataSource.DataSet;
 }
 internal void GenerateDataSource(DesignDataSource dtDataSource, CodeCompileUnit codeCompileUnit, CodeNamespace mainNamespace, string dataSetNamespace, System.Data.Design.TypedDataSetGenerator.GenerateOption generateOption)
 {
     this.designDataSource = dtDataSource;
     this.generateOption = generateOption;
     this.dataSetNamespace = dataSetNamespace;
     bool generateHierarchicalUpdate = ((generateOption & System.Data.Design.TypedDataSetGenerator.GenerateOption.HierarchicalUpdate) == System.Data.Design.TypedDataSetGenerator.GenerateOption.HierarchicalUpdate) && dtDataSource.EnableTableAdapterManager;
     this.AddUserData(codeCompileUnit);
     CodeTypeDeclaration declaration = this.CreateDataSourceDeclaration(dtDataSource);
     mainNamespace.Types.Add(declaration);
     bool flag2 = CodeGenHelper.SupportsMultipleNamespaces(this.codeProvider);
     CodeNamespace namespace2 = null;
     if (!this.GenerateSingleNamespace && flag2)
     {
         string name = this.CreateAdaptersNamespace(dtDataSource.GeneratorDataSetName);
         if (!StringUtil.Empty(mainNamespace.Name))
         {
             name = mainNamespace.Name + "." + name;
         }
         namespace2 = new CodeNamespace(name);
     }
     DataComponentGenerator generator = new DataComponentGenerator(this);
     bool flag3 = false;
     foreach (DesignTable table in dtDataSource.DesignTables)
     {
         if (table.TableType == TableType.RadTable)
         {
             flag3 = true;
             table.PropertyCache = new DesignTable.CodeGenPropertyCache(table);
             CodeTypeDeclaration declaration2 = generator.GenerateDataComponent(table, false, generateHierarchicalUpdate);
             if (this.GenerateSingleNamespace)
             {
                 mainNamespace.Types.Add(declaration2);
             }
             else if (flag2)
             {
                 namespace2.Types.Add(declaration2);
             }
             else
             {
                 declaration2.Name = declaration.Name + declaration2.Name;
                 mainNamespace.Types.Add(declaration2);
             }
         }
     }
     generateHierarchicalUpdate = generateHierarchicalUpdate && flag3;
     if ((dtDataSource.Sources != null) && (dtDataSource.Sources.Count > 0))
     {
         DesignTable designTable = new DesignTable {
             TableType = TableType.RadTable,
             MainSource = null,
             GeneratorDataComponentClassName = dtDataSource.GeneratorFunctionsComponentClassName
         };
         foreach (Source source in dtDataSource.Sources)
         {
             designTable.Sources.Add(source);
         }
         CodeTypeDeclaration declaration3 = generator.GenerateDataComponent(designTable, true, generateHierarchicalUpdate);
         if (this.GenerateSingleNamespace)
         {
             mainNamespace.Types.Add(declaration3);
         }
         else if (flag2)
         {
             namespace2.Types.Add(declaration3);
         }
         else
         {
             declaration3.Name = declaration.Name + declaration3.Name;
             mainNamespace.Types.Add(declaration3);
         }
     }
     if ((namespace2 != null) && (namespace2.Types.Count > 0))
     {
         codeCompileUnit.Namespaces.Add(namespace2);
     }
     if (generateHierarchicalUpdate)
     {
         CodeTypeDeclaration declaration4 = new TableAdapterManagerGenerator(this).GenerateAdapterManager(this.designDataSource, declaration);
         if (this.GenerateSingleNamespace)
         {
             mainNamespace.Types.Add(declaration4);
         }
         else if (flag2)
         {
             namespace2.Types.Add(declaration4);
         }
         else
         {
             declaration4.Name = declaration.Name + declaration4.Name;
             mainNamespace.Types.Add(declaration4);
         }
     }
 }
        internal void GenerateDataSource(DesignDataSource dtDataSource, CodeCompileUnit codeCompileUnit, CodeNamespace mainNamespace, string dataSetNamespace, System.Data.Design.TypedDataSetGenerator.GenerateOption generateOption)
        {
            this.designDataSource = dtDataSource;
            this.generateOption   = generateOption;
            this.dataSetNamespace = dataSetNamespace;
            bool generateHierarchicalUpdate = ((generateOption & System.Data.Design.TypedDataSetGenerator.GenerateOption.HierarchicalUpdate) == System.Data.Design.TypedDataSetGenerator.GenerateOption.HierarchicalUpdate) && dtDataSource.EnableTableAdapterManager;

            this.AddUserData(codeCompileUnit);
            CodeTypeDeclaration declaration = this.CreateDataSourceDeclaration(dtDataSource);

            mainNamespace.Types.Add(declaration);
            bool          flag2      = CodeGenHelper.SupportsMultipleNamespaces(this.codeProvider);
            CodeNamespace namespace2 = null;

            if (!this.GenerateSingleNamespace && flag2)
            {
                string name = this.CreateAdaptersNamespace(dtDataSource.GeneratorDataSetName);
                if (!StringUtil.Empty(mainNamespace.Name))
                {
                    name = mainNamespace.Name + "." + name;
                }
                namespace2 = new CodeNamespace(name);
            }
            DataComponentGenerator generator = new DataComponentGenerator(this);
            bool flag3 = false;

            foreach (DesignTable table in dtDataSource.DesignTables)
            {
                if (table.TableType == TableType.RadTable)
                {
                    flag3 = true;
                    table.PropertyCache = new DesignTable.CodeGenPropertyCache(table);
                    CodeTypeDeclaration declaration2 = generator.GenerateDataComponent(table, false, generateHierarchicalUpdate);
                    if (this.GenerateSingleNamespace)
                    {
                        mainNamespace.Types.Add(declaration2);
                    }
                    else if (flag2)
                    {
                        namespace2.Types.Add(declaration2);
                    }
                    else
                    {
                        declaration2.Name = declaration.Name + declaration2.Name;
                        mainNamespace.Types.Add(declaration2);
                    }
                }
            }
            generateHierarchicalUpdate = generateHierarchicalUpdate && flag3;
            if ((dtDataSource.Sources != null) && (dtDataSource.Sources.Count > 0))
            {
                DesignTable designTable = new DesignTable {
                    TableType  = TableType.RadTable,
                    MainSource = null,
                    GeneratorDataComponentClassName = dtDataSource.GeneratorFunctionsComponentClassName
                };
                foreach (Source source in dtDataSource.Sources)
                {
                    designTable.Sources.Add(source);
                }
                CodeTypeDeclaration declaration3 = generator.GenerateDataComponent(designTable, true, generateHierarchicalUpdate);
                if (this.GenerateSingleNamespace)
                {
                    mainNamespace.Types.Add(declaration3);
                }
                else if (flag2)
                {
                    namespace2.Types.Add(declaration3);
                }
                else
                {
                    declaration3.Name = declaration.Name + declaration3.Name;
                    mainNamespace.Types.Add(declaration3);
                }
            }
            if ((namespace2 != null) && (namespace2.Types.Count > 0))
            {
                codeCompileUnit.Namespaces.Add(namespace2);
            }
            if (generateHierarchicalUpdate)
            {
                CodeTypeDeclaration declaration4 = new TableAdapterManagerGenerator(this).GenerateAdapterManager(this.designDataSource, declaration);
                if (this.GenerateSingleNamespace)
                {
                    mainNamespace.Types.Add(declaration4);
                }
                else if (flag2)
                {
                    namespace2.Types.Add(declaration4);
                }
                else
                {
                    declaration4.Name = declaration.Name + declaration4.Name;
                    mainNamespace.Types.Add(declaration4);
                }
            }
        }
Example #24
0
 public DesignTableCollection(DesignDataSource dataSource) : base(dataSource)
 {
     this.dataSource = dataSource;
 }
 internal DataSourceXmlTextReader(DesignDataSource dataSource, Stream stream, string baseURI) : base(baseURI, stream)
 {
     this.dataSource = dataSource;
     this.readingDataSource = false;
 }
 internal DataSourceXmlTextReader(DesignDataSource dataSource, TextReader textReader, string baseURI) : base(baseURI, textReader)
 {
     this.dataSource = dataSource;
     this.readingDataSource = false;
 }
 public static string GetProviderName(string inputFileContent, string tableName)
 {
     if ((inputFileContent == null) || (inputFileContent.Length == 0))
     {
         throw new ArgumentException(System.Design.SR.GetString("CG_DataSetGeneratorFail_InputFileEmpty"));
     }
     StringReader textReader = new StringReader(inputFileContent);
     DesignDataSource source = new DesignDataSource();
     try
     {
         source.ReadXmlSchema(textReader, null);
     }
     catch (Exception exception)
     {
         throw new Exception(System.Design.SR.GetString("CG_DataSetGeneratorFail_UnableToConvertToDataSet", new object[] { CreateExceptionMessage(exception) }), exception);
     }
     if ((tableName == null) || (tableName.Length == 0))
     {
         if (source.DefaultConnection != null)
         {
             return source.DefaultConnection.Provider;
         }
     }
     else
     {
         DesignTable table = source.DesignTables[tableName];
         if (table != null)
         {
             return table.Connection.Provider;
         }
     }
     return null;
 }
 internal static string GenerateInternal(DesignDataSource designDS, CodeCompileUnit compileUnit, CodeNamespace mainNamespace, CodeDomProvider codeProvider, GenerateOption generateOption, string dataSetNamespace)
 {
     if (StringUtil.Empty(designDS.Name))
     {
         designDS.Name = "DataSet1";
     }
     try
     {
         TypedDataSourceCodeGenerator generator = new TypedDataSourceCodeGenerator {
             CodeProvider = codeProvider,
             GenerateSingleNamespace = false
         };
         if (mainNamespace == null)
         {
             mainNamespace = new CodeNamespace();
         }
         if (compileUnit == null)
         {
             compileUnit = new CodeCompileUnit();
             compileUnit.Namespaces.Add(mainNamespace);
         }
         generator.GenerateDataSource(designDS, compileUnit, mainNamespace, dataSetNamespace, generateOption);
         foreach (string str in imports)
         {
             mainNamespace.Imports.Add(new CodeNamespaceImport(str));
         }
     }
     catch (Exception exception)
     {
         throw new Exception(System.Design.SR.GetString("CG_DataSetGeneratorFail_FailToGenerateCode", new object[] { CreateExceptionMessage(exception) }), exception);
     }
     ArrayList list = new ArrayList(fixedReferences);
     list.AddRange(TypedDataSourceCodeGenerator.GetProviderAssemblies(designDS));
     if ((generateOption & GenerateOption.LinqOverTypedDatasets) == GenerateOption.LinqOverTypedDatasets)
     {
         Assembly entityAssembly = EntityAssembly;
         if (entityAssembly != null)
         {
             list.Add(entityAssembly);
         }
     }
     referencedAssemblies = (Assembly[]) list.ToArray(typeof(Assembly));
     foreach (Assembly assembly2 in referencedAssemblies)
     {
         compileUnit.ReferencedAssemblies.Add(assembly2.GetName().Name + ".dll");
     }
     return designDS.GeneratorDataSetName;
 }
Example #29
0
 internal DataSourceXmlTextReader(DesignDataSource dataSource, Stream stream, string baseURI) : base(baseURI, stream)
 {
     this.dataSource        = dataSource;
     this.readingDataSource = false;
 }
 internal DatasetMethodGenerator(TypedDataSourceCodeGenerator codeGenerator, DesignDataSource dataSource)
 {
     this.codeGenerator = codeGenerator;
     this.dataSource    = dataSource;
     this.dataSet       = dataSource.DataSet;
 }
 public DesignRelationCollection(DesignDataSource dataSource) : base(dataSource)
 {
     this.dataSource = dataSource;
 }
 internal static ArrayList GetProviderAssemblies(DesignDataSource designDS)
 {
     ArrayList list = new ArrayList();
     foreach (IDesignConnection connection in designDS.DesignConnections)
     {
         IDbConnection connection2 = connection.CreateEmptyDbConnection();
         if (connection2 != null)
         {
             Assembly item = connection2.GetType().Assembly;
             if (!list.Contains(item))
             {
                 list.Add(item);
             }
         }
     }
     return list;
 }
 public DesignTableCollection(DesignDataSource dataSource)
     : base(dataSource)
 {
     this.dataSource = dataSource;
 }
 public DesignRelationCollection(DesignDataSource dataSource) : base(dataSource)
 {
     this.dataSource = dataSource;
 }
 public void SetMethodSourceContent(string methodSourceContent)
 {
     DesignDataSource source = new DesignDataSource();
     StringReader textReader = new StringReader(methodSourceContent);
     source.ReadXmlSchema(textReader, null);
     if ((source.Sources == null) || (source.Sources.Count != 1))
     {
         throw new InternalException("Unexpected number of sources in deserialized DataSource.");
     }
     IEnumerator enumerator = source.Sources.GetEnumerator();
     enumerator.MoveNext();
     this.methodSource = (DbSource) enumerator.Current;
 }
 public static string Generate(string inputFileContent, CodeCompileUnit compileUnit, CodeNamespace mainNamespace, CodeDomProvider codeProvider, GenerateOption option, string dataSetNamespace, string basePath)
 {
     if ((inputFileContent == null) || (inputFileContent.Length == 0))
     {
         throw new ArgumentException(System.Design.SR.GetString("CG_DataSetGeneratorFail_InputFileEmpty"));
     }
     if (mainNamespace == null)
     {
         throw new ArgumentException(System.Design.SR.GetString("CG_DataSetGeneratorFail_CodeNamespaceNull"));
     }
     if (codeProvider == null)
     {
         throw new ArgumentNullException("codeProvider");
     }
     StringReader textReader = new StringReader(inputFileContent);
     DesignDataSource designDS = new DesignDataSource();
     try
     {
         designDS.ReadXmlSchema(textReader, basePath);
     }
     catch (Exception exception)
     {
         throw new Exception(System.Design.SR.GetString("CG_DataSetGeneratorFail_UnableToConvertToDataSet", new object[] { CreateExceptionMessage(exception) }), exception);
     }
     return GenerateInternal(designDS, compileUnit, mainNamespace, codeProvider, option, dataSetNamespace);
 }
Example #37
0
 internal DataSourceXmlTextReader(DesignDataSource dataSource, TextReader textReader, string baseURI) : base(baseURI, textReader)
 {
     this.dataSource        = dataSource;
     this.readingDataSource = false;
 }
Example #38
0
 internal void GenerateMemberNames(DesignDataSource dataSource, CodeDomProvider codeProvider, bool languageCaseInsensitive, ArrayList problemList)
 {
     this.languageCaseInsensitive = languageCaseInsensitive;
     this.validator = new MemberNameValidator(new string[] { tablesPropertyName, relationsPropertyName }, codeProvider, this.languageCaseInsensitive);
     this.ProcessMemberNames(dataSource);
 }