private void TestSortingDisplaySetsBySeriesNumber(bool reverse) { DisplaySetCollection orderedCollection = new DisplaySetCollection(); DisplaySetCollection nonOrderedCollection = new DisplaySetCollection(); for (int i = 1; i <= 20; ++i) { string id = i.ToString(); DisplaySet displaySet = new DisplaySet(id, id); ImageSop sop = NewImageSop(id, id, i); IPresentationImage image = new DicomGrayscalePresentationImage(sop.Frames[1]); sop.Dispose(); IImageSopProvider sopProvider = (IImageSopProvider)image; DicomMessageSopDataSource dataSource = ((DicomMessageSopDataSource)sopProvider.ImageSop.DataSource); dataSource.SourceMessage.DataSet[DicomTags.SeriesNumber].SetInt32(0, i); displaySet.PresentationImages.Add(image); orderedCollection.Add(displaySet); } Randomize(orderedCollection, nonOrderedCollection); Debug.WriteLine("Before Sort\n------------------------\n"); CollectionUtils.ForEach(nonOrderedCollection, delegate(IDisplaySet displaySet) { Debug.WriteLine(String.Format("name: {0}", displaySet.Name)); }); nonOrderedCollection.Sort(new SeriesNumberComparer(reverse)); Debug.WriteLine("\nAfter Sort\n------------------------\n"); CollectionUtils.ForEach(nonOrderedCollection, delegate(IDisplaySet displaySet) { Debug.WriteLine(String.Format("name: {0}", displaySet.Name)); }); int j = reverse ? 20 : 1; foreach (IDisplaySet set in nonOrderedCollection) { Assert.AreEqual(j.ToString(), set.Name); j += reverse ? -1 : 1; } foreach (DisplaySet set in nonOrderedCollection) { set.Dispose(); } foreach (DisplaySet set in orderedCollection) { set.Dispose(); } }
private void DisposeDisplaySets() { if (this.DisplaySets == null) return; List<IDisplaySet> displaySetCopies = _displaySetCopies; _displaySetCopies = null; foreach (DisplaySet copy in displaySetCopies) copy.Dispose(); foreach (DisplaySet displaySet in this.DisplaySets) displaySet.Dispose(); _displaySets.ItemAdded -= OnDisplaySetAdded; _displaySets.ItemChanging -= OnDisplaySetChanging; _displaySets.ItemRemoved -= OnDisplaySetRemoved; _displaySets.ItemChanged -= OnDisplaySetChanged; _displaySets = null; }