public async Task StartStreamAsync(Func<string, bool> processObject, Func<HttpWebRequest> generateWebRequest)
        {
            IStreamTask streamTask;

            lock (_lockStream)
            {
                if (IsRunning)
                {
                    throw new OperationCanceledException(Resources.Stream_IllegalMultipleStreams);
                }

                if (processObject == null)
                {
                    throw new NullReferenceException(Resources.Stream_ObjectDelegateIsNull);
                }

                var processObjectParameter = _streamTaskFactory.GenerateParameterOverrideWrapper("processObject", processObject);
                var generateWebRequestParameter = _streamTaskFactory.GenerateParameterOverrideWrapper("generateWebRequest", generateWebRequest);
                
                streamTask = _streamTaskFactory.Create(processObjectParameter, generateWebRequestParameter);

                _currentStreamTask = streamTask;
                _currentStreamTask.StreamStarted += StreamTaskStarted;
                _currentStreamTask.StreamStateChanged += StreamTaskStateChanged;
            }

            await TaskEx.Run(() =>
            {
                streamTask.Start();
            });
        }
        public async Task StartStreamAsync(Func <string, bool> processObject, Func <ITwitterQuery> generateTwitterQuery)
        {
            IStreamTask streamTask;

            lock (_lockStream)
            {
                if (IsRunning)
                {
                    throw new OperationCanceledException(Resources.Stream_IllegalMultipleStreams);
                }

                if (processObject == null)
                {
                    throw new NullReferenceException(Resources.Stream_ObjectDelegateIsNull);
                }

                var processObjectParameter      = _streamTaskFactory.GenerateParameterOverrideWrapper("processObject", processObject);
                var generateWebRequestParameter = _streamTaskFactory.GenerateParameterOverrideWrapper("generateTwitterQuery", generateTwitterQuery);

                streamTask = _streamTaskFactory.Create(processObjectParameter, generateWebRequestParameter);

                _currentStreamTask = streamTask;
                _currentStreamTask.StreamStarted      += StreamTaskStarted;
                _currentStreamTask.StreamStateChanged += StreamTaskStateChanged;
            }

            await TaskEx.Run(() =>
            {
                streamTask.Start();
            }).ConfigureAwait(false);
        }
Example #3
0
        public async Task StartAsync(Func <string, bool> onJsonReceivedCallback, Func <ITwitterRequest> createTwitterRequest)
        {
            IStreamTask streamTask;

            lock (_lockStream)
            {
                if (IsRunning)
                {
                    throw new OperationCanceledException(Resources.Stream_IllegalMultipleStreams);
                }

                if (onJsonReceivedCallback == null)
                {
                    throw new NullReferenceException(Resources.Stream_ObjectDelegateIsNull);
                }

                streamTask = _streamTaskFactory.Create(onJsonReceivedCallback, createTwitterRequest);

                _currentStreamTask = streamTask;
                _currentStreamTask.StreamStarted      += StreamTaskStarted;
                _currentStreamTask.StreamStateChanged += StreamTaskStateChanged;
                _currentStreamTask.KeepAliveReceived  += KeepAliveReceived;
            }

            await streamTask.StartAsync().ConfigureAwait(false);
        }
        private StreamExceptionEventArgs StopStreamAndUnsubscribeFromEvents()
        {
            var streamTask = _currentStreamTask;

            if (streamTask != null)
            {
                streamTask.StreamStarted      -= StreamTaskStarted;
                streamTask.StreamStateChanged -= StreamTaskStateChanged;
                streamTask.Stop();

                if (_currentStreamTask == streamTask)
                {
                    _currentStreamTask = null;
                }

                return(new StreamExceptionEventArgs(streamTask.LastException));
            }

            return(new StreamExceptionEventArgs(null));
        }
Example #5
0
        private StreamStoppedEventArgs StopStreamAndUnsubscribeFromEvents()
        {
            var streamTask = _currentStreamTask;

            if (streamTask != null)
            {
                streamTask.StreamStarted      -= StreamTaskStarted;
                streamTask.StreamStateChanged -= StreamTaskStateChanged;
                streamTask.KeepAliveReceived  -= KeepAliveReceived;
                streamTask.Stop();

                if (_currentStreamTask == streamTask)
                {
                    _currentStreamTask = null;
                }

                return(new StreamStoppedEventArgs());
            }

            return(new StreamStoppedEventArgs(null));
        }
Example #6
0
 public Worker(ILogger <Worker> logger, IStreamTask streamTask, IRepository repository)
 {
     _logger     = logger;
     _streamTask = streamTask;
     _repository = repository;
 }
        private StreamExceptionEventArgs StopStreamAndUnsubscribeFromEvents()
        {
            var streamTask = _currentStreamTask;
            if (streamTask != null)
            {
                streamTask.StreamStarted -= StreamTaskStarted;
                streamTask.StreamStateChanged -= StreamTaskStateChanged;
                streamTask.Stop();

                if (_currentStreamTask == streamTask)
                {
                    _currentStreamTask = null;
                }

                return new StreamExceptionEventArgs(streamTask.LastException);
            }

            return new StreamExceptionEventArgs(null);
        }