aboutsummaryrefslogtreecommitdiff
path: root/Emby.Server.Implementations
diff options
context:
space:
mode:
authorLuke Pulverenti <luke.pulverenti@gmail.com>2017-10-20 12:16:56 -0400
committerLuke Pulverenti <luke.pulverenti@gmail.com>2017-10-20 12:16:56 -0400
commit060215143ff62e4cf475a493e57c8607beca8640 (patch)
tree1d1095525a83bb8183184db952d28556bc05f323 /Emby.Server.Implementations
parent86226ff97c7d6dc4005c3bb1978861e948de1e20 (diff)
improve httpclient resource disposal
Diffstat (limited to 'Emby.Server.Implementations')
-rw-r--r--Emby.Server.Implementations/HttpClientManager/HttpClientManager.cs62
-rw-r--r--Emby.Server.Implementations/Library/Resolvers/TV/SeasonResolver.cs4
-rw-r--r--Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs3
-rw-r--r--Emby.Server.Implementations/LiveTv/Listings/SchedulesDirect.cs115
-rw-r--r--Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHost.cs38
-rw-r--r--Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHttpStream.cs15
-rw-r--r--Emby.Server.Implementations/Localization/LocalizationManager.cs5
-rw-r--r--Emby.Server.Implementations/News/NewsEntryPoint.cs13
-rw-r--r--Emby.Server.Implementations/Security/PluginSecurityManager.cs9
-rw-r--r--Emby.Server.Implementations/Session/HttpSessionController.cs9
-rw-r--r--Emby.Server.Implementations/Updates/InstallationManager.cs19
11 files changed, 138 insertions, 154 deletions
diff --git a/Emby.Server.Implementations/HttpClientManager/HttpClientManager.cs b/Emby.Server.Implementations/HttpClientManager/HttpClientManager.cs
index fe545ecff..3fdd05135 100644
--- a/Emby.Server.Implementations/HttpClientManager/HttpClientManager.cs
+++ b/Emby.Server.Implementations/HttpClientManager/HttpClientManager.cs
@@ -279,40 +279,10 @@ namespace Emby.Server.Implementations.HttpClientManager
public async Task<Stream> Get(HttpRequestOptions options)
{
var response = await GetResponse(options).ConfigureAwait(false);
-
return response.Content;
}
/// <summary>
- /// Performs a GET request and returns the resulting stream
- /// </summary>
- /// <param name="url">The URL.</param>
- /// <param name="resourcePool">The resource pool.</param>
- /// <param name="cancellationToken">The cancellation token.</param>
- /// <returns>Task{Stream}.</returns>
- public Task<Stream> Get(string url, SemaphoreSlim resourcePool, CancellationToken cancellationToken)
- {
- return Get(new HttpRequestOptions
- {
- Url = url,
- ResourcePool = resourcePool,
- CancellationToken = cancellationToken,
- BufferContent = resourcePool != null
- });
- }
-
- /// <summary>
- /// Gets the specified URL.
- /// </summary>
- /// <param name="url">The URL.</param>
- /// <param name="cancellationToken">The cancellation token.</param>
- /// <returns>Task{Stream}.</returns>
- public Task<Stream> Get(string url, CancellationToken cancellationToken)
- {
- return Get(url, null, cancellationToken);
- }
-
- /// <summary>
/// send as an asynchronous operation.
/// </summary>
/// <param name="options">The options.</param>
@@ -590,26 +560,6 @@ namespace Emby.Server.Implementations.HttpClientManager
}
/// <summary>
- /// Performs a POST request
- /// </summary>
- /// <param name="url">The URL.</param>
- /// <param name="postData">Params to add to the POST data.</param>
- /// <param name="resourcePool">The resource pool.</param>
- /// <param name="cancellationToken">The cancellation token.</param>
- /// <returns>stream on success, null on failure</returns>
- public Task<Stream> Post(string url, Dictionary<string, string> postData, SemaphoreSlim resourcePool, CancellationToken cancellationToken)
- {
- return Post(new HttpRequestOptions
- {
- Url = url,
- ResourcePool = resourcePool,
- CancellationToken = cancellationToken,
- BufferContent = resourcePool != null
-
- }, postData);
- }
-
- /// <summary>
/// Downloads the contents of a given url into a temporary location
/// </summary>
/// <param name="options">The options.</param>
@@ -891,18 +841,6 @@ namespace Emby.Server.Implementations.HttpClientManager
}
}
- /// <summary>
- /// Posts the specified URL.
- /// </summary>
- /// <param name="url">The URL.</param>
- /// <param name="postData">The post data.</param>
- /// <param name="cancellationToken">The cancellation token.</param>
- /// <returns>Task{Stream}.</returns>
- public Task<Stream> Post(string url, Dictionary<string, string> postData, CancellationToken cancellationToken)
- {
- return Post(url, postData, null, cancellationToken);
- }
-
private Task<WebResponse> GetResponseAsync(WebRequest request, TimeSpan timeout)
{
var taskCompletion = new TaskCompletionSource<WebResponse>();
diff --git a/Emby.Server.Implementations/Library/Resolvers/TV/SeasonResolver.cs b/Emby.Server.Implementations/Library/Resolvers/TV/SeasonResolver.cs
index a859d8ec8..a0ff29482 100644
--- a/Emby.Server.Implementations/Library/Resolvers/TV/SeasonResolver.cs
+++ b/Emby.Server.Implementations/Library/Resolvers/TV/SeasonResolver.cs
@@ -55,10 +55,10 @@ namespace Emby.Server.Implementations.Library.Resolvers.TV
if (season.IndexNumber.HasValue)
{
var seasonNumber = season.IndexNumber.Value;
-
+
season.Name = seasonNumber == 0 ?
args.LibraryOptions.SeasonZeroDisplayName :
- string.Format(_localization.GetLocalizedString("NameSeasonNumber"), seasonNumber.ToString(UsCulture));
+ string.Format(_localization.GetLocalizedString("NameSeasonNumber"), seasonNumber.ToString(UsCulture), args.GetLibraryOptions().PreferredMetadataLanguage);
}
return season;
diff --git a/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs b/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs
index 5c32086ff..e7a360594 100644
--- a/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs
+++ b/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs
@@ -1463,6 +1463,9 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
_timerProvider.AddOrUpdate(timer, false);
await SaveRecordingMetadata(timer, recordPath, seriesPath).ConfigureAwait(false);
+
+ CreateRecordingFolders();
+
TriggerRefresh(recordPath);
EnforceKeepUpTo(timer, seriesPath);
};
diff --git a/Emby.Server.Implementations/LiveTv/Listings/SchedulesDirect.cs b/Emby.Server.Implementations/LiveTv/Listings/SchedulesDirect.cs
index b7cfdea1b..136d0cc7f 100644
--- a/Emby.Server.Implementations/LiveTv/Listings/SchedulesDirect.cs
+++ b/Emby.Server.Implementations/LiveTv/Listings/SchedulesDirect.cs
@@ -541,27 +541,30 @@ namespace Emby.Server.Implementations.LiveTv.Listings
try
{
- using (Stream responce = await Get(options, false, info).ConfigureAwait(false))
+ using (var httpResponse = await Get(options, false, info).ConfigureAwait(false))
{
- var root = _jsonSerializer.DeserializeFromStream<List<ScheduleDirect.Headends>>(responce);
-
- if (root != null)
+ using (Stream responce = httpResponse.Content)
{
- foreach (ScheduleDirect.Headends headend in root)
+ var root = _jsonSerializer.DeserializeFromStream<List<ScheduleDirect.Headends>>(responce);
+
+ if (root != null)
{
- foreach (ScheduleDirect.Lineup lineup in headend.lineups)
+ foreach (ScheduleDirect.Headends headend in root)
{
- lineups.Add(new NameIdPair
+ foreach (ScheduleDirect.Lineup lineup in headend.lineups)
{
- Name = string.IsNullOrWhiteSpace(lineup.name) ? lineup.lineup : lineup.name,
- Id = lineup.uri.Substring(18)
- });
+ lineups.Add(new NameIdPair
+ {
+ Name = string.IsNullOrWhiteSpace(lineup.name) ? lineup.lineup : lineup.name,
+ Id = lineup.uri.Substring(18)
+ });
+ }
}
}
- }
- else
- {
- _logger.Info("No lineups available");
+ else
+ {
+ _logger.Info("No lineups available");
+ }
}
}
}
@@ -671,13 +674,13 @@ namespace Emby.Server.Implementations.LiveTv.Listings
return await Post(options, false, providerInfo).ConfigureAwait(false);
}
- private async Task<Stream> Get(HttpRequestOptions options,
+ private async Task<HttpResponseInfo> Get(HttpRequestOptions options,
bool enableRetry,
ListingsProviderInfo providerInfo)
{
try
{
- return await _httpClient.Get(options).ConfigureAwait(false);
+ return await _httpClient.SendAsync(options, "GET").ConfigureAwait(false);
}
catch (HttpException ex)
{
@@ -797,11 +800,14 @@ namespace Emby.Server.Implementations.LiveTv.Listings
try
{
- using (var response = await Get(options, false, null).ConfigureAwait(false))
+ using (var httpResponse = await Get(options, false, null).ConfigureAwait(false))
{
- var root = _jsonSerializer.DeserializeFromStream<ScheduleDirect.Lineups>(response);
+ using (var response = httpResponse.Content)
+ {
+ var root = _jsonSerializer.DeserializeFromStream<ScheduleDirect.Lineups>(response);
- return root.lineups.Any(i => string.Equals(info.ListingsId, i.lineup, StringComparison.OrdinalIgnoreCase));
+ return root.lineups.Any(i => string.Equals(info.ListingsId, i.lineup, StringComparison.OrdinalIgnoreCase));
+ }
}
}
catch (HttpException ex)
@@ -879,53 +885,56 @@ namespace Emby.Server.Implementations.LiveTv.Listings
var list = new List<ChannelInfo>();
- using (var response = await Get(httpOptions, true, info).ConfigureAwait(false))
+ using (var httpResponse = await Get(httpOptions, true, info).ConfigureAwait(false))
{
- var root = _jsonSerializer.DeserializeFromStream<ScheduleDirect.Channel>(response);
- _logger.Info("Found " + root.map.Count + " channels on the lineup on ScheduleDirect");
- _logger.Info("Mapping Stations to Channel");
-
- var allStations = root.stations ?? new List<ScheduleDirect.Station>();
-
- foreach (ScheduleDirect.Map map in root.map)
+ using (var response = httpResponse.Content)
{
- var channelNumber = GetChannelNumber(map);
-
- var station = allStations.FirstOrDefault(item => string.Equals(item.stationID, map.stationID, StringComparison.OrdinalIgnoreCase));
- if (station == null)
- {
- station = new ScheduleDirect.Station
- {
- stationID = map.stationID
- };
- }
+ var root = _jsonSerializer.DeserializeFromStream<ScheduleDirect.Channel>(response);
+ _logger.Info("Found " + root.map.Count + " channels on the lineup on ScheduleDirect");
+ _logger.Info("Mapping Stations to Channel");
- var name = channelNumber;
+ var allStations = root.stations ?? new List<ScheduleDirect.Station>();
- var channelInfo = new ChannelInfo
+ foreach (ScheduleDirect.Map map in root.map)
{
- Number = channelNumber,
- Name = name
- };
+ var channelNumber = GetChannelNumber(map);
- if (station != null)
- {
- if (!string.IsNullOrWhiteSpace(station.name))
+ var station = allStations.FirstOrDefault(item => string.Equals(item.stationID, map.stationID, StringComparison.OrdinalIgnoreCase));
+ if (station == null)
{
- channelInfo.Name = station.name;
+ station = new ScheduleDirect.Station
+ {
+ stationID = map.stationID
+ };
}
- channelInfo.Id = station.stationID;
- channelInfo.CallSign = station.callsign;
+ var name = channelNumber;
- if (station.logo != null)
+ var channelInfo = new ChannelInfo
{
- channelInfo.ImageUrl = station.logo.URL;
- channelInfo.HasImage = true;
+ Number = channelNumber,
+ Name = name
+ };
+
+ if (station != null)
+ {
+ if (!string.IsNullOrWhiteSpace(station.name))
+ {
+ channelInfo.Name = station.name;
+ }
+
+ channelInfo.Id = station.stationID;
+ channelInfo.CallSign = station.callsign;
+
+ if (station.logo != null)
+ {
+ channelInfo.ImageUrl = station.logo.URL;
+ channelInfo.HasImage = true;
+ }
}
- }
- list.Add(channelInfo);
+ list.Add(channelInfo);
+ }
}
}
diff --git a/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHost.cs b/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHost.cs
index cfdaaed10..f8bb766d2 100644
--- a/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHost.cs
+++ b/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHost.cs
@@ -86,16 +86,19 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
CancellationToken = cancellationToken,
BufferContent = false
};
- using (var stream = await _httpClient.Get(options).ConfigureAwait(false))
+ using (var response = await _httpClient.SendAsync(options, "GET").ConfigureAwait(false))
{
- var lineup = JsonSerializer.DeserializeFromStream<List<Channels>>(stream) ?? new List<Channels>();
-
- if (info.ImportFavoritesOnly)
+ using (var stream = response.Content)
{
- lineup = lineup.Where(i => i.Favorite).ToList();
- }
+ var lineup = JsonSerializer.DeserializeFromStream<List<Channels>>(stream) ?? new List<Channels>();
+
+ if (info.ImportFavoritesOnly)
+ {
+ lineup = lineup.Where(i => i.Favorite).ToList();
+ }
- return lineup.Where(i => !i.DRM).ToList();
+ return lineup.Where(i => !i.DRM).ToList();
+ }
}
}
@@ -143,26 +146,29 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
try
{
- using (var stream = await _httpClient.Get(new HttpRequestOptions()
+ using (var response = await _httpClient.SendAsync(new HttpRequestOptions()
{
Url = string.Format("{0}/discover.json", GetApiUrl(info, false)),
CancellationToken = cancellationToken,
TimeoutMs = Convert.ToInt32(TimeSpan.FromSeconds(5).TotalMilliseconds),
BufferContent = false
- }).ConfigureAwait(false))
+ }, "GET").ConfigureAwait(false))
{
- var response = JsonSerializer.DeserializeFromStream<DiscoverResponse>(stream);
-
- if (!string.IsNullOrWhiteSpace(info.Id))
+ using (var stream = response.Content)
{
- lock (_modelCache)
+ var discoverResponse = JsonSerializer.DeserializeFromStream<DiscoverResponse>(stream);
+
+ if (!string.IsNullOrWhiteSpace(info.Id))
{
- _modelCache[info.Id] = response;
+ lock (_modelCache)
+ {
+ _modelCache[info.Id] = discoverResponse;
+ }
}
- }
- return response;
+ return discoverResponse;
+ }
}
}
catch (HttpException ex)
diff --git a/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHttpStream.cs b/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHttpStream.cs
index ad9c0d894..f3d89c6cc 100644
--- a/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHttpStream.cs
+++ b/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHttpStream.cs
@@ -92,14 +92,17 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
}, "GET").ConfigureAwait(false))
{
- Logger.Info("Opened HDHR stream from {0}", url);
+ using (var stream = response.Content)
+ {
+ Logger.Info("Opened HDHR stream from {0}", url);
- Logger.Info("Beginning multicastStream.CopyUntilCancelled");
+ Logger.Info("Beginning multicastStream.CopyUntilCancelled");
- FileSystem.CreateDirectory(FileSystem.GetDirectoryName(TempFilePath));
- using (var fileStream = FileSystem.GetFileStream(TempFilePath, FileOpenMode.Create, FileAccessMode.Write, FileShareMode.Read, FileOpenOptions.None))
- {
- StreamHelper.CopyTo(response.Content, fileStream, 81920, () => Resolve(openTaskCompletionSource), cancellationToken);
+ FileSystem.CreateDirectory(FileSystem.GetDirectoryName(TempFilePath));
+ using (var fileStream = FileSystem.GetFileStream(TempFilePath, FileOpenMode.Create, FileAccessMode.Write, FileShareMode.Read, FileOpenOptions.None))
+ {
+ StreamHelper.CopyTo(stream, fileStream, 81920, () => Resolve(openTaskCompletionSource), cancellationToken);
+ }
}
}
}
diff --git a/Emby.Server.Implementations/Localization/LocalizationManager.cs b/Emby.Server.Implementations/Localization/LocalizationManager.cs
index b0cee12be..48df96289 100644
--- a/Emby.Server.Implementations/Localization/LocalizationManager.cs
+++ b/Emby.Server.Implementations/Localization/LocalizationManager.cs
@@ -315,6 +315,11 @@ namespace Emby.Server.Implementations.Localization
public string GetLocalizedString(string phrase, string culture)
{
+ if (string.IsNullOrWhiteSpace(culture))
+ {
+ culture = _configurationManager.Configuration.UICulture;
+ }
+
var dictionary = GetLocalizationDictionary(culture);
string value;
diff --git a/Emby.Server.Implementations/News/NewsEntryPoint.cs b/Emby.Server.Implementations/News/NewsEntryPoint.cs
index 03c79c2c1..74366233c 100644
--- a/Emby.Server.Implementations/News/NewsEntryPoint.cs
+++ b/Emby.Server.Implementations/News/NewsEntryPoint.cs
@@ -88,15 +88,18 @@ namespace Emby.Server.Implementations.News
BufferContent = false
};
- using (var stream = await _httpClient.Get(requestOptions).ConfigureAwait(false))
+ using (var response = await _httpClient.SendAsync(requestOptions, "GET").ConfigureAwait(false))
{
- using (var reader = XmlReader.Create(stream))
+ using (var stream = response.Content)
{
- var news = ParseRssItems(reader).ToList();
+ using (var reader = XmlReader.Create(stream))
+ {
+ var news = ParseRssItems(reader).ToList();
- _json.SerializeToFile(news, path);
+ _json.SerializeToFile(news, path);
- await CreateNotifications(news, lastUpdate, CancellationToken.None).ConfigureAwait(false);
+ await CreateNotifications(news, lastUpdate, CancellationToken.None).ConfigureAwait(false);
+ }
}
}
}
diff --git a/Emby.Server.Implementations/Security/PluginSecurityManager.cs b/Emby.Server.Implementations/Security/PluginSecurityManager.cs
index d42fae3ad..615ffa1f4 100644
--- a/Emby.Server.Implementations/Security/PluginSecurityManager.cs
+++ b/Emby.Server.Implementations/Security/PluginSecurityManager.cs
@@ -293,10 +293,13 @@ namespace Emby.Server.Implementations.Security
options.SetPostData(data);
- using (var json = (await _httpClient.Post(options).ConfigureAwait(false)).Content)
+ using (var response = (await _httpClient.Post(options).ConfigureAwait(false)))
{
- reg = _jsonSerializer.DeserializeFromStream<RegRecord>(json);
- success = true;
+ using (var json = response.Content)
+ {
+ reg = _jsonSerializer.DeserializeFromStream<RegRecord>(json);
+ success = true;
+ }
}
if (reg.registered)
diff --git a/Emby.Server.Implementations/Session/HttpSessionController.cs b/Emby.Server.Implementations/Session/HttpSessionController.cs
index bd53da1bd..940c821e2 100644
--- a/Emby.Server.Implementations/Session/HttpSessionController.cs
+++ b/Emby.Server.Implementations/Session/HttpSessionController.cs
@@ -66,19 +66,22 @@ namespace Emby.Server.Implementations.Session
return SendMessage(name, new Dictionary<string, string>(), cancellationToken);
}
- private Task SendMessage(string name,
+ private async Task SendMessage(string name,
Dictionary<string, string> args,
CancellationToken cancellationToken)
{
var url = PostUrl + "/" + name + ToQueryString(args);
- return _httpClient.Post(new HttpRequestOptions
+ using ((await _httpClient.Post(new HttpRequestOptions
{
Url = url,
CancellationToken = cancellationToken,
BufferContent = false
- });
+ }).ConfigureAwait(false)))
+ {
+
+ }
}
public Task SendSessionEndedNotification(SessionInfoDto sessionInfo, CancellationToken cancellationToken)
diff --git a/Emby.Server.Implementations/Updates/InstallationManager.cs b/Emby.Server.Implementations/Updates/InstallationManager.cs
index 772f2338a..51acfee88 100644
--- a/Emby.Server.Implementations/Updates/InstallationManager.cs
+++ b/Emby.Server.Implementations/Updates/InstallationManager.cs
@@ -175,13 +175,24 @@ namespace Emby.Server.Implementations.Updates
{ "systemid", _applicationHost.SystemId }
};
- using (var json = await _httpClient.Post("https://www.mb3admin.com/admin/service/package/retrieveall?includeAllRuntimes=true", data, cancellationToken).ConfigureAwait(false))
+ var options = new HttpRequestOptions
{
- cancellationToken.ThrowIfCancellationRequested();
+ Url = "https://www.mb3admin.com/admin/service/package/retrieveall?includeAllRuntimes=true",
+ CancellationToken = cancellationToken
+ };
+
+ options.SetPostData(data);
+
+ using (var response = await _httpClient.SendAsync(options, "POST").ConfigureAwait(false))
+ {
+ using (var json = response.Content)
+ {
+ cancellationToken.ThrowIfCancellationRequested();
- var packages = _jsonSerializer.DeserializeFromStream<PackageInfo[]>(json);
+ var packages = _jsonSerializer.DeserializeFromStream<PackageInfo[]>(json);
- return FilterPackages(packages, packageType, applicationVersion);
+ return FilterPackages(packages, packageType, applicationVersion);
+ }
}
}
else