public async Task <Exception> GetProgramList(ObservableSortedCollection <ProgramInfo> programs, Action <double> onProgress = null) { Exception result = null; await Task.Run(() => result = GetProgramListSync(programs, onProgress)); return(result); }
public void ResortItemTest() { var comparer = Comparer <ValueClass> .Create((v1, v2) => { int comp = v1.Number.CompareTo(v2.Number); if (comp == 0) { comp = String.Compare(v1.Text, v2.Text, StringComparison.InvariantCulture); } return(comp); }); var collection = new ObservableSortedCollection <ValueClass>(comparer); var array = Enumerable.Range(0, 5).Select(val => val * 10) .SelectMany(val => Enumerable.Range(val, 10).Reverse()) .Select(val => new ValueClass($"Text{val}", val)) .ToArray(); collection.AddRange(array); Assert.IsTrue(areItemsInOrder(collection, comparer)); collection[5].Number = -50; Assert.IsFalse(areItemsInOrder(collection, comparer)); collection.ResortItem(5); Assert.IsTrue(areItemsInOrder(collection, comparer)); }
public void Initialize() { this.basis = new SortedList <double, double>(); var eventCount = 0; var itemCount = 0; NotifyCollectionChangedEventHandler testCollectionChanged = (s, e) => { this.CollectionChangedHandler(e, ref eventCount, ref itemCount); }; this.test = new ObservableSortedCollection <double>(); this.test.DetailedCollectionChanged += testCollectionChanged; double[] values = { 15, 65, -1, 2, 44, 100, 123, -456, 0, 10 }; foreach (var value in values) { this.basis.Add(value, value); this.test.Add(value); } Assert.AreEqual(eventCount, values.Length); Assert.AreEqual(itemCount, values.Length); Assert.AreEqual(this.basis.Count, values.Length); UnitTestHelper.AssertAreEqual(this.basis.Values, this.test, values.Length); this.test.DetailedCollectionChanged -= testCollectionChanged; }
public void EmptyTest() { var basisEmpty = new SortedList <double, double>(); var testEmpty = new ObservableSortedCollection <double>(); Assert.AreEqual(testEmpty.Count, 0); Assert.AreEqual(basisEmpty.Count, testEmpty.Count); }
public override void OnLoaded() { if (TransferredFiles == null) { TransferredFiles = new ObservableSortedCollection <ILocalDiskFile>( AcceleriderUser .GetNetDiskUsers() .SelectMany(item => item.GetDownloadedFiles()), DefaultTransferredFileComparer); } }
public void UpdateTest() { var temp = new[] { "gsa", "dfb", "sar", "ac", "fgfbg", "hek", "fsaw", "l;fg", "" }; var temp2 = new[] { "aba", "zzz", "aac", "aaa ", "aca", "abb", "aab", "abc", "acb", "acc", "jhgj" }; var testObject = new ObservableSortedCollection <string>(temp, Comparer <string> .Default.Compare); foreach (var item in temp2) { testObject.Add(item); } }
public override ObservableSortedTree <ValueClass> CreateTestTree() { var root = base.CreateTestTree(); var array = root.Children.ToArray(); root.Children.Clear(); var obs = new ObservableSortedCollection <ObservableSortedTree <ValueClass> >(root.Comparer); foreach (var child in array) { root.Children.Add(child); } return(root); }
private void onDirListChanged(ObservableSortedCollection <DirectoryInfo> old) { if (old != null) { old.ItemAdded -= DirList_ItemAdded; old.ItemRemoved -= DirList_ItemRemoved; old.ItemChanged -= DirList_ItemChanged; } if (this.DirList != null) { this.DirList.ItemAdded += DirList_ItemAdded; this.DirList.ItemRemoved += DirList_ItemRemoved; this.DirList.ItemChanged += DirList_ItemChanged; } }
public void ComparerChangedTest() { var collection = new ObservableSortedCollection <int>(); bool comparerChangedEvent = false; collection.ComparerChanged += (sender, old) => { Assert.IsTrue(ReferenceEquals(sender, collection)); Assert.IsNull(old); comparerChangedEvent = true; }; collection.Comparer = Comparer <int> .Create((i1, i2) => i2.CompareTo(i1)); Assert.IsTrue(comparerChangedEvent); }
public void MyObservableSortedCollectionTest_ref() { var defaultComparer = Comparer <ValueClass> .Default; var collection = new ObservableSortedCollection <ValueClass>(); var array = Enumerable.Range(0, 5).Select(val => val * 10) .SelectMany(val => Enumerable.Range(val, 10).Reverse()) .Select(val => new ValueClass("Text" + val, val)) .ToArray(); collection.AddRange(array); Assert.IsTrue(areItemsInOrder(collection, defaultComparer)); Assert.IsTrue(array.Length == collection.Count); array.ForEach(val => Assert.IsTrue(collection.Contains(val))); collection[5] = new ValueClass(99); Assert.IsTrue(areItemsInOrder(collection, defaultComparer)); collection.Insert(5, new ValueClass(100)); Assert.IsTrue(areItemsInOrder(collection, defaultComparer)); Assert.IsTrue(collection.Count == array.Length + 1); collection.RemoveAt(5); Assert.IsTrue(collection.Count == array.Length); collection.Remove(collection.First(item => item.Number >= 10)); Assert.IsTrue(collection.Count == array.Length - 1); Assert.IsTrue(areItemsInOrder(collection, defaultComparer)); bool exceptionThrown = false; try { collection.Move(0, 1); } catch (Exception) { exceptionThrown = true; } Assert.IsTrue(exceptionThrown); int oldCount = collection.Count; var oldItems = collection.ToArray(); var reverseComparer = Comparer <ValueClass> .Create((i1, i2) => i2.CompareTo(i1)); collection.Comparer = reverseComparer; Assert.AreEqual(oldCount, collection.Count); oldItems.ForEach(item => Assert.IsTrue(collection.Contains(item))); Assert.IsTrue(areItemsInOrder(collection, reverseComparer)); }
public void Prepare(Workspace workspace) { if (this.curWorkspace == workspace) { return; } if (this._FilesCollection == null) { this._FilesCollection = new ObservableSortedCollection <SolutionFileBase>(); } this.CmdContextMenu_Add_NewItem = new UI.Commands.RelayCommand(this.CreateNewItem); this.CmdContextMenu_Add_ExistingItem = new UI.Commands.RelayCommand(this.AddExistingItem); this.CmdContextMenu_Add_NewFolder = new UI.Commands.RelayCommand(this.AddNewFolder); this.curWorkspace = workspace; this.FSWatcher = new FileSystemWatcher(this.curWorkspace.WorkingDir); this.FSWatcher.Changed += FSWatcher_Changed; }
public void GetAllEpisode(ObservableSortedCollection <ProgramInfo> programs) { Task.Run(() => { try { if (GetAll) { return; } GetAll = true; ObservableSortedCollection <EpisodeInfo> films = null; Parallel.ForEach(new List <ProgramInfo>(programs), (ProgramInfo program) => { GetEpisodeListSync(program, (p) => program.Progress = p); if (program.Episodes.Count == 0) { programs.Remove(program); } else if (program.IsMovie) { programs.Remove(program); program.Name = GulliDataSource.FilmProgramName; DbUpdate(program); lock (GetAllLocker) if (films == null) { films = program.Episodes; programs.Add(program); } else { films.Add(program.Episodes); } } }); } catch (Exception e) { Debug.Write(e.Message); } GetAll = false; }); }
public void MyObservableSortedCollectionTest_int() { var collection = new ObservableSortedCollection <int>(); var array = Enumerable.Range(0, 5).Select(val => val * 10) .SelectMany(val => Enumerable.Range(val, 10).Reverse()) .ToArray(); collection.AddRange(array); Assert.IsTrue(areIntegersInOrder(collection)); Assert.IsTrue(array.Length == collection.Count); array.ForEach(val => Assert.IsTrue(collection.Contains(val))); collection[5] = 99; Assert.IsTrue(areIntegersInOrder(collection)); collection.Insert(5, 100); Assert.IsTrue(areIntegersInOrder(collection)); Assert.IsTrue(collection.Count == array.Length + 1); collection.RemoveAt(5); Assert.IsTrue(collection.Count == array.Length); collection.Remove(10); Assert.IsTrue(collection.Count == array.Length - 1); Assert.IsTrue(areIntegersInOrder(collection)); bool exceptionThrown = false; try { collection.Move(0, 1); } catch (Exception) { exceptionThrown = true; } Assert.IsTrue(exceptionThrown); int oldCount = collection.Count; var oldItems = collection.ToArray(); var reverseComparer = Comparer <int> .Create((i1, i2) => i2.CompareTo(i1)); collection.Comparer = reverseComparer; Assert.AreEqual(oldCount, collection.Count); oldItems.ForEach(item => Assert.IsTrue(collection.Contains(item))); Assert.IsTrue(areIntegersInReverseOrder(collection)); }
public override void OnLoaded() { if (TransferTasks == null) { TransferTasks = new ObservableSortedCollection <IDownloadingFile>(DownloadingFileComparer); AcceleriderUser .GetNetDiskUsers() .SelectMany(item => item.GetDownloadingFiles()) .ForEach(item => { if (item.DownloadInfo.Status != TransferStatus.Completed) { InitializeTransferItem(item); } else { EventAggregator .GetEvent <TransferItemCompletedEvent>() .Publish(LocalDiskFile.Create(item)); } }); } }
protected override void onChildrenGenerated() { base.onChildrenGenerated(); this.FileList = new ObservableSortedCollection <FileInfo>(fileComparer); this.FileList.AddRange(this.getFileInfoList2()); }
public SolutionFileBase() { this._Children = new ObservableSortedCollection <SolutionFileBase>(); }
public OutputPane() { this._AvailableTargets = new ObservableSortedCollection <string>(DocumentDictionary.Keys); this.CmdClearOutputWindow = new RelayCommand((p) => this.Document.Text = string.Empty); Instance = this; }
public CategoryDirectoryInfo2() { this.LinkedRootList = new ObservableSortedCollection <LinkedLayTree>(LinkedTreeComparer); this.SourceRootList = new ObservableSortedCollection <LazyDirectoryTree>(LazyDirectoryTree.DirectoryComparer); this.DirList = new ObservableSortedCollection <DirectoryInfo>(DirectoryComparer); }
public Exception GetProgramListSync(ObservableSortedCollection <ProgramInfo> programs, Action <double> onProgress = null) { if (SynchronizationContext.Current == null) { SynchronizationContext.SetSynchronizationContext(programs.SynchronizationObject); } try { lock (ProgramLock) { if (PogrameUpdating) { onProgress?.Invoke(1); return(null); } else { onProgress?.Invoke(0); PogrameUpdating = true; } } TableQuery <ProgramInfo> query = null; lock (DbLocker) query = db.Table <ProgramInfo>(); if (query != null) { programs.Add(query); } Regex ProgramRegex = new Regex(@"(<div\s+class=""wrap-img\s+program""\s*>" + @"\s*<a\s+href=""(?<url>http://replay\.gulli\.fr/(?<type>[^/]+)/[^""]+)""\s*>" + @"\s*<img\s+src=""(?<img>http://[a-z1-9]+-gulli\.ladmedia\.fr/r/[^""]+/img/var/storage/imports/(?<filename>[^""]+))""\s*alt=""(?<name>[^""]+)""\s*/>" + @"\s*</a>\s*</div>)", RegexOptions.Multiline | RegexOptions.ExplicitCapture | RegexOptions.Singleline); string content = ProgramPage.GetContent(); MatchCollection matches = ProgramRegex.Matches(content); List <Match> matcheList = new List <Match>(matches.Count); for (int i = 0; i < matches.Count; i++) { matcheList.Add(matches[i]); } int count = 0; Parallel.ForEach(matcheList, (Match m) => { count++; onProgress?.Invoke((double)count / matcheList.Count); string s = m.Value; string url = m.Groups["url"].Value; if (query.Where((p) => p.Url == url).Count() == 0) { if (SynchronizationContext.Current == null) { SynchronizationContext.SetSynchronizationContext(programs.SynchronizationObject); } ProgramInfo program = new ProgramInfo( m.Groups["url"].Value, m.Groups["type"].Value, WebUtility.HtmlDecode(m.Groups["name"].Value), GetImageUrl(m.Groups["filename"].Value)); DbInsert(program); programs.Add(program); } }); GetAllEpisode(programs); } catch (Exception e) { Debug.Write(e.Message); return(e); } finally { PogrameUpdating = false; } return(null); }