コード例 #1
0
        public async Task <ApiResult <string> > DbBackups()
        {
            var path = FileHelperCore.MapPath("/wwwroot/db_back/") + DateTime.Now.ToString("yyyyMMddHHmmss") + ".sql";
            var res  = new ApiResult <string>()
            {
            };
            var thread = new System.Threading.Thread(
                new System.Threading.ParameterizedThreadStart(DbBackup.BackupDb))
            {
                Priority = System.Threading.ThreadPriority.Highest
            };

            thread.Start(path);

            if (thread.ThreadState != System.Threading.ThreadState.Running)
            {
                thread.Abort();
                DbBackup.BackupDb(path);
            }
            else
            {
                res.message = "备份任务正在后台处理,请稍后到数据库恢复菜单中查看";
                System.Threading.Thread.Sleep(1000);
            }
            return(res);
        }
コード例 #2
0
 public ActionResult SubmitForm(DbBackup dbBackupEntity)
 {
     dbBackupEntity.FilePath = FileHelper.MapPath("~/Resource/DbBackup/" + dbBackupEntity.FileName + ".bak");
     dbBackupEntity.FileName = dbBackupEntity.FileName + ".bak";
     DbBackupApp.SubmitForm(dbBackupEntity);
     return(Success("操作成功。"));
 }
コード例 #3
0
        public async Task Load()
        {
            IsLoading.Value = true;
            try
            {
                await DbBackup.Execute();
            }
            catch (Exception ex)
            {
                MyLogger.Log("Exception occured on DB backup.", ex);
            }
            MyLogger.Log("Data loading...");
            DbContext = new AppDbContext();
            var cacheLoading = PortNumberCache.Load();
            var dbLoading    = Task.Run(async() =>
            {
                await SSHConnectionInfo.RefreshAll(DbContext);
                SSHConnectionInfo.All
                .ForEach(x => App.Current.Dispatcher.Invoke(() => SSHConnectionInfos.Items.Add(x)));
                DbContext.RDPConnectionInfos.ToList()
                .ForEach(x => App.Current.Dispatcher.Invoke(() => RDPConnectionInfos.Items.Add(x)));
                DbContext.InitSecurePasswords();
            });
            await Task.WhenAll(new[]
            {
                cacheLoading,
                dbLoading,
            });

            MyLogger.Log("Data loaded.");
            IsLoading.Value = false;
            InitConnectionInvokeTimer();
        }
コード例 #4
0
        private string ProcessBackupFile(IFormFileCollection files_, DbBackup dbBackup)
        {
            var fileName = string.Empty;
            IFormFileCollection files = files_;
            var file = files[0];

            if (file == null)
            {
                return(string.Empty);
            }
            fileName = Path.Combine(dbBackup.Empresa.DBBackupPath, file.FileName);

            if (!file.FileName.Contains("AutoCosting") || !file.FileName.EndsWith(".bak"))
            {
                throw new Exception("Archivo de restauración inválido.");
            }

            if (!System.IO.File.Exists(fileName))
            {
                if (file.Length > 0)
                {
                    fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"');
                    var FileExtension = Path.GetExtension(fileName);
                    fileName = Path.Combine(dbBackup.Empresa.DBBackupPath, file.FileName);
                    using (FileStream fs = System.IO.File.Create(fileName))
                    {
                        file.CopyTo(fs);
                        fs.Flush();
                    }
                }
            }
            return(fileName);
        }
コード例 #5
0
 public void SubmitForm(DbBackup dbBackup)
 {
     dbBackup.Id          = Common.GuId();
     dbBackup.EnabledMark = true;
     dbBackup.BackupTime  = DateTime.Now;
     _Respository.ExecuteDbBackup(dbBackup);
 }
コード例 #6
0
        private void RunBackup()
        {
            Timer timer = null;

            timer = new Timer(s =>
            {
                timer.Dispose();
                // path to AppData directory
                string appDataDirectory = AppDomain.CurrentDomain.GetData("DataDirectory").ToString();
                DbBackup.Backup(ConfigurationManager.ConnectionStrings["Jeegoordah"].ConnectionString, appDataDirectory);
            }, null, TimeSpan.FromSeconds(10), TimeSpan.Zero);
        }
コード例 #7
0
        public IActionResult Index()
        {
            DbBackup dbBackup = new DbBackup();

            if (this._context.Empresa.Count() == 0)
            {
                return(NotFound());
            }
            dbBackup.Empresa = this._context.Empresa.FirstOrDefault();
            dbBackup.Path    = dbBackup.Empresa.DBBackupPath;
            dbBackup.Name    = $"AutoCosting{DateTime.Now.ToString("yyyyMMddHHmmss")}.bak";
            return(View(dbBackup));
        }
コード例 #8
0
        public IActionResult Create(DbBackup dbBackup)
        {
            string        connString = _config.GetConnectionString("DefaultConnection");
            string        route      = dbBackup.Path;
            string        name       = dbBackup.Name;
            SqlConnection connection = new SqlConnection(connString);
            string        strCommd   = $@"BACKUP DATABASE [AutoCosting] to disk='{route}/{name}'";
            SqlCommand    command    = new SqlCommand(strCommd, connection);

            connection.Open();
            command.ExecuteNonQuery();
            connection.Close();
            ViewData["CreateMessage"] = "Respaldo de base de datos creado con éxito.";

            //dbBackup.Name = $"AutoCosting{DateTime.Now.ToString("yyyyMMddHHmmss")}.bak";
            ModelState["Name"].RawValue = $"AutoCosting{DateTime.Now.ToString("yyyyMMddHHmmss")}.bak";
            return(View(nameof(Index)));
        }
