Exemplo n.º 1
0
        private void RestoreAtDateExecute(ServerAccess ba, SqlServerAccess sa, FileInfo f, string dbName, RestoreOption opt)
        {
            try
            {
                using (new NetworkConnection(ba.uri, new NetworkCredential(ba.username, ba.password)))
                {
                    var filePath = f.FullName;
                    using (new NetworkConnection(sa.uri, new NetworkCredential(sa.username, sa.password)))
                    {
                        string destPath = Path.Combine(sa.uri, sa.folder, f.Name);
                        if (File.Exists(destPath))
                        {
                            File.Delete(destPath);
                        }
                        File.Copy(filePath, destPath); var bakFilePath = destPath;
                        destPath = destPath.Replace(sa.uri, sa.disk);

                        SMOHelper restoreInstance = new SMOHelper(sa);
                        restoreInstance.Restore(destPath, dbName, opt);
                        if (File.Exists(bakFilePath))
                        {
                            File.Delete(bakFilePath);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message);
            }
        }
Exemplo n.º 2
0
        private List <string> CopyAllTransactionFiles(FileInfo[] transactionFiles, SqlServerAccess sa, DateTime BAKDate, DateTime EndDate)
        {
            var transactionsFilesDestPath = new List <string>();
            var tfList = transactionFiles.OrderBy(tf => tf.CreationTime).ToList();
            var copy   = true;

            foreach (var f in tfList)
            {
                if (f.CreationTime > BAKDate && copy)
                {
                    string destPath = Path.Combine(sa.uri, sa.folder, f.Name);
                    if (File.Exists(destPath))
                    {
                        File.Delete(destPath);
                    }
                    File.Copy(f.FullName, destPath);
                    transactionsFilesDestPath.Add(destPath);
                    if (f.CreationTime > EndDate)
                    {
                        copy = false;
                    }
                }
            }
            return(transactionsFilesDestPath);
        }
Exemplo n.º 3
0
 private async Task UpdateBackUpInfoExecute(SqlServerAccess sa)
 {
     try
     {
         // Now load the information from the machine.
         if (RemoteSysInfo.Get(sa.host, sa.username, sa.password) != 0)
         {
             throw new Exception(RemoteSysInfo.Error);
         }
         foreach (var d in RemoteSysInfo.LogicalDrives)
         {
             if (d.Name == sa.disk)
             {
                 await Dispatcher.BeginInvoke(DispatcherPriority.Send, (ThreadStart)(() =>
                 {
                     Drive = d;
                 }));
             }
         }
     }
     catch (Exception ex)
     {
         Logger.Error(ex.Message);
     }
 }
Exemplo n.º 4
0
 //依赖注入
 public Allot_Business()
 {
     if (_sqlServerAccess == null)
     {
         _sqlServerAccess = base.sqlServer;
     }
 }
Exemplo n.º 5
0
        public int GetComplexTypeModelCount()
        {
            ICraneAccess dataAccess = new SqlServerAccess(ConnectionString);

            return(dataAccess
                   .Query()
                   .ExecuteScalar <int>("dbo.GetComplexModelCount"));
        }
Exemplo n.º 6
0
        public void ReseedBookIdentity(int idStart)
        {
            ICraneAccess dataAccess = new SqlServerAccess(ConnectionString);

            dataAccess
            .Command()
            .AddSqlParameter("@IdStart", idStart)
            .ExecuteNonQuery("dbo.ReseedBookIdentity");
        }
Exemplo n.º 7
0
        public List <ReservedColumnNameTest> GetReservedColumnNameTests()
        {
            ICraneAccess dataAccess = new SqlServerAccess(ConnectionString);

            return(dataAccess
                   .Query()
                   .ExecuteReader <ReservedColumnNameTest>("dbo.GetReservedColumnNameTests")
                   .ToList());
        }
Exemplo n.º 8
0
        public List <Book> GetBookList(string isbn = null)
        {
            ICraneAccess dataAccess = new SqlServerAccess(ConnectionString);

            return(dataAccess
                   .Query()
                   .AddSqlParameter("@Isbn", isbn)
                   .ExecuteReader <Book>("dbo.GetBooks")
                   .ToList());
        }
Exemplo n.º 9
0
        public List <SchemaTest2> GetSchemaTest2List()
        {
            ICraneAccess dataAccess = new SqlServerAccess(ConnectionString);

            return(dataAccess
                   .Query()
                   .AddSqlParameter("@Schema", "AnotherSchema")
                   .ExecuteReader <SchemaTest2>("dbo.GetSchemaTest")
                   .ToList());
        }
Exemplo n.º 10
0
        public List <CustomIdentityColumnNameTest> GetCustomIdentityColumnNameTestList()
        {
            ICraneAccess dataAccess = new SqlServerAccess(ConnectionString);

            return(dataAccess
                   .Query()
                   .CustomColumnMapping <CustomIdentityColumnNameTest>(x => x.Id, "ID_COMPANY")
                   .ExecuteReader <CustomIdentityColumnNameTest>("dbo.GetCustomIdentityColumnNameTestList")
                   .ToList());
        }
Exemplo n.º 11
0
        public static DBAccessFactory GetDBAccess(string dbtype)
        {
            DBAccessFactory dbservice = new SqlServerAccess();

            switch (dbtype)
            {
            case "sqlserver": return(new SqlServerAccess());
            }
            return(dbservice);
        }
Exemplo n.º 12
0
        public List <CustomColumnMappingTest> GetCustomColumnMappingTests()
        {
            ICraneAccess dataAccess = new SqlServerAccess(ConnectionString);

            return(dataAccess
                   .Query()
                   .CustomColumnMapping <CustomColumnMappingTest>(x => x.NaturalIdTest, "NaturalId")
                   .CustomColumnMapping <CustomColumnMappingTest>(x => x.ColumnXIsDifferent, "ColumnX")
                   .CustomColumnMapping <CustomColumnMappingTest>(x => x.ColumnYIsDifferentInDatabase, "ColumnY")
                   .ExecuteReader <CustomColumnMappingTest>("dbo.GetCustomColumnMappingTests")
                   .ToList());
        }
Exemplo n.º 13
0
        private void RestoreAtTimeExecute(ServerAccess ba, SqlServerAccess sa, string c, string dbName, DateTime time, RestoreOption opt)
        {
            try
            {
                using (new NetworkConnection(ba.uri, new NetworkCredential(ba.username, ba.password)))
                {
                    string        path             = Path.Combine(ba.uri, ba.dailyfolder, c);
                    DirectoryInfo dir              = new DirectoryInfo(path);
                    FileInfo[]    files            = dir.GetFiles("*.bak").OrderByDescending(p => p.CreationTime).ToArray();
                    var           f                = files.FirstOrDefault();
                    var           filePath         = f.FullName;
                    var           creationDate     = f.CreationTime;
                    FileInfo[]    transactionFiles = dir.GetFiles("*.trn").OrderByDescending(p => p.CreationTime).ToArray();
                    using (new NetworkConnection(sa.uri, new NetworkCredential(sa.username, sa.password)))
                    {
                        string destPath = Path.Combine(sa.uri, sa.folder, f.Name);
                        if (File.Exists(destPath))
                        {
                            File.Delete(destPath);
                        }
                        File.Copy(filePath, destPath);
                        var bakFilePath          = destPath;
                        var transactionFilesPath = CopyAllTransactionFiles(transactionFiles, sa, creationDate, time);

                        destPath = destPath.Replace(sa.uri, sa.disk);
                        var transactionFilesDestPath = new List <string>();
                        foreach (var tf in transactionFilesPath)
                        {
                            transactionFilesDestPath.Add(tf.Replace(sa.uri, sa.disk));
                        }

                        SMOHelper restoreInstance = new SMOHelper(sa);
                        restoreInstance.RestoreAtTime(destPath, transactionFilesDestPath, time, dbName, opt);
                        if (File.Exists(bakFilePath))
                        {
                            File.Delete(bakFilePath);
                        }
                        foreach (var fileToDel in transactionFilesPath)
                        {
                            if (File.Exists(fileToDel))
                            {
                                File.Delete(bakFilePath);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message);
            }
        }
        public CustomerEntity GetCustomer(long customerId)
        {
            var sqlAccess = new SqlServerAccess("stp_getCustomer");

            sqlAccess.AddParameter("@CustomerId", customerId);

            return(sqlAccess.ExecuteReaderFirstRowIfExists(r => new CustomerEntity
            {
                CustomerId = r.To <long>("Id"),
                FirstName = r.To <string>("FirstName"),
                LastName = r.To <string>("LastName")
            }));
        }
Exemplo n.º 15
0
        private async Task Shrink(string db)
        {
            SqlServerAccess sa = null;
            await Dispatcher.BeginInvoke(DispatcherPriority.Send, (ThreadStart)(() =>
            {
                sa = SqlSourcesCombo.SelectedItem as SqlServerAccess;
            }));

            if (sa != null)
            {
                await Task.Run(() => ShrinkExecute(sa, db));
            }
        }
Exemplo n.º 16
0
        private async Task UpdateBackUpInfo()
        {
            SqlServerAccess sa = null;
            await Dispatcher.BeginInvoke(DispatcherPriority.Send, (ThreadStart)(() =>
            {
                sa = SqlSourcesCombo.SelectedItem as SqlServerAccess;
            }));

            if (sa != null)
            {
                await Task.Run(() => UpdateBackUpInfoExecute(sa));
            }
        }
Exemplo n.º 17
0
        private async Task SqlOnClickExecute(SqlServerAccess sa)
        {
            SMOHelper restoreInstance = new SMOHelper(sa);
            var       bddList         = restoreInstance.GetDatabase();

            await Dispatcher.BeginInvoke(DispatcherPriority.Send, (ThreadStart)(() =>
            {
                SourceDatabases.Clear();
                foreach (var bdd in bddList)
                {
                    SourceDatabases.Add(bdd);
                }
            }));
        }
Exemplo n.º 18
0
        private async Task Clean(string db)
        {
            SqlServerAccess sa  = null;
            RestoreOption   opt = RestoreOption.None;
            await Dispatcher.BeginInvoke(DispatcherPriority.Send, (ThreadStart)(() =>
            {
                opt = (CleanTable ? RestoreOption.CleanTable : 0);
                sa = SqlSourcesCombo.SelectedItem as SqlServerAccess;
            }));

            if (sa != null)
            {
                await Task.Run(() => CleanExecute(sa, opt, db));
            }
        }
Exemplo n.º 19
0
        private async Task RemoveBAKFilesExecute(SqlServerAccess sa)
        {
            using (new NetworkConnection(sa.uri, new NetworkCredential(sa.username, sa.password)))
            {
                string        path  = Path.Combine(sa.uri, sa.folder);
                DirectoryInfo dir   = new DirectoryInfo(path);
                FileInfo[]    files = dir.GetFiles("*.bak").OrderByDescending(p => p.CreationTime).ToArray();

                int i = 0;
                foreach (var f in files)
                {
                    File.Delete(f.FullName);
                    i++;
                }
            }
        }
Exemplo n.º 20
0
 public AuthInfrastructure(SqlServerAccess <RefreshToken> dataAccess)
 {
     this.dataAccess = dataAccess;
 }
Exemplo n.º 21
0
        private async Task CleanExecute(SqlServerAccess sa, RestoreOption opt, string db)
        {
            SMOHelper instance = new SMOHelper(sa);

            instance.Clean(db, opt);
        }
Exemplo n.º 22
0
        private async Task ShrinkExecute(SqlServerAccess sa, string db)
        {
            SMOHelper instance = new SMOHelper(sa);

            instance.Shrink(db);
        }
Exemplo n.º 23
0
        private async Task ShrinkFileExecute(SqlServerAccess sa)
        {
            SMOHelper instance = new SMOHelper(sa);

            instance.ShrinkAllDBFile();
        }
Exemplo n.º 24
0
 public DataAccess()
 {
     _dataAccess = new SqlServerAccess(ConfigurationManager.ConnectionStrings["SqlBulkToolsTest"].ConnectionString);
 }
Exemplo n.º 25
0
 public AccountInfrastructure(SqlServerAccess <Usuario> dataAccess)
 {
     this.dataAccess = dataAccess;
 }