private void AddFunctionToDataComponent(CodeTypeDeclaration classDeclaration, DbSource dbSource, int commandIndex, bool isFunctionsDataComponent)
 {
     FunctionGenerator generator;
     if (!this.DeclarationsOnly || (dbSource.Modifier == MemberAttributes.Public))
     {
         generator = new FunctionGenerator(this.codeGenerator) {
             DeclarationOnly = this.declarationsOnly,
             MethodSource = dbSource,
             CommandIndex = commandIndex,
             DesignTable = this.designTable,
             IsFunctionsDataComponent = isFunctionsDataComponent
         };
         if (generator.MethodSource.Connection != null)
         {
             generator.ProviderFactory = ProviderManager.GetFactory(generator.MethodSource.Connection.Provider);
             goto Label_00A5;
         }
         if (this.designTable.Connection != null)
         {
             generator.ProviderFactory = ProviderManager.GetFactory(this.designTable.Connection.Provider);
             goto Label_00A5;
         }
     }
     return;
 Label_00A5:
     generator.MethodName = dbSource.GeneratorSourceName;
     generator.ParameterOption = this.languageSupportsNullables ? ParameterGenerationOption.ClrTypes : ParameterGenerationOption.Objects;
     CodeMemberMethod method = generator.Generate();
     if (method != null)
     {
         classDeclaration.Members.Add(method);
     }
 }
 private bool DbSourceNameExist(DbSource dbSource, bool isFillName, string nameToBeChecked)
 {
     if (isFillName && StringUtil.EqualValue(nameToBeChecked, dbSource.GetMethodName, true))
     {
         return true;
     }
     if (!isFillName && StringUtil.EqualValue(nameToBeChecked, dbSource.FillMethodName, true))
     {
         return true;
     }
     foreach (DbSource source in this)
     {
         if ((source != dbSource) && source.NameExist(nameToBeChecked))
         {
             return true;
         }
     }
     DbSource mainSource = this.MainSource;
     return (((dbSource != mainSource) && (mainSource != null)) && mainSource.NameExist(nameToBeChecked));
 }
 public override object Clone()
 {
     DbSource parent = new DbSource();
     if (this.connection != null)
     {
         parent.connection = (DesignConnection) this.connection.Clone();
     }
     if (this.selectCommand != null)
     {
         parent.selectCommand = (DbSourceCommand) this.selectCommand.Clone();
         parent.selectCommand.SetParent(parent);
     }
     if (this.insertCommand != null)
     {
         parent.insertCommand = (DbSourceCommand) this.insertCommand.Clone();
         parent.insertCommand.SetParent(parent);
     }
     if (this.updateCommand != null)
     {
         parent.updateCommand = (DbSourceCommand) this.updateCommand.Clone();
         parent.updateCommand.SetParent(parent);
     }
     if (this.deleteCommand != null)
     {
         parent.deleteCommand = (DbSourceCommand) this.deleteCommand.Clone();
         parent.deleteCommand.SetParent(parent);
     }
     parent.Name = this.Name;
     parent.Modifier = base.Modifier;
     parent.scalarCallRetval = this.scalarCallRetval;
     parent.generateMethods = this.generateMethods;
     parent.queryType = this.queryType;
     parent.getMethodModifier = this.getMethodModifier;
     parent.getMethodName = this.getMethodName;
     parent.generatePagingMethods = this.generatePagingMethods;
     return parent;
 }
 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;
 }
 internal void ProcessSourceName(DbSource source)
 {
     bool flag = !StringUtil.EqualValue(source.Name, source.UserSourceName, this.languageCaseInsensitive);
     bool flag2 = !StringUtil.EqualValue(source.GetMethodName, source.UserGetMethodName, this.languageCaseInsensitive);
     if ((source.GenerateMethods == GenerateMethodTypes.Fill) || (source.GenerateMethods == GenerateMethodTypes.Both))
     {
         if (flag || StringUtil.Empty(source.GeneratorSourceName))
         {
             source.GeneratorSourceName = this.validator.GenerateIdName(source.Name);
         }
         else
         {
             source.GeneratorSourceName = this.validator.GenerateIdName(source.GeneratorSourceName);
         }
     }
     if ((source.QueryType == QueryType.Rowset) && ((source.GenerateMethods == GenerateMethodTypes.Get) || (source.GenerateMethods == GenerateMethodTypes.Both)))
     {
         if (flag2 || StringUtil.Empty(source.GeneratorGetMethodName))
         {
             source.GeneratorGetMethodName = this.validator.GenerateIdName(source.GetMethodName);
         }
         else
         {
             source.GeneratorGetMethodName = this.validator.GenerateIdName(source.GeneratorGetMethodName);
         }
     }
     if ((source.QueryType == QueryType.Rowset) && source.GeneratePagingMethods)
     {
         if ((source.GenerateMethods == GenerateMethodTypes.Fill) || (source.GenerateMethods == GenerateMethodTypes.Both))
         {
             if (flag || StringUtil.Empty(source.GeneratorSourceNameForPaging))
             {
                 source.GeneratorSourceNameForPaging = this.validator.GenerateIdName(source.Name + pagingMethodSuffix);
             }
             else
             {
                 source.GeneratorSourceNameForPaging = this.validator.GenerateIdName(source.GeneratorSourceNameForPaging);
             }
         }
         if ((source.GenerateMethods == GenerateMethodTypes.Get) || (source.GenerateMethods == GenerateMethodTypes.Both))
         {
             if (flag2 || StringUtil.Empty(source.GeneratorGetMethodNameForPaging))
             {
                 source.GeneratorGetMethodNameForPaging = this.validator.GenerateIdName(source.GetMethodName + pagingMethodSuffix);
             }
             else
             {
                 source.GeneratorGetMethodNameForPaging = this.validator.GenerateIdName(source.GeneratorGetMethodNameForPaging);
             }
         }
     }
 }
