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_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 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)); }