Пример #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="files"></param>
        /// <param name="token"></param>
        protected void BackupInternal(IEnumerable <String> files, CancellationToken?token = null)
        {
            TotalSteps  = files.Count();
            CurrentStep = 0;

            foreach (var fileFullPath in files)
            {
                if (!Backups.ContainsKey(fileFullPath))
                {
                    var backupDirPath = TryGetBackupDirForFile(fileFullPath);
                    if (backupDirPath == null)
                    {
                        backupDirPath = CreateBackupDirForFile(fileFullPath);
                        BackupDirectories.Add(backupDirPath);
                    }
                    var fileBackupPath = Path.Combine(backupDirPath, Path.GetRandomFileName());

                    if (token.HasValue)
                    {
                        FileUtilities.CopyFileEx(fileFullPath, fileBackupPath, token.Value);
                    }
                    else
                    {
                        FileUtilities.CopyFileEx(fileFullPath, fileBackupPath);
                    }

                    // Zastnowić się nad tym czy kolejność danych w słowniku jest dobra (w sensie klucz\wartość)
                    Backups.Add(fileFullPath, fileBackupPath);
                }

                CurrentStep++;
            }

            CurrentStep = TotalSteps;
        }
Пример #2
0
        /// <summary>
        /// Method that will generage and save the configuration file for all the backups
        /// </summary>
        /// <param name="filename">File name of the backup</param>
        private void SerializeCollection(string filename)
        {
            _logger.Info("Save backup in the configuration file : " + filename);

            // Create the collection of backups
            Backups backups = new Backups();

            // Name te collection
            backups.CollectionName = "Backups";

            // Add the value to the collection from the existing backup list
            foreach (var backup in _mainProcess.backupList)
            {
                backups.Add(backup);
            }

            // Initiate a Serializer
            XmlSerializer x = new XmlSerializer(typeof(Backups));

            // Initiate a stream writer
            TextWriter writer = new StreamWriter(filename);

            // Serialise the collection and print it into the file
            x.Serialize(writer, backups);

            // Close the file
            writer.Close();
        }
Пример #3
0
 /// <summary>
 ///     Add a backup file if it doesn't exist
 /// </summary>
 /// <param name="backupFile"></param>
 public void AddBackUp(BackUpFile backupFile)
 {
     if (!ExistBackUp(backupFile))
     {
         Backups.Add(backupFile);
     }
 }
Пример #4
0
 public void AddBackup(string filePath, string backupPath, StorageType storageType)
 {
     if (!File.Exists(filePath))
     {
         BackupLogger.GetInstance().Error($"Cannot add backup for the file {filePath}." +
                                          $" File {filePath} does not exist.");
         return;
     }
     Backups.Add(new Backup(filePath, backupPath, storageType));
     BackupLogger.GetInstance().Info($"Backup for the file {filePath} was added to the current backup system.");
 }
Пример #5
0
        private async Task GetFiles()
        {
            var folder = await StorageFolder.GetFolderFromPathAsync(UserDataPaths.GetDefault().Music);

            StorageFolder assets = await folder.GetFolderAsync("Backups");

            Backups.Clear();
            var files = await assets.GetFilesAsync();

            foreach (var fileToAdd in files)
            {
                Backups.Add(fileToAdd);
            }
        }
Пример #6
0
        public bool AddBackupToXml(BackupDefenition bs)
        {
            if (bs == null)
            {
                return(false);
            }
            if (Backups.ContainsKey(bs.Name))
            {
                MetroMessageBox.Show(Application.OpenForms[0],
                                     "Couldn't save backup! You already defined another backup with this name:" + bs.Name,
                                     "Couldn't save backup", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(false);
            }
            if (string.IsNullOrEmpty(bs.Name))
            {
                MetroMessageBox.Show(Application.OpenForms[0],
                                     "Couldn't save backup! You didn't enter a name for this backup!",
                                     "Couldn't save backup", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(false);
            }
            try
            {
                string content = "<backup name=\"" + bs.Name + "\">" +
                                 "	<folders>"+ StringUtil.ListToCsv(bs.Folders, ';') + "</folders>" +
                                 "	<destination>"+ bs.TargetDirectory + "</destination>" +
                                 "	<compression>"+ bs.Compression.ToString().ToLower() + "</compression>" +
                                 "</backup>";
                _backupXml.FirstChild.InnerXml += content;

                _backupXml.Save(_backupXmlPath);

                Backups.Add(bs.Name, bs);
                if (BackupsLoaded != null)
                {
                    BackupsLoaded();
                }
            }
            catch (Exception ex)
            {
                Logger.Log(LogLevel.Severe, "Backupmanager", "Severe error in addBackup! " + ex.Message);
                return(false);
            }
            return(true);
        }
 /// <summary>
 /// Initialize the ViewModel to examine the specified device backup directory.
 /// </summary>
 /// <param name="deviceBackupDirectory">Device backup directory.</param>
 /// <param name="backupFileName">The name of the backup file used to populate the dialog.</param>
 /// <param name="fileExtensions">An enumerable of file extensions used to count how many items will be restored by a  backup, if <paramref name="showItemsCount"/> is <c>true</c>.</param>
 /// <param name="showItemsCount">If <c>true</c>, the 'Number of Items' column will be displayed.</param>
 internal void Initialize(string deviceBackupDirectory, string backupFileName, IEnumerable <string> fileExtensions, bool showItemsCount)
 {
     SelectedIndex  = -1;
     ShowItemsCount = showItemsCount;
     if (System.IO.Directory.Exists(deviceBackupDirectory))
     {
         var backupDirectories = System.IO.Directory.EnumerateDirectories(deviceBackupDirectory);
         foreach (var backupDirectory in backupDirectories)
         {
             if (System.IO.File.Exists(System.IO.Path.Combine(backupDirectory, backupFileName)))
             {
                 try
                 {
                     Backups.Add(new BackupInfoViewModel(backupDirectory, fileExtensions));
                 }
                 catch (System.ArgumentOutOfRangeException)
                 {
                     // Ignore out-of-range or ill-formatted entries
                 }
             }
         }
     }
 }