private Task <Dictionary <ushort, string> > GetStringsAsync(Settings.Notes notes) { return(Task <Dictionary <ushort, string> > .Run( delegate { var strings = new Dictionary <ushort, string>(); try { using (var store = new Tools.Notes()) { foreach (var n in notes) { strings[n.SID] = store.Get(n.SID); } } } catch (Exception e) { Util.Logging.Log(e); } return strings; })); }
async void message_EditClick(object sender, EventArgs e) { if (isBusy) { return; } var c = (NoteMessage)sender; var note = (Settings.Notes.Note)c.Tag; var currentTab = this.selectedTab; using (var f = new formNote(c.Expires, c.Message, note.Notify)) { if (f.ShowDialog(this) == System.Windows.Forms.DialogResult.OK) { var changed = false; var sid = note.SID; if (!c.Message.Equals(f.Message, StringComparison.Ordinal)) { isBusy = true; try { using (var store = new Tools.Notes()) { sid = await store.ReplaceAsync(note.SID, f.Message); await store.CloseAsync(); if (changed = note.SID != sid) { strings.Remove(note.SID); } strings[sid] = f.Message; } } catch (Exception ex) { Util.Logging.Log(ex); MessageBox.Show(this, "An error is preventing the note from being created:\n\n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { isBusy = false; } var y = c.Bottom; var h = c.Height; c.Message = f.Message; h -= c.Height; if (h != 0) { if (y != panelContent.Height) { foreach (Control control in panelContent.Controls) { if (control.Top > y) { control.Top -= h; } } } panelContent.Height -= h; } } if (note.Expires != f.Expires) { changed = true; c.Expires = f.Expires; } if (changed) { var notes = account.Notes; if (notes == null) { account.Notes = notes = new Settings.Notes(); } notes.Remove(note); var n = new Settings.Notes.Note(f.Expires, sid, f.NotifyOnExpiry); notes.Add(n); c.Tag = n; var wasExpired = DateTime.UtcNow >= note.Expires; var isExpired = DateTime.UtcNow >= f.Expires; if (wasExpired != isExpired) { if (wasExpired) { ExpiredCount--; MessageCount++; } else { ExpiredCount++; MessageCount--; } Remove(c); } modified = true; if (NoteChanged != null) { NoteChanged(this, n); } } else { if (note.Notify != f.NotifyOnExpiry) { changed = true; modified = true; note.Notify = f.NotifyOnExpiry; } if (changed && NoteChanged != null) { NoteChanged(this, note); } } } } }