Пример #1
0
        void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            var copy_file = new CustomFileCopier("", "");

            var files = Directory.GetFiles(source, "*.*", SearchOption.AllDirectories);

            progressMax = files.Count();

            fileprogress = 0;

            //Now Create all of the directories
            foreach (string dirPath in Directory.GetDirectories(source, "*",
                                                                SearchOption.AllDirectories))
            {
                Directory.CreateDirectory(dirPath.Replace(source, destination));
            }

            //Copy all the files
            foreach (string newPath in Directory.GetFiles(source, "*.*",
                                                          SearchOption.AllDirectories))
            {
                copy_file.SourceFilePath = newPath;
                copy_file.DestFilePath   = newPath.Replace(source, destination);

                copy_file.Copy();

                fileprogress++;

                backgroundWorker.ReportProgress(fileprogress, newPath);
            }
        }
Пример #2
0
        private void Copy_Load(object sender, EventArgs e)
        {
            CustomFileCopier c = new CustomFileCopier(_source, _destination);

            c.OnProgressChanged += c_OnProgressChanged;
            c.OnComplete        += c_OnComplete;
            new Thread(c.Copy).Start();
        }
Пример #3
0
        private void CopyFile(StatusDetail statusDetail, string targetPath, Guid batchId)
        {
            bool copy    = false;
            var  status  = statusDetail.Status;
            bool updated = true;

            if (File.Exists(targetPath))
            {
                var decision =
                    DecisionManager.Instance.GetDecision <FileExistDialogDecision>(batchId);

                var choice = FileExistDialog.FileExistActionEnum.None;

                if (decision != null &&
                    ((FileExistDialog.FileExistActionEnum)decision.Choice & FileExistDialog.FileExistActionEnum.All) == FileExistDialog.FileExistActionEnum.All)
                {
                    choice = (FileExistDialog.FileExistActionEnum)decision.Choice;
                }
                else
                {
                    choice = GetDecisionFromMessageBox(statusDetail, targetPath);
                    DecisionManager.Instance.SaveDecision(new Decision(batchId, (int)choice));
                }


                if ((choice & FileExistDialog.FileExistActionEnum.Override) ==
                    FileExistDialog.FileExistActionEnum.Override)
                {
                    copy = true;
                    statusDetail.Status = StatusEnum.Synched;
                }
                else if ((choice & FileExistDialog.FileExistActionEnum.SkipButSynched) ==
                         FileExistDialog.FileExistActionEnum.SkipButSynched)
                {
                }
                else if (choice == FileExistDialog.FileExistActionEnum.None)
                {
                    return;
                }
                else
                {
                    updated = false;
                }

                log.Debug($"Conflict with the target file: '{targetPath}' - Source : '{statusDetail.SourceFile}' - Copy: {copy} - New status: {status}");
            }
            else //No conflicts
            {
                copy = true;
            }

            if (copy)
            {
                string directory = Path.GetDirectoryName(targetPath);
                CreateDirectory(new DirectoryInfo(directory));

                log.Info($"Copying from: '{statusDetail.SourceFile}' to '{targetPath}'");
                var fileCopier = new CustomFileCopier(statusDetail.SourceFile, targetPath, this);
                fileCopier.OnProgressChanged += (double persentage, ref bool cancel) =>
                {
                    IncrementProgress(10 + (int)((persentage / 100) * 90)); //10% for the name the rest for the copy
                };
                fileCopier.Copy();
                log.Info("File copied");
            }

            if (updated)
            {
                statusDetail.DestinationFile = targetPath;
                statusDetail.SynchDate       = DateTime.Now;
                statusDetail.Status          = StatusEnum.Synched;
            }
        }