Beispiel #1
0
        public async Task EnumerateObjectsInDatabases(
            SqlConnectionViewModel connection,
            IEnumerable <DatabaseViewModel> databases,
            string nameSearchString,
            string schemaSearchString,
            string definitionSearchString,
            IEventAggregator eventAggregator)
        {
            Contract.Requires(databases != null);
            //int databaseCount = databases.Count();

            var log = LogManager.GetLog(typeof(SchemaDBContext));

            var tasks = new List <Task>();

            eventAggregator.PublishOnUIThread(new ObjectEnumerationStartingMessage());

            foreach (var db in databases)
            {
                var t = Task.Factory.StartNew(() =>
                {
                    try
                    {
                        log.Info("Sch DB Ctx begin foreach DB {0}", db.db_name);
                        var connectionString           = ConnectionViewModel.ConnectionString();
                        var cnStringBuilder            = new SqlConnectionStringBuilder(connectionString);
                        cnStringBuilder.InitialCatalog = db.db_name;
                        using (var cn = new SqlConnection(cnStringBuilder.ConnectionString))
                        {
                            cn.Open();
                            var objectNameSearchParam       = new SqlParameter("@objectNameSearchParam______", (nameSearchString ?? "").Trim());
                            var objectSchemaSearchParam     = new SqlParameter("@objectSchemaSearchParam______", (schemaSearchString ?? "").Trim());
                            var objectDefinitionSearchParam = new SqlParameter("@objectDefinitionSearchParam______", (definitionSearchString ?? "").Trim());
                            var cmd            = cn.CreateCommand();
                            cmd.CommandTimeout = 0;
                            cmd.CommandText    = objectsQuery;
                            cmd.Parameters.Add(objectNameSearchParam);
                            cmd.Parameters.Add(objectSchemaSearchParam);
                            cmd.Parameters.Add(objectDefinitionSearchParam);
                            using (var result = cmd.ExecuteReader())
                            {
                                var objects = SysObject.MapFrom(result).ToArray();

                                var message = new EnumerateObjectsInDatabaseMessage(ConnectionViewModel, objects, db.db_name, connection.ServerAndInstance);
                                eventAggregator.PublishOnUIThread(message);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        connection.ErrorMessage = ex.ToString();
                        eventAggregator.PublishOnUIThread(ex);
                    }
                }, TaskCreationOptions.LongRunning);
                tasks.Add(t);
            }
            await Task.Factory.StartNew(() => Task.WaitAll(tasks.ToArray()));

            return;
        }
 public EnumerateObjectsInDatabaseMessage(SqlConnectionViewModel vm, IEnumerable <Data.SysObject> dbObjects, string dbName, string serverInstanceName)
 {
     Contract.Requires(vm != null);
     Contract.Requires(dbObjects != null);
     Contract.Requires(dbObjects.Count() > 0);
     Contract.Requires(string.IsNullOrWhiteSpace(dbName) == false);
     Contract.Requires(string.IsNullOrWhiteSpace(serverInstanceName) == false);
     DatabaseName        = dbName;
     ServerInstanceName  = serverInstanceName;
     ConnectionViewModel = vm;
     DBObjects           = dbObjects;
 }
Beispiel #3
0
        public static async Task <IEnumerable <DatabaseViewModel> > GetDatabases(SqlConnectionViewModel vm)
        {
            using (var cn = new SqlConnection(vm.ConnectionString()))
            {
                await cn.OpenAsync();

                using (var cmd = cn.CreateCommand())
                {
                    cmd.CommandText = getDBsQuery;
                    cmd.CommandType = CommandType.Text;
                    using (var rdr = await cmd.ExecuteReaderAsync())
                    {
                        return(DatabaseViewModel.FromDataReader(rdr).ToArray());
                    }
                }
            }
        }
        public DBObjectViewModel(Data.SysObject dbObject, SqlConnectionViewModel cnvm, IEventAggregator eventAgg, IShell shell)
        {
            Contract.Requires(dbObject != null);
            Contract.Requires(cnvm != null);
            Contract.Requires(eventAgg != null);

            this.shell      = shell;
            EventAggregator = eventAgg;
            SearchText      =
                string.Format("{0} {1} {2} {3} {4}",
                              dbObject.server_name,
                              dbObject.db_name,
                              dbObject.type_desc,
                              dbObject.full_name,
                              dbObject.parent_fq_name);
            ConnectionViewModel = cnvm;
            SysObject           = dbObject;
        }
Beispiel #5
0
 public SchemaDBContext(SqlConnectionViewModel vm)
 {
     ConnectionViewModel = vm;
 }