Exemple #1
0
 protected override void OnPathRenamed(string p1, string p2)
 {
     lock (_contents) {
         if (_contents.Contains(p1))
         {
             _contents.Rename(p1, p2);
         }
     }
 }
Exemple #2
0
        /// <summary>
        /// Will process the report generated by the Compare methods by adding, removing and updating files to the <paramref name="destStore"/> file store.
        /// </summary>
        /// <param name="report">The report, generated by one of the Compare methods, to process.</param>
        /// <param name="sourcePath">The source directory to process.</param>
        /// <param name="destStore">The file store to process.</param>
        /// <param name="feedback">Provides a means to gather feedback from the mirroring process.</param>
        public static void MirrorSourceToDestination(
            IEnumerable <ICompareResult> report,
            string sourcePath,
            IFileStore destStore,
            Action <ICompareResult, double> feedback)
        {
            // **** initialize
            var total = (from x in report
                         where x.ItemType == CompareType.File &&
                         (x.Action == CompareAction.New || x.Action == CompareAction.Update || x.Action == CompareAction.Remove)
                         select x).Count();
            var count = 0;
            // **** save the original 'original filenames'
            var originalFilenames = ((IFileStoreAdvanced)destStore).GetOriginalFilenames();

            // **** delete REMOVE files from MIRROR
            foreach (var item in from x in report
                     where x.ItemType == CompareType.File && x.Action == CompareAction.Remove
                     select x)
            {
                if (feedback != null)
                {
                    feedback(item, (double)((double)count / (double)total));
                    ++count;
                }
                if (destStore.Contains(item.DestinationRootFilename))
                {
                    destStore.Delete(item.DestinationRootFilename);
                }
            }
            // **** add NEW and UPDATE files to SOURCE
            foreach (var item in from x in report
                     where x.ItemType == CompareType.File &&
                     (x.Action == CompareAction.New || x.Action == CompareAction.Update)
                     select x)
            {
                if (feedback != null)
                {
                    feedback(item, (double)((double)count / (double)total));
                    ++count;
                }
                destStore.Add(item.SourceRootFilename, item.SourceFullPath, item.SourceLastModifiedTimeUtc, item.SourceFileSizeInBytes);
            }
            // **** save store (finalize mirror process)
            feedback?.Invoke(null, 1);
            destStore.Save(false);
            // **** clear/restore the 'original filenames'
            ((IFileStoreAdvanced)destStore).ClearOriginalFilenames();
            ((IFileStoreAdvanced)destStore).SetOriginalFilenames(originalFilenames);
        }
Exemple #3
0
        /// <summary>
        /// Will process the report generated by the Compare methods by adding, removing and updating files to the <paramref name="destStore"/> file store.
        /// </summary>
        /// <param name="report">The report, generated by one of the Compare methods, to process.</param>
        /// <param name="sourceStore">The file store to process.</param>
        /// <param name="destStore">The file store to process.</param>
        /// <param name="feedback">Provides a means to gather feedback from the mirroring process.</param>
        public static void MirrorSourceToDestination(
            IEnumerable <ICompareResult> report,
            IFileStore sourceStore,
            IFileStore destStore,
            Action <ICompareResult, double> feedback)
        {
            // **** initialize
            var total = (from x in report
                         where x.ItemType == CompareType.File &&
                         (x.Action == CompareAction.New || x.Action == CompareAction.Update || x.Action == CompareAction.Remove)
                         select x).Count();
            var count = 0;
            // create temporary extraction folder
            var tempPath = CreateTemporaryDirectory();
            // temporarily change source extraction path
            var originalExtractionPath = sourceStore.ExtractionRootDirectory;

            sourceStore.ExtractionRootDirectory = tempPath;
            // save the original 'original filenames'
            var originalFilenames = ((IFileStoreAdvanced)destStore).GetOriginalFilenames();
            // **** extract NEW and UPDATE files from SOURCE to temporary extraction folder
            var list = new List <IFileStoreItem>();

            foreach (var item in from x in report
                     where x.ItemType == CompareType.File &&
                     (x.Action == CompareAction.New || x.Action == CompareAction.Update)
                     select x)
            {
                if (feedback != null)
                {
                    feedback(item, (double)((double)count / (double)total));
                    ++count;
                }
                if (sourceStore.Contains(item.SourceRootFilename))
                {
                    list.Add(sourceStore.Get(item.SourceRootFilename));
                }
            }
            sourceStore.Extract(list, true);
            // **** delete REMOVE files from MIRROR
            foreach (var item in from x in report
                     where x.ItemType == CompareType.File &&
                     x.Action == CompareAction.Remove
                     select x)
            {
                if (feedback != null)
                {
                    feedback(item, (double)((double)count / (double)total));
                    ++count;
                }
                if (destStore.Contains(item.DestinationRootFilename))
                {
                    destStore.Delete(item.DestinationRootFilename);
                }
            }
            // **** add/update NEW and UPDATE files, from temporary extraction folder, into MIRROR
            foreach (var item in list)
            {
                destStore.Add(item.RootFilename, item.ExtractedFilename, item.RootFileLastModifiedTimeUtc, item.FileSize);
            }
            // **** save store (finalize mirror process)
            destStore.Save(false);
            // **** clear/restore the 'original filenames'
            ((IFileStoreAdvanced)destStore).ClearOriginalFilenames();
            ((IFileStoreAdvanced)destStore).SetOriginalFilenames(originalFilenames);
            // **** restore original source extraction path
            sourceStore.ExtractionRootDirectory = originalExtractionPath;
            // **** delete temporary extraction folder
            DeleteDirectory(tempPath);
        }
