aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid <daullmer@gmail.com>2020-12-24 10:31:51 +0100
committerDavid <daullmer@gmail.com>2020-12-24 10:31:51 +0100
commite835dfb27d4a25e2057047692fd58af439b15acc (patch)
tree68a346bbdfde7e4537b93f05895d63755813f3aa
parenta714008b596b108a44020f61ca384b30263df984 (diff)
Use sync string instead of file
-rw-r--r--Emby.Server.Implementations/ApplicationHost.cs6
-rw-r--r--Emby.Server.Implementations/Channels/ChannelManager.cs5
-rw-r--r--Emby.Server.Implementations/LiveTv/EmbyTV/ItemDataProvider.cs4
-rw-r--r--Emby.Server.Implementations/ScheduledTasks/ScheduledTaskWorker.cs11
4 files changed, 17 insertions, 9 deletions
diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs
index 99cd3b6cc..6e360ed85 100644
--- a/Emby.Server.Implementations/ApplicationHost.cs
+++ b/Emby.Server.Implementations/ApplicationHost.cs
@@ -10,6 +10,7 @@ using System.Net;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Security.Cryptography.X509Certificates;
+using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using Emby.Dlna;
@@ -100,7 +101,6 @@ using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Prometheus.DotNetRuntime;
-using JsonSerializer = System.Text.Json.JsonSerializer;
using OperatingSystem = MediaBrowser.Common.System.OperatingSystem;
using WebSocketManager = Emby.Server.Implementations.HttpServer.WebSocketManager;
@@ -1047,8 +1047,8 @@ namespace Emby.Server.Implementations
var metafile = Path.Combine(dir, "meta.json");
if (File.Exists(metafile))
{
- using FileStream jsonStream = File.OpenRead(metafile);
- var manifest = JsonSerializer.DeserializeAsync<PluginManifest>(jsonStream, jsonOptions).GetAwaiter().GetResult();
+ var jsonString = File.ReadAllText(metafile);
+ var manifest = JsonSerializer.Deserialize<PluginManifest>(jsonString, jsonOptions);
if (!Version.TryParse(manifest.TargetAbi, out var targetAbi))
{
diff --git a/Emby.Server.Implementations/Channels/ChannelManager.cs b/Emby.Server.Implementations/Channels/ChannelManager.cs
index 3663e5094..f06ad4436 100644
--- a/Emby.Server.Implementations/Channels/ChannelManager.cs
+++ b/Emby.Server.Implementations/Channels/ChannelManager.cs
@@ -340,8 +340,8 @@ namespace Emby.Server.Implementations.Channels
try
{
- using FileStream jsonStream = File.OpenRead(path);
- return JsonSerializer.DeserializeAsync<List<MediaSourceInfo>>(jsonStream, JsonDefaults.GetOptions()).GetAwaiter().GetResult()
+ var jsonString = File.ReadAllText(path);
+ return JsonSerializer.Deserialize<List<MediaSourceInfo>>(jsonString, JsonDefaults.GetOptions())
?? new List<MediaSourceInfo>();
}
catch
@@ -368,6 +368,7 @@ namespace Emby.Server.Implementations.Channels
}
Directory.CreateDirectory(Path.GetDirectoryName(path));
+
await using FileStream createStream = File.Create(path);
await JsonSerializer.SerializeAsync(createStream, mediaSources, JsonDefaults.GetOptions()).ConfigureAwait(false);
}
diff --git a/Emby.Server.Implementations/LiveTv/EmbyTV/ItemDataProvider.cs b/Emby.Server.Implementations/LiveTv/EmbyTV/ItemDataProvider.cs
index 1b9abaa78..bbe9b50dd 100644
--- a/Emby.Server.Implementations/LiveTv/EmbyTV/ItemDataProvider.cs
+++ b/Emby.Server.Implementations/LiveTv/EmbyTV/ItemDataProvider.cs
@@ -44,8 +44,8 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
try
{
- using FileStream jsonStream = File.OpenRead(_dataPath);
- _items = JsonSerializer.DeserializeAsync<T[]>(jsonStream, JsonDefaults.GetOptions()).GetAwaiter().GetResult();
+ var jsonString = File.ReadAllText(_dataPath);
+ _items = JsonSerializer.Deserialize<T[]>(jsonString, JsonDefaults.GetOptions());
return;
}
catch (Exception ex)
diff --git a/Emby.Server.Implementations/ScheduledTasks/ScheduledTaskWorker.cs b/Emby.Server.Implementations/ScheduledTasks/ScheduledTaskWorker.cs
index a9f459986..eee7aeea3 100644
--- a/Emby.Server.Implementations/ScheduledTasks/ScheduledTaskWorker.cs
+++ b/Emby.Server.Implementations/ScheduledTasks/ScheduledTaskWorker.cs
@@ -139,8 +139,15 @@ namespace Emby.Server.Implementations.ScheduledTasks
{
try
{
- using FileStream jsonStream = File.OpenRead(path);
- _lastExecutionResult = JsonSerializer.DeserializeAsync<TaskResult>(jsonStream, JsonDefaults.GetOptions()).GetAwaiter().GetResult();
+ var jsonString = File.ReadAllText(path);
+ if (!string.IsNullOrWhiteSpace(jsonString))
+ {
+ _lastExecutionResult = JsonSerializer.Deserialize<TaskResult>(jsonString, JsonDefaults.GetOptions());
+ }
+ else
+ {
+ _logger.LogDebug("Scheduled Task history file {path} is empty. Skipping deserialization.", path);
+ }
}
catch (Exception ex)
{