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 CreateTypedRowEventArg(DesignTable designTable)
        {
            if (designTable == null)
            {
                throw new InternalException("DesignTable should not be null.");
            }
            DataTable           dataTable               = designTable.DataTable;
            string              generatorRowClassName   = designTable.GeneratorRowClassName;
            string              generatorTableClassName = designTable.GeneratorTableClassName;
            string              type        = designTable.GeneratorRowClassName;
            CodeTypeDeclaration declaration = CodeGenHelper.Class(designTable.GeneratorRowEvArgName, false, TypeAttributes.Public);

            declaration.BaseTypes.Add(CodeGenHelper.GlobalType(typeof(EventArgs)));
            declaration.Comments.Add(CodeGenHelper.Comment("Row event argument class", true));
            declaration.Members.Add(CodeGenHelper.FieldDecl(CodeGenHelper.Type(type), "eventRow"));
            declaration.Members.Add(CodeGenHelper.FieldDecl(CodeGenHelper.GlobalType(typeof(DataRowAction)), "eventAction"));
            declaration.Members.Add(this.EventArgConstructor(type));
            CodeMemberProperty property = CodeGenHelper.PropertyDecl(CodeGenHelper.Type(type), "Row", MemberAttributes.Public | MemberAttributes.Final);

            property.GetStatements.Add(CodeGenHelper.Return(CodeGenHelper.Field(CodeGenHelper.This(), "eventRow")));
            declaration.Members.Add(property);
            property = CodeGenHelper.PropertyDecl(CodeGenHelper.GlobalType(typeof(DataRowAction)), "Action", MemberAttributes.Public | MemberAttributes.Final);
            property.GetStatements.Add(CodeGenHelper.Return(CodeGenHelper.Field(CodeGenHelper.This(), "eventAction")));
            declaration.Members.Add(property);
            return(declaration);
        }
        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 CodeTypeDeclaration GenerateDataComponent(DesignTable designTable, bool isFunctionsComponent, bool generateHierarchicalUpdate)
        {
            CodeTypeDeclaration dataComponentClass = CodeGenHelper.Class(designTable.GeneratorDataComponentClassName, true, designTable.DataAccessorModifier);

            dataComponentClass.BaseTypes.Add(CodeGenHelper.GlobalType(designTable.BaseClass));
            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.DataObjectAttribute", CodeGenHelper.Primitive(true)));
            dataComponentClass.CustomAttributes.Add(CodeGenHelper.AttributeDecl("System.ComponentModel.DesignerAttribute", CodeGenHelper.Str(adapterDesigner + ", Microsoft.VSDesigner, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")));
            dataComponentClass.CustomAttributes.Add(CodeGenHelper.AttributeDecl(typeof(HelpKeywordAttribute).FullName, CodeGenHelper.Str("vs.data.TableAdapter")));
            if (designTable.WebServiceAttribute)
            {
                CodeAttributeDeclaration declaration2 = new CodeAttributeDeclaration("System.Web.Services.WebService");
                declaration2.Arguments.Add(new CodeAttributeArgument("Namespace", CodeGenHelper.Str(designTable.WebServiceNamespace)));
                declaration2.Arguments.Add(new CodeAttributeArgument("Description", CodeGenHelper.Str(designTable.WebServiceDescription)));
                dataComponentClass.CustomAttributes.Add(declaration2);
            }
            dataComponentClass.Comments.Add(CodeGenHelper.Comment("Represents the connection and commands used to retrieve and save data.", true));
            new DataComponentMethodGenerator(this.dataSourceGenerator, designTable, generateHierarchicalUpdate).AddMethods(dataComponentClass, isFunctionsComponent);
            CodeGenerator.ValidateIdentifiers(dataComponentClass);
            QueryHandler handler = new QueryHandler(this.dataSourceGenerator, designTable);

            if (isFunctionsComponent)
            {
                handler.AddFunctionsToDataComponent(dataComponentClass, true);
                return(dataComponentClass);
            }
            handler.AddQueriesToDataComponent(dataComponentClass);
            return(dataComponentClass);
        }
