Exemplo n.º 1
0
 public void AddFile(BinaryFile file)
 {
     files.Enqueue(file);
     LogsManager.LogToTextFile(new Log
     {
         Severity = LogSeverity.Low,
         Type     = LogType.FileCreated,
         Text     = "New data file created."
     });
 }
Exemplo n.º 2
0
 public void DeleteLiveDataFile()
 {
     if (File.Exists(GlobalConfig.LiveDataFilePath))
     {
         File.Delete(GlobalConfig.LiveDataFilePath);
         LogsManager.LogToTextFile(new Log
         {
             Severity = LogSeverity.Low,
             Type     = LogType.FileDeleted,
             Text     = "Live data file deleted at the end of the work day."
         });
     }
 }
Exemplo n.º 3
0
 private FilesManager()
 {
     try
     {
         files = BinaryConnector.StaticLoad <Queue <BinaryFile> >(GlobalConfig.DataCacheFilePath);
     }
     catch (Exception e)
     {
         files = new Queue <BinaryFile>();
         LogsManager.LogToTextFile(new ErrorLog
         {
             Severity = LogSeverity.Low,
             Type     = ErrorType.IOError,
             Text     = "No cahced data file was found. - " + e.Message
         });
     }
 }
Exemplo n.º 4
0
        public async Task SyncFiles(User user)
        {
            var api = ApiHelper.GetApiHelper();

            while (files.Count > 0)
            {
                bool isPosted;
                try
                {
                    // !!!!!!!!!!!!!! NOT SENDING DATA TO SERVER !!!!!!!!!!!!!!!
                    isPosted = await api.PostFile(files.Peek(), user);

                    if (isPosted)
                    {
                        files.Dequeue();
                    }
                }
                catch (Exception)
                {
                    BinaryConnector.StaticSave(files, GlobalConfig.DataCacheFilePath);
                    LogsManager.LogToTextFile(new ErrorLog
                    {
                        Severity = LogSeverity.Medium,
                        Type     = ErrorType.ConnectionError,
                        Text     = "Failed to sync data files, no connection to the server."
                    });
                    break;
                }
            }
            if (files.Count == 0)
            {
                if (File.Exists(GlobalConfig.DataCacheFilePath))
                {
                    File.Delete(GlobalConfig.DataCacheFilePath);
                    LogsManager.LogToTextFile(new Log
                    {
                        Severity = LogSeverity.Low,
                        Type     = LogType.FileDeleted,
                        Text     = "Data cache file deleted after syncing properly."
                    });
                }
            }
        }