示例#1
0
        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>());
            }
        }
示例#2
0
 public void Lock( )
 {
     AppDataFolder.AccessFolder();
     if (!File.Exists(lockFile))
     {
         s = new FileStream(lockFile, FileMode.CreateNew, FileAccess.ReadWrite, FileShare.None);
     }
 }
示例#3
0
文件: Logger.cs 项目: lamarch/WpfData
        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)));
        }
示例#4
0
 public void Unlock( )
 {
     if (s != null)
     {
         s.Close();
     }
     AppDataFolder.AccessFolder();
     if (File.Exists(lockFile))
     {
         File.Delete(lockFile);
     }
 }
示例#5
0
        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()
            });
        }
示例#6
0
文件: Logger.cs 项目: lamarch/WpfData
        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);
        }
示例#7
0
        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.");
            }
        }
示例#8
0
 public bool Check( )
 {
     AppDataFolder.AccessFolder();
     return(!File.Exists(lockFile));
 }