コード例 #1
0
 protected override void OnHandleIntent(Intent intent)
 {
     Task.Run(async() =>
     {
         try
         {
             string noteType    = intent.GetStringExtra(GlobalConstants.NOTE_TYPE);
             string noteContent = intent.GetStringExtra(GlobalConstants.NOTE_CONTENT);
             string noteCreated = intent.GetStringExtra(GlobalConstants.NOTE_CREATION_DATE);
             string noteTitle   = intent.GetStringExtra(GlobalConstants.NOTE_TITLE);
             if (!String.IsNullOrEmpty(noteType) && !String.IsNullOrEmpty(noteContent))
             {
                 if (String.IsNullOrEmpty(noteCreated))
                 {
                     noteCreated = JsonSerializer.Serialize(DateTime.Now);
                 }
                 if (noteTitle == null)
                 {
                     noteTitle = String.Empty;
                 }
                 string password = await SecureStorage.GetAsync("AppPassword");
                 if (password == null)
                 {
                     throw new Exception("App's password missing");
                 }
                 EncryptionResult encryptionResult = EncryptionService.EncryptText(noteContent, password);
                 if (encryptionResult.Result)
                 {
                     NoteModel newNote = new NoteModel()
                     {
                         NoteContent          = encryptionResult.EncryptedString,
                         NoteTitle            = noteTitle,
                         NoteCreationTime     = JsonSerializer.Deserialize <DateTime>(noteCreated),
                         NoteType             = noteType,
                         NoteLastModifiedTime = JsonSerializer.Deserialize <DateTime>(noteCreated),
                         LastEncrypted        = DateTime.Now
                     };
                     await NotesDatabase.SaveOrUpdateNode(newNote);
                 }
                 else
                 {
                     throw new Exception(encryptionResult.Error);
                 }
             }
         }
         catch (Exception)
         {
             Xamarin.Essentials.MainThread.BeginInvokeOnMainThread(() =>
             {
                 Toast.MakeText(Android.App.Application.Context, "Note could not be saved", ToastLength.Long).Show();
             });
         }
     });
 }
コード例 #2
0
 protected override void OnHandleIntent(Intent intent)
 {
     Task.Run(async() =>
     {
         try
         {
             int noteID              = int.Parse(intent.GetStringExtra(GlobalConstants.NOTE_ID));
             string noteContent      = intent.GetStringExtra(GlobalConstants.NOTE_CONTENT);
             DateTime noteUpdateTime = JsonSerializer.Deserialize <DateTime>(intent.GetStringExtra(GlobalConstants.NOTE_UPDATION_DATE));
             string password         = await SecureStorage.GetAsync("AppPassword");
             if (password == null)
             {
                 throw new Exception("App's password missing");
             }
             NoteModel noteModel = await NotesDatabase.GetNoteWithID(noteID);
             if (noteModel == null)
             {
                 throw new Exception("Note doesn't exist");
             }
             EncryptionResult encryptionResult = EncryptionService.EncryptText(noteContent, password);
             if (encryptionResult.Result)
             {
                 noteModel.LastEncrypted        = DateTime.Now;
                 noteModel.NoteContent          = encryptionResult.EncryptedString;
                 noteModel.NoteLastModifiedTime = noteUpdateTime;
                 await NotesDatabase.SaveOrUpdateNode(noteModel);
             }
             else
             {
                 throw new Exception(encryptionResult.Error);
             }
         }
         catch (Exception)
         {
             Xamarin.Essentials.MainThread.BeginInvokeOnMainThread(() =>
             {
                 Toast.MakeText(Android.App.Application.Context, "Note could not be updated", ToastLength.Long).Show();
             });
         }
     });
 }