private void SuperintendentSavingAll(object sender, EventArgs e) { foreach (var item in InnerWrappersList.Select(x => x.Value).OfType <T>().Where(x => x.Changed)) { item.SaveAsync(); } }
private void Superintendent_Closing(object sender, Superintendent.ClosingEventArgs e) { foreach (var item in InnerWrappersList.Select(x => x.Value).OfType <T>().Where(x => x.Changed)) { Logging.Debug(item); e.Add(item.DisplayName); } }
void IWatchingChangeApplier.ApplyChange(string dir, WatchingChange change) { #if LOGGING Debug.WriteLine($"ACMGR [NEW]: IWatchingChangeApplier.ApplyChange({dir}, {change.Type})\n" + $" ORIGINAL FILENAME: {change.FullFilename}\n" + $" NEW LOCATION: {change.NewLocation}"); #endif string id; try { id = LocationToId(dir); } catch (Exception) { // can’t get location from id return; } bool isFreshlyLoaded; var obj = GetById(id, out isFreshlyLoaded); #if LOGGING Debug.WriteLine($" id: {id}; object: {obj}; location: {obj?.Location}"); if (obj != null && !obj.Location.Equals(dir, StringComparison.OrdinalIgnoreCase)) { if (change.Type == WatcherChangeTypes.Created) { Debug.WriteLine(@" wrong location, removed"); RemoveFromList(obj.Id); } else { Debug.WriteLine(@" wrong location, nulled"); } obj = null; } #else if (obj != null && !obj.Location.Equals(dir, StringComparison.OrdinalIgnoreCase)) { if (change.Type == WatcherChangeTypes.Created) { RemoveFromList(obj.Id); } obj = null; } #endif switch (change.Type) { case WatcherChangeTypes.Changed: if (obj != null && !isFreshlyLoaded && (change.FullFilename == null || !obj.HandleChangedFile(change.FullFilename))) { obj.Reload(); } break; case WatcherChangeTypes.Created: if (obj != null) { if (!isFreshlyLoaded) { obj.Reload(); } } else if (FileUtils.Exists(dir) && Filter(dir)) { id = LocationToId(FileUtils.GetOriginalFilename(dir)); obj = CreateAndLoadAcObject(id, Directories.CheckIfEnabled(dir)); InnerWrappersList.Add(new AcItemWrapper(this, obj)); UpdateList(); } break; case WatcherChangeTypes.Deleted: if (obj != null) { if (FileUtils.Exists(dir) && Filter(dir)) { if (!isFreshlyLoaded) { obj.Reload(); } } else { RemoveFromList(obj.Id); } } break; case WatcherChangeTypes.Renamed: if (obj != null) { if (dir == change.NewLocation) { if (isFreshlyLoaded) { obj.Reload(); } break; } RemoveFromList(obj.Id); } if (FileUtils.Exists(change.NewLocation)) { obj = CreateAndLoadAcObject(LocationToId(change.NewLocation), Directories.CheckIfEnabled(change.NewLocation)); InnerWrappersList.Add(new AcItemWrapper(this, obj)); UpdateList(); } break; case WatcherChangeTypes.All: Logging.Warning("WatcherChangeTypes.All!"); break; default: throw new ArgumentOutOfRangeException(); } #if LOGGING Debug.WriteLine(@" current list: " + InnerWrappersList.Select(x => x.Value.Id).JoinToString(", ")); #endif }