protected override void ProcessRecord()
        {
            LogInitializer.Initialize();

            var ctx = new Bb.Oracle.Reader.ArgumentContext()
            {
                Login           = Username,
                Pwd             = Password,
                Source          = Source,
                Filename        = this.OutputFilename,
                ExcludeCode     = ExcludeCode,
                Name            = string.IsNullOrEmpty(Name) ? Source : Name,
                ExcludedSchemas = ExcludedSchemas,
                OwnerFilter     = this.OwnerFilter
            };

            FileInfo f = new FileInfo(this.OutputFilename);

            if (!f.Directory.Exists)
            {
                f.Directory.Create();
            }

            OracleDatabase db = Database.GenerateFile(ctx);

            base.WriteObject(db);

            base.ProcessRecord();
        }
Beispiel #2
0
        /// <summary>
        /// Filtre
        /// Utilisation
        /// Le filtrage réagit lorsqu'on affecte la valeur
        /// à une ou plusieurs propriétés quelconques
        /// (OwnerName, PackageName, ProcedureName, TableName)
        /// ci-dessous. Sans aucune affectation, ou avec "" chaine vide, la génération se fait sur
        /// la totalité de la base de données selon le droit d'accés autorisé
        /// par le login.
        /// </summary>
        static void Filtre(ArgumentContext ctx, string connectionString)
        {
            if (!string.IsNullOrEmpty(ctx.ExcludeFile))
            {
                ExcludeSection.Configuration = ExcludeSection.LoadFile(ctx.ExcludeFile);
            }

            if (ctx.OwnerFilter == null || ctx.OwnerFilter == "*")
            {
                ctx.OwnerFilter = ContextLoader.GetOwners(connectionString, ctx);
            }

            SetFilter(Database.OwnerNames, ctx.OwnerFilter);
            SetFilter(Database.ProcedureNames, ctx.Procedures);
            SetFilter(Database.TableNames, ctx.Tables);
        }
Beispiel #3
0
        public static string GetOwners(string connectionString, ArgumentContext ctx)
        {
            if (!string.IsNullOrEmpty(ctx.ExcludedSchemas))
            {
                foreach (var item in ctx.ExcludedSchemas.Split(';').Where(c => !string.IsNullOrEmpty(c)))
                {
                    ContextLoader.excluded.Add(item.ToUpper());
                }
            }

            StringBuilder sb = new StringBuilder();

            LoadSchemas(sb, connectionString, Sql1.Replace("{userFilter}", System.Configuration.ConfigurationManager.AppSettings["userFilter"]));

            string result = sb.ToString();

            result = result.Trim(';');
            return(result);
        }
Beispiel #4
0
        /// <summary>
        /// Generates the file.
        /// </summary>
        /// <param name="connectionString">The connection string.</param>
        /// <param name="outputfileFullPath">The outputfile full path.</param>
        /// <param name="use">The use.</param>
        /// <returns></returns>
        public static OracleDatabase GenerateFile(ArgumentContext ctx, Func <string, bool> use = null)
        {
            System.Data.Common.DbConnectionStringBuilder builder = new System.Data.Common.DbConnectionStringBuilder();
            builder.ConnectionString = string.Format(@"Data source={0};USER ID={1};Password={2};", ctx.Source, ctx.Login, ctx.Pwd);

            var manager = new OracleManager(builder.ConnectionString);

            if (System.Diagnostics.Debugger.IsAttached)
            {
                Trace.WriteLine("{0} Success", builder.ConnectionString.Replace(ctx.Pwd, "".PadLeft(ctx.Pwd.Length, '*')));
            }

            if (use == null)
            {
                use = shema => true;
            }

            DbContextOracle dbContext = new DbContextOracle(manager)
            {
                Use = use, ExcludeCode = ctx.ExcludeCode
            };

            dbContext.Database = new OracleDatabase()
            {
                Name         = "Instance server " + ctx.Source,
                SourceScript = false
            };

            if (!string.IsNullOrEmpty(ctx.Name))
            {
                dbContext.Database.Name = ctx.Name;
            }
            else
            {
                dbContext.Database.Name = ctx.Source;
            }

            Filtre(ctx, builder.ConnectionString);

            var version = new OracleVersionQuery().GetVersion(dbContext);

            dbContext.Version = version;

            Trace.WriteLine($"server version {version}");

            Run(dbContext);

            if (!string.IsNullOrEmpty(ctx.Filename))
            {
                FileInfo f = new FileInfo(ctx.Filename);
                if (!f.Directory.Exists)
                {
                    f.Directory.Create();
                }

                Trace.WriteLine("Writing file at " + ctx.Filename);
                dbContext.Database.WriteFile(ctx.Filename);
            }

            Trace.WriteLine("the end");

            return(dbContext.Database);
        }