/// <summary> /// Perform an asynchronous dataset walk. /// </summary> /// <param name="walker">Walker implementation.</param> /// <param name="items">Queue of internal items; must be initialized and empty when called from external method.</param> private static async Task DoWalkAsync(IDicomDatasetWalker walker, Queue <DicomItem> items) { try { walker.OnBeginWalk(); while (items.Count > 0) { var item = items.Dequeue(); if (item is DicomElement) { await walker.OnElementAsync(item as DicomElement).ConfigureAwait(false); } else if (item is DicomFragmentSequence) { walker.OnBeginFragment(item as DicomFragmentSequence); } else if (item is DicomFragmentItem) { await walker.OnFragmentItemAsync((item as DicomFragmentItem).Buffer).ConfigureAwait(false); } else if (item is EndDicomFragment) { walker.OnEndFragment(); } else if (item is DicomSequence) { walker.OnBeginSequence(item as DicomSequence); } else if (item is BeginDicomSequenceItem) { walker.OnBeginSequenceItem((item as BeginDicomSequenceItem).Dataset); } else if (item is EndDicomSequenceItem) { walker.OnEndSequenceItem(); } else if (item is EndDicomSequence) { walker.OnEndSequence(); } } walker.OnEndWalk(); } catch (Exception e) { try { walker.OnEndWalk(); throw; } catch { throw e; } } }
/// <summary> /// Perform an asynchronous dataset walk. /// </summary> /// <param name="walker">Walker implementation.</param> /// <param name="items">Queue of internal items; must be initialized and empty when called from external method.</param> private static async Task DoWalkAsync(IDicomDatasetWalker walker, Queue<DicomItem> items) { try { walker.OnBeginWalk(); while (items.Count > 0) { var item = items.Dequeue(); if (item is DicomElement) { await walker.OnElementAsync(item as DicomElement).ConfigureAwait(false); } else if (item is DicomFragmentSequence) { walker.OnBeginFragment(item as DicomFragmentSequence); } else if (item is DicomFragmentItem) { await walker.OnFragmentItemAsync((item as DicomFragmentItem).Buffer).ConfigureAwait(false); } else if (item is EndDicomFragment) { walker.OnEndFragment(); } else if (item is DicomSequence) { walker.OnBeginSequence(item as DicomSequence); } else if (item is BeginDicomSequenceItem) { walker.OnBeginSequenceItem((item as BeginDicomSequenceItem).Dataset); } else if (item is EndDicomSequenceItem) { walker.OnEndSequenceItem(); } else if (item is EndDicomSequence) { walker.OnEndSequence(); } } walker.OnEndWalk(); } catch (Exception e) { try { walker.OnEndWalk(); throw; } catch { throw e; } } }
private void Walk(object state) { try { if (_items == null) { _items = new Queue <DicomItem>(); BuildWalkQueue(_dataset); _walker.OnBeginWalk(this, NextWalkItem); } DicomItem item = null; while (_items.Count > 0) { item = _items.Peek(); if (item is DicomElement) { if (!_walker.OnElement(item as DicomElement)) { return; } } else if (item is DicomFragmentSequence) { if (!_walker.OnBeginFragment(item as DicomFragmentSequence)) { return; } } else if (item is DicomFragmentItem) { if (!_walker.OnFragmentItem((item as DicomFragmentItem).Buffer)) { return; } } else if (item is EndDicomFragment) { if (!_walker.OnEndFragment()) { return; } } else if (item is DicomSequence) { if (!_walker.OnBeginSequence(item as DicomSequence)) { return; } } else if (item is BeginDicomSequenceItem) { if (!_walker.OnBeginSequenceItem((item as BeginDicomSequenceItem).Dataset)) { return; } } else if (item is EndDicomSequenceItem) { if (!_walker.OnEndSequenceItem()) { return; } } else if (item is EndDicomSequence) { if (!_walker.OnEndSequence()) { return; } } _items.Dequeue(); } _walker.OnEndWalk(); _items = null; _async.Set(); } catch (Exception e) { try { _walker.OnEndWalk(); } catch { } _exception = e; _items = null; _async.Set(); } }