Пример #1
0
        private void SettingsForm_Load(object sender, EventArgs e)
        {
            try
            {
                m_dictSettings.LoadData();

                m_Settings = m_dictSettings[Settings.GetUnitKey()];

                if (m_Settings != null)
                {
                    checkBoxMonday.Checked    = IsDayChecked(enumWeekdays.Monday, m_Settings.BackupDays);
                    checkBoxTuesday.Checked   = IsDayChecked(enumWeekdays.Tuesday, m_Settings.BackupDays);
                    checkBoxWednesday.Checked = IsDayChecked(enumWeekdays.Wednesday, m_Settings.BackupDays);
                    checkBoxThursday.Checked  = IsDayChecked(enumWeekdays.Thursday, m_Settings.BackupDays);
                    checkBoxFriday.Checked    = IsDayChecked(enumWeekdays.Friday, m_Settings.BackupDays);
                    checkBoxSaturday.Checked  = IsDayChecked(enumWeekdays.Saturday, m_Settings.BackupDays);
                    checkBoxSunday.Checked    = IsDayChecked(enumWeekdays.Sunday, m_Settings.BackupDays);

                    dateTimePicker_BackupAt.Value = m_Settings.BackupTime;

                    numericUpDown_RunForNHours.Value = m_Settings.RunBackupForNHours;

                    textBox_BackupRoot.Text = m_Settings.BackupDestinationRootPath;

                    checkBoxWatchFolders.Checked = m_Settings.WatchFolders;
                }
            }
            catch (Exception exp)
            {
                Logger.WriteError(exp, "8a8d680d-5cc4-4783-b0df-db06a4338309");
            }
        }
Пример #2
0
        private void Form1_Load(object sender, EventArgs e)
        {
            m_Settings = new SerializableDictionary <string, Settings>();
            m_FI       = new SerializableDictionary <string, FolderInfo>();

            f1();

            m_Settings.LoadData();
            m_FI.LoadData();
        }
Пример #3
0
        private void BackupperForm_Load(object sender, EventArgs e)
        {
            try
            {
                m_FI.LoadData();

                foreach (FolderInfo fi in m_FI.ValuesToList())
                {
                    this.dataGridView.Rows.Add(fi.FolderSourcePath
                                               , fi.NumberOfSubFolderInSource
                                               , fi.NumberOfSubFoldersInDestination
                                               , fi.NumberOfFilesInSource
                                               , fi.SizeOfFolderInDestination
                                               , fi.SizeOfFolderInSource
                                               , fi.SizeOfFolderInDestination
                                               , fi.IsDeleted);

                    m_lBackedFiles   += fi.NumberOfFilesInDestination;
                    m_lBackupSize    += fi.SizeOfFolderInDestination;
                    m_lFilesToBackup += fi.NumberOfFilesInSource;
                    m_lSizeToBackup  += fi.SizeOfFolderInSource;

                    if (fi.IsDeleted == true)
                    {
                        RemoveRestoreRow(this.dataGridView.Rows[this.dataGridView.Rows.Count - 1]);
                    }
                }

                toolStripStatusLabel_FilesToBackup.Text = GetFormatedNumber(m_lFilesToBackup);
                toolStripStatusLabel_SizeToBackup.Text  = GetFormatedNumberInGB(m_lSizeToBackup);
                toolStripStatusLabel_BackupSize.Text    = GetFormatedNumberInGB(m_lBackupSize);
                toolStripStatusLabel_FilesInBackup.Text = GetFormatedNumber(m_lBackedFiles);

                this.dataGridView.AutoResizeColumns();
            }
            catch (Exception exp)
            {
                Logger.WriteErrorLogOnly(exp, "eae5b998-667d-47ea-b21e-9dbfbd7ea88a");
                Logger.ShowErrorMessageBox(exp, "Failed to load data.");
            }
        }
Пример #4
0
        public void BackupThread(object oStop)
        {
            try
            {
                lock (oStop)
                {
                    DateTime          dtStartBackupHour = DateTime.Now;
                    List <FolderInfo> lstFoldrs         = null;
                    string            sDestinationRoot  = string.Empty;
                    DirectoryInfo     di          = null;
                    string            sFolderName = string.Empty;
                    long lSizeOfFiles             = 0;

                    IBackup inBackup = (IBackup)Activator.CreateInstance(typeof(T));

                    lock (SettingsManager.Instance)
                    {
                        sDestinationRoot = SettingsManager.Instance.Settings.BackupDestinationRootPath;
                    }

                    lock (m_FI)
                    {
                        m_FI.LoadData();
                        lstFoldrs = m_FI.ValuesToList();
                    }

                    while (true)
                    {
                        if (Monitor.Wait(oStop, m_tsBackupperInterval) == true)
                        {
                            m_meBackupFunction.Set();

                            break;
                        }
                        else
                        {
                            string sFolderToDelete = string.Empty;

                            // if backup is running less the hours to run from settings then continue. Otherwise stop backup
                            if (SettingsManager.Instance.IsBackupRunningTooLong(dtStartBackupHour) == false)
                            {
                                if (lstFoldrs != null)
                                {
                                    foreach (FolderInfo fi in lstFoldrs)
                                    {
                                        if (fi.IsDeleted == true)
                                        {
                                            lock (m_FI)
                                            {
                                                m_FI.Remove(fi.FolderSourcePath);
                                            }

                                            di = new DirectoryInfo(fi.FolderSourcePath);

                                            fi.NumberOfFilesInSource = di.GetFiles("*", SearchOption.AllDirectories).Length;

                                            // if fi.FolderSourcePath = "C:\\" replace the folder name with empty string.
                                            // Otherwise Path.Combine(sDestinationRoot, "C:\\") will return "C:\\"
                                            sFolderName = (di.Root.FullName != di.Name) ? di.Name : string.Empty;

                                            sFolderToDelete = Path.Combine(sDestinationRoot, sFolderName);

                                            if (Directory.Exists(sFolderToDelete) == true)
                                            {
                                                Directory.Delete(sFolderToDelete, true);
                                            }
                                        }
                                        else
                                        {
                                            lSizeOfFiles += inBackup.BackupFolder(fi.FolderSourcePath, sDestinationRoot, dtStartBackupHour, m_meBackupFunction);
                                        }
                                    }

                                    lock (m_FI)
                                    {
                                        m_FI.SaveData();
                                    }
                                }
                            }
                            else
                            {
                                // the backup was running longer than defined by a user in the serrings
                                break;
                            }
                        }
                    }
                }
            }
            catch (Exception exp)
            {
                Logger.WriteErrorLogOnly(exp, "a4569866-14a5-411b-8bb9-f01a4412557f");
            }
            finally
            {
                m_tBackupper       = null;
                m_bIsBackupRunning = false;
            }
        }