| | | 1 | | /* |
| | | 2 | | * Copyright 2017 Stanislav Muhametsin. All rights Reserved. |
| | | 3 | | * |
| | | 4 | | * Licensed under the Apache License, Version 2.0 (the "License"); |
| | | 5 | | * you may not use this file except in compliance with the License. |
| | | 6 | | * You may obtain a copy of the License at |
| | | 7 | | * |
| | | 8 | | * http://www.apache.org/licenses/LICENSE-2.0 |
| | | 9 | | * |
| | | 10 | | * Unless required by applicable law or agreed to in writing, software |
| | | 11 | | * distributed under the License is distributed on an "AS IS" BASIS, |
| | | 12 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or |
| | | 13 | | * implied. |
| | | 14 | | * |
| | | 15 | | * See the License for the specific language governing permissions and |
| | | 16 | | * limitations under the License. |
| | | 17 | | */ |
| | | 18 | | using AsyncEnumeration.Abstractions; |
| | | 19 | | using AsyncEnumeration.Observability; |
| | | 20 | | using CBAM.Abstractions; |
| | | 21 | | using System; |
| | | 22 | | using System.Collections.Generic; |
| | | 23 | | using System.Text; |
| | | 24 | | using System.Threading; |
| | | 25 | | using System.Threading.Tasks; |
| | | 26 | | using UtilPack; |
| | | 27 | | |
| | | 28 | | namespace CBAM.Abstractions.Implementation |
| | | 29 | | { |
| | | 30 | | /// <summary> |
| | | 31 | | /// This is base class for <see cref="ConnectionImpl{TStatement, TStatementInformation, TStatementCreationArgs, TEnum |
| | | 32 | | /// </summary> |
| | | 33 | | /// <typeparam name="TConnectionFunctionality">The type of actual connection functionality.</typeparam> |
| | | 34 | | public abstract class ConnectionImpl<TConnectionFunctionality> |
| | | 35 | | where TConnectionFunctionality : class |
| | | 36 | | { |
| | | 37 | | internal ConnectionImpl( |
| | | 38 | | TConnectionFunctionality functionality |
| | | 39 | | ) |
| | | 40 | | { |
| | | 41 | | this.ConnectionFunctionality = ArgumentValidator.ValidateNotNull( nameof( functionality ), functionality ); |
| | | 42 | | |
| | | 43 | | } |
| | | 44 | | |
| | | 45 | | /// <summary> |
| | | 46 | | /// Gets the <see cref="Connection{TStatement, TStatementInformation, TStatementCreationArgs, TEnumerableItem, TVe |
| | | 47 | | /// </summary> |
| | | 48 | | /// <value>The <see cref="Connection{TStatement, TStatementInformation, TStatementCreationArgs, TEnumerableItem, T |
| | | 49 | | internal protected TConnectionFunctionality ConnectionFunctionality { get; } |
| | | 50 | | } |
| | | 51 | | |
| | | 52 | | /// <summary> |
| | | 53 | | /// This class provides facade implementation of <see cref="Connection{TStatement, TStatementInformation, TStatementC |
| | | 54 | | /// It does so by having a reference to <see cref="PooledConnectionFunctionality{TStatement, TStatementInformation, T |
| | | 55 | | /// This way, any components of this connection may use connection-related services (e.g. creating <see cref="IAsyncE |
| | | 56 | | /// </summary> |
| | | 57 | | /// <typeparam name="TStatement">The type of objects used to manipulate or query remote resource.</typeparam> |
| | | 58 | | /// <typeparam name="TStatementInformation">The type of objects describing <typeparamref name="TStatement"/>s.</typep |
| | | 59 | | /// <typeparam name="TStatementCreationArgs">The type of object used to create an instance of <typeparamref name="TSt |
| | | 60 | | /// <typeparam name="TEnumerableItem">The type of object representing the response of manipulation or querying remote |
| | | 61 | | /// <typeparam name="TVendorFunctionality">The type of object describing vendor-specific information, as specified by |
| | | 62 | | /// <typeparam name="TActualVendorFunctionality">The actual type of object describing vendor-specific information.</t |
| | | 63 | | /// <typeparam name="TConnectionFunctionality">The type of object actually implementing functionality for this facade |
| | | 64 | | public abstract class ConnectionImpl<TStatement, TStatementInformation, TStatementCreationArgs, TEnumerableItem, TVen |
| | | 65 | | where TStatement : TStatementInformation |
| | | 66 | | where TVendorFunctionality : ConnectionVendorFunctionality<TStatement, TStatementCreationArgs> |
| | | 67 | | where TConnectionFunctionality : DefaultConnectionFunctionality<TStatement, TStatementInformation, TStatementCreat |
| | | 68 | | where TActualVendorFunctionality : TVendorFunctionality |
| | | 69 | | { |
| | | 70 | | /// <summary> |
| | | 71 | | /// Creats a new instance of <see cref="ConnectionImpl{TStatement, TStatementInformation, TStatementCreationArgs, |
| | | 72 | | /// </summary> |
| | | 73 | | /// <param name="functionality">The <see cref="PooledConnectionFunctionality{TStatement, TStatementInformation, TS |
| | | 74 | | /// <exception cref="ArgumentNullException">If <paramref name="functionality"/> is <c>null</c>.</exception> |
| | | 75 | | public ConnectionImpl( |
| | | 76 | | TConnectionFunctionality functionality |
| | | 77 | | ) : base( functionality ) |
| | | 78 | | { |
| | | 79 | | } |
| | | 80 | | |
| | | 81 | | /// <summary> |
| | | 82 | | /// Forwards the property to <see cref="Connection{TStatement, TStatementInformation, TStatementCreationArgs, TEnu |
| | | 83 | | /// </summary> |
| | | 84 | | /// <value>The value of <see cref="Connection{TStatement, TStatementInformation, TStatementCreationArgs, TEnumerab |
| | | 85 | | public TActualVendorFunctionality VendorFunctionality => this.ConnectionFunctionality.VendorFunctionality; |
| | | 86 | | |
| | | 87 | | /// <summary> |
| | | 88 | | /// Forwards the property to <see cref="Connection{TStatement, TStatementInformation, TStatementCreationArgs, TEnu |
| | | 89 | | /// </summary> |
| | | 90 | | /// <value>The value of <see cref="Connection{TStatement, TStatementInformation, TStatementCreationArgs, TEnumerab |
| | | 91 | | TVendorFunctionality Connection<TStatement, TStatementInformation, TStatementCreationArgs, TEnumerableItem, TVendo |
| | | 92 | | |
| | | 93 | | /// <summary> |
| | | 94 | | /// Implements the <see cref="AsyncEnumerationObservation{T, TMetadata}.BeforeEnumerationStart"/> event. |
| | | 95 | | /// </summary> |
| | | 96 | | public event GenericEventHandler<EnumerationStartedEventArgs<TStatementInformation>> BeforeEnumerationStart; |
| | | 97 | | //{ |
| | | 98 | | // add |
| | | 99 | | // { |
| | | 100 | | // this.ConnectionFunctionality.BeforeEnumerationStart += value; |
| | | 101 | | // } |
| | | 102 | | // remove |
| | | 103 | | // { |
| | | 104 | | // this.ConnectionFunctionality.BeforeEnumerationStart -= value; |
| | | 105 | | // } |
| | | 106 | | //} |
| | | 107 | | |
| | | 108 | | /// <summary> |
| | | 109 | | /// Implements the <see cref="AsyncEnumerationObservation{T, TMetadata}.AfterEnumerationStart"/> event. |
| | | 110 | | /// </summary> |
| | | 111 | | public event GenericEventHandler<EnumerationStartedEventArgs<TStatementInformation>> AfterEnumerationStart; |
| | | 112 | | //{ |
| | | 113 | | // add |
| | | 114 | | // { |
| | | 115 | | // this.ConnectionFunctionality.AfterEnumerationStart += value; |
| | | 116 | | // } |
| | | 117 | | // remove |
| | | 118 | | // { |
| | | 119 | | // this.ConnectionFunctionality.AfterEnumerationStart -= value; |
| | | 120 | | // } |
| | | 121 | | //} |
| | | 122 | | |
| | | 123 | | /// <summary> |
| | | 124 | | /// Implements the <see cref="AsyncEnumerationObservation{T, TMetadata}.BeforeEnumerationEnd"/> event. |
| | | 125 | | /// </summary> |
| | | 126 | | public event GenericEventHandler<EnumerationEndedEventArgs<TStatementInformation>> BeforeEnumerationEnd; |
| | | 127 | | //{ |
| | | 128 | | // add |
| | | 129 | | // { |
| | | 130 | | // this.ConnectionFunctionality.BeforeEnumerationEnd += value; |
| | | 131 | | // } |
| | | 132 | | // remove |
| | | 133 | | // { |
| | | 134 | | // this.ConnectionFunctionality.BeforeEnumerationEnd -= value; |
| | | 135 | | // } |
| | | 136 | | //} |
| | | 137 | | |
| | | 138 | | /// <summary> |
| | | 139 | | /// Implements the <see cref="AsyncEnumerationObservation{T, TMetadata}.AfterEnumerationEnd"/> event. |
| | | 140 | | /// </summary> |
| | | 141 | | public event GenericEventHandler<EnumerationEndedEventArgs<TStatementInformation>> AfterEnumerationEnd; |
| | | 142 | | //{ |
| | | 143 | | // add |
| | | 144 | | // { |
| | | 145 | | // this.ConnectionFunctionality.AfterEnumerationEnd += value; |
| | | 146 | | // } |
| | | 147 | | // remove |
| | | 148 | | // { |
| | | 149 | | // this.ConnectionFunctionality.AfterEnumerationEnd -= value; |
| | | 150 | | // } |
| | | 151 | | //} |
| | | 152 | | |
| | | 153 | | /// <summary> |
| | | 154 | | /// Implements the <see cref="AsyncEnumerationObservation{T, TMetadata}.AfterEnumerationItemEncountered"/>. |
| | | 155 | | /// </summary> |
| | | 156 | | public event GenericEventHandler<EnumerationItemEventArgs<TEnumerableItem, TStatementInformation>> AfterEnumeratio |
| | | 157 | | //{ |
| | | 158 | | // add |
| | | 159 | | // { |
| | | 160 | | // this.ConnectionFunctionality.AfterEnumerationItemEncountered += value; |
| | | 161 | | // } |
| | | 162 | | // remove |
| | | 163 | | // { |
| | | 164 | | // this.ConnectionFunctionality.AfterEnumerationItemEncountered -= value; |
| | | 165 | | // } |
| | | 166 | | //} |
| | | 167 | | |
| | | 168 | | /// <summary> |
| | | 169 | | /// Implements the <see cref="AsyncEnumerationObservation{T}.BeforeEnumerationStart"/> event by forwarding it to t |
| | | 170 | | /// </summary> |
| | | 171 | | event GenericEventHandler<EnumerationStartedEventArgs> AsyncEnumerationObservation<TEnumerableItem>.BeforeEnumerat |
| | | 172 | | { |
| | | 173 | | add |
| | | 174 | | { |
| | | 175 | | this.BeforeEnumerationStart += value; |
| | | 176 | | } |
| | | 177 | | remove |
| | | 178 | | { |
| | | 179 | | this.BeforeEnumerationStart -= value; |
| | | 180 | | } |
| | | 181 | | } |
| | | 182 | | |
| | | 183 | | /// <summary> |
| | | 184 | | /// Implements the <see cref="AsyncEnumerationObservation{T}.AfterEnumerationStart"/> event by forwarding it to th |
| | | 185 | | /// </summary> |
| | | 186 | | event GenericEventHandler<EnumerationStartedEventArgs> AsyncEnumerationObservation<TEnumerableItem>.AfterEnumerati |
| | | 187 | | { |
| | | 188 | | add |
| | | 189 | | { |
| | | 190 | | this.AfterEnumerationStart += value; |
| | | 191 | | } |
| | | 192 | | remove |
| | | 193 | | { |
| | | 194 | | this.AfterEnumerationStart -= value; |
| | | 195 | | } |
| | | 196 | | } |
| | | 197 | | |
| | | 198 | | /// <summary> |
| | | 199 | | /// Implements the <see cref="AsyncEnumerationObservation{T}.AfterEnumerationItemEncountered"/> event by forwardin |
| | | 200 | | /// </summary> |
| | | 201 | | event GenericEventHandler<EnumerationItemEventArgs<TEnumerableItem>> AsyncEnumerationObservation<TEnumerableItem>. |
| | | 202 | | { |
| | | 203 | | add |
| | | 204 | | { |
| | | 205 | | this.AfterEnumerationItemEncountered += value; |
| | | 206 | | } |
| | | 207 | | remove |
| | | 208 | | { |
| | | 209 | | this.AfterEnumerationItemEncountered -= value; |
| | | 210 | | } |
| | | 211 | | } |
| | | 212 | | |
| | | 213 | | /// <summary> |
| | | 214 | | /// Implements the <see cref="AsyncEnumerationObservation{T}.BeforeEnumerationEnd"/> event by forwarding it to thi |
| | | 215 | | /// </summary> |
| | | 216 | | event GenericEventHandler<EnumerationEndedEventArgs> AsyncEnumerationObservation<TEnumerableItem>.BeforeEnumeratio |
| | | 217 | | { |
| | | 218 | | add |
| | | 219 | | { |
| | | 220 | | this.BeforeEnumerationEnd += value; |
| | | 221 | | } |
| | | 222 | | remove |
| | | 223 | | { |
| | | 224 | | this.BeforeEnumerationEnd -= value; |
| | | 225 | | } |
| | | 226 | | } |
| | | 227 | | |
| | | 228 | | /// <summary> |
| | | 229 | | /// Implements the <see cref="AsyncEnumerationObservation{T}.AfterEnumerationEnd"/> event by forwarding it to this |
| | | 230 | | /// </summary> |
| | | 231 | | event GenericEventHandler<EnumerationEndedEventArgs> AsyncEnumerationObservation<TEnumerableItem>.AfterEnumeration |
| | | 232 | | { |
| | | 233 | | add |
| | | 234 | | { |
| | | 235 | | this.AfterEnumerationEnd += value; |
| | | 236 | | } |
| | | 237 | | remove |
| | | 238 | | { |
| | | 239 | | this.AfterEnumerationEnd -= value; |
| | | 240 | | } |
| | | 241 | | } |
| | | 242 | | |
| | | 243 | | /// <summary> |
| | | 244 | | /// Implements the <see cref="Connection{TStatement, TStatementInformation, TStatementCreationArgs, TEnumerableIte |
| | | 245 | | /// </summary> |
| | | 246 | | /// <value>Whether to disable observability aspect of enumerables created by <see cref="PrepareStatementForExecuti |
| | | 247 | | public Boolean DisableEnumerableObservability { get; set; } |
| | | 248 | | |
| | | 249 | | /// <summary> |
| | | 250 | | /// Forwards the method call to <see cref="Connection{TStatement, TStatementInformation, TStatementCreationArgs, T |
| | | 251 | | /// </summary> |
| | | 252 | | /// <param name="statementBuilder">The statement builder, created by <see cref="ConnectionVendorFunctionality{TSta |
| | | 253 | | /// <returns>A new instance of <see cref="IAsyncEnumerable{T}"/>.</returns> |
| | | 254 | | public IAsyncEnumerable<TEnumerableItem> PrepareStatementForExecution( TStatementInformation statementBuilder ) |
| | | 255 | | { |
| | | 256 | | var retVal = this.ConnectionFunctionality.PrepareStatementForExecution( statementBuilder, out var info ); |
| | | 257 | | if ( !this.DisableEnumerableObservability ) |
| | | 258 | | { |
| | | 259 | | var observable = retVal.AsObservable( info ); |
| | | 260 | | observable.BeforeEnumerationStart += args => this.BeforeEnumerationStart?.InvokeAllEventHandlers( evt => evt |
| | | 261 | | observable.AfterEnumerationStart += args => this.AfterEnumerationStart?.InvokeAllEventHandlers( evt => evt( |
| | | 262 | | observable.AfterEnumerationItemEncountered += args => this.AfterEnumerationItemEncountered?.InvokeAllEventHa |
| | | 263 | | observable.BeforeEnumerationEnd += args => this.BeforeEnumerationEnd?.InvokeAllEventHandlers( evt => evt( ar |
| | | 264 | | observable.AfterEnumerationEnd += args => this.AfterEnumerationEnd?.InvokeAllEventHandlers( evt => evt( args |
| | | 265 | | retVal = observable; |
| | | 266 | | } |
| | | 267 | | |
| | | 268 | | return retVal; |
| | | 269 | | } |
| | | 270 | | } |
| | | 271 | | |
| | | 272 | | /// <summary> |
| | | 273 | | /// This interface exists so that life would be a bit easier when using properties of <see cref="PooledConnectionFunc |
| | | 274 | | /// </summary> |
| | | 275 | | public interface PooledConnectionFunctionality |
| | | 276 | | { |
| | | 277 | | /// <summary> |
| | | 278 | | /// Gets or sets the current cancellation token. |
| | | 279 | | /// </summary> |
| | | 280 | | /// <value>The current cancellation token.</value> |
| | | 281 | | CancellationToken CurrentCancellationToken { get; set; } |
| | | 282 | | |
| | | 283 | | |
| | | 284 | | /// <summary> |
| | | 285 | | /// This method resets current cancellation token, so that <see cref="CurrentCancellationToken"/> property getter |
| | | 286 | | /// </summary> |
| | | 287 | | void ResetCancellationToken(); |
| | | 288 | | |
| | | 289 | | /// <summary> |
| | | 290 | | /// Gets the value indicating whether this connection can be returned to the pool (e.g. underlying stream is open) |
| | | 291 | | /// </summary> |
| | | 292 | | /// <value>The value indicating whether this connection can be returned to the pool (e.g. underlying stream is ope |
| | | 293 | | Boolean CanBeReturnedToPool { get; } |
| | | 294 | | } |
| | | 295 | | |
| | | 296 | | /// <summary> |
| | | 297 | | /// This class provides the skeleton implementation for <see cref="Connection{TStatement, TStatementInformation, TSta |
| | | 298 | | /// </summary> |
| | | 299 | | /// <typeparam name="TStatement">The type of objects used to manipulate or query remote resource.</typeparam> |
| | | 300 | | /// <typeparam name="TStatementInformation">The type of objects describing <typeparamref name="TStatement"/>s.</typep |
| | | 301 | | /// <typeparam name="TStatementCreationArgs">The type of object used to create an instance of <typeparamref name="TSt |
| | | 302 | | /// <typeparam name="TVendor">The type of object describing vendor-specific information.</typeparam> |
| | | 303 | | /// <typeparam name="TEnumerableItem">The type parameter of <see cref="IAsyncEnumerable{T}"/> returned by <see cref=" |
| | | 304 | | public abstract class DefaultConnectionFunctionality<TStatement, TStatementInformation, TStatementCreationArgs, TVend |
| | | 305 | | where TStatement : TStatementInformation |
| | | 306 | | where TVendor : ConnectionVendorFunctionality<TStatement, TStatementCreationArgs> |
| | | 307 | | { |
| | | 308 | | /// <summary> |
| | | 309 | | /// Creates a new instance of <see cref="PooledConnectionFunctionality{TStatement, TStatementInformation, TStateme |
| | | 310 | | /// </summary> |
| | | 311 | | /// <param name="vendorFunctionality">The connection vendor.</param> |
| | | 312 | | public DefaultConnectionFunctionality( TVendor vendorFunctionality ) |
| | | 313 | | { |
| | | 314 | | this.VendorFunctionality = vendorFunctionality; |
| | | 315 | | } |
| | | 316 | | |
| | | 317 | | /// <summary> |
| | | 318 | | /// Gets the <see cref="ConnectionVendorFunctionality{TStatement, TStatementCreationArgs}"/> of this <see cref="Po |
| | | 319 | | /// </summary> |
| | | 320 | | /// <value>The <see cref="ConnectionVendorFunctionality{TStatement, TStatementCreationArgs}"/> of this <see cref=" |
| | | 321 | | public TVendor VendorFunctionality { get; } |
| | | 322 | | |
| | | 323 | | /// <summary> |
| | | 324 | | /// Validates the statement by calling <see cref="ValidateStatementOrThrow(TStatementInformation)"/> and then crea |
| | | 325 | | /// </summary> |
| | | 326 | | /// <param name="statement">The statement which describes how to manipulate/query remote resource.</param> |
| | | 327 | | /// <param name="info">This parameter will contain the read-only statement information, which is either <paramref |
| | | 328 | | /// <returns>The enumerable which can be used to execute the <paramref name="statement"/> statement and iterate th |
| | | 329 | | public IAsyncEnumerable<TEnumerableItem> PrepareStatementForExecution( TStatementInformation statement, out TState |
| | | 330 | | { |
| | | 331 | | info = statement is TStatement stmt ? this.GetInformationFromStatement( stmt ) : statement; |
| | | 332 | | this.ValidateStatementOrThrow( info ); |
| | | 333 | | return this.CreateEnumerable( |
| | | 334 | | info |
| | | 335 | | ); |
| | | 336 | | } |
| | | 337 | | |
| | | 338 | | |
| | | 339 | | |
| | | 340 | | /// <summary> |
| | | 341 | | /// Derived classes should override this abstract method in order to extract read-only statement information objec |
| | | 342 | | /// </summary> |
| | | 343 | | /// <param name="statement">The modifiable statement object.</param> |
| | | 344 | | /// <returns>Read-only information about the <paramref name="statement"/>.</returns> |
| | | 345 | | protected abstract TStatementInformation GetInformationFromStatement( TStatement statement ); |
| | | 346 | | |
| | | 347 | | /// <summary> |
| | | 348 | | /// This method should create actual <see cref="AsyncEnumeratorObservable{T, TMetadata}"/> from given parameters. |
| | | 349 | | /// </summary> |
| | | 350 | | /// <param name="metadata">The statement information.</param> |
| | | 351 | | /// <returns>The enumerable used to asynchronously enumerate over the results of statement execution.</returns> |
| | | 352 | | protected abstract IAsyncEnumerable<TEnumerableItem> CreateEnumerable( |
| | | 353 | | TStatementInformation metadata |
| | | 354 | | ); |
| | | 355 | | |
| | | 356 | | |
| | | 357 | | /// <summary> |
| | | 358 | | /// This method should validate the given read-only information about a statement. |
| | | 359 | | /// </summary> |
| | | 360 | | /// <param name="statement">The read-only information about the statement.</param> |
| | | 361 | | /// <remarks> |
| | | 362 | | /// The <paramref name="statement"/> may be <c>null</c> at this point. |
| | | 363 | | /// </remarks> |
| | | 364 | | protected abstract void ValidateStatementOrThrow( TStatementInformation statement ); |
| | | 365 | | } |
| | | 366 | | |
| | | 367 | | /// <summary> |
| | | 368 | | /// This class extends <see cref="DefaultConnectionFunctionality{TStatement, TStatementInformation, TStatementCreatio |
| | | 369 | | /// </summary> |
| | | 370 | | /// <typeparam name="TStatement">The type of objects used to manipulate or query remote resource.</typeparam> |
| | | 371 | | /// <typeparam name="TStatementInformation">The type of objects describing <typeparamref name="TStatement"/>s.</typep |
| | | 372 | | /// <typeparam name="TStatementCreationArgs">The type of object used to create an instance of <typeparamref name="TSt |
| | | 373 | | /// <typeparam name="TVendor">The type of object describing vendor-specific information.</typeparam> |
| | | 374 | | /// <typeparam name="TEnumerableItem">The type parameter of <see cref="IAsyncEnumerable{T}"/> returned by <see cref=" |
| | | 375 | | public abstract class PooledConnectionFunctionality<TStatement, TStatementInformation, TStatementCreationArgs, TVendo |
| | | 376 | | where TStatement : TStatementInformation |
| | | 377 | | where TVendor : ConnectionVendorFunctionality<TStatement, TStatementCreationArgs> |
| | | 378 | | { |
| | | 379 | | |
| | | 380 | | private Object _cancellationToken; |
| | | 381 | | |
| | | 382 | | /// <summary> |
| | | 383 | | /// Creates a new instance of <see cref="PooledConnectionFunctionality{TStatement, TStatementInformation, TStateme |
| | | 384 | | /// </summary> |
| | | 385 | | /// <param name="vendorFunctionality">The connection vendor.</param> |
| | | 386 | | public PooledConnectionFunctionality( TVendor vendorFunctionality ) |
| | 26 | 387 | | : base( vendorFunctionality ) |
| | | 388 | | { |
| | 26 | 389 | | } |
| | | 390 | | |
| | | 391 | | |
| | | 392 | | /// <summary> |
| | | 393 | | /// Gets or sets the current cancellation token. |
| | | 394 | | /// </summary> |
| | | 395 | | /// <value>The current cancellation token.</value> |
| | | 396 | | public CancellationToken CurrentCancellationToken |
| | | 397 | | { |
| | | 398 | | get |
| | | 399 | | { |
| | 1423 | 400 | | var retVal = this._cancellationToken; |
| | 1424 | 401 | | if ( retVal == null ) |
| | | 402 | | { |
| | 0 | 403 | | throw new InvalidOperationException( "There currently is no cancellation token set for connection." ); |
| | | 404 | | } |
| | 1430 | 405 | | return (CancellationToken) retVal; |
| | | 406 | | } |
| | | 407 | | set |
| | | 408 | | { |
| | 56 | 409 | | Interlocked.Exchange( ref this._cancellationToken, value ); |
| | 56 | 410 | | } |
| | | 411 | | } |
| | | 412 | | |
| | | 413 | | |
| | | 414 | | /// <summary> |
| | | 415 | | /// This method resets current cancellation token, so that <see cref="CurrentCancellationToken"/> property getter |
| | | 416 | | /// </summary> |
| | | 417 | | public void ResetCancellationToken() |
| | | 418 | | { |
| | 56 | 419 | | Interlocked.Exchange( ref this._cancellationToken, null ); |
| | 56 | 420 | | } |
| | | 421 | | |
| | | 422 | | /// <summary> |
| | | 423 | | /// Gets the value indicating whether this connection can be returned to the pool (e.g. underlying stream is open) |
| | | 424 | | /// </summary> |
| | | 425 | | /// <value>The value indicating whether this connection can be returned to the pool (e.g. underlying stream is ope |
| | | 426 | | public abstract Boolean CanBeReturnedToPool { get; } |
| | | 427 | | } |
| | | 428 | | |
| | | 429 | | } |