コード例 #1
0
        /// <summary>
        /// The load.
        /// </summary>
        /// <param name="parameters">
        /// The parameters.
        /// </param>
        /// <returns>
        /// The <see cref="object"/>.
        /// </returns>
        public override object Load(object parameters)
        {
            Logger.Trace("Started Import()");

            string path = this.ReturnFilePath(parameters as string);

            Logger.Debug($"Path: {path}");
            AdoSourceOptions result = null;

            if (File.Exists(path))
            {
                Logger.Trace("Path Exists");
                result = ObjectXMLSerializer <AdoSourceOptions> .Load(path);
            }
            else
            {
                Logger.Trace("Path Doesn't Exist");
                result = new AdoSourceOptions
                {
                    ProviderName     = "System.Data.SqlClient",
                    ConnectionString =
                        @"Data Source=.\SQLEXPRESS;Integrated Security=true;Initial Catalog=BankingDesign"
                };
            }

            Logger.Trace("Completed Import()");

            return(result);
        }
コード例 #2
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="AdoUserControl" /> class.
 /// </summary>
 public AdoUserControl()
 {
     Logger.Trace("Started AdoUserControl()");
     this.InitializeComponent();
     this.options = new AdoSourceOptions();
     Logger.Trace("Completed AdoUserControl()");
 }
コード例 #3
0
        /// <summary>
        /// The test.
        /// </summary>
        /// <param name="parameters">
        /// The parameters.
        /// </param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        /// <exception cref="NotImplementedException">
        /// </exception>
        public override bool Test(object parameters)
        {
            Logger.Trace("Started Test()");
            bool result = false;

            AdoSourceOptions adoOptions = parameters as AdoSourceOptions;

            using (SqlConnection connection = new SqlConnection(adoOptions.ConnectionString))
            {
                // Open the connection in a try/catch block.
                // Create and execute the DataReader, writing the result
                // set to the console window.
                try
                {
                    connection.Open();

                    result = true;
                }
                catch (Exception ex)
                {
                    Logger.Error($"Unable to connect to database:{ex.Message}");
                }
            }

            Logger.Trace("Complete Test()");

            return(result);
        }
コード例 #4
0
        /// <summary>
        /// The load.
        /// </summary>
        /// <param name="parameters">
        /// The parameters.
        /// </param>
        /// <exception cref="NotImplementedException">
        /// </exception>
        /// <returns>
        /// The <see cref="object"/>.
        /// </returns>
        public override object Load(object parameters)
        {
            Logger.Trace("Started Import()");

            string path = this.ReturnFilePath(parameters as string);

            Logger.Debug($"Path: {path}");
            AdoSourceOptions result = null;

            if (File.Exists(path))
            {
                Logger.Trace("Path Exists");
                result = ObjectXMLSerializer <AdoSourceOptions> .Load(path);
            }
            else
            {
                Logger.Trace("Path Doesn't Exist");
                result = new AdoSourceOptions
                {
                    ProviderName     = "Oracle.ManagedDataAccess.Client",
                    ConnectionString =
                        @"DATA SOURCE=localhost:1521/xe;PERSIST SECURITY INFO=True;USER ID=dbo;PASSWORD=Password123#"
                };
            }

            Logger.Trace("Completed Import()");

            return(result);
        }
コード例 #5
0
        /// <summary>
        /// The load.
        /// </summary>
        /// <param name="parameters">
        /// The parameters.
        /// </param>
        /// <returns>
        /// The <see cref="object"/>.
        /// </returns>
        public override object Load(object parameters)
        {
            Logger.Trace("Started Import()");

            string path = this.ReturnFilePath(parameters as string);

            Logger.Debug($"Path: {path}");
            AdoSourceOptions result = null;

            if (File.Exists(path))
            {
                Logger.Trace("Path Exists");
                result = ObjectXMLSerializer <AdoSourceOptions> .Load(path);
            }
            else
            {
                Logger.Trace("Path Doesn't Exist");
                result = new AdoSourceOptions
                {
                    ProviderName     = "MySql.Data.MySqlClient",
                    ConnectionString =
                        @"server=localhost;userid=test;password=password;database=test;SslMode=none"
                };
            }

            Logger.Trace("Completed Import()");

            return(result);
        }
コード例 #6
0
        public void GenericAdoSourceTypeUnitTest_Import()
        {
            SqlServerAdoSourceType import = new SqlServerAdoSourceType();

            this.SourceType = import;
            var options = new AdoSourceOptions();

            options.ConnectionString = @"Data Source=.\SQLEXPRESS2017;Integrated Security=true;Initial Catalog=AutoNLayered";
            options.Schemas.Add("dbo");
            DatabaseModel databaseModel = import.Import(options);

            this.BaseSourceTypeUnitTest_TestValues(databaseModel);
        }
