Add Phoenix remote desktop, action connector, documentation engine, and gamification support. Refactor support-case processing and search/action UI, and update installer assets and dependencies.
71 lines
2.3 KiB
C#
71 lines
2.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Text;
|
|
|
|
namespace F4SD.Gamification.Services
|
|
{
|
|
internal static class PersistenceService
|
|
{
|
|
private static readonly string _databaseName = "F4SD-gmfc.txt";
|
|
private static readonly string _directory = $@"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)}\Consulting4IT GmbH\C4IT First Aid Service Desk";
|
|
|
|
private static string GetConnectionString()
|
|
{
|
|
return Path.Combine(_directory, _databaseName);
|
|
}
|
|
|
|
internal static void Persist(CockpitAction action)
|
|
{
|
|
Initialize();
|
|
|
|
using var writer = File.AppendText(GetConnectionString());
|
|
string actionLine = $"{DateTime.UtcNow},{action}";
|
|
string base64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(actionLine));
|
|
writer.WriteLine(base64);
|
|
}
|
|
|
|
internal static void Initialize()
|
|
{
|
|
Directory.CreateDirectory(_directory);
|
|
|
|
if (!File.Exists(GetConnectionString()))
|
|
{
|
|
FileStream createdFile = File.Create(GetConnectionString());
|
|
File.SetAttributes(GetConnectionString(), FileAttributes.Hidden);
|
|
createdFile.Close();
|
|
}
|
|
}
|
|
|
|
internal static IEnumerable<(DateTime Time, CockpitAction Action)> GetActions()
|
|
{
|
|
using StreamReader reader = new(GetConnectionString());
|
|
|
|
string line;
|
|
while ((line = reader.ReadLine()) != null)
|
|
{
|
|
string encodedLine = string.Empty;
|
|
|
|
try { encodedLine = Encoding.UTF8.GetString(Convert.FromBase64String(line)); }
|
|
catch { continue; }
|
|
|
|
if (string.IsNullOrWhiteSpace(encodedLine))
|
|
continue;
|
|
|
|
string[] splittedLine = encodedLine.Split(',');
|
|
|
|
if (splittedLine.Length < 2)
|
|
continue;
|
|
|
|
if (!DateTime.TryParse(splittedLine[0], out var date))
|
|
continue;
|
|
|
|
if (!(Enum.TryParse(splittedLine[1], out CockpitAction action)))
|
|
continue;
|
|
|
|
yield return new(date, action);
|
|
}
|
|
}
|
|
}
|
|
}
|