Switch to Newtonsoft.Json for serialization
This commit is contained in:
parent
0afbcd9bbf
commit
afe36ab2ef
@ -1,16 +1,15 @@
|
|||||||
using System.Text.Json;
|
using Newtonsoft.Json;
|
||||||
using System.Text.Json.Serialization;
|
|
||||||
|
|
||||||
namespace Tranga;
|
namespace Tranga;
|
||||||
|
|
||||||
public struct Publication
|
public struct Publication
|
||||||
{
|
{
|
||||||
public string sortName { get; }
|
public string sortName { get; }
|
||||||
public string[,] altTitles { get; }
|
[JsonIgnore]public string[,] altTitles { get; }
|
||||||
public string? description { get; }
|
public string? description { get; }
|
||||||
public string[] tags { get; }
|
public string[] tags { get; }
|
||||||
public string? posterUrl { get; }
|
public string? posterUrl { get; }
|
||||||
public string[,]? links { get; }
|
[JsonIgnore]public string[,]? links { get; }
|
||||||
public int? year { get; }
|
public int? year { get; }
|
||||||
public string? originalLanguage { get; }
|
public string? originalLanguage { get; }
|
||||||
public string status { get; }
|
public string status { get; }
|
||||||
@ -35,7 +34,7 @@ public struct Publication
|
|||||||
public string GetSeriesInfo()
|
public string GetSeriesInfo()
|
||||||
{
|
{
|
||||||
SeriesInfo si = new (new Metadata(this.sortName, this.year.ToString() ?? string.Empty, this.status, this.description ?? ""));
|
SeriesInfo si = new (new Metadata(this.sortName, this.year.ToString() ?? string.Empty, this.status, this.description ?? ""));
|
||||||
return JsonSerializer.Serialize(si, JsonSerializerOptions.Default);
|
return System.Text.Json.JsonSerializer.Serialize(si);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal struct SeriesInfo
|
internal struct SeriesInfo
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using System.Text.Json;
|
using Newtonsoft.Json;
|
||||||
|
using Tranga.Connectors;
|
||||||
|
|
||||||
namespace Tranga;
|
namespace Tranga;
|
||||||
|
|
||||||
@ -54,18 +55,21 @@ public class TaskManager
|
|||||||
string filePath = Path.Join(importFolderPath, "tasks.json");
|
string filePath = Path.Join(importFolderPath, "tasks.json");
|
||||||
if (!File.Exists(filePath))
|
if (!File.Exists(filePath))
|
||||||
return new HashSet<TrangaTask>();
|
return new HashSet<TrangaTask>();
|
||||||
|
|
||||||
FileStream file = new FileStream(filePath, FileMode.Open);
|
|
||||||
|
|
||||||
TrangaTask[] importTasks = JsonSerializer.Deserialize<TrangaTask[]>(file, JsonSerializerOptions.Default)!;
|
string toRead = File.ReadAllText(filePath);
|
||||||
|
|
||||||
|
TrangaTask[] importTasks = JsonConvert.DeserializeObject<TrangaTask[]>(toRead)!;
|
||||||
|
|
||||||
|
foreach(TrangaTask task in importTasks.Where(task => task.publication is not null))
|
||||||
|
this._chapterCollection.Add((Publication)task.publication!, new List<Chapter>());
|
||||||
|
|
||||||
return importTasks.ToHashSet();
|
return importTasks.ToHashSet();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ExportTasks(string exportFolderPath)
|
public void ExportTasks(string exportFolderPath)
|
||||||
{
|
{
|
||||||
FileStream file = new FileStream(Path.Join(exportFolderPath, "tasks.json"), FileMode.CreateNew);
|
string filePath = Path.Join(exportFolderPath, "tasks.json");
|
||||||
JsonSerializer.Serialize(file, _allTasks.ToArray(), JsonSerializerOptions.Default);
|
string toWrite = JsonConvert.SerializeObject(_allTasks.ToArray());
|
||||||
file.Close();
|
File.WriteAllText(filePath,toWrite);
|
||||||
file.Dispose();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -6,4 +6,8 @@
|
|||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
@ -1,15 +1,13 @@
|
|||||||
using System.Text.Json.Serialization;
|
namespace Tranga;
|
||||||
|
|
||||||
namespace Tranga;
|
|
||||||
|
|
||||||
public struct TrangaTask
|
public struct TrangaTask
|
||||||
{
|
{
|
||||||
[JsonInclude]public TimeSpan reoccurrence { get; }
|
public TimeSpan reoccurrence { get; }
|
||||||
[JsonInclude]public DateTime lastExecuted { get; set; }
|
public DateTime lastExecuted { get; set; }
|
||||||
[JsonInclude]public Connector connector { get; }
|
public string connectorName { get; }
|
||||||
[JsonInclude]public Task task { get; }
|
public Task task { get; }
|
||||||
[JsonInclude]public Publication publication { get; }
|
public Publication? publication { get; }
|
||||||
[JsonInclude]public string language { get; }
|
public string language { get; }
|
||||||
|
|
||||||
public TrangaTask(Connector connector, Task task, Publication publication, TimeSpan reoccurrence, string language = "")
|
public TrangaTask(Connector connector, Task task, Publication publication, TimeSpan reoccurrence, string language = "")
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user