Convert using statements to using declarations where applicable

pull/2772/head
Patrick Barron 5 years ago
parent 5966ee6d87
commit 6a3f9253db

@ -743,24 +743,22 @@ namespace MediaBrowser.Api.Images
/// <returns>Task.</returns>
public async Task PostImage(BaseItem entity, Stream inputStream, ImageType imageType, string mimeType)
{
using (var reader = new StreamReader(inputStream))
{
var text = await reader.ReadToEndAsync().ConfigureAwait(false);
using var reader = new StreamReader(inputStream);
var text = await reader.ReadToEndAsync().ConfigureAwait(false);
var bytes = Convert.FromBase64String(text);
var bytes = Convert.FromBase64String(text);
var memoryStream = new MemoryStream(bytes)
{
Position = 0
};
var memoryStream = new MemoryStream(bytes)
{
Position = 0
};
// Handle image/png; charset=utf-8
mimeType = mimeType.Split(';').FirstOrDefault();
// Handle image/png; charset=utf-8
mimeType = mimeType.Split(';').FirstOrDefault();
await _providerManager.SaveImage(entity, memoryStream, mimeType, imageType, null, CancellationToken.None).ConfigureAwait(false);
await _providerManager.SaveImage(entity, memoryStream, mimeType, imageType, null, CancellationToken.None).ConfigureAwait(false);
entity.UpdateToRepository(ItemUpdateType.ImageUpdate, CancellationToken.None);
}
entity.UpdateToRepository(ItemUpdateType.ImageUpdate, CancellationToken.None);
}
}
}

@ -261,27 +261,25 @@ namespace MediaBrowser.Api.Images
/// <returns>Task.</returns>
private async Task DownloadImage(string url, Guid urlHash, string pointerCachePath)
{
using (var result = await _httpClient.GetResponse(new HttpRequestOptions
using var result = await _httpClient.GetResponse(new HttpRequestOptions
{
Url = url,
BufferContent = false
}).ConfigureAwait(false))
{
var ext = result.ContentType.Split('/').Last();
var fullCachePath = GetFullCachePath(urlHash + "." + ext);
}).ConfigureAwait(false);
var ext = result.ContentType.Split('/').Last();
Directory.CreateDirectory(Path.GetDirectoryName(fullCachePath));
using (var stream = result.Content)
using (var filestream = new FileStream(fullCachePath, FileMode.Create, FileAccess.Write, FileShare.Read, IODefaults.FileStreamBufferSize, true))
{
await stream.CopyToAsync(filestream).ConfigureAwait(false);
}
var fullCachePath = GetFullCachePath(urlHash + "." + ext);
Directory.CreateDirectory(Path.GetDirectoryName(pointerCachePath));
File.WriteAllText(pointerCachePath, fullCachePath);
Directory.CreateDirectory(Path.GetDirectoryName(fullCachePath));
using (var stream = result.Content)
{
using var filestream = new FileStream(fullCachePath, FileMode.Create, FileAccess.Write, FileShare.Read, IODefaults.FileStreamBufferSize, true);
await stream.CopyToAsync(filestream).ConfigureAwait(false);
}
Directory.CreateDirectory(Path.GetDirectoryName(pointerCachePath));
File.WriteAllText(pointerCachePath, fullCachePath);
}
/// <summary>

@ -885,11 +885,10 @@ namespace MediaBrowser.Api.LiveTv
{
// SchedulesDirect requires a SHA1 hash of the user's password
// https://github.com/SchedulesDirect/JSON-Service/wiki/API-20141201#obtain-a-token
using (SHA1 sha = SHA1.Create())
{
return Hex.Encode(
sha.ComputeHash(Encoding.UTF8.GetBytes(str)));
}
using SHA1 sha = SHA1.Create();
return Hex.Encode(
sha.ComputeHash(Encoding.UTF8.GetBytes(str)));
}
public void Delete(DeleteListingProvider request)

