Exemplo n.º 1
0
        public void UpdateDestination(bool deleteSource = false)
        {
            var ignoreFiles = CheckSourceForDuplicates();

            foreach (var destination in _filesByDestination)
            {
                _filesUtility.EmptyDirectory(destination.Key);
                foreach (var copyFile in destination.Value)
                {
                    if (!ignoreFiles.Contains(copyFile.File))
                    {
                        if (deleteSource)
                        {
                            _filesUtility.SafeMoveFile(copyFile.File, copyFile.Target);
                        }
                        else
                        {
                            _filesUtility.SafeCopyFile(copyFile.File, copyFile.Target);
                        }
                    }
                    else
                    {
                        if (deleteSource)
                        {
                            _filesUtility.SafeDeleteFile(copyFile.File);
                        }
                    }
                }
            }
            _filesByDestination.Clear();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Moves only the successfully generated file groups to the cache folder, otherwise keeps the old cached files.
        /// Deletes all generated files.
        /// </summary>
        public void MoveGeneratedFilesToCache()
        {
            // Group files by name without extension:

            var generatedFiles = _filesUtility.SafeGetFiles(Paths.GeneratedFolder, "*", SearchOption.AllDirectories)
                                 .GroupBy(file => Path.GetFileNameWithoutExtension(file))
                                 .ToDictionary(g => g.Key, g => g.ToList());

            var oldFiles = ListCachedFiles();

            // Move the successfully generated file groups to the cache, delete the others:

            var succesfullyGeneratedGroups = generatedFiles.Keys
                                             .Where(key => !oldFiles.ContainsKey(key) || generatedFiles[key].Count() >= oldFiles[key].Count())
                                             .ToList();

            foreach (string moveGroup in succesfullyGeneratedGroups)
            {
                foreach (string moveFile in generatedFiles[moveGroup])
                {
                    _syncer.AddFile(moveFile, Path.Combine(Paths.GeneratedFilesCacheFolder, moveGroup));
                }
            }
            _syncer.UpdateDestination(deleteSource: true);

            foreach (string deleteGroup in generatedFiles.Keys.Except(succesfullyGeneratedGroups))
            {
                foreach (string deleteFile in generatedFiles[deleteGroup])
                {
                    _filesUtility.SafeDeleteFile(deleteFile);
                }
            }
        }
Exemplo n.º 3
0
        /// <param name="deleteSource">Deleting the source files might improve performance because it moves the files instead of copying them.</param>
        public void UpdateDestination(bool deleteSource = false)
        {
            var sw = Stopwatch.StartNew();

            int countDestination = 0;
            int countMoved       = 0;
            int countCopied      = 0;
            int countDeleted     = 0;

            var ignoreFiles = CheckSourceForDuplicates();

            foreach (var destination in _filesByDestination)
            {
                _filesUtility.EmptyDirectory(destination.Key);
                countDestination++;

                foreach (var copyFile in destination.Value)
                {
                    if (!ignoreFiles.Contains(copyFile.File))
                    {
                        if (deleteSource)
                        {
                            _filesUtility.SafeMoveFile(copyFile.File, copyFile.Target);
                            countMoved++;
                        }
                        else
                        {
                            _filesUtility.SafeCopyFile(copyFile.File, copyFile.Target);
                            countCopied++;
                        }
                    }
                    else
                    {
                        if (deleteSource)
                        {
                            _filesUtility.SafeDeleteFile(copyFile.File);
                            countDeleted++;
                        }
                    }
                }
            }
            _filesByDestination.Clear();

            var report = new StringBuilder(100);

            report.Append("UpdateDestination ").Append(countDestination).Append(" destinations");
            if (countMoved > 0)
            {
                report.Append($", {countMoved} moved");
            }
            if (countCopied > 0)
            {
                report.Append($", {countCopied} copied");
            }
            if (countDeleted > 0)
            {
                report.Append($", {countDeleted} deleted");
            }
            report.Append(".");

            _performanceLogger.Write(sw, () => report.ToString());
        }