public static void LoadData( ) { logger.Log(Logger.LogType.Event, Logger.LogLevel.Info, "static:DataLayer.LoadData()", "Call"); if (!isInit) { logger.LogException("isInit", new ValueUnavailableException("false")); throw new InvalidOperationException("Init method not called !"); } AppDataFolder.AccessFolder(); try { dailyMeasures.Load(); } catch (Exception ex) { logger.LogException("static,await:dailyMeasures.Load()", ex); MessageBox.Show("Une erreur est survenue lors du chargement des données, contactez le dev."); } if (dailyMeasures.Get() == null) { dailyMeasures.Set(new List <NetworkMeasure>()); } }
public void Lock( ) { AppDataFolder.AccessFolder(); if (!File.Exists(lockFile)) { s = new FileStream(lockFile, FileMode.CreateNew, FileAccess.ReadWrite, FileShare.None); } }
public Logger( ) { fileName = $"LOG (v_{AppDataFolder.GetVersion()}) {DateTime.Now.ToString("G").Replace(':', '-').Replace("/", "-")}.txt"; filePath = AppDataFolder.GetPath(Path.Combine(folderName, subFolderName, fileName)); AppDataFolder.Views.Add(new Util.FolderView(folderName, new Util.FolderView(subFolderName, null))); }
public void Unlock( ) { if (s != null) { s.Close(); } AppDataFolder.AccessFolder(); if (File.Exists(lockFile)) { File.Delete(lockFile); } }
public static void Init(Logger _logger) { isInit = true; logger = _logger; logger.Log(Logger.LogType.Event, Logger.LogLevel.Info, "static:DataLayer.Init()", "Call"); AppDataFolder.Views.Add(new FolderView("data", new FolderView("monthly"))); dailyMeasures = new BinarySerializer <List <NetworkMeasure> >(AppDataFolder.GetPath(@"data\monthly\.measures")); dailyMeasures.Set(new List <NetworkMeasure>() { new NetworkMeasure() }); }
public void Log(LogType t, LogLevel l, string name, object message = null, [CallerMemberName] string caller = "Unknown", [CallerLineNumber] int line = -1) { AppDataFolder.AccessFolder(); string finalMessage = "None"; finalMessage = message?.ToString(); string final = $"{DateTime.Now.ToString()}\t{l} / {t} [{caller} at {line}], {name.ToUpperInvariant()} : {finalMessage}\n\n"; File.AppendAllText(filePath, final); }
public static void SaveData( ) { logger.Log(Logger.LogType.Event, Logger.LogLevel.Info, "static:DataLayer.SaveData()", "Call"); if (!isInit) { logger.LogException("isInit", new ValueUnavailableException("false")); throw new InvalidOperationException("Init method not called !"); } AppDataFolder.AccessFolder(); try { dailyMeasures.Save(); } catch (Exception ex) { logger.LogException("static,await:dailyMeasures.Save()", ex); MessageBox.Show("Une erreur est survenue lors de la sauvegarde des données, contactez le dev."); } }
public bool Check( ) { AppDataFolder.AccessFolder(); return(!File.Exists(lockFile)); }