コード例 #7
0
        public void MySqlSourceTypeUnitTest_Import()
        {
            OracleAdoSourceType import = new OracleAdoSourceType();

            this.SourceType = import;

            AdoSourceOptions sourceOptions = new AdoSourceOptions {
                ProviderName = "Oracle.ManagedDataAccess.Client", ConnectionString = ConfigurationManager.ConnectionStrings["RepoTestOracle"].ConnectionString
            };

            sourceOptions.Schemas.Add("DBO");

            DatabaseModel databaseModel = import.Import(sourceOptions);

            this.BaseSourceTypeUnitTest_TestValues(databaseModel);
        }
コード例 #8
0
        public void MySqlSourceTypeUnitTest_Import()
        {
            MySqlAdoSourceType import = new MySqlAdoSourceType();

            this.SourceType = import;

            AdoSourceOptions sourceOptions = new AdoSourceOptions {
                ProviderName = "MySql.Data.MySqlClient", ConnectionString = ConfigurationManager.ConnectionStrings["RepoTestMySql"].ConnectionString
            };

            sourceOptions.Schemas.Add("repotest");

            DatabaseModel databaseModel = import.Import(sourceOptions);

            this.BaseSourceTypeUnitTest_TestValues(databaseModel);
        }
コード例 #9
0
        /// <summary>
        /// The load data.
        /// </summary>
        /// <param name="parameters">
        /// The parameters.
        /// </param>
        /// <exception cref="NotImplementedException">
        /// </exception>
        public void LoadData(object parameters)
        {
            Logger.Trace("Started LoadData()");

            this.options = this.SourceType.Load(parameters) as AdoSourceOptions;

            if (this.options != null)
            {
                this.TxtConnection.Text = this.options.ConnectionString;
            }
            else
            {
                this.TxtConnection.Text = string.Empty;
            }

            Logger.Trace("Completed LoadData()");
        }
コード例 #10
0
ファイル: AdoSource.cs プロジェクト: laredoza/.NetScaffolder
        /// <summary>
        /// The save.
        /// </summary>
        /// <param name="parameters">
        /// The parameters.
        /// </param>
        public void Save(object parameters)
        {
            Logger.Trace("Started Save()");

            List <object> saveParameters = parameters as List <object>;
            string        path           = this.ReturnFilePath(saveParameters[0] as string);

            Logger.Debug($"Path: {path}");

            AdoSourceOptions options = saveParameters[1] as AdoSourceOptions;

            if (options == null)
            {
                options = new AdoSourceOptions();
            }

            ObjectXMLSerializer <AdoSourceOptions> .Save(options, path, SerializedFormat.Document);

            Logger.Trace("Completed Save()");
        }
コード例 #11
0
ファイル: AdoSource.cs プロジェクト: laredoza/.NetScaffolder
        /// <summary>
        /// The return schemas.
        /// </summary>
        /// <param name="options">
        /// The options.
        /// </param>
        /// <returns>
        /// The <see cref="List"/>.
        /// </returns>
        public List <string> ReturnSchemas(object options)
        {
            this.Schemas.Clear();
            AdoSourceOptions adoOptions = options as AdoSourceOptions;
            var databaseReader          = new DatabaseReader(adoOptions.ConnectionString, adoOptions.ProviderName);

            this.Schemas.Clear();
            IList <DatabaseTable> tables = databaseReader.TableList();

            foreach (var table in tables)
            {
                if (!this.Schemas.Any(s => s == table.SchemaOwner))
                {
                    this.Schemas.Add(table.SchemaOwner);
                }
            }

            this.Schemas = this.Schemas.OrderBy(s => s).ToList();

            return(this.Schemas);
        }
コード例 #12
0
        /// <summary>
        /// The load.
        /// </summary>
        /// <param name="parameters">
        /// The parameters.
        /// </param>
        /// <exception cref="NotImplementedException">
        /// </exception>
        public object Load(object parameters)
        {
            Logger.Trace("Started Import()");

            string path = this.ReturnFilePath(parameters as string);

            Logger.Debug($"Path: {path}");
            AdoSourceOptions result = null;

            if (File.Exists(path))
            {
                Logger.Trace("Path Exists");
                result = ObjectXMLSerializer <AdoSourceOptions> .Load(path);
            }
            else
            {
                Logger.Trace("Path Doesn't Exist");
            }

            Logger.Trace("Completed Import()");

            return(result);
        }
コード例 #13
0
ファイル: AdoSource.cs プロジェクト: laredoza/.NetScaffolder
 /// <summary>
 /// The import.
 /// </summary>
 /// <param name="options">
 /// The options.
 /// </param>
 /// <param name="result">
 /// The result.
 /// </param>
 /// <param name="schemas">
 /// The schemas.
 /// </param>
 /// <param name="databaseReader">
 /// The database reader.
 /// </param>
 private void Import(object options, DatabaseModel result, List <string> schemas, DatabaseReader databaseReader)
 {
     AdoSourceOptions adoOptions = options as AdoSourceOptions;
 }
