private void OnFileDownloaded(object sender, DownloadEventArgs e) { if (e.FileSaved) { Log.Debug("Download", "File have been downloaded with success"); _NbFileDownloaded++; if (_NbFileDownloaded == 2) { SharedPreferenceManager.SaveString(ApplicationContext, Constants.DATE_DOWNLAOD, DateTime.Now.ToString()); SharedPreferenceManager.SaveString(ApplicationContext, Constants.SHARED_DATABASE_PATH, System.IO.Path.Combine(_DownloadDirectoryPath, Constants.DATABASE_FILE_NAME)); if (Controller.Permission.CheckPermission.PermissionGranted(ApplicationContext, Manifest.Permission.ReadExternalStorage)) { DataManager.GetInstance(ConfigInstance.GetInstance().IsDev, SharedPreferenceManager.GetString(ApplicationContext, Constants.SHARED_DATABASE_PATH, "")); string pathZipFile = System.IO.Path.Combine(_DownloadDirectoryPath, Constants.IMG_FILE_NAME); ZipManager.Unzip(pathZipFile, _ImgDirectoryPath); } else { Toast.MakeText(ApplicationContext, "Permission non accordée pour la lecture du fichier, aller dans les paramètres de l'application pour modifier cette valeur.", ToastLength.Long).Show(); } //delete temporary file after get values File.Delete(System.IO.Path.Combine(_DownloadDirectoryPath, Constants.IMG_FILE_NAME)); HideProgressBar(); StartActivity(typeof(HomeActivity)); Finish(); } } else { Log.Error("Download", "Error while saving the file"); } }
async Task <string> GetJournalContent(UserJournal journalItem) { if (journalItem == null) { return(null); } using (MemoryStream outFile = new MemoryStream()) { var journalIdentifier = journalItem.S3Path; try { var stats = await _minioClient.StatObjectAsync("journal-limpet", journalIdentifier); await _minioClient.GetObjectAsync("journal-limpet", journalIdentifier, 0, stats.Size, cb => { cb.CopyTo(outFile); } ); outFile.Seek(0, SeekOrigin.Begin); var journalContent = ZipManager.Unzip(outFile.ToArray()); return(journalContent); } catch (ObjectNotFoundException) { return(null); } } }
private void OnFileDownloaded(object sender, DownloadEventArgs e) { if (e.FileSaved) { Log.Warning("Download", "File have been downloaded with success"); _NbFileDownloaded++; ProgressBar.ProgressTo(ProgressBar.Progress + 0.3, SIZE_PROGRESS_LONG, Easing.Linear); if (_NbFileDownloaded == 2) { Preferences.Set(Constants.DATE_DOWNLAOD, DateTime.Now.ToString()); Preferences.Set(Constants.SHARED_DATABASE_PATH, Path.Combine(_DownloadDirectoryPath, Constants.DATABASE_FILE_NAME)); DataManager.GetInstance(ConfigInstance.GetInstance().IsDev, Preferences.Get(Constants.SHARED_DATABASE_PATH, "")); string pathZipFile = Path.Combine(_DownloadDirectoryPath, Constants.IMG_FILE_NAME); ZipManager.Unzip(pathZipFile, _ImgDirectoryPath); //delete temporary file after get values File.Delete(Path.Combine(_DownloadDirectoryPath, Constants.IMG_FILE_NAME)); ProgressBar.ProgressTo(0.99, SIZE_PROGRESS_LONG, Easing.Linear); _App.ChangePage(new MainPage()); } } else { Log.Warning("Download", "Error while saving the file"); } }
async Task <(string fileName, string journalContent)> GetJournalForDate(DateTime journalDate) { var f = "CAPIJournal." + journalDate.Year.ToString().Substring(2) + journalDate.Month.ToString().PadLeft(2, '0') + journalDate.Day.ToString().PadLeft(2, '0') + journalDate.Hour.ToString().PadLeft(2, '0') + journalDate.Minute.ToString().PadLeft(2, '0') + journalDate.Second.ToString().PadLeft(2, '0') + ".01.log"; var journalItem = await _db.ExecuteSingleRowAsync <UserJournal>( "SELECT * FROM user_journal WHERE user_identifier = @user_identifier AND journal_date = @journal_date", new SqlParameter("user_identifier", User.Identity.Name), new SqlParameter("journal_date", journalDate.Date) ); if (journalItem == null) { return(null, null); } using (MemoryStream outFile = new MemoryStream()) { var journalIdentifier = journalItem.S3Path; try { var stats = await _minioClient.StatObjectAsync("journal-limpet", journalIdentifier); await _minioClient.GetObjectAsync("journal-limpet", journalIdentifier, 0, stats.Size, cb => { cb.CopyTo(outFile); } ); outFile.Seek(0, SeekOrigin.Begin); var journalContent = ZipManager.Unzip(outFile.ToArray()); return(f, journalContent); } catch (ObjectNotFoundException) { return(null, null); } } }
public static async Task <string[]> LoadJournal(MinioClient _minioClient, UserJournal journalItem, MemoryStream outFile) { var stats = await _minioClient.StatObjectAsync("journal-limpet", journalItem.S3Path); await _minioClient.GetObjectAsync("journal-limpet", journalItem.S3Path, 0, stats.Size, cb => { cb.CopyTo(outFile); } ); outFile.Seek(0, SeekOrigin.Begin); var journalContent = ZipManager.Unzip(outFile.ToArray()); var journalRows = journalContent.Trim().Split('\n', StringSplitOptions.RemoveEmptyEntries); return(journalRows); }