public void Close() { // Method entry trace const string method = "Close"; if (EventSource.IsEnabled(Event.MethodEnter)) { EventSource.Raise(Event.MethodEnter, method); } try { // Finalize all the sources _source.Close(); _source = null; _initialised = false; } catch (Exception ex) { if (EventSource.IsEnabled(Event.CriticalError)) { EventSource.Raise(Event.CriticalError, method, "Cannot close the channel.", ex); } } // Method exit trace if (EventSource.IsEnabled(Event.MethodExit)) { EventSource.Raise(Event.MethodExit, method); } }
// constructors /// <summary> /// Initializes a new instance of the <see cref="AsyncCursor{TDocument}"/> class. /// </summary> /// <param name="channelSource">The channel source.</param> /// <param name="collectionNamespace">The collection namespace.</param> /// <param name="comment">The comment.</param> /// <param name="firstBatch">The first batch.</param> /// <param name="cursorId">The cursor identifier.</param> /// <param name="batchSize">The size of a batch.</param> /// <param name="limit">The limit.</param> /// <param name="serializer">The serializer.</param> /// <param name="messageEncoderSettings">The message encoder settings.</param> /// <param name="maxTime">The maxTime for each batch.</param> public AsyncCursor( IChannelSource channelSource, CollectionNamespace collectionNamespace, BsonValue comment, IReadOnlyList <TDocument> firstBatch, long cursorId, int?batchSize, int?limit, IBsonSerializer <TDocument> serializer, MessageEncoderSettings messageEncoderSettings, TimeSpan?maxTime = null) : this( channelSource, collectionNamespace, comment, firstBatch, cursorId, null, // postBatchResumeToken batchSize, limit, serializer, messageEncoderSettings, maxTime) { }
// constructors /// <summary> /// Initializes a new instance of the <see cref="AsyncCursor{TDocument}"/> class. /// </summary> /// <param name="channelSource">The channel source.</param> /// <param name="collectionNamespace">The collection namespace.</param> /// <param name="query">The query.</param> /// <param name="firstBatch">The first batch.</param> /// <param name="cursorId">The cursor identifier.</param> /// <param name="batchSize">The size of a batch.</param> /// <param name="limit">The limit.</param> /// <param name="serializer">The serializer.</param> /// <param name="messageEncoderSettings">The message encoder settings.</param> /// <param name="maxTime">The maxTime for each batch.</param> public AsyncCursor( IChannelSource channelSource, CollectionNamespace collectionNamespace, BsonDocument query, IReadOnlyList <TDocument> firstBatch, long cursorId, int?batchSize, int?limit, IBsonSerializer <TDocument> serializer, MessageEncoderSettings messageEncoderSettings, TimeSpan?maxTime = null) { _operationId = EventContext.OperationId; _channelSource = channelSource; _collectionNamespace = Ensure.IsNotNull(collectionNamespace, nameof(collectionNamespace)); _query = Ensure.IsNotNull(query, nameof(query)); _firstBatch = Ensure.IsNotNull(firstBatch, nameof(firstBatch)); _cursorId = cursorId; _batchSize = Ensure.IsNullOrGreaterThanOrEqualToZero(batchSize, nameof(batchSize)); _limit = Ensure.IsNullOrGreaterThanOrEqualToZero(limit, nameof(limit)); _serializer = Ensure.IsNotNull(serializer, nameof(serializer)); _messageEncoderSettings = messageEncoderSettings; _maxTime = maxTime; if (_limit > 0 && _firstBatch.Count > _limit) { _firstBatch = _firstBatch.Take(_limit.Value).ToList(); } _count = _firstBatch.Count; DisposeChannelSourceIfNoLongerNeeded(); }
public AsyncCursor( IChannelSource channelSource, CollectionNamespace collectionNamespace, BsonDocument query, // no longer used, so ingore it IReadOnlyList <TDocument> firstBatch, long cursorId, BsonDocument postBatchResumeToken, int?batchSize, int?limit, IBsonSerializer <TDocument> serializer, MessageEncoderSettings messageEncoderSettings, TimeSpan?maxTime) : this( channelSource, collectionNamespace, comment : null, firstBatch, cursorId, postBatchResumeToken, batchSize, limit, serializer, messageEncoderSettings, maxTime) { }
public static IConnectionHandle _reference_instance_channel_connection(this IChannelSource channelSource) { var reference = Reflector.GetFieldValue(channelSource, "_reference"); var instance = Reflector.GetFieldValue(reference, "_instance"); var channel = Reflector.GetFieldValue(instance, "_channel"); return((IConnectionHandle)Reflector.GetFieldValue(channel, "_connection")); }
private void DisposeChannelSourceIfNoLongerNeeded() { if (_channelSource != null && _cursorId == 0) { _channelSource.Dispose(); _channelSource = null; } }
private void InitializeCore() { Debug.Assert(!_initialised, "!_initialised"); var source = Container.Current.Resolve <IChannelSource>(); source.Open(); _source = source; }
/// <summary> /// Executes the protocol. /// </summary> /// <param name="channelSource">The channel source.</param> /// <param name="readPreference">The read preference.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>A Task whose result is the command result.</returns> protected async Task <TCommandResult> ExecuteProtocolAsync( IChannelSource channelSource, ReadPreference readPreference, CancellationToken cancellationToken) { using (var channel = await channelSource.GetChannelAsync(cancellationToken).ConfigureAwait(false)) { return(await ExecuteProtocolAsync(channel, channelSource.ServerDescription, readPreference, cancellationToken).ConfigureAwait(false)); } }
/// <summary> /// Executes the protocol. /// </summary> /// <param name="channelSource">The channel source.</param> /// <param name="readPreference">The read preference.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>A Task whose result is the command result.</returns> protected TCommandResult ExecuteProtocol( IChannelSource channelSource, ReadPreference readPreference, CancellationToken cancellationToken) { using (var channel = channelSource.GetChannel(cancellationToken)) { return(ExecuteProtocol(channel, channelSource.ServerDescription, readPreference, cancellationToken)); } }
/// <summary> /// Executes the protocol. /// </summary> /// <param name="channelSource">The channel source.</param> /// <param name="session">The session.</param> /// <param name="readPreference">The read preference.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns> /// A Task whose result is the command result. /// </returns> protected TCommandResult ExecuteProtocol( IChannelSource channelSource, ICoreSessionHandle session, ReadPreference readPreference, CancellationToken cancellationToken) { using (var channel = channelSource.GetChannel(cancellationToken)) { return(ExecuteProtocol(channel, session, readPreference, cancellationToken)); } }
public ICollection<IDownloadSource> GetPage(IChannelSource source, int page) { BlipVideoChannelSource channelSource = (BlipVideoChannelSource)source; // page is relative to the current page // instead of throwing an exception for the current page, // it could just return the current download sources int actualPage = channelSource.CurrentPage + page; if (actualPage <= 0 || actualPage > channelSource.TotalPages) throw new ArgumentOutOfRangeException("page"); string pagingUrlFormat = channelSource.PagingUrlFormat; string pagingUrl = String.Format(pagingUrlFormat, actualPage); Uri pagingUri = new Uri(channelSource.Uri, pagingUrl); string pageData = GetPageData(pagingUri); IDownloadSource[] downloadSources = ParseDownloadSources(pageData, channelSource).ToArray(); return downloadSources; }
public ICollection<IDownloadSource> GetPage(IChannelSource source, int page) { var channelSource = (YoutubeVideoChannelSource)source; // youtube channels are always on page zero, // so relative pages must be greater than zero if (page <= 0) throw new ArgumentOutOfRangeException("page"); string ajaxSessionInfo = channelSource.AjaxSessionInfo; string postData = String.Format(pagingPostDataFormat, page, ajaxSessionInfo); string pagingUrl = String.Format(pagingUrlFormat, channelSource.User); var pagingUri = new Uri(channelSource.Uri, pagingUrl); string pageData = GetPageData(pagingUri, postData); string escapedMarkup = pageData.GetStringBetween("\"data\"", "\"", "<\\/div>\""); string markup = Regex.Unescape(escapedMarkup); IDownloadSource[] downloadSources = ParseDownloadSources(markup, channelSource).ToArray(); return downloadSources; }
// constructors /// <summary> /// Initializes a new instance of the <see cref="AsyncCursor{TDocument}"/> class. /// </summary> /// <param name="channelSource">The channel source.</param> /// <param name="collectionNamespace">The collection namespace.</param> /// <param name="query">The query.</param> /// <param name="firstBatch">The first batch.</param> /// <param name="cursorId">The cursor identifier.</param> /// <param name="batchSize">The size of a batch.</param> /// <param name="limit">The limit.</param> /// <param name="serializer">The serializer.</param> /// <param name="messageEncoderSettings">The message encoder settings.</param> public AsyncCursor( IChannelSource channelSource, CollectionNamespace collectionNamespace, BsonDocument query, IReadOnlyList <TDocument> firstBatch, long cursorId, int batchSize, int limit, IBsonSerializer <TDocument> serializer, MessageEncoderSettings messageEncoderSettings) { _operationId = EventContext.OperationId; _channelSource = channelSource; _collectionNamespace = Ensure.IsNotNull(collectionNamespace, nameof(collectionNamespace)); _query = Ensure.IsNotNull(query, nameof(query)); _firstBatch = Ensure.IsNotNull(firstBatch, nameof(firstBatch)); _cursorId = cursorId; _batchSize = Ensure.IsGreaterThanOrEqualToZero(batchSize, nameof(batchSize)); _limit = Ensure.IsGreaterThanOrEqualToZero(limit, nameof(limit)); _serializer = Ensure.IsNotNull(serializer, nameof(serializer)); _messageEncoderSettings = messageEncoderSettings; if (_limit == 0) { _limit = int.MaxValue; } if (_firstBatch.Count > _limit) { _firstBatch = _firstBatch.Take(_limit).ToList(); } _count = _firstBatch.Count; // if we aren't going to need the channel source we can go ahead and Dispose it now if (_cursorId == 0 && _channelSource != null) { _channelSource.Dispose(); _channelSource = null; } }
public void Setup() { _channelSource = Substitute.For <IChannelSource>(); }
// constructors /// <summary> /// Initializes a new instance of the <see cref="ChannelSourceHandle"/> class. /// </summary> /// <param name="channelSource">The channel source.</param> public ChannelSourceHandle(IChannelSource channelSource) : this(new ReferenceCounted<IChannelSource>(channelSource)) { }
// static methods public static IChannelHandle GetChannel(this IChannelSource channelSource, CancellationToken cancellationToken = default(CancellationToken)) { return(channelSource.GetChannelAsync(cancellationToken).GetAwaiter().GetResult()); }
// constructors /// <summary> /// Initializes a new instance of the <see cref="ChannelSourceHandle"/> class. /// </summary> /// <param name="channelSource">The channel source.</param> public ChannelSourceHandle(IChannelSource channelSource) : this(new ReferenceCounted <IChannelSource>(channelSource)) { }
public void Setup() { _channelSource = Substitute.For<IChannelSource>(); }
public static int _reference_referenceCount(this IChannelSource channelSourceHandle) { var reference = Reflector.GetFieldValue(channelSourceHandle, "_reference"); return((int)Reflector.GetFieldValue(reference, "_referenceCount")); }