Example #1
0
        // Stream Profile Image
        public Task <Stream> GetProfileImageStream(IGetProfileImageParameters parameters, ITwitterRequest request)
        {
            var url = _userQueryGenerator.DownloadProfileImageURL(parameters);

            request.Query.Url        = url;
            request.Query.HttpMethod = HttpMethod.GET;

            return(_webHelper.GetResponseStreamAsync(request));
        }
Example #2
0
        private StreamReader CreateStreamReaderFromWebRequest(WebRequest webRequest)
        {
            if (webRequest == null)
            {
                SetStreamState(StreamState.Stop);
                return(null);
            }

            StreamReader reader = null;

            try
            {
                var twitterQuery = _twitterQueryFactory.Create(webRequest.RequestUri.AbsoluteUri);
                var queryBeforeExecuteEventArgs = new QueryBeforeExecuteEventArgs(twitterQuery);
                _tweetinviEvents.RaiseBeforeQueryExecute(queryBeforeExecuteEventArgs);

                if (queryBeforeExecuteEventArgs.Cancel)
                {
                    SetStreamState(StreamState.Stop);
                    return(null);
                }

                // TODO : LINVI - THIS CODE HAS CHANGED AND NEEDS TO BE CHECKED WITH ASP.NET
                var responseStream = _webHelper.GetResponseStreamAsync(webRequest).Result;
                if (responseStream != null)
                {
                    reader = new StreamReader(responseStream, Encoding.GetEncoding("utf-8"));
                }
            }
            catch (WebException wex)
            {
                HandleWebException(wex);
            }
            catch (Exception ex)
            {
                if (ex is ArgumentException)
                {
                    if (ex.Message == "Stream was not readable.")
                    {
                        webRequest.Abort();
                    }
                }

                _lastException = ex;
                SetStreamState(StreamState.Stop);
            }

            return(reader);
        }
Example #3
0
        private async Task <StreamReader> InitWebRequest(WebRequest webRequest)
        {
            StreamReader reader = null;

            try
            {
                var responseStream = await _webHelper.GetResponseStreamAsync(webRequest);

                if (responseStream != null)
                {
                    reader = new StreamReader(responseStream, System.Text.Encoding.GetEncoding("utf-8"));
                }
            }
            catch (WebException wex)
            {
                if (_exceptionHandler.LogExceptions)
                {
                    _exceptionHandler.AddWebException(wex, webRequest.RequestUri.AbsoluteUri);
                }

                if (!_exceptionHandler.SwallowWebExceptions)
                {
                    throw;
                }
            }
            catch (Exception ex)
            {
                if (ex is ArgumentException)
                {
                    if (ex.Message == "Stream was not readable.")
                    {
                        webRequest.Abort();
                    }
                }

                _lastException = ex;
                StreamState    = StreamState.Stop;
            }

            return(reader);
        }
Example #4
0
        public async Task GetProfileImageStream_ReturnsWebHelperResultAsync()
        {
            // Arrange
            var queryExecutor = CreateUserQueryExecutor();
            var stream        = A.Fake <Stream>();
            var url           = TestHelper.GenerateString();
            var request       = A.Fake <ITwitterRequest>();

            var parameter = new GetProfileImageParameters("some url");

            A.CallTo(() => _fakeUserQueryGenerator.DownloadProfileImageURL(parameter)).Returns(url);
            A.CallTo(() => _fakeWebHelper.GetResponseStreamAsync(request)).Returns(stream);

            // Act
            var result = await queryExecutor.GetProfileImageStreamAsync(parameter, request);

            // Assert
            Assert.Equal(result, stream);
            Assert.Equal(request.Query.Url, url);
            Assert.Equal(HttpMethod.GET, request.Query.HttpMethod);
        }