Example #1
0
        private void ActionDelete(FileExtended sourceFileExtended, FileExtended destFileExtended,
                                  Direction actionDirection)
        {
            FileExtended fileToDelete = null;

            switch (actionDirection)
            {
            case Direction.SourceToDestination:
                fileToDelete = destFileExtended;
                FileMappingFromCsv.Remove(destFileExtended);
                break;

            case Direction.DestinationToSource:
                fileToDelete = sourceFileExtended;
                FileMappingFromCsv.Remove(sourceFileExtended);
                break;
            }

            if (fileToDelete != null)
            {
                string pathForArchival = Path.Combine(SyncConfig.Parameters["ArchiveFolder"], DateTime.Now.ToString("yyyy-MM-dd"));
                string logFile         = SyncConfig.SyncLog;
                WorkingWithFiles.ArchiveFile(fileToDelete, logFile, pathForArchival, "deletion");
            }
        }
        private static void CleanupDuplicateFiles(List <FileExtended> duplFiles, FileType fileType,
                                                  SyncExecution syncExec)
        {
            var    currentStep   = 0;
            string syncLog       = syncExec.SyncConfig.SyncLog;
            string archiveFolder = syncExec.SyncConfig.Parameters["ArchiveFolder"];
            var    filesList     = fileType == FileType.Source ? syncExec.SourceFiles : syncExec.DestFiles;

            var duplValues = duplFiles
                             .Select(x => x.FileNameAndSize)
                             .Distinct()
                             .ToList();

            foreach (var v in duplValues)
            {
                var tempFiles = duplFiles.FindAll(x => x.FileNameAndSize == v);
                while (tempFiles.Count > 1)
                {
                    int lastInd  = tempFiles.Count - 1;
                    var lastFile = tempFiles[lastInd];

                    tempFiles.Remove(lastFile);
                    duplFiles.Remove(lastFile);
                    filesList.Remove(lastFile.fileID);
                    WorkingWithFiles.ArchiveFile(lastFile, syncLog, archiveFolder, "duplicate");
                    currentStep++;
                    Init.DisplayCompletionInfo("files processed",
                                               currentStep, duplFiles.Count - duplValues.Count + currentStep);
                }
            }
            Console.Write("\rDone.                                                                ");
        }