/// <summary> /// Push data from source to destination /// </summary> /// <param name="factory">Storage Factory</param> private static void Push(StorageFactory factory) { Parallel.ForEach<IStorageItem>(factory.Source(), (from, state) => { Trace.WriteLine(string.Format("Processing file: '{0}'.", from)); var to = factory.To(from); var exists = to.Exists(); if (!exists) { Trace.WriteLine(string.Format("Synchronizing new file: '{0}'.", from)); } if (!exists || to.MD5 != from.MD5 || to.MD5 == null) { to.Save(from, exists); Trace.WriteLine(string.Format("Synchronizing file: '{0}'.", from)); } else { Trace.WriteLine(string.Format("File '{0}' already exists at '{1}', synchronization avoided.", from.Path, to.Path)); } to = null; from = null; }); }
/// <summary> /// Push data from source to destination /// </summary> /// <param name="factory">Storage Factory</param> private static void Push(StorageFactory factory) { Parallel.ForEach <IStorageItem>(factory.Source(), (from, state) => { Trace.WriteLine(string.Format("Processing file: '{0}'.", from)); var to = factory.To(from); var exists = to.Exists(); if (!exists) { Trace.WriteLine(string.Format("Synchronizing new file: '{0}'.", from)); } if (!exists || to.MD5 != from.MD5 || to.MD5 == null) { to.Save(from, exists); Trace.WriteLine(string.Format("Synchronizing file: '{0}'.", from)); } else { Trace.WriteLine(string.Format("File '{0}' already exists at '{1}', synchronization avoided.", from.Path, to.Path)); } to = null; from = null; }); }
/// <summary> /// Delete items from destination /// </summary> /// <param name="factory">Storage Factory</param> private static void Delete(StorageFactory factory) { var items = new HashSet<string>(); foreach (var item in factory.Source()) { items.Add(item.RelativePath); } Parallel.ForEach<IStorageItem>(factory.Destination(), (item, state) => { if (!items.Contains(item.RelativePath)) { item.Delete(); } }); }
/// <summary> /// Delete items from destination /// </summary> /// <param name="factory">Storage Factory</param> private static void Delete(StorageFactory factory) { var items = new HashSet <string>(); foreach (var item in factory.Source()) { items.Add(item.RelativePath); } Parallel.ForEach <IStorageItem>(factory.Destination(), (item, state) => { if (!items.Contains(item.RelativePath)) { item.Delete(); } }); }