Beispiel #1
0
        public BindingList <BackupItem> ReadBackupItems()
        {
            BindingList <BackupItem> items = new BindingList <BackupItem>();

            using (SqlConnection conn = new SqlConnection(_connString))
            {
                conn.Open();
                string query = "SELECT * FROM BackupItems (NOLOCK) WHERE IsDeleted = 0 ORDER BY SourcePath";
                using (SqlCommand cmd = new SqlCommand(query, conn))
                {
                    cmd.CommandType = CommandType.Text;
                    SqlDataReader reader = cmd.ExecuteReader();
                    while (reader.Read())
                    {
                        BackupItem item = new BackupItem();
                        item.BackupItemId = int.Parse(reader["BackupItemID"].ToString());
                        item.Name         = reader["Name"].ToString();
                        item.SourcePath   = reader["SourcePath"].ToString();
                        item.TargetPath   = reader["TargetPath"].ToString();
                        item.Status       = "LOADING...";
                        items.Add(item);
                    }
                    reader.Close();
                }
            }

            return(items);
        }
Beispiel #2
0
        //private void InitializeFrequencyList()
        //{
        //    RefreshFrequencyList = new List<string>();
        //    RefreshFrequencyList.Add("Never");
        //    RefreshFrequencyList.Add("30s");
        //    RefreshFrequencyList.Add("60s");
        //    RefreshFrequencyList.Add("15m");
        //    RefreshFrequencyList.Add("30m");
        //    RefreshFrequencyList.Add("60m");
        //    RefreshFrequencyList.Add("2h");
        //    RefreshFrequencyList.Add("4h");
        //    RefreshFrequencyList.Add("12h");
        //    RefreshFrequencyList.Add("24h");
        //    RefreshFrequencyList.Add("2d");
        //    RefreshFrequencyList.Add("3d");

        //    RefreshFrequency = "30s";
        //}


        private void UpdateItemStatus(BackupItem item)
        {
            //item.OriginalSourceDirText = GetFolderContents(item.SourcePath);
            //item.NewSourceDirText = GetFolderContents(item.TargetPath);
            //if (item.OriginalSourceDirText.Equals(item.NewSourceDirText))
            //{
            //    item.Status = "SAME";
            //}
            //else
            //{
            //    item.Status = "DIFFERENT";
            //}
            int sourceFileCount = GetFolderFileCount(item.SourcePath);
            int targetFileCount = GetFolderFileCount(item.TargetPath);

            if (sourceFileCount > targetFileCount)
            {
                item.Status = STATUS_NEEDSUPDATE_FILECOUNT;
            }
            else
            {
                DateTime sourceUpdatedDate = GetFolderMostRecentDate(item.SourcePath);
                DateTime targetUpdatedDate = GetFolderMostRecentDate(item.TargetPath);
                if (sourceUpdatedDate > targetUpdatedDate)
                {
                    item.Status = STATUS_NEEDSUPDATE_DATE;
                }
                else
                {
                    item.Status = STATUS_OK;
                }
            }
        }
Beispiel #3
0
        private void CopyFilesBackground(object sender, DoWorkEventArgs e)
        {
            BackupItem item = (BackupItem)e.Argument;

            item.Note = CopyFiles(item.SourcePath, item.TargetPath);
            UpdateItemStatus(item);
        }
Beispiel #4
0
 public void CreateBackupItem(BackupItem newItem)
 {
     using (SqlConnection conn = new SqlConnection(_connString))
     {
         conn.Open();
         string query = "INSERT BackupItems (Name, SourcePath, TargetPath) ";
         query += " VALUES ('";
         query += newItem.Name;
         query += "', '";
         query += newItem.SourcePath;
         query += "', '";
         query += newItem.TargetPath;
         query += "')";
         using (SqlCommand cmd = new SqlCommand(query, conn))
         {
             cmd.CommandType = CommandType.Text;
             cmd.ExecuteNonQuery();
         }
     }
 }
Beispiel #5
0
        private void CopyFiles(BackupItem item)
        {
            //if (_bgCopyFiles.IsBusy)
            //{
            //    StatusText = "Worker is busy. Try again later";
            //}
            //else
            //{
            //    item.Status = STATUS_BACKINGUP;
            //    //item.Note = CopyFiles(item.SourcePath, item.TargetPath, commandOptions);
            //    //UpdateItemStatus(item);
            //    _bgCopyFiles.RunWorkerAsync(item);
            //}
            var bgCopyFiles = new BackgroundWorker();

            bgCopyFiles.DoWork             += CopyFilesBackground;
            bgCopyFiles.RunWorkerCompleted += UpdateBackgroundWorkerStatus;
            _bgCopyFiles.Add(bgCopyFiles);
            StatusText  = String.Format("Working on files for {0} folders", _bgCopyFiles.Count);
            item.Status = STATUS_BACKINGUP;
            bgCopyFiles.RunWorkerAsync(item);
        }