| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System; |
| | | 5 | | using CoreWCF.Collections.Generic; |
| | | 6 | | |
| | | 7 | | namespace CoreWCF.Dispatcher |
| | | 8 | | { |
| | | 9 | | public class ChannelDispatcherCollection : SynchronizedCollection<ChannelDispatcherBase> |
| | | 10 | | { |
| | | 11 | | private readonly ServiceHostBase _service; |
| | | 12 | | |
| | | 13 | | internal ChannelDispatcherCollection(ServiceHostBase service, object syncRoot) |
| | 591 | 14 | | : base(syncRoot) |
| | | 15 | | { |
| | 591 | 16 | | _service = service ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(service)); |
| | 591 | 17 | | } |
| | | 18 | | |
| | | 19 | | protected override void ClearItems() |
| | | 20 | | { |
| | 0 | 21 | | ChannelDispatcherBase[] array = new ChannelDispatcherBase[Count]; |
| | 0 | 22 | | CopyTo(array, 0); |
| | 0 | 23 | | base.ClearItems(); |
| | | 24 | | |
| | 0 | 25 | | if (_service != null) |
| | | 26 | | { |
| | 0 | 27 | | foreach (ChannelDispatcherBase channelDispatcher in array) |
| | | 28 | | { |
| | 0 | 29 | | _service.OnRemoveChannelDispatcher(channelDispatcher); |
| | | 30 | | } |
| | | 31 | | } |
| | 0 | 32 | | } |
| | | 33 | | |
| | | 34 | | protected override void InsertItem(int index, ChannelDispatcherBase item) |
| | | 35 | | { |
| | 640 | 36 | | if (_service != null) |
| | | 37 | | { |
| | 640 | 38 | | if (_service.State == CommunicationState.Closed) |
| | | 39 | | { |
| | 0 | 40 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ObjectDisposedException(_service.GetTy |
| | | 41 | | } |
| | | 42 | | |
| | 640 | 43 | | _service.OnAddChannelDispatcher(item); |
| | | 44 | | } |
| | | 45 | | |
| | 640 | 46 | | base.InsertItem(index, item); |
| | 640 | 47 | | } |
| | | 48 | | |
| | | 49 | | protected override void RemoveItem(int index) |
| | | 50 | | { |
| | 0 | 51 | | ChannelDispatcherBase channelDispatcher = Items[index]; |
| | 0 | 52 | | base.RemoveItem(index); |
| | 0 | 53 | | if (_service != null) |
| | | 54 | | { |
| | 0 | 55 | | _service.OnRemoveChannelDispatcher(channelDispatcher); |
| | | 56 | | } |
| | 0 | 57 | | } |
| | | 58 | | |
| | | 59 | | protected override void SetItem(int index, ChannelDispatcherBase item) |
| | | 60 | | { |
| | 0 | 61 | | if (_service != null) |
| | | 62 | | { |
| | 0 | 63 | | if (_service.State == CommunicationState.Closed) |
| | | 64 | | { |
| | 0 | 65 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ObjectDisposedException(_service.GetTy |
| | | 66 | | } |
| | | 67 | | } |
| | | 68 | | |
| | 0 | 69 | | if (_service != null) |
| | | 70 | | { |
| | 0 | 71 | | _service.OnAddChannelDispatcher(item); |
| | | 72 | | } |
| | | 73 | | |
| | | 74 | | ChannelDispatcherBase old; |
| | | 75 | | |
| | 0 | 76 | | lock (SyncRoot) |
| | | 77 | | { |
| | 0 | 78 | | old = Items[index]; |
| | 0 | 79 | | base.SetItem(index, item); |
| | 0 | 80 | | } |
| | | 81 | | |
| | 0 | 82 | | if (_service != null) |
| | | 83 | | { |
| | 0 | 84 | | _service.OnRemoveChannelDispatcher(old); |
| | | 85 | | } |
| | 0 | 86 | | } |
| | | 87 | | } |
| | | 88 | | } |