public void BackupFiles(object source, ExecutedRoutedEventArgs e)
        {
            // Get files from the DB that we know are ready to be backed up - zip them for storage
            List <string> filesToBackup = new List <string>();

            foreach (var file in fileBackupEntitesContext.FilesUpdatedOrAddeds)
            {
                filesToBackup.Add(file.FileFullNamePath);
            }
            string storageLocation = ZipFiles(filesToBackup);

            // Go through again and push the information (including storageLocation) to the database
            foreach (var file in fileBackupEntitesContext.FilesUpdatedOrAddeds)
            {
                string userLocalFileName = Path.GetFileName(file.FileFullNamePath);

                // See if this file has been backed up before & update the entry in the main section & create a new history log
                //FileBackupMain fileBackupEntry = new FileBackupMain();
                FileBackupMain fileBackupMain = fileBackupEntitesContext.FileBackupMains.FirstOrDefault(x => x.FileName == userLocalFileName);

                if (fileBackupMain == null)
                {
                    fileBackupMain          = new FileBackupMain();
                    fileBackupMain.FileName = userLocalFileName;
                    fileBackupMain.FileLastEditedDateTime = file.FileChangeDateTime;

                    fileBackupEntitesContext.FileBackupMains.Add(fileBackupMain);
                }


                // Create new history Log
                FileBackupHistory newBackupHistory = new FileBackupHistory();
                newBackupHistory.FileHistoryBackupDateTime = DateTime.Now;
                newBackupHistory.FileHistoryDescription    = "Test String For Now";
                newBackupHistory.FileHistoryEditedDateTime = file.FileChangeDateTime;
                newBackupHistory.FileHistoryOriginPath     = file.FileFullNamePath;
                newBackupHistory.FileHistoryUserName       = Environment.UserName;
                newBackupHistory.FileHistoryZipPathName    = storageLocation;
                fileBackupMain.FileBackupHistories.Add(newBackupHistory);
            }

            fileBackupEntitesContext.SaveChanges();
            // Remove files from the `potential to backup`  temporary database
            var objCtx = ((IObjectContextAdapter)fileBackupEntitesContext).ObjectContext;

            objCtx.ExecuteStoreCommand("TRUNCATE TABLE [FilesUpdatedOrAdded]");
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Change handler for the main listing of a backed up file --> Pushes all of its history to the history UI for viewing etc
        /// </summary>
        private void fileBackupMainDataGrid_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
        {
            FileBackupMain selectedFiles = fileBackupMainViewSource.View.CurrentItem as FileBackupMain;

            fileBackupMainFileBackupHistoriesViewSource = ((CollectionViewSource)(this.FindResource("fileBackupMainFileBackupHistoriesViewSource")));
        }