private async void Modified(string Path) { await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, async() => { try { await Locker.WaitAsync(); try { if (CurrentLocation == System.IO.Path.GetDirectoryName(Path)) { if (await FileSystemStorageItemBase.OpenAsync(Path) is FileSystemStorageItemBase ModifiedItem) { PathConfiguration Config = await SQLite.Current.GetPathConfigurationAsync(CurrentLocation); if (CurrentCollection.FirstOrDefault((Item) => Item.Path.Equals(Path, StringComparison.OrdinalIgnoreCase)) is FileSystemStorageItemBase OldItem) { if (ModifiedItem.GetType() == OldItem.GetType()) { await OldItem.RefreshAsync(); } else { CurrentCollection.Remove(OldItem); if (!SettingControl.IsDisplayProtectedSystemItems || !ModifiedItem.IsSystemItem) { if ((ModifiedItem is IHiddenStorageItem && SettingControl.IsDisplayHiddenItem) || ModifiedItem is not IHiddenStorageItem) { if (CurrentCollection.Any()) { int Index = SortCollectionGenerator.SearchInsertLocation(CurrentCollection, ModifiedItem, Config.SortTarget.GetValueOrDefault(), Config.SortDirection.GetValueOrDefault()); if (Index >= 0) { CurrentCollection.Insert(Index, ModifiedItem); } else { CurrentCollection.Add(ModifiedItem); } } else { CurrentCollection.Add(ModifiedItem); } } } } } else if (ModifiedItem is not IHiddenStorageItem) { if (CurrentCollection.Any()) { int Index = SortCollectionGenerator.SearchInsertLocation(CurrentCollection, ModifiedItem, Config.SortTarget.GetValueOrDefault(), Config.SortDirection.GetValueOrDefault()); if (Index >= 0) { CurrentCollection.Insert(Index, ModifiedItem); } else { CurrentCollection.Add(ModifiedItem); } } else { CurrentCollection.Add(ModifiedItem); } } } } } finally { Locker.Release(); } } catch (Exception ex) { LogTracer.Log(ex, $"{ nameof(StorageAreaWatcher)}: Modify item in collection failed"); } });
public async Task <IEnumerable <FileSystemStorageItemBase> > GetFilterCollection() { List <FileSystemStorageItemBase> NameFilterResult = null; List <FileSystemStorageItemBase> ModTimeFilterResult = null; List <FileSystemStorageItemBase> TypeFilterResult = null; List <FileSystemStorageItemBase> SizeFilterResult = null; if (NameCondition != NameFilterCondition.None) { NameFilterResult = new List <FileSystemStorageItemBase>(); if (NameCondition.HasFlag(NameFilterCondition.Regex)) { try { NameFilterResult.AddRange(OriginCopy.Where((Item) => Regex.IsMatch(Item.Name, RegexExpression))); } catch { NameFilterResult.AddRange(OriginCopy); } } else { if (NameCondition.HasFlag(NameFilterCondition.From_A_To_G)) { NameFilterResult.AddRange(OriginCopy.Where((Item) => (Item.Name.FirstOrDefault() >= 65 && Item.Name.FirstOrDefault() <= 71) || (Item.Name.FirstOrDefault() >= 97 && Item.Name.FirstOrDefault() <= 103))); } if (NameCondition.HasFlag(NameFilterCondition.From_H_To_N)) { NameFilterResult.AddRange(OriginCopy.Where((Item) => (Item.Name.FirstOrDefault() >= 72 && Item.Name.FirstOrDefault() <= 78) || (Item.Name.FirstOrDefault() >= 104 && Item.Name.FirstOrDefault() <= 110))); } if (NameCondition.HasFlag(NameFilterCondition.From_O_To_T)) { NameFilterResult.AddRange(OriginCopy.Where((Item) => (Item.Name.FirstOrDefault() >= 79 && Item.Name.FirstOrDefault() <= 84) || (Item.Name.FirstOrDefault() >= 111 && Item.Name.FirstOrDefault() <= 116))); } if (NameCondition.HasFlag(NameFilterCondition.From_U_To_Z)) { NameFilterResult.AddRange(OriginCopy.Where((Item) => (Item.Name.FirstOrDefault() >= 85 && Item.Name.FirstOrDefault() <= 90) || (Item.Name.FirstOrDefault() >= 117 && Item.Name.FirstOrDefault() <= 112))); } if (NameCondition.HasFlag(NameFilterCondition.Other)) { NameFilterResult.AddRange(OriginCopy.Where((Item) => Item.Name.FirstOrDefault() < 65 || (Item.Name.FirstOrDefault() > 90 && Item.Name.FirstOrDefault() < 97) || Item.Name.FirstOrDefault() > 122)); } } } if (ModTimeCondition != ModTimeFilterCondition.None) { ModTimeFilterResult = new List <FileSystemStorageItemBase>(); if (ModTimeCondition.HasFlag(ModTimeFilterCondition.Range)) { ModTimeFilterResult.AddRange(OriginCopy.Where((Item) => Item.ModifiedTimeRaw >= ModTimeFrom && Item.ModifiedTimeRaw <= ModTimeTo)); } if (ModTimeCondition.HasFlag(ModTimeFilterCondition.One_Month_Ago)) { ModTimeFilterResult.AddRange(OriginCopy.Where((Item) => Item.ModifiedTimeRaw >= DateTimeOffset.Now.AddMonths(-1))); } if (ModTimeCondition.HasFlag(ModTimeFilterCondition.Three_Month_Ago)) { ModTimeFilterResult.AddRange(OriginCopy.Where((Item) => Item.ModifiedTimeRaw >= DateTimeOffset.Now.AddMonths(-3))); } if (ModTimeCondition.HasFlag(ModTimeFilterCondition.Long_Ago)) { ModTimeFilterResult.AddRange(OriginCopy.Where((Item) => Item.ModifiedTimeRaw < DateTimeOffset.Now.AddMonths(-3))); } } if (TypeFilter.Count > 0) { TypeFilterResult = OriginCopy.Where((Item) => TypeFilter.Contains(Item.Type.ToLower())).ToList(); } if (SizeCondition != SizeFilterCondition.None) { SizeFilterResult = new List <FileSystemStorageItemBase>(); if (SizeCondition.HasFlag(SizeFilterCondition.Smaller)) { SizeFilterResult.AddRange(OriginCopy.Where((Item) => Item.SizeRaw >> 10 < 1024)); } if (SizeCondition.HasFlag(SizeFilterCondition.Medium)) { SizeFilterResult.AddRange(OriginCopy.Where((Item) => Item.SizeRaw >> 10 >= 1024 && Item.SizeRaw >> 20 < 128)); } if (SizeCondition.HasFlag(SizeFilterCondition.Larger)) { SizeFilterResult.AddRange(OriginCopy.Where((Item) => Item.SizeRaw >> 20 >= 128 && Item.SizeRaw >> 20 < 1024)); } if (SizeCondition.HasFlag(SizeFilterCondition.Huge)) { SizeFilterResult.AddRange(OriginCopy.Where((Item) => Item.SizeRaw >> 30 >= 1)); } } IEnumerable <FileSystemStorageItemBase> FilterIntersct = null; if (NameFilterResult != null) { if (FilterIntersct == null) { FilterIntersct = NameFilterResult; } else { FilterIntersct = FilterIntersct.Intersect(NameFilterResult); } } if (ModTimeFilterResult != null) { if (FilterIntersct == null) { FilterIntersct = ModTimeFilterResult; } else { FilterIntersct = FilterIntersct.Intersect(ModTimeFilterResult); } } if (TypeFilterResult != null) { if (FilterIntersct == null) { FilterIntersct = TypeFilterResult; } else { FilterIntersct = FilterIntersct.Intersect(TypeFilterResult); } } if (SizeFilterResult != null) { if (FilterIntersct == null) { FilterIntersct = SizeFilterResult; } else { FilterIntersct = FilterIntersct.Intersect(SizeFilterResult); } } if (FilterIntersct != null && FilterIntersct.Any()) { PathConfiguration Config = await SQLite.Current.GetPathConfigurationAsync(CurrentPath); return(SortCollectionGenerator.GetSortedCollection(FilterIntersct, Config.Target.GetValueOrDefault(), Config.Direction.GetValueOrDefault())); } else { return(new List <FileSystemStorageItemBase>(0)); } }