コード例 #14
0
ファイル: AdoSource.cs プロジェクト: laredoza/.NetScaffolder
        /// <summary>
        /// The import.
        /// </summary>
        /// <param name="options">
        /// The options.
        /// </param>
        /// <returns>
        /// The <see cref="DatabaseModel"/>.
        /// </returns>
        public DatabaseModel Import(object options)
        {
            Logger.Trace("Started Import()");
            DatabaseModel result = new DatabaseModel();

            AdoSourceOptions adoOptions = options as AdoSourceOptions;

            if (adoOptions == null)
            {
                return(result);
            }

            //foreach (var schemaOwner in adoOptions.Schemas)
            {
                var databaseReader = new DatabaseReader(adoOptions.ConnectionString, adoOptions.ProviderName);

                databaseReader.Exclusions.TableFilter.FilterExclusions.Add("sysdiagrams");
                databaseReader.Exclusions.TableFilter.FilterExclusions.Add("__migrationhistory");
                databaseReader.Exclusions.TableFilter.FilterExclusions.Add("__MigrationHistory");
                databaseReader.Exclusions.TableFilter.FilterExclusions.Add("sys_config");

                databaseReader.AllTables();
                databaseReader.AllViews();



                // databaseReader.AllStoredProcedures(); //but not this one!
                // var schemaMetaData = databaseReader.ReadAll();
                var schemaMetaData = databaseReader.DatabaseSchema;

                List <DatabaseTable> tables = schemaMetaData.Tables
                                              //.Where(t => t.Name != "sysdiagrams" && t.Name != "__migrationhistory" && t.Name != "__MigrationHistory")
                                              .ToList();

                foreach (var table in tables)
                {
                    if (adoOptions.Schemas.Any(s => s == table.SchemaOwner))
                    {
                        DatabaseSchemaFixer.UpdateReferences(schemaMetaData);

                        var newTable = new Table {
                            TableName = table.Name, SchemaName = table.SchemaOwner
                        };
                        result.Tables.Add(newTable);

                        this.AddColumns(table, newTable);

                        this.AddforeignKeys(table, schemaMetaData, newTable);

                        this.AddforeignKeyChildren(table, schemaMetaData, newTable);

                        FormatNavigationPropertiesToBeUnique(newTable);

                        AddIndexes(table, newTable);
                    }
                }
            }

            this.Fix(result);
            Logger.Trace("Completed Import()");
            return(result);
        }
コード例 #15
0
        /// <summary>
        /// Import data structure.
        /// </summary>
        /// <param name="options">
        /// The options.
        /// </param>
        /// <returns>
        /// The <see cref="DatabaseModel"/>.
        /// </returns>
        public DatabaseModel Import(object options)
        {
            DatabaseModel result = new DatabaseModel();

            AdoSourceOptions adoOptions = options as AdoSourceOptions;
            var dbReader = new DatabaseReader(adoOptions.ConnectionString, adoOptions.ProviderName);
            var schema   = dbReader.ReadAll();

            // schema.Tables[0].CheckConstraints[0].RefersToConstraint
            Table  newTable  = new Table();
            Column newColumn = new Column();

            foreach (var table in schema.Tables.Where(t => t.Name != "sysdiagrams"))
            {
                // foreach (var table in schema.Tables.Where(t => t.Name == "BankAccount"))
                // Debug.WriteLine("Table " + table.Name);
                newTable = new Table {
                    TableName = table.Name
                };
                result.Tables.Add(newTable);

                foreach (var column in table.Columns)
                {
                    newColumn = new Column
                    {
                        ColumnName     = column.Name,
                        CSharpDataType = this.MapDatabaseTypeToCSharp(column.DataType.TypeName),
                        IsRequired     = column.IsPrimaryKey,
                        ColumnOrder    = table.Columns.IndexOf(column) + 1,
                        Precision      = column.Precision.HasValue ? column.Precision.Value : 0,
                        Scale          = column.Scale.HasValue ? column.Scale.Value : 0,
                        Length         = column.Length.HasValue ? column.Length.Value : 0,
                        IsPrimaryKey   = column.IsPrimaryKey
                    };

                    newTable.Columns.Add(newColumn);
                }

                foreach (var foreignKey in table.ForeignKeys)
                {
                    newTable.RelationShips.Add(
                        new Relationship
                    {
                        TableName              = foreignKey.RefersToTable,
                        ColumnName             = foreignKey.Columns[0],
                        ForeignColumnName      = foreignKey.ReferencedColumns(schema).ToList()[0],
                        DependencyRelationShip = RelationshipType.ForeignKey
                    });
                }

                foreach (var foreignKeyChildren in table.ForeignKeyChildren)
                {
                    foreach (var foreignKey in foreignKeyChildren.ForeignKeys)
                    {
                        if (foreignKey.RefersToTable == table.Name)
                        {
                            newTable.RelationShips.Add(
                                new Relationship
                            {
                                TableName              = foreignKey.TableName,
                                ColumnName             = foreignKey.ReferencedColumns(schema).ToList()[0],
                                ForeignColumnName      = foreignKey.Columns[0],
                                DependencyRelationShip = RelationshipType.ForeignKeyChild
                            });
                        }
                    }
                }
            }

            return(result);
        }