Exemplo n.º 1
0
 /// <summary>
 /// Determines whether the specified <see cref="System.Object"/>, is equal to this instance.
 /// </summary>
 /// <param name="obj">The <see cref="System.Object"/> to compare with this instance.</param>
 /// <returns>
 /// <c>true</c> if the specified <see cref="System.Object"/> is equal to this instance;
 /// otherwise, <c>false</c>.
 /// </returns>
 public override bool Equals(object obj)
 {
     return((obj is Source Item) &&
            Functions.All(x => Item.Functions.Contains(x)) &&
            Name == Item.Name &&
            StoredProcedures.All(x => Item.StoredProcedures.Contains(x)) &&
            Tables.All(x => Item.Tables.Contains(x)) &&
            Views.All(x => Item.Views.Contains(x)));
 }
Exemplo n.º 2
0
        public async Task CreateEntrysAsync(string connection, string outputPath, string database)
        {
            Status = "Try to connect";
            //Data Source=(LocalDb)\ProjectsV12;Integrated Security=True;Database=TestDB;
            IsEnumeratingDatabase = true;
            TargetDir             = outputPath;


            var checkDatabase = false;

            if (connection.StartsWith("file:\\\\"))
            {
                MsSqlStructure = new DacpacMsSqlStructure(connection.Replace("file:\\\\", ""));
            }
            else
            {
                var dbAccessLayer = new DbAccessLayer(DbAccessType.MsSql, connection);
                MsSqlStructure = new DatabaseMsSqlStructure(dbAccessLayer);
                try
                {
                    checkDatabase = dbAccessLayer.CheckDatabase();
                }
                catch (Exception)
                {
                    IsEnumeratingDatabase = false;
                    Connected             = false;
                    checkDatabase         = false;
                }

                var databaseName = string.IsNullOrEmpty(MsSqlStructure.GetDatabaseName())
                                        ? database
                                        : MsSqlStructure.GetDatabaseName();
                if (string.IsNullOrEmpty(databaseName))
                {
                    IsEnumeratingDatabase = false;
                    Status    = "Database not exists. Maybe wrong Connection or no Selected Database?";
                    Connected = false;
                    return;
                }
            }

            DbConfig.EnableGlobalThreadSafety = true;
            if (!Connected)
            {
                IsEnumeratingDatabase = false;
                Status = "Database not accessible. Maybe wrong Connection or no Selected Database?";
                return;
            }


            Status = "Connection OK ... Reading Server Version ...";

            //SqlVersion = Manager.RunPrimetivSelect<string>("SELECT SERVERPROPERTY('productversion')").FirstOrDefault();
            Status = "Reading Tables";

            var counter      = 2;
            var createTables = SimpleWork(() =>
            {
                var tables = MsSqlStructure.GetTables()
                             .Select(
                    s =>
                    new TableInfoModel(s, MsSqlStructure.GetDatabaseName(),
                                       MsSqlStructure))
                             .Select(s => new TableInfoViewModel(s, this))
                             .ToList();
                foreach (var source in tables)
                {
                    if (Tables.All(f => f.Info.TableName != source.Info.TableName))
                    {
                        Tables.Add(source);
                    }
                }
            });
            var createViews = SimpleWork(() =>
            {
                var views =
                    MsSqlStructure.GetViews()
                    .Select(s => new TableInfoModel(s, MsSqlStructure.GetDatabaseName(), MsSqlStructure))
                    .Select(s => new TableInfoViewModel(s, this))
                    .ToList();

                foreach (var source in views)
                {
                    if (Views.All(f => f.Info.TableName != source.Info.TableName))
                    {
                        Views.Add(source);
                    }
                }
            });

            await createTables;
            await createViews;

            SelectedTable = Tables.FirstOrDefault();

            IsEnumeratingDatabase = false;
            Status = "Done";
        }