From 2c6a9892f2082c6a288ba01033f3fd7d517fa92e Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Tue, 8 Apr 2014 00:17:18 -0400 Subject: update translations --- .../HttpClientManager/HttpClientManager.cs | 52 ++++++++++++++++------ 1 file changed, 38 insertions(+), 14 deletions(-) (limited to 'MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs') diff --git a/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs b/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs index ac9a51ea1..7fd7c8c1c 100644 --- a/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs +++ b/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs @@ -162,8 +162,6 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager /// /// The options. /// Task{HttpResponseInfo}. - /// - /// public Task GetResponse(HttpRequestOptions options) { return SendAsync(options, "GET"); @@ -174,8 +172,6 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager /// /// The options. /// Task{Stream}. - /// - /// public async Task Get(HttpRequestOptions options) { var response = await GetResponse(options).ConfigureAwait(false); @@ -322,9 +318,7 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager } catch (WebException ex) { - _logger.ErrorException("Error getting response from " + options.Url, ex); - - throw new HttpException(ex.Message, ex); + throw GetException(ex, options); } catch (Exception ex) { @@ -341,6 +335,42 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager } } + /// + /// Gets the exception. + /// + /// The ex. + /// The options. + /// HttpException. + private HttpException GetException(WebException ex, HttpRequestOptions options) + { + _logger.ErrorException("Error getting response from " + options.Url, ex); + + if (options.LogErrorResponseBody) + { + try + { + using (var stream = ex.Response.GetResponseStream()) + { + if (stream != null) + { + using (var reader = new StreamReader(stream)) + { + var msg = reader.ReadToEnd(); + + _logger.Error(msg); + } + } + } + } + catch + { + + } + } + + return new HttpException(ex.Message, ex); + } + private HttpResponseInfo GetResponseInfo(HttpWebResponse httpResponse, Stream content, long? contentLength) { return new HttpResponseInfo @@ -384,10 +414,6 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager /// The options. /// Params to add to the POST data. /// stream on success, null on failure - /// - /// - /// postData - /// public async Task Post(HttpRequestOptions options, Dictionary postData) { var strings = postData.Keys.Select(key => string.Format("{0}={1}", key, postData[key])); @@ -426,8 +452,6 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager /// The options. /// Task{System.String}. /// progress - /// - /// public async Task GetTempFile(HttpRequestOptions options) { var response = await GetTempFileResponse(options).ConfigureAwait(false); @@ -580,7 +604,7 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager if (webException != null) { - return new HttpException(ex.Message, ex); + throw GetException(webException, options); } return ex; -- cgit v1.2.3 From b9aa4ac8be483ea0d0da235b6446bef4009de297 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Tue, 8 Apr 2014 08:27:22 -0400 Subject: dlna didl fixes --- .../HttpClientManager/HttpClientManager.cs | 59 +++++++++++----------- MediaBrowser.Dlna/PlayTo/Device.cs | 7 ++- MediaBrowser.Dlna/PlayTo/DidlBuilder.cs | 4 +- 3 files changed, 37 insertions(+), 33 deletions(-) (limited to 'MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs') diff --git a/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs b/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs index 7fd7c8c1c..96c207b7b 100644 --- a/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs +++ b/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs @@ -113,11 +113,11 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager AddRequestHeaders(request, options); request.AutomaticDecompression = enableHttpCompression ? DecompressionMethods.Deflate : DecompressionMethods.None; - + request.CachePolicy = options.CachePolicy == Net.HttpRequestCachePolicy.None ? new RequestCachePolicy(RequestCacheLevel.BypassCache) : new RequestCachePolicy(RequestCacheLevel.Revalidate); - + request.ConnectionGroupName = GetHostFromUrl(options.Url); request.KeepAlive = true; request.Method = method; @@ -270,18 +270,18 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager var httpResponse = (HttpWebResponse)response; - EnsureSuccessStatusCode(httpResponse); + EnsureSuccessStatusCode(httpResponse, options); options.CancellationToken.ThrowIfCancellationRequested(); return GetResponseInfo(httpResponse, httpResponse.GetResponseStream(), GetContentLength(httpResponse)); } - + using (var response = await httpWebRequest.GetResponseAsync().ConfigureAwait(false)) { var httpResponse = (HttpWebResponse)response; - EnsureSuccessStatusCode(httpResponse); + EnsureSuccessStatusCode(httpResponse, options); options.CancellationToken.ThrowIfCancellationRequested(); @@ -345,29 +345,6 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager { _logger.ErrorException("Error getting response from " + options.Url, ex); - if (options.LogErrorResponseBody) - { - try - { - using (var stream = ex.Response.GetResponseStream()) - { - if (stream != null) - { - using (var reader = new StreamReader(stream)) - { - var msg = reader.ReadToEnd(); - - _logger.Error(msg); - } - } - } - } - catch - { - - } - } - return new HttpException(ex.Message, ex); } @@ -496,7 +473,7 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager { var httpResponse = (HttpWebResponse)response; - EnsureSuccessStatusCode(httpResponse); + EnsureSuccessStatusCode(httpResponse, options); options.CancellationToken.ThrowIfCancellationRequested(); @@ -686,13 +663,35 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager return exception; } - private void EnsureSuccessStatusCode(HttpWebResponse response) + private void EnsureSuccessStatusCode(HttpWebResponse response, HttpRequestOptions options) { var statusCode = response.StatusCode; var isSuccessful = statusCode >= HttpStatusCode.OK && statusCode <= (HttpStatusCode)299; if (!isSuccessful) { + if (options.LogErrorResponseBody) + { + try + { + using (var stream = response.GetResponseStream()) + { + if (stream != null) + { + using (var reader = new StreamReader(stream)) + { + var msg = reader.ReadToEnd(); + + _logger.Error(msg); + } + } + } + } + catch + { + + } + } throw new HttpException(response.StatusDescription) { StatusCode = response.StatusCode }; } } diff --git a/MediaBrowser.Dlna/PlayTo/Device.cs b/MediaBrowser.Dlna/PlayTo/Device.cs index 12d4b41d1..08ea4f550 100644 --- a/MediaBrowser.Dlna/PlayTo/Device.cs +++ b/MediaBrowser.Dlna/PlayTo/Device.cs @@ -577,6 +577,11 @@ namespace MediaBrowser.Dlna.PlayTo var trackString = (string) track; + if (string.IsNullOrWhiteSpace(trackString) || string.Equals(trackString, "NOT_IMPLEMENTED", StringComparison.OrdinalIgnoreCase)) + { + return false; + } + XElement uPnpResponse; try @@ -586,7 +591,7 @@ namespace MediaBrowser.Dlna.PlayTo catch { _logger.Error("Unable to parse xml {0}", trackString); - throw; + return false; } var e = uPnpResponse.Element(uPnpNamespaces.items); diff --git a/MediaBrowser.Dlna/PlayTo/DidlBuilder.cs b/MediaBrowser.Dlna/PlayTo/DidlBuilder.cs index 80235740f..95622f3f7 100644 --- a/MediaBrowser.Dlna/PlayTo/DidlBuilder.cs +++ b/MediaBrowser.Dlna/PlayTo/DidlBuilder.cs @@ -24,8 +24,8 @@ namespace MediaBrowser.Dlna.PlayTo const string DIDL_RELEASEDATE = @" {0}" + CRLF; const string DIDL_GENRE = @" {0}" + CRLF; const string DESCRIPTION = @" {0}" + CRLF; - const string DIDL_VIDEO_RES = @" {4}" + CRLF; - const string DIDL_AUDIO_RES = @" {3}" + CRLF; + const string DIDL_VIDEO_RES = @" {4}" + CRLF; + const string DIDL_AUDIO_RES = @" {3}" + CRLF; const string DIDL_IMAGE_RES = @" {0}" + CRLF; const string DIDL_ALBUMIMAGE_RES = @" {0}" + CRLF; const string DIDL_RATING = @" {0}" + CRLF; -- cgit v1.2.3