mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-05-31 21:08:27 +01:00
Remove custom Json serializer from Emby.Server.Implementations
This commit is contained in:
@@ -4,13 +4,14 @@ using System;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Jellyfin.Data.Events;
|
||||
using MediaBrowser.Common.Configuration;
|
||||
using MediaBrowser.Common.Extensions;
|
||||
using MediaBrowser.Common.Json;
|
||||
using MediaBrowser.Common.Progress;
|
||||
using MediaBrowser.Model.Serialization;
|
||||
using MediaBrowser.Model.Tasks;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
@@ -21,11 +22,6 @@ namespace Emby.Server.Implementations.ScheduledTasks
|
||||
/// </summary>
|
||||
public class ScheduledTaskWorker : IScheduledTaskWorker
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the json serializer.
|
||||
/// </summary>
|
||||
/// <value>The json serializer.</value>
|
||||
private readonly IJsonSerializer _jsonSerializer;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the application paths.
|
||||
@@ -88,7 +84,7 @@ namespace Emby.Server.Implementations.ScheduledTasks
|
||||
/// or
|
||||
/// logger.
|
||||
/// </exception>
|
||||
public ScheduledTaskWorker(IScheduledTask scheduledTask, IApplicationPaths applicationPaths, ITaskManager taskManager, IJsonSerializer jsonSerializer, ILogger logger)
|
||||
public ScheduledTaskWorker(IScheduledTask scheduledTask, IApplicationPaths applicationPaths, ITaskManager taskManager, ILogger logger)
|
||||
{
|
||||
if (scheduledTask == null)
|
||||
{
|
||||
@@ -105,11 +101,6 @@ namespace Emby.Server.Implementations.ScheduledTasks
|
||||
throw new ArgumentNullException(nameof(taskManager));
|
||||
}
|
||||
|
||||
if (jsonSerializer == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(jsonSerializer));
|
||||
}
|
||||
|
||||
if (logger == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(logger));
|
||||
@@ -118,7 +109,6 @@ namespace Emby.Server.Implementations.ScheduledTasks
|
||||
ScheduledTask = scheduledTask;
|
||||
_applicationPaths = applicationPaths;
|
||||
_taskManager = taskManager;
|
||||
_jsonSerializer = jsonSerializer;
|
||||
_logger = logger;
|
||||
|
||||
InitTriggerEvents();
|
||||
@@ -150,7 +140,15 @@ namespace Emby.Server.Implementations.ScheduledTasks
|
||||
{
|
||||
try
|
||||
{
|
||||
_lastExecutionResult = _jsonSerializer.DeserializeFromFile<TaskResult>(path);
|
||||
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)
|
||||
{
|
||||
@@ -174,7 +172,8 @@ namespace Emby.Server.Implementations.ScheduledTasks
|
||||
|
||||
lock (_lastExecutionResultSyncLock)
|
||||
{
|
||||
_jsonSerializer.SerializeToFile(value, path);
|
||||
using FileStream createStream = File.OpenWrite(path);
|
||||
JsonSerializer.SerializeAsync(createStream, value, JsonDefaults.GetOptions());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -537,7 +536,8 @@ namespace Emby.Server.Implementations.ScheduledTasks
|
||||
TaskTriggerInfo[] list = null;
|
||||
if (File.Exists(path))
|
||||
{
|
||||
list = _jsonSerializer.DeserializeFromFile<TaskTriggerInfo[]>(path);
|
||||
var jsonString = File.ReadAllText(path);
|
||||
list = JsonSerializer.Deserialize<TaskTriggerInfo[]>(jsonString, JsonDefaults.GetOptions());
|
||||
}
|
||||
|
||||
// Return defaults if file doesn't exist.
|
||||
@@ -573,7 +573,8 @@ namespace Emby.Server.Implementations.ScheduledTasks
|
||||
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(path));
|
||||
|
||||
_jsonSerializer.SerializeToFile(triggers, path);
|
||||
using FileStream stream = File.OpenWrite(path);
|
||||
JsonSerializer.SerializeAsync(stream, triggers, JsonDefaults.GetOptions());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user