예제 #1
0
        private void copyWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            var worker = sender as BackgroundWorker;

            this.CopyInProgress = true;
            worker.ReportProgress(0);

            var directories = Directory.GetDirectories(source, "*", System.IO.SearchOption.AllDirectories);
            var files       = Directory.GetFiles(source, "*.*", System.IO.SearchOption.AllDirectories);
            var total       = directories.Length + files.Length;
            int complete    = 0;

            foreach (string dir in directories)
            {
                if (!ExcludedDirectories.Contains(dir))
                {
                    Directory.CreateDirectory(destination + dir.Substring(source.Length));
                }
                complete++;
                worker.ReportProgress(CalculateProgress(total, complete));
            }

            foreach (string file_name in files)
            {
                if (!File.Exists(Path.Combine(destination + file_name.Substring(source.Length))))
                {
                    File.Copy(file_name, destination + file_name.Substring(source.Length));
                }
                complete++;
                worker.ReportProgress(CalculateProgress(total, complete));
            }
        }
예제 #2
0
        private void ProcessDestinationDirectoryForPossibleDelete(DirectoryInfo di)
        {
            //Get the source directory
            string srcDirectory = SourceDirectory + di.FullName.Substring(DestinationDirectory.Length);
            var    srcDir       = new DirectoryInfo(srcDirectory);

            try
            {
                //Delete the destination directory if it doesn't exist at the source
                // or if the directory is in the ignore list but is present at the destination
                if (!Directory.Exists(srcDirectory) ||
                    ExcludedDirectories.Contains(srcDirectory))
                {
                    try
                    {
                        ActionQueue.Enqueue(new DeleteFolderAction(di.FullName));
                        OnActionAddedToQueue(new EventArgs());
                    }
                    catch (Exception ex)
                    {
                        _log.ErrorFormat("ProcessDestinationDirectoryForPossibleDelete: {0} {1}", di.FullName, ex.Message);
                    }
                }
                else
                {
                    foreach (FileInfo fi in di.GetFiles("*.*", SearchOption.TopDirectoryOnly))
                    {
                        string srcPath = srcDir + "\\" + fi.Name;
                        try
                        {
                            Debug.WriteLine(di.FullName);

                            //Delete the destination file if it doesn't exist at the source
                            if (!File.Exists(srcPath))
                            {
                                ActionQueue.Enqueue(new DeleteFileAction(fi.FullName));
                                OnActionAddedToQueue(new EventArgs());
                            }
                        }
                        catch (Exception ex)
                        {
                            _log.ErrorFormat("ProcessDestinationDirectoryForPossibleDelete: {0} {1}", di.FullName, ex.Message);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _log.ErrorFormat("ProcessDestinationDirectoryForPossibleDelete: {0} {1}", di.FullName, ex.Message);
            }
        }
예제 #3
0
        static void Rename(DirectoryInfo root, string projectName)
        {
            var directories = root.GetDirectories();

            RenameFiles(root, projectName);
            foreach (DirectoryInfo dir in directories)
            {
                // Recurse into sub-directories if not excluded
                if (!ExcludedDirectories.Contains(dir.Name))
                {
                    Rename(dir, projectName);
                }
            }
            RenameFolders(root, projectName);
        }
예제 #4
0
 public bool Equals(EngineSettings other) =>
 other != null &&
 BasePath == other.BasePath &&
 ExcludedDirectories.OrderBy(e => e).SequenceEqual(
     other.ExcludedDirectories.OrderBy(e => e)) &&
 FileExtensions.OrderBy(e => e).SequenceEqual(
     other.FileExtensions.OrderBy(e => e)) &&
 Recursive == other.Recursive &&
 DifferenceType == other.DifferenceType &&
 MaxDurationDifferenceSeconds
 == other.MaxDurationDifferenceSeconds &&
 MaxDurationDifferencePercent
 == other.MaxDurationDifferencePercent &&
 MaxImageCompares == other.MaxImageCompares &&
 MaxDifferentImages == other.MaxDifferentImages &&
 MaxImageDifferencePercent == other.MaxImageDifferencePercent;
예제 #5
0
        /// <summary>
        /// Method to invoke when the AddBackupSet command is executed.
        /// </summary>
        private void OnExcludeDirectoriesExecute()
        {
            //// Note that we use the type factory here because it will automatically take care of any dependencies
            //// that the BackupSetViewModel will add in the future
            var typeFactory            = this.GetTypeFactory();
            var excludedFilesViewModel = typeFactory.CreateInstanceWithParametersAndAutoCompletion <ExcludedDirectoriesViewModel>(BackupSet);

            if (_uiVisualizerService.ShowDialog(excludedFilesViewModel) ?? false)
            {
                ExcludedDirectories.Clear();
                foreach (var ed in excludedFilesViewModel.GetExcludedDirectories(excludedFilesViewModel.Items[0]))//..ExcludedDirectories;
                {
                    ExcludedDirectories.Add(ed.FullPath);
                }
            }
        }
예제 #6
0
        /// <summary>
        /// Reads a text file encoded like below:
        /// 1:path
        /// 2:username
        /// 3:password
        /// 4:local-path
        /// 4: ...
        /// 4: local-path
        /// 5: excluded-path
        /// 5: ...
        /// </summary>
        /// <param name="file"></param>
        private void ReadSettings(String file)
        {
            BackupDirectories.Clear();
            if (!File.Exists(file))
            {
                return;
            }
            String line = String.Empty;

            using (StreamReader sr = new StreamReader(file))
            {
                while ((line = sr.ReadLine()) != null && !String.IsNullOrEmpty(line.Trim()))
                {
                    if (line.StartsWith("1:"))
                    {
                        TextBoxPath.Text = line.Substring(2);
                    }
                    else if (line.StartsWith("2:"))
                    {
                        TextBoxUsername.Text = line.Substring(2);
                    }
                    else if (line.StartsWith("3:"))
                    {
                        TextBoxPassword.Text = line.Substring(2);
                    }
                    else if (line.StartsWith("4:"))
                    {
                        BackupDirectories.Add(line.Substring(2));
                    }
                    else if (line.StartsWith("5:"))
                    {
                        ExcludedDirectories.Add(line.Substring(2));
                    }
                    else
                    {
                        throw new Exception(line);
                    }
                }
                sr.Close();
            }
        }
예제 #7
0
        static void RenameFolders(DirectoryInfo root, string projectName)
        {
            var directories = root.GetDirectories();

            foreach (DirectoryInfo dir in directories)
            {
                // Rename if matches and is not exluced
                if (dir.Name.Contains(TemplateName) && !ExcludedDirectories.Contains(dir.Name))
                {
                    var path    = dir.Parent.FullName;
                    var newName = Path.Combine(path, dir.Name.Replace(TemplateName, projectName));
                    Console.WriteLine("Renaming " + newName);
                    try
                    {
                        Directory.Move(dir.FullName, newName);
                    } catch (Exception ex)
                    {
                        Console.WriteLine("FAILED: Could not rename " + dir.FullName + ". "
                                          + ex.Message);
                    }
                }
            }
        }
예제 #8
0
        private void BuildActionQueue()
        {
            _log.Info("Building Action Queue");
            ProcessingStatus = BackupProcessingStatus.BuildingActionQueue;
            //Clear the action Queues
            ActionQueue.Clear();
            SkipFileActionQueue.Clear();
            DeleteActionStack.Clear();

            if (_cancelToken.IsCancellationRequested)
            {
                _log.Info("Building Action Queue Cancelled");
                ProcessingStatus = BackupProcessingStatus.Cancelled;
                return;
            }

            if (CheckDriveExists(SourceDirectory.Substring(0, 1)) &&
                CheckSourceRootExists() &&
                CheckDriveExists(DestinationDirectory.Substring(0, 1)))
            {
                if (BackupMode == BackupSetMode.Backup && RemoveDeleted)
                {
                    List <DirectoryInfo> destDirs = IOHelper.GetDirectoriesPostOrder(DestinationDirectory);
                    if (destDirs != null)
                    {
                        foreach (DirectoryInfo di in destDirs)
                        {
                            if (_cancelToken.IsCancellationRequested)
                            {
                                ProcessingStatus = BackupProcessingStatus.Cancelled;
                                return;
                            }
                            ProcessDestinationDirectoryForPossibleDelete(di);
                        }
                    }
                }

                var dirs = IOHelper.GetDirectories(SourceDirectory);
                if (dirs != null)
                {
                    foreach (DirectoryInfo di in dirs)
                    {
                        //Check if the directory should be excluded
                        if (ExcludedDirectories == null || !ExcludedDirectories.Contains(di.FullName))
                        {
                            if (_cancelToken.IsCancellationRequested)
                            {
                                ProcessingStatus = BackupProcessingStatus.Cancelled;
                                return;
                            }
                            ProcessDirectoryForActions(di);
                        }
                        else
                        {
                            IOHelper.GetFiles(di.FullName)
                            .ForEach(fi => SkipFileActionQueue.Enqueue(new SkipFileAction(fi.FullName)));
                        }
                    }
                }
            }
            _log.Info("Finished Building Action Queue");
            ProcessingStatus = BackupProcessingStatus.ActionQueueBuilt;
        }