Ejemplo n.º 5
0
        private CodeTypeDeclaration GenerateTable(DesignTable designTable, CodeTypeDeclaration dataSourceClass)
        {
            string              generatorTableClassName = designTable.GeneratorTableClassName;
            TypedColumnHandler  columnHandler           = this.codeGenerator.TableHandler.GetColumnHandler(designTable.Name);
            CodeTypeDeclaration dataTableClass          = CodeGenHelper.Class(generatorTableClassName, true, TypeAttributes.Public);

            if ((this.codeGenerator.GenerateOptions & System.Data.Design.TypedDataSetGenerator.GenerateOption.LinqOverTypedDatasets) == System.Data.Design.TypedDataSetGenerator.GenerateOption.LinqOverTypedDatasets)
            {
                dataTableClass.BaseTypes.Add(CodeGenHelper.GlobalGenericType(LINQOverTDSTableBaseClass, CodeGenHelper.Type(designTable.GeneratorRowClassName)));
            }
            else
            {
                dataTableClass.BaseTypes.Add(CodeGenHelper.GlobalType(typeof(DataTable)));
                dataTableClass.BaseTypes.Add(CodeGenHelper.GlobalType(typeof(IEnumerable)));
            }
            dataTableClass.CustomAttributes.Add(CodeGenHelper.AttributeDecl("System.Serializable"));
            dataTableClass.CustomAttributes.Add(CodeGenHelper.AttributeDecl(typeof(XmlSchemaProviderAttribute).FullName, CodeGenHelper.Primitive("GetTypedTableSchema")));
            dataTableClass.Comments.Add(CodeGenHelper.Comment("Represents the strongly named DataTable class.", true));
            columnHandler.AddPrivateVariables(dataTableClass);
            columnHandler.AddTableColumnProperties(dataTableClass);
            dataTableClass.Members.Add(this.CountProperty());
            if (this.codeGenerator.CodeProvider.Supports(GeneratorSupport.DeclareIndexerProperties))
            {
                dataTableClass.Members.Add(this.IndexProperty(designTable));
            }
            if (this.codeGenerator.CodeProvider.Supports(GeneratorSupport.DeclareEvents) && this.codeGenerator.CodeProvider.Supports(GeneratorSupport.DeclareDelegates))
            {
                this.codeGenerator.RowHandler.AddTypedRowEvents(dataTableClass, designTable.Name);
            }
            new TableMethodGenerator(this.codeGenerator, designTable).AddMethods(dataTableClass);
            return(dataTableClass);
        }
        private CodeTypeDeclaration GenerateRow(DesignTable table)
        {
            if (table == null)
            {
                throw new InternalException("DesignTable should not be null.");
            }
            string              generatorRowClassName   = table.GeneratorRowClassName;
            string              generatorTableClassName = table.GeneratorTableClassName;
            string              generatorTableVarName   = table.GeneratorTableVarName;
            TypedColumnHandler  columnHandler           = this.codeGenerator.TableHandler.GetColumnHandler(table.Name);
            CodeTypeDeclaration rowClass = CodeGenHelper.Class(generatorRowClassName, true, TypeAttributes.Public);

            rowClass.BaseTypes.Add(CodeGenHelper.GlobalType(typeof(DataRow)));
            rowClass.Comments.Add(CodeGenHelper.Comment("Represents strongly named DataRow class.", true));
            rowClass.Members.Add(CodeGenHelper.FieldDecl(CodeGenHelper.Type(generatorTableClassName), generatorTableVarName));
            rowClass.Members.Add(this.RowConstructor(generatorTableClassName, generatorTableVarName));
            columnHandler.AddRowColumnProperties(rowClass);
            columnHandler.AddRowGetRelatedRowsMethods(rowClass);
            return(rowClass);
        }