Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="files"></param>
        /// <param name="token"></param>
        protected void RestoreInternal(IEnumerable <String> files, CancellationToken?token = null)
        {
            TotalSteps  = files.Count();
            CurrentStep = 0;

            foreach (var fileFullPath in files)
            {
                if (Backups.ContainsKey(fileFullPath))
                {
                    var fileBackupPath = Backups[fileFullPath];

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

                    CurrentStep++;
                }
            }

            CurrentStep = TotalSteps;
        }
Ejemplo n.º 2
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;
        }
        protected override void ExecuteInternal(CmdExecutionContext context, CancellationToken token)
        {
            InitializeProgress();

            String sourceFullPath = Path.Combine(context.InstallerTargetDirectory, Command.SourcePath);

            if (!File.Exists(sourceFullPath))
            {
                throw new CmdExecutionFailedException("A file given by the sourcePath doesn't exist.",
                                                      String.Format(Properties.Resources.CopyFileErrorParamMsg, Command.SourcePath));
            }

            String targetFullPath = Path.Combine(context.InstallerTargetDirectory, Command.TargetPath);

            if (!PathUtilities.IsValidPath(targetFullPath))
            {
                throw new CmdExecutionFailedException("A given targetPath is not a valid path.",
                                                      String.Format(Properties.Resources.CopyFileErrorParamMsg, Command.SourcePath));
            }

            PathUtilities.CreateDirectoryIfNotExist(Path.GetDirectoryName(targetFullPath));

            FileUtilities.CopyFileEx(sourceFullPath, targetFullPath, token);

            SetMaxProgress();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Restores all files, backuped by the service, to their orginal locations.
        /// </summary>
        /// <param name="token"></param>
        public void RestoreAll(CancellationToken token)
        {
            TotalSteps  = Backups.Count;
            CurrentStep = 0;

            foreach (var backup in Backups)
            {
                var fileOriginPath = backup.Key;
                var fileBackupPath = backup.Value;

                FileUtilities.CopyFileEx(fileBackupPath, fileOriginPath, token);

                CurrentStep++;
            }

            CurrentStep = TotalSteps;
        }
Ejemplo n.º 5
0
 public void CopyFileEx(string sourceFullPath, string targetFullPath)
 {
     FileUtilities.CreateDirectoryIfNotExist(Path.GetDirectoryName(targetFullPath));
     FileUtilities.CopyFileEx(sourceFullPath, targetFullPath, token);
 }