Exemple #4
0
        /// <summary>
        /// Will process the report generated by the Compare methods by adding, removing and updating files to the <paramref name="destPath"/> directory.
        /// </summary>
        /// <param name="report">The report, generated by one of the Compare methods, to process.</param>
        /// <param name="sourceStore">The file store to process.</param>
        /// <param name="destPath">The destination directory to process.</param>
        /// <param name="feedback">Provides a means to gather feedback from the mirroring process.</param>
        public static void MirrorSourceToDestination(
            IEnumerable <ICompareResult> report,
            IFileStore sourceStore,
            string destPath,
            Action <ICompareResult, double> feedback)
        {
            // **** initialize
            var total = (from x in report
                         where x.ItemType == CompareType.File &&
                         (x.Action == CompareAction.New || x.Action == CompareAction.Update || x.Action == CompareAction.Remove)
                         select x).Count();
            var count = 0;

            // **** delete REMOVE files from MIRROR
            foreach (var item in from x in report
                     where x.ItemType == CompareType.File && x.Action == CompareAction.Remove
                     select x)
            {
                if (feedback != null)
                {
                    feedback(item, (double)((double)count / (double)total));
                    ++count;
                }
                if (System.IO.File.Exists(item.DestinationFullPath))
                {
                    var fInfo = new System.IO.FileInfo(item.DestinationFullPath);
                    if (fInfo.IsReadOnly)
                    {
                        System.IO.File.SetAttributes(item.DestinationFullPath, System.IO.FileAttributes.Normal);
                    }
                    System.IO.File.Delete(item.DestinationFullPath);
                }
            }
            // **** add/update NEW and UPDATE files into MIRROR
            foreach (var item in from x in report
                     where x.ItemType == CompareType.File &&
                     (x.Action == CompareAction.New || x.Action == CompareAction.Update)
                     select x)
            {
                if (feedback != null)
                {
                    feedback(item, (double)((double)count / (double)total));
                    ++count;
                }
                if (sourceStore.Contains(item.SourceRootFilename))
                {
                    CreateDirectory(System.IO.Path.GetDirectoryName(System.IO.Path.Combine(destPath, item.SourceRootFilename)));
                    sourceStore.Extract(destPath, new IFileStoreItem[] { sourceStore.Get(item.SourceRootFilename) }, true);
                }
            }
            // **** process NEW/REMOVE folders
            foreach (var item in from x in report
                     where x.ItemType == CompareType.Directory &&
                     (x.Action == CompareAction.New || x.Action == CompareAction.Remove)
                     orderby(x.SourceFullPath + x.DestinationFullPath) descending
                     select x)
            {
                if (item.Action == CompareAction.New)
                {
                    // NEW
                    if (!System.IO.Directory.Exists(item.SourceFullPath))
                    {
                        try
                        {
                            System.IO.Directory.CreateDirectory(item.SourceFullPath);
                        }
                        catch { }
                    }
                }
                else
                {
                    // REMOVE
                    if (System.IO.Directory.Exists(item.DestinationFullPath))
                    {
                        if (System.IO.Directory.GetFiles(item.DestinationFullPath).Length == 0)
                        {
                            DeleteDirectory(item.DestinationFullPath);
                        }
                        else
                        {
                            throw new FileStoreException((IFileStoreItem)null, string.Format("Directory not empty; cannot delete directory. Directory={0}", item.DestinationFullPath));
                        }
                    }
                }
            }
        }