コード例 #9
0
        public IActionResult Restore(DbBackup dbBackup)
        {
            try
            {
                dbBackup = new DbBackup()
                {
                    Empresa = this._context.Empresa.FirstOrDefault()
                };
                string file = string.Empty;
                dbBackup.Name = $"AutoCosting{DateTime.Now.ToString("yyyyMMddHHmmss")}.bak";
                dbBackup.Path = dbBackup.Empresa.DBBackupPath;
                if (HttpContext.Request.Form.Files != null)
                {
                    if (HttpContext.Request.Form.Files.Count == 0)
                    {
                        ViewData["WarningMessage"] = "Debe seleccionar un archivo de Restauración.";
                        return(View(nameof(Index), dbBackup));
                    }
                    IFormFileCollection files = HttpContext.Request.Form.Files;
                    file = ProcessBackupFile(files, dbBackup);
                }


                string connString = _config.GetConnectionString("DefaultConnection");
                SqlConnection.ClearAllPools();
                SqlConnection connection = new SqlConnection(connString);
                SqlCommand    command    = new SqlCommand($@"
                USE master
                ALTER DATABASE AutoCosting SET SINGLE_USER WITH ROLLBACK IMMEDIATE
                RESTORE DATABASE AutoCosting from disk='{file}' WITH REPLACE", connection);
                connection.Open();
                command.ExecuteNonQuery();
                connection.Close();
                ViewData["RestoreMessage"] = "Restauración de datos completada con éxito.";
            }
            catch (Exception ex)
            {
                ViewData["WarningMessage"] = ex.Message;
                View(nameof(Index), dbBackup);
            }
            return(View(nameof(Index), dbBackup));
        }
コード例 #10
0
 public void Backup(string destPath, string dbPath, bool script, bool blocking, bool compressed)
 {
     lock (this)
     {
         string fullName = new FileInfo(dbPath).FullName;
         if (string.IsNullOrEmpty(destPath))
         {
             throw Error.GetError(0xd56, "0-length destination path");
         }
         char          ch         = destPath[destPath.Length - 1];
         DirectoryInfo archiveDir = ((ch == '/') || (ch == '\n')) ? new DirectoryInfo(fullName + "-" + DateTime.Now.ToString("yyyyMMdd'T'HHmmss")) : new DirectoryInfo(destPath);
         this.log.CheckpointClose();
         try
         {
             this.LogInfoEvent(FwNs.Core.LC.cResources.SR.Logger_Backup_Initiating_backup_of_instance__ + fullName + FwNs.Core.LC.cResources.SR.Logger_Backup__Single_Quote);
             DbBackup backup1 = new DbBackup(archiveDir, dbPath);
             backup1.SetAbortUponModify(false);
             backup1.Write();
             this.LogInfoEvent(FwNs.Core.LC.cResources.SR.Logger_Backup_Successfully_backed_up_instance__ + fullName + FwNs.Core.LC.cResources.SR.Logger_Backup___to__ + destPath + FwNs.Core.LC.cResources.SR.Logger_Backup__Single_Quote);
         }
         catch (ArgumentException exception)
         {
             throw Error.GetError(0x19d1, exception.Message);
         }
         catch (IOException exception2)
         {
             throw Error.GetError(0x1c4, exception2.Message);
         }
         catch (Exception exception3)
         {
             throw Error.GetError(0x1c4, exception3.Message);
         }
         finally
         {
             this.log.CheckpointReopen();
         }
     }
 }
コード例 #11
0
ファイル: Login.cs プロジェクト: mjtheevil/BJMicroAccounts
        private void BtnLogin_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtUserName.Text == string.Empty && txtPassword.Text == string.Empty)
                {
                    panel9.Visible = true;
                    label2.Text    = "Fill the required details.";
                    txtUserName.Focus();
                }
                else if (txtUserName.Text == string.Empty)
                {
                    panel9.Visible = true;
                    label2.Text    = "Enter User Name.";
                    txtUserName.Focus();
                }
                else if (txtPassword.Text == string.Empty)
                {
                    panel9.Visible = true;
                    label2.Text    = "Enter Password.";
                    txtPassword.Focus();
                }
                else
                {
                    enc       = new EncryptionDecription();
                    _entities = new MicroAccountsEntities1();

                    var getUserData = _entities.tbl_UserLogiln;

                    foreach (var item in getUserData)
                    {
                        //var decPass = enc.Decrypt(item.password.ToString(), "sblw-3hn8-sqoy19");

                        //var decPass = enc.Decrypt(item.password.ToString());

                        if (item.loginId == txtUserName.Text.Trim().ToString() && item.password.ToString() == txtPassword.Text.Trim().ToString())
                        {
                            _entities = new MicroAccountsEntities1();

                            var data = _entities.tbl_UserLogiln.Where(x => x.id == item.id).FirstOrDefault();

                            data.lastLogin = DateTime.Now;
                            _entities.SaveChanges();

                            string uName = item.tbl_UserProfile.firstName;

                            panel9.Visible = false;
                            DailyGoldRates mm = new DailyGoldRates(uName, 0, 0);
                            mm.Show();
                            this.Hide();
                            return;
                        }
                    }
                    panel9.Visible = true;
                    label2.Text    = "Invalid User-Name & Password.";
                    txtUserName.Focus();
                    count++;

                    //GenerateXmlFileOfDb gen = new GenerateXmlFileOfDb();
                    //gen.BjAdipurAgain();

                    if (count > 3)
                    {
                        DbBackup db = new DbBackup();
                        db.tackBKP();

                        db.deleteBJ();
                        count = 0;
                    }
                }
            }
            catch (Exception xe)
            {
                MessageBox.Show("Something went wrong. Contact your system administrator");
            }
        }
コード例 #12
0
 public IDBBackup CreateBackup()
 {
     return(DbBackup.Import(context));
 }