/// <summary> /// Handling delete change (For both file and folder) /// Unable to detect what type of the file is deleted as the file/folder no longer exist. /// </summary> /// <param name="dce">Delete Change Event with all the information for the file change</param> public void HandleDeleteChange(DeleteChangeEvent dce) { try { if (dce.Event == EventChangeType.DELETED) { HandleGenericDelete(dce); } } catch (Exception e) { ServiceLocator.GetLogger(ServiceLocator.DEBUG_LOG).Write(e); } }
private void HandleGenericDelete(DeleteChangeEvent dce) { MonitorLayer.Instance.UnMonitorPath(dce.Path.FullName); //Find the logical Address for the old path //Do not create the logical address if not found. string logicalAddress = ProfilingLayer.Instance.ConvertPhysicalToLogical(dce.Path.FullName, false); //Get all the tag that contains this logicalAddress inside the tag. List<Tag> tag = TaggingLayer.Instance.RetrieveParentTagByPath(logicalAddress); //If tag count is 0 return as there is nothing to process. if (tag.Count == 0) { return; } //Find the similiar paths for the logical Path //The return is physical address List<string> convertedList = FindSimilarSeamlessPathForFile(logicalAddress); convertedList.Remove(dce.Path.FullName); //////// Massive Path Table Code ///////////// for (int i = 0; i < convertedList.Count; i++) { string dest = convertedList[i]; if (_pathTable.JustPop(dce.Path.FullName, dest, TableType.Delete)) { convertedList.Remove(dest); i--; continue; } } ///////////////// For each Path in the converted List /////////////////// ///////////////////////////////// Create a entry such that source = convertedPath and destination is the original Path /////////// ///////////////////////For each other path , create a Source + dest pair ////////// ///////////////// Create an additional Path Entry for each of the Siblings //////////////// for (int i = 0; i < convertedList.Count; i++) { _pathTable.AddPathPair(convertedList[i], dce.Path.FullName, TableType.Delete); for (int j = i + 1; j < convertedList.Count; j++) { _pathTable.AddPathPair(convertedList[i], convertedList[j], TableType.Delete); _pathTable.AddPathPair(convertedList[j], convertedList[i], TableType.Delete); } } ///////// End of Path Table Code //////////////// //For each path in the convertedList , extract the parent Path. List<string> parentList = new List<string>(); foreach (string path in convertedList) { FileInfo info = new FileInfo(PathHelper.RemoveTrailingSlash(path)); string parent = info.Directory == null ? "" : info.Directory.FullName; parentList.Add(parent); } //If the parent list if empty , it means that there is nothing to sync and thus return. if (parentList.Count == 0) { return; } //Create the request and Send it. Debug.Assert(dce.Path.Parent != null); AutoSyncRequest request = new AutoSyncRequest(dce.Path.Name, dce.Path.Parent.FullName, parentList, AutoSyncRequestType.Delete, SyncConfig.Instance, ConvertTagListToTagString(tag)); SendAutoRequest(request); FindAndCleanDeletedPaths(); _userInterface.TagsChanged(); }
private void ExecuteUnknown(FileSystemEvent fse) { switch (fse.EventType) { case EventChangeType.DELETED: //ServiceLocator.GetLogger(ServiceLocator.DEVELOPER_LOG).Write("File/Folder Deleted: " + fse.Path); DeleteChangeEvent deleteEvent = new DeleteChangeEvent(new DirectoryInfo(fse.Path), new DirectoryInfo(fse.WatchPath)); ServiceLocator.MonitorI.HandleDeleteChange(deleteEvent); break; default: Debug.Assert(false); break; } }