//async void SendMailWithDB_Clicked(object sender, EventArgs e) //{ // //try // //{ // // ExperimentalFeatures.Enable(ExperimentalFeatures.EmailAttachments); //, ExperimentalFeatures.ShareFileRequest // // var message = new EmailMessage // // { // // Subject = "db", // // Body = "db backup", // // To = { "*****@*****.**" } // // }; // // message.Attachments.Add(new EmailAttachment(FileBase(DB.dbPath)); // // await Email.ComposeAsync(message); // ExperimentalFeatures.Enable(ExperimentalFeatures.EmailAttachments, ExperimentalFeatures.ShareFileRequest); // await Share.RequestAsync(new ShareFileRequest // { // Title = Title, // File = new ShareFile(DB.dbPath) // }); // //} // //catch (FeatureNotSupportedException fbsEx) // //{ // // // Email is not supported on this device // // DependencyService.Get<IMessage>().ShortAlert("Email is not supported on this device"); // //} // //catch (Exception ex) // //{ // // // Some other exception occurred // // DependencyService.Get<IMessage>().ShortAlert(ex.Message); // //} //} //private void DownloadBackup_Clicked(object sender, EventArgs e) //{ // try // { // //if automatic backup is activate copy DB in backup file // if (PY.AutomaticBackup) // { // if(File.Exists(DB.dbPathBkp)) // File.Copy(DB.dbPathBkp, Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonDocuments), "Backup", "MovieArchive.db3")); // } // } // catch (Exception ex) // { // throw ex; // } //} private async void RestoreDB_Clicked(object sender, EventArgs e) { try { if (await DisplayAlert(AppResources.MessageConfirmRestoreDB, AppResources.TitleConfirmRestoreDB, AppResources.ButtonConfirmRestore, AppResources.ButtonConfirmCancelRestore)) { var DBS = new DropBoxLib(); await DBS.Authorize(); if (DBS.IsAuthorized) { var db = await DBS.ReadFile("/" + Path.GetFileName(DB.dbPath)); //"/Database.db3" if (db != null) { File.WriteAllBytes(DB.dbPath, db); DependencyService.Get <IMessage>().ShortAlert(AppResources.MessageDataBaseRestored); } } } } catch (Exception ex) { Crashes.TrackError(ex); throw ex; }; }
protected async override void OnSleep() { // Se c'è connessione e il backup automatico è attivo eseguo backup try { var DB = new DataBase(); var PR = await DB.GetPropertyAsync(); if (PR != null && PR.AutomaticBackup) { var DBS = new DropBoxLib(); await DBS.Authorize(); if (DBS.IsAuthorized) { // Write the database to DropBox folder //await DBS.WriteFile(File.ReadAllBytes(DB.dbPath), "/"+Path.GetFileName(DB.dbPath)); MemoryStream s = DependencyService.Get <IFile>().GetFileStream(DB.dbPath); await DBS.WriteFile(s, "/" + Path.GetFileName(DB.dbPath)); } } } catch (Exception ex) { Crashes.TrackError(ex); throw ex; }; }
async void AutoBkp_Toggled(object sender, ToggledEventArgs e) { PY.AutomaticBackup = e.Value; int r = await DB.UpdatePropertyAsync(PY); if (PY.AutomaticBackup) { var DBS = new DropBoxLib(); await DBS.Authorize(); if (DBS.IsAuthorized) { DependencyService.Get <IMessage>().ShortAlert(AppResources.MessageDropBoxConnected); } else { DependencyService.Get <IMessage>().ShortAlert(AppResources.MessageDropBoxNotConnected); } } }