Esempio n. 1
0
 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;
     }));
 }
Esempio n. 2
0
        private async void labelAdd_Click(object sender, EventArgs e)
        {
            if (isBusy)
            {
                return;
            }

            labelAdd.Enabled = false;

            using (var f = new formNote())
            {
                if (f.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
                {
                    Settings.Notes.Note n = null;

                    isBusy = true;
                    try
                    {
                        var sid = await Tools.Notes.AddRange(f.Message);

                        strings[sid[0]] = f.Message;

                        var notes = this.account.Notes;
                        if (notes == null)
                        {
                            this.account.Notes = notes = new Settings.Notes();
                        }

                        n = new Settings.Notes.Note(f.Expires, sid[0], f.NotifyOnExpiry);
                        notes.Add(n);
                        modified = true;

                        if (DateTime.UtcNow < n.Expires)
                        {
                            if (selectedTab == buttonMessages)
                            {
                                SetupControls();
                            }
                            else
                            {
                                MessageCount++;
                            }
                        }
                        else
                        {
                            if (selectedTab == buttonExpired)
                            {
                                SetupControls();
                            }
                            else
                            {
                                ExpiredCount++;
                            }
                        }
                    }
                    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;
                    }

                    if (n != null && NoteChanged != null)
                    {
                        NoteChanged(this, n);
                    }
                }
            }

            labelAdd.Enabled = true;
        }
Esempio n. 3
0
        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);
                        }
                    }
                }
            }
        }