mirror of
https://github.com/C9Glax/tranga-website.git
synced 2025-07-02 08:54:17 +02:00
Switch to Newtonsoft.Json for serialization
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
using System.Text.Json;
|
||||
using Newtonsoft.Json;
|
||||
using Tranga.Connectors;
|
||||
|
||||
namespace Tranga;
|
||||
|
||||
@ -54,18 +55,21 @@ public class TaskManager
|
||||
string filePath = Path.Join(importFolderPath, "tasks.json");
|
||||
if (!File.Exists(filePath))
|
||||
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();
|
||||
}
|
||||
|
||||
public void ExportTasks(string exportFolderPath)
|
||||
{
|
||||
FileStream file = new FileStream(Path.Join(exportFolderPath, "tasks.json"), FileMode.CreateNew);
|
||||
JsonSerializer.Serialize(file, _allTasks.ToArray(), JsonSerializerOptions.Default);
|
||||
file.Close();
|
||||
file.Dispose();
|
||||
string filePath = Path.Join(exportFolderPath, "tasks.json");
|
||||
string toWrite = JsonConvert.SerializeObject(_allTasks.ToArray());
|
||||
File.WriteAllText(filePath,toWrite);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user