Ejemplo n.º 1
0
        private void SaveGridData()
        {
            try
            {
                if (this.dataGridView.Rows != null)
                {
                    foreach (DataGridViewRow row in this.dataGridView.Rows)
                    {
                        FolderInfo fi = new FolderInfo();

                        fi.FolderSourcePath                = (string)row.Cells["Folder"].Value;
                        fi.NumberOfSubFolderInSource       = (long)row.Cells["NumOfSubs"].Value;
                        fi.NumberOfSubFoldersInDestination = (long)row.Cells["NumSubFoldersInBackup"].Value;
                        fi.NumberOfFilesInSource           = (long)row.Cells["NumOfFiles"].Value;
                        fi.NumberOfSubFoldersInDestination = (long)row.Cells["NumFilesInBackup"].Value;
                        fi.SizeOfFolderInSource            = (long)row.Cells["SizeMb"].Value;
                        fi.SizeOfFolderInDestination       = (long)row.Cells["SizeInMbInBackup"].Value;
                        fi.IsDeleted = (bool)row.Cells["IsDeleted"].Value;

                        m_FI.Add(fi.GetUnitKey(), fi);
                    }

                    m_FI.SaveData();
                }
            }
            catch (Exception exp)
            {
                Logger.WriteErrorLogOnly(exp, "9723c66b-45b6-4a8a-b000-f27afd28f1c1");
                Logger.ShowErrorMessageBox(exp, "Failed to save folder list.");
            }
        }
Ejemplo n.º 2
0
        public void f1()
        {
            try
            {
                //SettingsConfigDict s = new SettingsConfigDict(InitSettingDictObjecForDebugModeSettingFileCreationDelegate);

                Settings _tSettings = null;

                _tSettings = new Settings();

                _tSettings.BackupDestinationRootPath = @"C:\Development";

                _tSettings.BackupTime = new DateTime(1, 1, 1, 5, 0, 0);

                _tSettings.BackupDays = (int)(enumWeekdays.Monday | enumWeekdays.Tuesday | enumWeekdays.Wednesday | enumWeekdays.Thursday | enumWeekdays.Friday);

                m_Settings.Add(_tSettings.GetUnitKey(), _tSettings);

                m_Settings.SaveData();

                // if(_tSettings.BackupDays & (int)enumWeekdays.Friday == (int)enumWeekdays.Friday)
                // if( _tSettings.BackupDays & (int)enumWeekdays.Friday > 0)

                FolderInfo fi = null;

                foreach (string path in Directory.GetDirectories(@"C:\Development"))
                {
                    fi = new FolderInfo();
                    fi.FolderSourcePath          = path;
                    fi.NumberOfFilesInSource     = Directory.GetFiles(path, "*.*", SearchOption.AllDirectories).Count();
                    fi.NumberOfSubFolderInSource = Directory.GetDirectories(path, "*", SearchOption.AllDirectories).Count();
                    m_FI.Add(fi.GetUnitKey(), fi);
                }

                m_FI.SaveData();
            }
            catch (Exception exp)
            {
                Logger.WriteError(exp, "cb720904-ae44-4536-9c72-e1d0828ef0bd");
            }
        }
Ejemplo n.º 3
0
        private void button_Save_Click(object sender, EventArgs e)
        {
            try
            {
                if (m_Settings == null)
                {
                    m_Settings = new Settings();
                }

                m_Settings.BackupDays |= (checkBoxMonday.Checked) ? (int)enumWeekdays.Monday : 0;
                m_Settings.BackupDays |= (checkBoxTuesday.Checked) ? (int)enumWeekdays.Tuesday : 0;
                m_Settings.BackupDays |= (checkBoxWednesday.Checked) ? (int)enumWeekdays.Wednesday : 0;
                m_Settings.BackupDays |= (checkBoxThursday.Checked) ? (int)enumWeekdays.Thursday : 0;
                m_Settings.BackupDays |= (checkBoxFriday.Checked) ? (int)enumWeekdays.Friday : 0;
                m_Settings.BackupDays |= (checkBoxSaturday.Checked) ? (int)enumWeekdays.Saturday : 0;
                m_Settings.BackupDays |= (checkBoxSunday.Checked) ? (int)enumWeekdays.Sunday : 0;

                m_Settings.BackupTime = dateTimePicker_BackupAt.Value;

                m_Settings.BackupDestinationRootPath = textBox_BackupRoot.Text;

                m_Settings.WatchFolders = checkBoxWatchFolders.Checked;

                m_Settings.RunBackupForNHours = (int)numericUpDown_RunForNHours.Value;

                m_dictSettings.Add(Settings.GetUnitKey(), m_Settings);


                m_dictSettings.SaveData();

                this.Close();
            }
            catch (Exception exp)
            {
                Logger.WriteErrorLogOnly(exp, "e59c96fd-58d0-421f-9be1-ca96641f12bd");

                Logger.ShowErrorMessageBox(exp, "Failed to save settings to file.");
            }
        }
Ejemplo n.º 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;
            }
        }