/// <summary> /// create SyncElementInfo /// </summary> /// <param name="syncInfo">synchronisation info</param> /// <param name="elementInfo">element info</param> /// <param name="initStatus">if true: SyncStatus is set to ElementFound</param> public SyncElementInfo(SyncInfo syncInfo, MyElementInfo elementInfo, bool initStatus) { SyncInfo = syncInfo; ElementInfo = elementInfo; ElementInfo.SyncElementInfo = this; if (initStatus) SyncStatus = SyncElementStatus.ElementFound; }
/// <summary> /// resume synchronisation /// </summary> public void ResumeSync() { if (!IsRunning) { return; } SyncTask.Resume(); SyncInfo.SyncContinued(); }
/// <summary> /// pause synchronisation /// </summary> public void PauseSync() { if (!IsRunning) { return; } SyncTask.Pause(); SyncInfo.SyncPaused(); }
/// <summary> /// detect files and directories that should be removed for One-Way synchronisation recursively /// </summary> /// <param name="sourceHomePath">absolute source folder path (homepath as defined in link)</param> /// <param name="destHomePath">absolute destination folder path (homepath as defined in link)</param> /// <param name="dir">the directory, in which you want to search</param> /// <param name="interruptChecker">is called when the cancellation or pause request should be checked in order to handel them</param> /// <returns>true if the operation was canceled</returns> public static void GetRemoveInfosOfDirRecursively_OneWay(string sourceHomePath, string destHomePath, MyDirInfo dir, SyncInfo si, Func <bool> interruptChecker) { interruptChecker(); string sourcePath = sourceHomePath + dir.FullPath; string destPath = destHomePath + dir.FullPath; try { //get directories to remove //detect destination child directories foreach (string name in Delimon.Win32.IO.Directory.GetDirectories(destPath)) { string newDirname = Delimon.Win32.IO.Path.GetFileName(name); MyDirInfo newDir = new MyDirInfo(dir.FullPath, newDirname); //remove destination directory if source directory doesn't exist (if remove is enabled) if (si.Link.Remove && !new Delimon.Win32.IO.DirectoryInfo(newDir.FullPath).Exists) { new SyncDirInfo(si, newDir, true); new SyncDirExecutionInfo(newDir.SyncDirInfo, si.Link.Direction, true); } GetRemoveInfosOfDirRecursively_OneWay(sourceHomePath, destHomePath, newDir, si, interruptChecker); } //get files to remove //Loop through all files in destination directory foreach (string path in Delimon.Win32.IO.Directory.GetFiles(destPath)) { string name = Delimon.Win32.IO.Path.GetFileName(path); MyFileInfo file = new MyFileInfo(dir.FullPath, name); string sourceFilePath = sourceHomePath + file.FullPath; string destFilePath = destHomePath + file.FullPath; //remove destination file if source file doesn't exist (if remove is enabled) if (!new Delimon.Win32.IO.FileInfo(sourceFilePath).Exists) { new SyncFileInfo(si, file, true); if (si.Link.Remove) { file.Size = new Delimon.Win32.IO.FileInfo(destFilePath).Length; new SyncFileExecutionInfo(file.SyncFileInfo, si.Link.Direction, true); } } } } catch (Exception e) { si.Log(new LogMessage(LogType.ERROR, e.Message, e)); } }
/// <summary> /// create SyncElementInfo /// </summary> /// <param name="syncInfo">synchronisation info</param> /// <param name="elementInfo">element info</param> /// <param name="initStatus">if true: SyncStatus is set to ElementFound</param> public SyncElementInfo(SyncInfo syncInfo, MyElementInfo elementInfo, bool initStatus) { SyncInfo = syncInfo; ElementInfo = elementInfo; ElementInfo.SyncElementInfo = this; if (initStatus) { SyncStatus = SyncElementStatus.ElementFound; } }
/// <summary> /// cancel synchronisation /// </summary> public void CancelSync() { if (!IsRunning) { return; } SyncTask.Cancel(); SyncInfo.SyncCancelled(); SyncTask = null; }
/// <summary> /// execute synchronisation, set listener before /// </summary> /// <param name="syncListener">listener or null if no listener should be set</param> public void Sync(ISyncListener syncListener) { SyncInfo = new SyncInfo(this); if (syncListener != null) { SyncInfo.SetListener(syncListener); } SyncTask = new SyncTask2(SyncInfo); SyncTask.Execute(); }
/// <summary> /// fetch files and detect subdirectory changes for One-Way synchronisation recursively /// </summary> /// <param name="sourceHomePath">absolute source folder path (homepath as defined in link)</param> /// <param name="destHomePath">absolute destination folder path (homepath as defined in link)</param> /// <param name="dir">the directory, in which you want to search</param> /// <param name="si">sync info</param> /// <param name="onFileFound">is called when a file was found</param> /// <param name="interruptChecker">is called when the cancellation or pause request should be checked in order to handel them</param> public static void FetchFilesInDirRecursively_OneWay(string sourceHomePath, string destHomePath, MyDirInfo dir, SyncInfo si, Action <SyncFileInfo> onFileFound, Func <bool> interruptChecker) { interruptChecker(); string sourcePath = sourceHomePath + dir.FullPath; string destPath = destHomePath + dir.FullPath; try { //create destination directory if not exists if (dir.SyncDirInfo != null && !new Delimon.Win32.IO.DirectoryInfo(destPath).Exists) { new SyncDirExecutionInfo(dir.SyncDirInfo, si.Link.Direction, false); } //detect source child directories foreach (string dirpath in Delimon.Win32.IO.Directory.GetDirectories(sourcePath)) { string name = Delimon.Win32.IO.Path.GetFileName(dirpath); MyDirInfo newDir = new MyDirInfo(dir.FullPath, name); new SyncDirInfo(si, newDir, true); FetchFilesInDirRecursively_OneWay(sourceHomePath, destHomePath, newDir, si, onFileFound, interruptChecker); } //loop through all files in source directory foreach (string filepath in Delimon.Win32.IO.Directory.GetFiles(sourcePath)) { //detect changes of file asynchronously string name = Delimon.Win32.IO.Path.GetFileName(filepath); MyFileInfo file = new MyFileInfo(dir.FullPath, name); new SyncFileInfo(si, file, true); onFileFound(file.SyncFileInfo); } } catch (OperationCanceledException) { } catch (Exception e) { si.Log(new LogMessage(LogType.ERROR, e.Message, e)); } }
/// <summary> /// create SyncService2 (call ExecuteSync to execute synchronisation) /// </summary> /// <param name="si">sync-info</param> public SyncService2(SyncInfo si) { _si = si; }
/// <summary> /// create SyncTask for running a synchronisation /// </summary> /// <param name="l"></param> public SyncTask(SyncInfo si) { _si = si; }
public DirsInfo(SyncInfo si) { _si = si; }
/// <summary> /// create SyncService /// </summary> /// <param name="si">information provider: will be updated while synchronisation is running</param> public AsyncSyncService(SyncInfo si) { _si = si; }
public SyncDirInfo(SyncInfo syncInfo, MyDirInfo dirInfo, bool initStatus) : base(syncInfo, dirInfo, initStatus) { }
public SyncFileInfo(SyncInfo syncInfo, MyFileInfo fileInfo, bool initStatus) : base(syncInfo, fileInfo, initStatus) { }
/// <summary> /// fetch files and subdirectories for Two-Way synchronisation recursively /// </summary> /// <param name="dir">the directory, in which you want to search</param> /// <param name="si">sync info</param> /// <param name="onFileFound">is called when a file was found</param> /// <param name="interruptChecker">is called when the cancellation or pause request should be checked in order to handel them</param> public static void FetchElementsInDirRecursively_TwoWay(MyDirInfo dir, SyncInfo si, Action <SyncFileInfo> onFileFound, Func <bool> interruptChecker) { interruptChecker(); string path1 = si.Link.Path1 + dir.FullPath; string path2 = si.Link.Path2 + dir.FullPath; //directory info Delimon.Win32.IO.DirectoryInfo di1 = new Delimon.Win32.IO.DirectoryInfo(path1); Delimon.Win32.IO.DirectoryInfo di2 = new Delimon.Win32.IO.DirectoryInfo(path2); List <string> dirNames = new List <string>(); List <string> fileNames = new List <string>(); try { #region detect changes of directories if (di1.Exists) { //loop through path1 dir foreach (string name in Delimon.Win32.IO.Directory.GetDirectories(path1)) { string newDirname = Delimon.Win32.IO.Path.GetFileName(name); dirNames.Add(newDirname); MyDirInfo newDir = new MyDirInfo(dir.FullPath, newDirname); new SyncDirInfo(si, newDir, true); FetchElementsInDirRecursively_TwoWay(newDir, si, onFileFound, interruptChecker); } } if (di2.Exists) { //loop through path2 dir except the dirs, which have already been detected in path1 foreach (string name in Delimon.Win32.IO.Directory.GetDirectories(path2)) { string newDirname = Delimon.Win32.IO.Path.GetFileName(name); if (!dirNames.Contains(newDirname)) { MyDirInfo newDir = new MyDirInfo(dir.FullPath, newDirname); new SyncDirInfo(si, newDir, true); FetchElementsInDirRecursively_TwoWay(newDir, si, onFileFound, interruptChecker); } } } #endregion #region detect files if (di1.Exists) { //Loop through all files in path1 foreach (string filepath in Delimon.Win32.IO.Directory.GetFiles(path1)) { string name = Delimon.Win32.IO.Path.GetFileName(filepath); MyFileInfo file = new MyFileInfo(dir.FullPath, name); new SyncFileInfo(si, file, true); fileNames.Add(name); onFileFound(file.SyncFileInfo); } } if (di2.Exists) { //Loop through all files in path2 except the files, which have already been detected in path1 foreach (string filepath in Delimon.Win32.IO.Directory.GetFiles(path2)) { string name = Delimon.Win32.IO.Path.GetFileName(filepath); if (fileNames.Contains(name)) { continue; } MyFileInfo file = new MyFileInfo(dir.FullPath, name); new SyncFileInfo(si, file, true); onFileFound(file.SyncFileInfo); } } #endregion } catch (Exception e) { si.Log(new LogMessage(LogType.ERROR, e.Message, e)); } }
public SyncTask2(SyncInfo si) : base(si) { }
/// <summary> /// fetch files and detect subdirectory changes for One-Way synchronisation recursively /// </summary> /// <param name="sourceHomePath">absolute source folder path (homepath as defined in link)</param> /// <param name="destHomePath">absolute destination folder path (homepath as defined in link)</param> /// <param name="dir">the directory, in which you want to search</param> /// <param name="si">sync info</param> /// <param name="onFileFound">is called when a file was found</param> /// <param name="interruptChecker">is called when the cancellation or pause request should be checked in order to handel them</param> public static void FetchFilesInDirRecursively_OneWay(string sourceHomePath, string destHomePath, MyDirInfo dir, SyncInfo si, Action<SyncFileInfo> onFileFound, Func<bool> interruptChecker) { interruptChecker(); string sourcePath = sourceHomePath + dir.FullPath; string destPath = destHomePath + dir.FullPath; try { //create destination directory if not exists if (dir.SyncDirInfo != null && !new Delimon.Win32.IO.DirectoryInfo(destPath).Exists) { new SyncDirExecutionInfo(dir.SyncDirInfo, si.Link.Direction, false); } //detect source child directories foreach (string dirpath in Delimon.Win32.IO.Directory.GetDirectories(sourcePath)) { string name = Delimon.Win32.IO.Path.GetFileName(dirpath); MyDirInfo newDir = new MyDirInfo(dir.FullPath, name); new SyncDirInfo(si, newDir, true); FetchFilesInDirRecursively_OneWay(sourceHomePath, destHomePath, newDir, si, onFileFound, interruptChecker); } //loop through all files in source directory foreach (string filepath in Delimon.Win32.IO.Directory.GetFiles(sourcePath)) { //detect changes of file asynchronously string name = Delimon.Win32.IO.Path.GetFileName(filepath); MyFileInfo file = new MyFileInfo(dir.FullPath, name); new SyncFileInfo(si, file, true); onFileFound(file.SyncFileInfo); } } catch (OperationCanceledException) { } catch (Exception e) { si.Log(new LogMessage(LogType.ERROR, e.Message, e)); } }
/// <summary> /// detect files and directories that should be removed for One-Way synchronisation recursively /// </summary> /// <param name="sourceHomePath">absolute source folder path (homepath as defined in link)</param> /// <param name="destHomePath">absolute destination folder path (homepath as defined in link)</param> /// <param name="dir">the directory, in which you want to search</param> /// <param name="interruptChecker">is called when the cancellation or pause request should be checked in order to handel them</param> /// <returns>true if the operation was canceled</returns> public static void GetRemoveInfosOfDirRecursively_OneWay(string sourceHomePath, string destHomePath, MyDirInfo dir, SyncInfo si, Func<bool> interruptChecker) { interruptChecker(); string sourcePath = sourceHomePath + dir.FullPath; string destPath = destHomePath + dir.FullPath; try { //get directories to remove //detect destination child directories foreach (string name in Delimon.Win32.IO.Directory.GetDirectories(destPath)) { string newDirname = Delimon.Win32.IO.Path.GetFileName(name); MyDirInfo newDir = new MyDirInfo(dir.FullPath, newDirname); //remove destination directory if source directory doesn't exist (if remove is enabled) if (si.Link.Remove && !new Delimon.Win32.IO.DirectoryInfo(newDir.FullPath).Exists) { new SyncDirInfo(si, newDir, true); new SyncDirExecutionInfo(newDir.SyncDirInfo, si.Link.Direction, true); } GetRemoveInfosOfDirRecursively_OneWay(sourceHomePath, destHomePath, newDir, si, interruptChecker); } //get files to remove //Loop through all files in destination directory foreach (string path in Delimon.Win32.IO.Directory.GetFiles(destPath)) { string name = Delimon.Win32.IO.Path.GetFileName(path); MyFileInfo file = new MyFileInfo(dir.FullPath, name); string sourceFilePath = sourceHomePath + file.FullPath; string destFilePath = destHomePath + file.FullPath; //remove destination file if source file doesn't exist (if remove is enabled) if (!new Delimon.Win32.IO.FileInfo(sourceFilePath).Exists) { new SyncFileInfo(si, file, true); if (si.Link.Remove) { file.Size = new Delimon.Win32.IO.FileInfo(destFilePath).Length; new SyncFileExecutionInfo(file.SyncFileInfo, si.Link.Direction, true); } } } } catch (Exception e) { si.Log(new LogMessage(LogType.ERROR, e.Message, e)); } }
/// <summary> /// fetch files and subdirectories for Two-Way synchronisation recursively /// </summary> /// <param name="dir">the directory, in which you want to search</param> /// <param name="si">sync info</param> /// <param name="onFileFound">is called when a file was found</param> /// <param name="interruptChecker">is called when the cancellation or pause request should be checked in order to handel them</param> public static void FetchElementsInDirRecursively_TwoWay(MyDirInfo dir, SyncInfo si, Action<SyncFileInfo> onFileFound, Func<bool> interruptChecker) { interruptChecker(); string path1 = si.Link.Path1 + dir.FullPath; string path2 = si.Link.Path2 + dir.FullPath; //directory info Delimon.Win32.IO.DirectoryInfo di1 = new Delimon.Win32.IO.DirectoryInfo(path1); Delimon.Win32.IO.DirectoryInfo di2 = new Delimon.Win32.IO.DirectoryInfo(path2); List<string> dirNames = new List<string>(); List<string> fileNames = new List<string>(); try { #region detect changes of directories if (di1.Exists) { //loop through path1 dir foreach (string name in Delimon.Win32.IO.Directory.GetDirectories(path1)) { string newDirname = Delimon.Win32.IO.Path.GetFileName(name); dirNames.Add(newDirname); MyDirInfo newDir = new MyDirInfo(dir.FullPath, newDirname); new SyncDirInfo(si, newDir, true); FetchElementsInDirRecursively_TwoWay(newDir, si, onFileFound, interruptChecker); } } if(di2.Exists) { //loop through path2 dir except the dirs, which have already been detected in path1 foreach (string name in Delimon.Win32.IO.Directory.GetDirectories(path2)) { string newDirname = Delimon.Win32.IO.Path.GetFileName(name); if (!dirNames.Contains(newDirname)) { MyDirInfo newDir = new MyDirInfo(dir.FullPath, newDirname); new SyncDirInfo(si, newDir, true); FetchElementsInDirRecursively_TwoWay(newDir, si, onFileFound, interruptChecker); } } } #endregion #region detect files if (di1.Exists) { //Loop through all files in path1 foreach (string filepath in Delimon.Win32.IO.Directory.GetFiles(path1)) { string name = Delimon.Win32.IO.Path.GetFileName(filepath); MyFileInfo file = new MyFileInfo(dir.FullPath, name); new SyncFileInfo(si, file, true); fileNames.Add(name); onFileFound(file.SyncFileInfo); } } if (di2.Exists) { //Loop through all files in path2 except the files, which have already been detected in path1 foreach (string filepath in Delimon.Win32.IO.Directory.GetFiles(path2)) { string name = Delimon.Win32.IO.Path.GetFileName(filepath); if (fileNames.Contains(name)) continue; MyFileInfo file = new MyFileInfo(dir.FullPath, name); new SyncFileInfo(si, file, true); onFileFound(file.SyncFileInfo); } } #endregion } catch (Exception e) { si.Log(new LogMessage(LogType.ERROR, e.Message, e)); } }
/// <summary> /// execute synchronisation, set listener before /// </summary> /// <param name="syncListener">listener or null if no listener should be set</param> public void Sync(ISyncListener syncListener) { SyncInfo = new SyncInfo(this); if(syncListener != null) SyncInfo.SetListener(syncListener); SyncTask = new SyncTask2(SyncInfo); SyncTask.Execute(); }
public TimeMeasurement(SyncInfo si) { _si = si; }
public AsyncSyncTask(SyncInfo si) : base(si) { }
public FilesInfo(SyncInfo si) { _si = si; }