PipefyProspUpdate/AppState.cs

54 lines
1.9 KiB
C#

using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
namespace PipefyProspUpdate
{
public class AppState
{
private static readonly List<Models.Suggestion> suggestions = new();
public DateTime LastUpdated { get; set; }
public List<Models.Suggestion>? Suggestions { get; set; } = suggestions;
public List<Models.Suggestion> MesoChangeBoxItems { get; set; } = new();
public List<Models.Suggestion> CityChangeBoxItems { get; set; } = new();
public List<Models.Users> Users { get; set; } = new();
public List<Models.Users> Prospectante { get; set; } = new();
public List<Models.Users> Others { get; set; } = new();
public List<Models.Node> ProspeccaoFilteredCards { get; set; } = new();
public List<Models.Node> recentMutations { get; set; } = new();
public bool filterFlag { get; set; }
public int currentItems { get; set; }
public string? selectedUF { get; set; }
public bool KeepProsp { get; set; }
public bool KeepResp { get; set; }
private static AppState? _instance;
private static readonly string FilePath = SetPath();
public static AppState Instance => _instance ??= Load();
private AppState() { }
public static string SetPath()
{
return $"{System.IO.Path.GetTempPath()}appstate.json";
}
public void Save()
{
var json = JsonConvert.SerializeObject(this, Formatting.Indented);
File.WriteAllText(FilePath, json);
}
private static AppState Load()
{
if (File.Exists(FilePath))
{
var json = File.ReadAllText(FilePath);
return JsonConvert.DeserializeObject<AppState>(json) ?? new AppState();
}
return new AppState();
}
}
}