@ -168,22 +168,19 @@ namespace MediaBrowser.Api.Playback.Hls
private string GetLivePlaylistText(string path, int segmentLength)
{
using (var stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
using (var reader = new StreamReader(stream))
{
var text = reader.ReadToEnd();
using var stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
using var reader = new StreamReader(stream);
text = text.Replace("#EXTM3U", "#EXTM3U\n#EXT-X-PLAYLIST-TYPE:EVENT");
var text = reader.ReadToEnd();
var newDuration = "#EXT-X-TARGETDURATION:" + segmentLength.ToString(CultureInfo.InvariantCulture);
text = text.Replace("#EXTM3U", "#EXTM3U\n#EXT-X-PLAYLIST-TYPE:EVENT");
text = text.Replace("#EXT-X-TARGETDURATION:" + (segmentLength - 1).ToString(CultureInfo.InvariantCulture), newDuration, StringComparison.OrdinalIgnoreCase);
//text = text.Replace("#EXT-X-TARGETDURATION:" + (segmentLength + 1).ToString(CultureInfo.InvariantCulture), newDuration, StringComparison.OrdinalIgnoreCase);
var newDuration = "#EXT-X-TARGETDURATION:" + segmentLength.ToString(CultureInfo.InvariantCulture);
return text;
}
}
text = text.Replace("#EXT-X-TARGETDURATION:" + (segmentLength - 1).ToString(CultureInfo.InvariantCulture), newDuration, StringComparison.OrdinalIgnoreCase);
//text = text.Replace("#EXT-X-TARGETDURATION:" + (segmentLength + 1).ToString(CultureInfo.InvariantCulture), newDuration, StringComparison.OrdinalIgnoreCase);
return text;
}
private string GetMasterPlaylistFileText(string firstPlaylist, int bitrate, int baselineStreamBitrate)
@ -212,29 +209,25 @@ namespace MediaBrowser.Api.Playback.Hls
try
{
// Need to use FileShare.ReadWrite because we're reading the file at the same time it's being written
using (var fileStream = GetPlaylistFileStream(playlist))
using var fileStream = GetPlaylistFileStream(playlist);
using var reader = new StreamReader(fileStream);
var count = 0;
while (!reader.EndOfStream)
{
using (var reader = new StreamReader(fileStream))
{
var count = 0;
var line = reader.ReadLine();
while (!reader.EndOfStream)
if (line.IndexOf("#EXTINF:", StringComparison.OrdinalIgnoreCase) != -1)
{
count++;
if (count >= segmentCount)
{
var line = reader.ReadLine();
if (line.IndexOf("#EXTINF:", StringComparison.OrdinalIgnoreCase) != -1)
{
count++;
if (count >= segmentCount)
{
Logger.LogDebug("Finished waiting for {0} segments in {1}", segmentCount, playlist);
return;
}
}
Logger.LogDebug("Finished waiting for {0} segments in {1}", segmentCount, playlist);
return;
}
await Task.Delay(100, cancellationToken).ConfigureAwait(false);
}
}
await Task.Delay(100, cancellationToken).ConfigureAwait(false);
}
catch (IOException)
{

@ -230,17 +230,14 @@ namespace MediaBrowser.Api.Subtitles
if (string.Equals(request.Format, "vtt", StringComparison.OrdinalIgnoreCase) && request.AddVttTimeMap)
{
using (var stream = await GetSubtitles(request).ConfigureAwait(false))
{
using (var reader = new StreamReader(stream))
{
var text = reader.ReadToEnd();
using var stream = await GetSubtitles(request).ConfigureAwait(false);
using var reader = new StreamReader(stream);
text = text.Replace("WEBVTT", "WEBVTT\nX-TIMESTAMP-MAP=MPEGTS:900000,LOCAL:00:00:00.000");
var text = reader.ReadToEnd();
return ResultFactory.GetResult(Request, text, MimeTypes.GetMimeType("file." + request.Format));
}
}
text = text.Replace("WEBVTT", "WEBVTT\nX-TIMESTAMP-MAP=MPEGTS:900000,LOCAL:00:00:00.000");
return ResultFactory.GetResult(Request, text, MimeTypes.GetMimeType("file." + request.Format));
}
return ResultFactory.GetResult(Request, await GetSubtitles(request).ConfigureAwait(false), MimeTypes.GetMimeType("file." + request.Format));

Loading…
Cancel
Save