Beispiel #6
0
        private void AddFunctionToDataComponent(CodeTypeDeclaration classDeclaration, DbSource dbSource, int commandIndex, bool isFunctionsDataComponent)
        {
            FunctionGenerator generator;

            if (!this.DeclarationsOnly || (dbSource.Modifier == MemberAttributes.Public))
            {
                generator = new FunctionGenerator(this.codeGenerator)
                {
                    DeclarationOnly          = this.declarationsOnly,
                    MethodSource             = dbSource,
                    CommandIndex             = commandIndex,
                    DesignTable              = this.designTable,
                    IsFunctionsDataComponent = isFunctionsDataComponent
                };
                if (generator.MethodSource.Connection != null)
                {
                    generator.ProviderFactory = ProviderManager.GetFactory(generator.MethodSource.Connection.Provider);
                    goto Label_00A5;
                }
                if (this.designTable.Connection != null)
                {
                    generator.ProviderFactory = ProviderManager.GetFactory(this.designTable.Connection.Provider);
                    goto Label_00A5;
                }
            }
            return;

Label_00A5:
            generator.MethodName      = dbSource.GeneratorSourceName;
            generator.ParameterOption = this.languageSupportsNullables ? ParameterGenerationOption.ClrTypes : ParameterGenerationOption.Objects;
            CodeMemberMethod method = generator.Generate();

            if (method != null)
            {
                classDeclaration.Members.Add(method);
            }
        }
 internal void SetParent(DbSource parent)
 {
     this._parent = parent;
 }
 public DbSourceCommand(DbSource parent, System.Data.Design.CommandOperation operation) : this()
 {
     this.SetParent(parent);
     this.CommandOperation = operation;
 }
 public DbSourceCommand(DbSource parent, System.Data.Design.CommandOperation operation)
     : this()
 {
     this.SetParent(parent);
     this.CommandOperation = operation;
 }
 internal void SetParent(DbSource parent)
 {
     this._parent = parent;
 }
 internal void ValidateUniqueDbSourceName(DbSource dbSource, string proposedName, bool isFillName)
 {
     if (this.DbSourceNameExist(dbSource, isFillName, proposedName))
     {
         throw new NameValidationException(System.Design.SR.GetString("CM_NameExist", new object[] { proposedName }));
     }
     this.NameService.ValidateName(proposedName);
 }
        private void AddInitCommandCollection(CodeTypeDeclaration dataComponentClass, bool isFunctionsDataComponent)
        {
            int count = this.designTable.Sources.Count;

            if (!isFunctionsDataComponent)
            {
                count++;
            }
            CodeMemberMethod method = CodeGenHelper.MethodDecl(CodeGenHelper.GlobalType(typeof(void)), DataComponentNameHandler.InitCmdCollection, MemberAttributes.Private | MemberAttributes.Final);
            Type             type   = null;

            if (isFunctionsDataComponent)
            {
                type = typeof(IDbCommand);
            }
            else
            {
                type = this.providerFactory.CreateCommand().GetType();
            }
            method.Statements.Add(CodeGenHelper.Assign(CodeGenHelper.Field(CodeGenHelper.This(), DataComponentNameHandler.SelectCmdCollectionVariableName), CodeGenHelper.NewArray(CodeGenHelper.GlobalType(type), count)));
            if ((!isFunctionsDataComponent && (this.designTable.MainSource != null)) && (this.designTable.MainSource is DbSource))
            {
                DbSourceCommand activeCommand = ((DbSource)this.designTable.MainSource).GetActiveCommand();
                if (activeCommand != null)
                {
                    CodeExpression commandExpression = CodeGenHelper.ArrayIndexer(CodeGenHelper.Field(CodeGenHelper.This(), DataComponentNameHandler.SelectCmdCollectionVariableName), CodeGenHelper.Primitive(0));
                    this.AddCommandInitStatements(method.Statements, commandExpression, activeCommand, this.providerFactory, isFunctionsDataComponent);
                }
            }
            if (this.designTable.Sources != null)
            {
                int primitive = 0;
                if (isFunctionsDataComponent)
                {
                    primitive--;
                }
                foreach (Source source2 in this.designTable.Sources)
                {
                    DbSource source3 = source2 as DbSource;
                    primitive++;
                    if (source3 != null)
                    {
                        DbProviderFactory providerFactory = this.providerFactory;
                        if (source3.Connection != null)
                        {
                            providerFactory = ProviderManager.GetFactory(source3.Connection.Provider);
                        }
                        if (providerFactory != null)
                        {
                            DbSourceCommand command = source3.GetActiveCommand();
                            if (command != null)
                            {
                                CodeExpression expression2 = CodeGenHelper.ArrayIndexer(CodeGenHelper.Field(CodeGenHelper.This(), DataComponentNameHandler.SelectCmdCollectionVariableName), CodeGenHelper.Primitive(primitive));
                                this.AddCommandInitStatements(method.Statements, expression2, command, providerFactory, isFunctionsDataComponent);
                            }
                        }
                    }
                }
            }
            dataComponentClass.Members.Add(method);
        }