/// <summary> /// Used on EnqueuingManager from MyFsWatcher + on TcpCommunication (PushNotification) /// </summary> /// <param name="changeType"></param> /// <param name="fullLocalPath"></param> /// <param name="oldFullLocalPath"></param> public CustomFileHash(FileChangeTypes changeType, string fullLocalPath, string oldFullLocalPath = "") { ChangeType = changeType; FullLocalPath = fullLocalPath; RelativePath = Helper.GetRelativePath(fullLocalPath); if (changeType == FileChangeTypes.DeletedOnClient || changeType == FileChangeTypes.CreatedOnServer) { return; } else if (changeType == FileChangeTypes.RenamedOnServer) { OldFullLocalPath = oldFullLocalPath; return; } else if (changeType == FileChangeTypes.RenamedOnClient) { OldRelativePath = Helper.GetRelativePath(oldFullLocalPath); } if (!Helper.IsDirectory(fullLocalPath)) { InitFileStream(); HashCode = GetFilesHashCode(); FileStream.Position = 0; FileInfo = new FileInfo(fullLocalPath); if (changeType == FileChangeTypes.ChangedOnClient || changeType == FileChangeTypes.RenamedOnClient) { WasReadOnly = FileInfo.IsReadOnly; } } }
/// <summary> /// Used in InitialSyncProcessor and on GetAllFileHashes /// </summary> /// <param name="changeType"></param> /// <param name="relativePath"></param> /// <param name="oldRelativePath"></param> /// <param name="hashCode"></param> /// <param name="oldHashCode"></param> /// <param name="isDeleted"></param> public CustomFileHash(FileChangeTypes changeType, string relativePath, string oldRelativePath, int hashCode, int oldHashCode, bool isDeleted = false) { ChangeType = changeType; RelativePath = relativePath; FullLocalPath = Helper.GetLocalPath(relativePath); OldRelativePath = oldRelativePath; OldFullLocalPath = Helper.GetLocalPath(oldRelativePath); HashCode = hashCode; OldHashCode = oldHashCode; IsDeleted = isDeleted; if (changeType == FileChangeTypes.ChangedOnClient || changeType == FileChangeTypes.ChangedOnServer || changeType == FileChangeTypes.DeletedOnServer) { FullLocalPath = Helper.GetLocalPath(RelativePath); } if (File.Exists(FullLocalPath)) { FileInfo = new FileInfo(FullLocalPath); } if (changeType != FileChangeTypes.None && changeType != FileChangeTypes.RenamedOnClient && changeType != FileChangeTypes.RenamedOnServer) { Helper.ValidateDirectoryForFile(RelativePath); FileStream = File.Open(FullLocalPath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None); } }
public FileSystemStalker(Folder folder, FileChangeTypes fileChangeTypes, FileChangedDelegate changedDelegate) { this.changedDelegate = changedDelegate; if (!folder.Exists()) return; watcher = new FileSystemWatcher(folder.FullName) {IncludeSubdirectories = true, EnableRaisingEvents = true}; if (AskedForEvent(fileChangeTypes, FileChangeTypes.Created)) watcher.Created += RaiseEvent; if (AskedForEvent(fileChangeTypes, FileChangeTypes.Changed)) watcher.Changed += RaiseEvent; if (AskedForEvent(fileChangeTypes, FileChangeTypes.Deleted)) watcher.Deleted += RaiseEvent; if (AskedForEvent(fileChangeTypes, FileChangeTypes.Renamed)) watcher.Renamed += RaiseEvent; }
private void EnqueuingManager(FileChangeTypes fileChangeType, string fullPath, string oldFullPath = "") { var relativePath = Helper.GetRelativePath(fullPath); if (fileChangeType == FileChangeTypes.DeletedOnClient || (!Helper.IsFileLocked(fullPath) && !_syncProcessor.InProcessingList(relativePath) && Helper.ExtensionIsNotExcluded(Path.GetExtension(fullPath).ToLower()))) { var fileHash = new CustomFileHash(fileChangeType, fullPath, oldFullPath); _syncProcessor.AddChangedFile(fileHash); Logger.WriteFileHash(fileHash); } }
private static bool AskedForEvent(FileChangeTypes fileChangeTypes, FileChangeTypes eventToCheck) { return (eventToCheck & fileChangeTypes) == eventToCheck; }