public MUCReminderItem(Reminder rem)
        {
            InitializeComponent();
            this.Reminder = rem;

            AddFont(Properties.Resources.Roboto_Medium);

            MaterialSkin.MaterialSkinManager.Instance.ThemeChanged += UpdateTheme;

            //todo: make black/white
            tpInformation.SetToolTip(btnSettings, "Click for more options");
            tpInformation.SetToolTip(btnDisable, "Enable/Disable the reminder");
            tpInformation.SetToolTip(btnDelete, "Delete a reminder");
            tpInformation.SetToolTip(btnEdit, "Edit a reminder");

            //Assign right-click settings popup to these 2 panels
            this.MouseClick             += rightClick_Settings;
            pnlActionButtons.MouseClick += rightClick_Settings;

            SetTooltips();
        }
Example #2
0
        public Popup2(Reminder rem)
        {
            InitializeComponent();
            this.rem = rem;

            this.Size    = new Size((int)BLPopupDimensions.GetPopupDimensions().FormWidth, (int)BLPopupDimensions.GetPopupDimensions().FormHeight);
            tbTitle.Font = new Font(tbTitle.Font.FontFamily, BLPopupDimensions.GetPopupDimensions().FontTitleSize, FontStyle.Bold);
            tbText.Font  = new Font(tbText.Font.FontFamily, BLPopupDimensions.GetPopupDimensions().FontNoteSize, FontStyle.Bold);


            initialWidth    = Width;
            initialHeight   = Height;
            initialFontSize = lblTitle.Font.Size;


            //Assign the events that the user can raise while doing something on the popup. The stopflash event stops the taskbar icon from flashing
            tbTitle.MouseClick += stopFlash_Event;
            tbText.MouseClick  += stopFlash_Event;
            this.MouseClick    += stopFlash_Event;
            this.ResizeEnd     += stopFlash_Event;
        }
        private void hideReminderToolStripMenuItem_Click(object sender, EventArgs e)
        {
            BLIO.Log("Toolstrip option clicked: Hide (" + rem.Id + ")");

            string message = "You can hide reminders with this option. The reminder will not be deleted, you just won't be able to see it"
                             + " in the list of reminders. This creates a sense of surprise.\r\n\r\nDo you wish to hide this reminder?";

            BLIO.Log("Attempting to hide reminder(s)");
            if (BLLocalDatabase.Setting.HideReminderOptionEnabled || MaterialRemindMeBox.Show(message, RemindMeBoxReason.YesNo, true) == DialogResult.Yes)
            {
                //Enable the hide flag here
                rem.Hide = 1;
                BLIO.Log("Marked reminder with id " + rem.Id + " as hidden");
                BLReminder.EditReminder(rem);
                this.Reminder = null;
                MUCReminders.Instance.UpdateCurrentPage();

                new Thread(() =>
                {
                    //Log an entry to the database, for data!
                    try
                    {
                        BLOnlineDatabase.HideCount++;
                    }
                    catch (ArgumentException ex)
                    {
                        BLIO.Log("Exception at BLOnlineDatabase.HideCount++. -> " + ex.Message);
                        BLIO.WriteError(ex, ex.Message, true);
                    }
                    finally
                    {
                        GC.Collect();
                    }
                }).Start();
            }
            else
            {
                BLIO.Log("Attempting to hide reminder(s) failed.");
            }
        }
Example #4
0
        private Reminder CopyReminder(Reminder rem)
        {
            //Wouldn't it be nice if there was some sort of general C# method that copies objects?
            Reminder copy = new Reminder();

            copy.Corrupted              = rem.Corrupted;
            copy.Date                   = rem.Date;
            copy.DayOfMonth             = rem.DayOfMonth;
            copy.Deleted                = rem.Deleted;
            copy.EnableAdvancedReminder = rem.EnableAdvancedReminder;
            copy.Enabled                = rem.Enabled;
            copy.EveryXCustom           = rem.EveryXCustom;
            copy.Hide                   = rem.Hide;
            copy.Id            = -1;
            copy.Name          = rem.Name;
            copy.Note          = rem.Note;
            copy.PostponeDate  = rem.PostponeDate;
            copy.RepeatDays    = rem.RepeatDays;
            copy.RepeatType    = rem.RepeatType;
            copy.SoundFilePath = rem.SoundFilePath;
            return(copy);
        }
        public UCResizePopup()
        {
            InitializeComponent();

            testrem      = new Reminder();
            testrem.Date = Convert.ToDateTime("2010-10-10 00:00:00").ToString();
            testrem.Name = "Test reminder";
            testrem.Note = "Test Note\r\nWith spaces\r\n\r\nAnd more spaces";
            testrem.Id   = -1;//mark it to be invalid

            trbWidth.Maximum  = Screen.GetWorkingArea(this).Width;
            trbHeight.Maximum = Screen.GetWorkingArea(this).Height;


            trbHeight.MouseUp    += Trackbar_Value_End;
            trbWidth.MouseUp     += Trackbar_Value_End;
            trbNoteFont.MouseUp  += Trackbar_Value_End;
            trbTitleFont.MouseUp += Trackbar_Value_End;


            FillValues();
        }
Example #6
0
        private void PreviewReminder()
        {
            if (rem == null)
            {
                BLIO.Log("Reminder in PreviewReminder() is null. Interesting... ;)");
                RemindMeMessageFormManager.MakeMessagePopup("Could not preview that reminder. It doesn't exist anymore!", 4, "Error");
                return;
            }

            BLIO.Log("Previewing reminder with id " + rem.Id);
            Reminder previewRem = CopyReminder(rem);

            previewRem.Id = -1; //give the >temporary< reminder an invalid id, so that the real reminder won't be altered
            Popup p = new Popup(previewRem);

            p.Show();
            new Thread(() =>
            {
                //Log an entry to the database, for data!
                try
                {
                    try
                    {
                        BLOnlineDatabase.PreviewCount++;
                    }
                    catch (ArgumentException ex)
                    {
                        BLIO.Log("Exception at BLOnlineDatabase.PreviewCount++. -> " + ex.Message);
                        BLIO.WriteError(ex, ex.Message, true);
                    }
                }
                catch (ArgumentException ex)
                {
                    BLIO.Log("Exception at BLOnlineDatabase.PreviewCount++. -> " + ex.Message);
                    BLIO.WriteError(ex, ex.Message, true);
                }
            }).Start();
        }
Example #7
0
        public Popup(Reminder rem)
        {
            BLIO.Log("Constructing Popup reminderId = " + rem.Id);
            InitializeComponent();
            this.Opacity = 0;
            this.rem     = rem;

            this.Size        = new Size((int)BLPopupDimensions.GetPopupDimensions().FormWidth, (int)BLPopupDimensions.GetPopupDimensions().FormHeight);
            lblTitle.Font    = new Font(lblTitle.Font.FontFamily, BLPopupDimensions.GetPopupDimensions().FontTitleSize, FontStyle.Bold);
            lblNoteText.Font = new Font(lblNoteText.Font.FontFamily, BLPopupDimensions.GetPopupDimensions().FontNoteSize, FontStyle.Bold);
            this.Text        = rem.Name;

            lblNoteText.MaximumSize = new Size((pnlText.Width - lblNoteText.Location.X) - 10, 0);
            lblTitle.MaximumSize    = new Size((pnlTitle.Width - lblTitle.Location.X) - 10, 0);


            //Assign the events that the user can raise while doing something on the popup. The stopflash event stops the taskbar icon from flashing
            lblTitle.MouseClick    += stopFlash_Event;
            lblNoteText.MouseClick += stopFlash_Event;
            this.MouseClick        += stopFlash_Event;
            this.ResizeEnd         += stopFlash_Event;

            BLIO.Log("Popup constructed");
        }
Example #8
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            rem = BLReminder.GetReminderById(rem.Id);

            if (rem == null)
            {
                goto close;
            }

            if (rem.Id != -1 && rem.Deleted == 0) //Don't do stuff if the id is -1, invalid. the id is set to -1 when the user previews an reminder
            {
                if (BLReminder.GetReminderById(rem.Id) == null)
                {
                    //The reminder popped up, it existed, but when pressing OK it doesn't exist anymore (maybe the user deleted it or tempered with the .db file)
                    BLIO.Log("DETECTED NONEXISTING REMINDER WITH ID " + rem.Id + ", Attempted to press OK on a reminder that somehow doesn't exist");
                    goto close;
                }

                if (cbPostpone.Checked)
                {
                    BLIO.Log("Postponing reminder with id " + rem.Id);
                    if (numPostponeTime.Value == 0)
                    {
                        return;
                    }

                    DateTime newReminderTime = new DateTime();

                    if (cbPostpone.Checked && tbPostpone.ForeColor == Color.White && !string.IsNullOrWhiteSpace(tbPostpone.Text)) //postpone option is x minutes
                    {
                        newReminderTime  = DateTime.Now.AddMinutes(BLFormLogic.GetTextboxMinutes(tbPostpone));
                        rem.PostponeDate = newReminderTime.ToString();
                    }
                    else
                    {
                        rem.PostponeDate = null;
                        BLReminder.UpdateReminder(rem);
                    }



                    BLIO.Log("Postpone date assigned to reminder");
                    rem.Enabled = 1;
                    BLReminder.EditReminder(rem);
                    new Thread(() =>
                    {
                        //Log an entry to the database, for data!
                        BLOnlineDatabase.PostponeCount++;
                    }).Start();
                    BLIO.Log("Reminder postponed!");
                }
                else
                {
                    rem.PostponeDate = null;
                    BLReminder.UpdateReminder(rem);
                }
            }

close:
            UCReminders.Instance.UpdateCurrentPage();
            BLIO.Log("Stopping media player & Closing popup");
            myPlayer.controls.stop();
            btnOk.Enabled = false;
            this.Close();
        }
Example #9
0
        private async void ExecuteHttpRequest(object sender, EventArgs e, HttpRequests http, Reminder rem)
        {
            try
            {
                if (!BLIO.HasInternetAccess())
                {
                    BLIO.Log("Cancelling ExecuteHttpRequest(). No internet access");
                    return;
                }

                BLIO.Log("ExecuteHttpRequest timer tick! [ " + http.URL + " ]");
                if (httpTimers.Where(t => t.Key.Id == rem.Id) == null)
                {
                    BLIO.Log("Attempted to ExecuteHttpRequest() from a timer that no longer exists. Cancelling.");
                    return;
                }

                JObject response = await BLIO.HttpRequest(http.Type, http.URL, http.OtherHeaders, http.AcceptHeader, http.ContentTypeHeader, http.Body);



                List <HttpCondition> conditions = new List <HttpCondition>();
                foreach (HttpRequestCondition cond in BLLocalDatabase.HttpRequestConditions.GetConditions(http.Id))
                {
                    conditions.Add(new HttpCondition(cond, response));
                }

                bool conditionMet = conditions.Count > 0;
                foreach (HttpCondition con in conditions) //Check for ALL conditions and see if all of them return true
                {
                    if (!con.Evaluate())
                    {
                        conditionMet = false;
                    }
                }

                if (conditionMet)
                {
                    //All conditions returned true!

                    MakeReminderPopup(rem);

                    if (http.AfterPopup == "Stop")
                    {
                        var timer = GetTimer(rem);
                        if (timer != null)
                        {
                            timer.Stop();

                            //remove from dictionary
                            httpTimers.Remove(rem);
                        }
                    }
                }
                else
                {
                    BLIO.Log("ExecuteHttpRequest returned FALSE");
                }
            }
            catch (Exception ex)
            {
                BLIO.Log("ExecuteHttpRequest() Failed. " + ex.GetType().ToString());
            }
        }
Example #10
0
        /// <summary>
        /// Display changes on the current page. (For example a deleted or enabled/disabled reminder)
        /// </summary>
        /// <param name="editedReminder">If a reminder has been edited, this object will contain that reminder</param>
        public void UpdateCurrentPage(Reminder editedReminder = null)
        {
            MaterialSkin.MaterialSkinManager.Themes theme = MaterialSkin.MaterialSkinManager.Instance.Theme;

            BLIO.Log("Starting UpdateCurrentPage()...");

            //Reminder list containing normal reminders and conditional reminders, enabled and disabled
            List <Reminder> reminders = BLReminder.GetOrderedReminders();

            //^ All reminders in one list with the disabled ones at the end of the list
            BLIO.Log(reminders.Count + " reminders loaded");

startMethod:
            if ((pageNumber * 7) + 1 > reminders.Count)
            {
                if (theme == MaterialSkin.MaterialSkinManager.Themes.DARK)
                {
                    btnNextPage.Icon = Properties.Resources.nextDisabledDark;
                }
                else
                {
                    btnNextPage.Icon = Properties.Resources.nextDisabledDark;
                }
            }
            else
            {
                if (theme == MaterialSkin.MaterialSkinManager.Themes.DARK)
                {
                    btnNextPage.Icon = Properties.Resources.NextWhite;
                }
                else
                {
                    btnNextPage.Icon = Properties.Resources.nextDark;
                }
            }

            int reminderItemCounter = 0;

            for (int i = (pageNumber - 1) * 7; i < ((pageNumber) * 7); i++)
            {
                if (reminders.Count - 1 >= i) //Safely within index numbers
                {
                    if (reminderItemCounter >= pnlReminders.Controls.Count)
                    {
                        return;
                    }

                    //Get the user control item from the panel. There's 7 user controls in the panel, so we have another counter for those
                    MUCReminderItem itm = (MUCReminderItem)pnlReminders.Controls[reminderItemCounter];
                    //Update the reminder object inside the user control, that's waay faster than removing and re-drawing a new control.
                    itm.Reminder = reminders[i];
                    itm.RefreshLabelFont();
                }
                else
                {
                    //User deleted a reminder, which was the last one out of the list from that page. Navigate to the previous page.
                    if (i % 7 == 0 && pageNumber > 1)
                    {
                        BLIO.Log("navigating to the previous page after deletion of an reminder...");
                        pageNumber--;
                        goto startMethod;
                    }

                    for (int ii = i; ii < 7; ii++)
                    {
                        if (ii >= pnlReminders.Controls.Count)
                        {
                            break;
                        }

                        MUCReminderItem itm = (MUCReminderItem)pnlReminders.Controls[ii];
                        itm.Reminder = null;
                    }

                    //This happens when an reminder has been deleted, and there are less than 7 reminders on that page. Empty out the remaining reminder items.
                    while (reminderItemCounter <= 6)
                    {
                        BLIO.Log("Detected the deletion of an reminder on the current page.");
                        //Get the user control item from the panel. There's 7 user controls in the panel, so we have another counter for those
                        try
                        {
                            MUCReminderItem itm = (MUCReminderItem)pnlReminders.Controls[reminderItemCounter];

                            if (itm.Reminder != null)
                            {
                                BLIO.Log("Emptying ReminderItem with ID " + itm.Reminder.Id);
                            }
                            //Update the reminder object inside the user control, that's waay faster than removing and re-drawing a new control.
                            itm.Reminder = null;

                            reminderItemCounter++;
                        }
                        catch (Exception ex)
                        {
                            BLIO.Log("Setting new Reminder value failed. -> " + ex.GetType().ToString());
                        }
                    }

                    break;
                }

                reminderItemCounter++;

                if (reminderItemCounter == 7)
                {
                    break;
                }
            }



            if (reminders.Count <= 7)
            {
                MaterialForm1.Instance.UpdatePageNumber(-1);
            }
            else
            {
                MaterialForm1.Instance.UpdatePageNumber(pageNumber);
            }

            if (Instance != null)
            {
                Instance.tmrCheckReminder.Start();
            }


            if (editedReminder != null && editedReminder.HttpId != null)
            {
                //This object has been altered. Deleted, Perma-deleted, edited OR disabled
                if (BLReminder.GetReminderById(editedReminder.Id) == null || editedReminder.Deleted > 0 || editedReminder.Enabled == 0)
                {
                    //perma-deleted, soft-deleted or turned off
                    if (GetTimer(editedReminder) != null)
                    {
                        GetTimer(editedReminder).Stop();
                    }
                    RemoveTimer(editedReminder);
                }
                else //Reminder is still active, so it probably has been edited
                {
                    HttpRequests httpObj = BLLocalDatabase.HttpRequest.GetHttpRequestById((long)editedReminder.Id);
                    var          kvp     = httpTimers.Where(r => r.Key.Id == editedReminder.Id).FirstOrDefault();
                    if (kvp.Key != null)
                    {
                        //Already exist, stop timer, change & restart
                        RemoveTimer(editedReminder);
                        var timer = new System.Windows.Forms.Timer();
                        timer.Interval = Convert.ToInt32(httpObj.Interval * 60000);
                        timer.Tick    += (object s, EventArgs a) => ExecuteHttpRequest(s, a, httpObj, editedReminder);
                        timer.Start();
                        httpTimers.Add(editedReminder, timer);
                    }
                    else if (editedReminder.Enabled == 1) //Reminder has been re-enabled
                    {
                        System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
                        httpTimers.Add(editedReminder, timer);
                        timer.Interval = Convert.ToInt32(httpObj.Interval * 60000);
                        timer.Tick    += (object s, EventArgs a) => ExecuteHttpRequest(s, a, httpObj, editedReminder);
                        timer.Start();
                    }
                }
            }
            else
            {
                //Http requests
                foreach (Reminder rem in BLReminder.GetReminders(true).Where(r => r.HttpId != null).Where(r => r.Enabled == 1))
                {
                    HttpRequests httpObj = BLLocalDatabase.HttpRequest.GetHttpRequestById((long)rem.Id);

                    if (GetTimer(rem) == null)
                    {
                        //Don't add duplicates
                        System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
                        httpTimers.Add(rem, timer);
                        timer.Interval = Convert.ToInt32(httpObj.Interval * 60000);
                        timer.Tick    += (object s, EventArgs a) => ExecuteHttpRequest(s, a, httpObj, rem);
                        timer.Start();
                    }
                }
            }



            BLIO.Log("UpdateCurrentPage() completed.");
        }
Example #11
0
        public async Task UpdateReminder(Reminder reminder)
        {
            await _reminderTable.UpdateAsync(reminder);

            UpdateEvent?.Invoke(reminder);
        }
Example #12
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            if (xClose)
            {
                xClose = false;
            }

            if (rem != null)
            {
                rem = BLReminder.GetReminderById(rem.Id);
            }

            if (rem == null)
            {
                goto close;
            }

            if (rem.HttpId != null)
            {
                //Conditional reminder
                HttpRequests req = BLLocalDatabase.HttpRequest.GetHttpRequestById(rem.Id);
                if (req.AfterPopup == "Stop")
                {
                    rem.Deleted = 1;
                    BLReminder.EditReminder(rem);
                    goto close;
                }
                else if (req.AfterPopup == "Repeat")
                {
                    goto close;
                }
                //else .... ?
            }

            if (rem.Id != -1 && rem.Deleted == 0) //Don't do stuff if the id is -1, invalid. the id is set to -1 when the user previews an reminder
            {
                if (BLReminder.GetReminderById(rem.Id) == null)
                {
                    //The reminder popped up, it existed, but when pressing OK it doesn't exist anymore (maybe the user deleted it or tempered with the .db file)
                    BLIO.Log("DETECTED NONEXISTING REMINDER WITH ID " + rem.Id + ", Attempted to press OK on a reminder that somehow doesn't exist");
                    goto close;
                }

                if (cbPostpone.Checked)
                {
                    BLIO.Log("Postponing reminder with id " + rem.Id);
                    if (BLFormLogic.GetTextboxMinutes(tbPostpone) <= 0)
                    {
                        return;
                    }

                    DateTime newReminderTime = new DateTime();

                    if (!string.IsNullOrWhiteSpace(tbPostpone.Text)) //postpone option is x minutes
                    {
                        newReminderTime  = DateTime.Now.AddMinutes(BLFormLogic.GetTextboxMinutes(tbPostpone));
                        rem.PostponeDate = newReminderTime.ToString();
                    }
                    else
                    {
                        rem.PostponeDate = null;
                        BLReminder.UpdateReminder(rem);
                    }



                    BLIO.Log("Postpone date assigned to reminder");
                    rem.Enabled = 1;
                    BLReminder.EditReminder(rem);
                    new Thread(() =>
                    {
                        //Log an entry to the database, for data!
                        try
                        {
                            BLOnlineDatabase.PostponeCount++;
                        }
                        catch (ArgumentException ex)
                        {
                            BLIO.Log("Exception at BLOnlineDatabase.PostponeCount++. -> " + ex.Message);
                            BLIO.WriteError(ex, ex.Message, true);
                        }
                    }).Start();
                    BLIO.Log("Reminder postponed!");
                }
                else
                {
                    rem.PostponeDate = null;
                    BLReminder.UpdateReminder(rem);
                }
            }

close:
            MUCReminders.Instance.UpdateCurrentPage(rem);
            BLIO.Log("Stopping media player & Closing popup");

            if (BLLocalDatabase.Setting.Settings.PopupType != "SoundOnly")
            {
                myPlayer.controls.stop();
            }

            this.Close();

            GC.Collect();
        }
Example #13
0
        /// <summary>
        /// Creates a new instance of popup
        /// </summary>
        private void MakeReminderPopup(Reminder rem)
        {
            Popup p = new Popup(rem);

            p.Show();
        }
Example #14
0
        public override async Task OnMessage(MessageCreateEventArgs e)
        {
            // Try and decipher the output.
            string[]     splitMessage = e.Message.Content.Split(' ');
            TimeZoneInfo userTimeZone = UserTimeZone.UserTimeZone.GetUserTimeZone(this, e.Author);

            // Try and look for the "to" index.
            int toIndex = 0;

            while (toIndex < splitMessage.Length && splitMessage[toIndex] != "to")
            {
                ++toIndex;
            }

            if (toIndex == splitMessage.Length)
            {
                await BotMethods.SendMessage(this, new SendMessageEventArgs {
                    Message    = "Incorrect syntax, make sure you use the word \"to\" after you indicate the time you want the reminder!",
                    Channel    = e.Channel,
                    LogMessage = "ReminderErrorNoTo"
                });

                return;
            }
            else if (toIndex == splitMessage.Length - 1)
            {
                await BotMethods.SendMessage(this, new SendMessageEventArgs {
                    Message    = "Incorrect syntax, make sure you type a message after that \"to\"!",
                    Channel    = e.Channel,
                    LogMessage = "ReminderErrorNoMessage"
                });

                return;
            }

            // Now decipher the time.
            DateTime foundTime = DateTime.UtcNow;

            string[] writtenTime = splitMessage.Skip(2).Take(toIndex - 2).ToArray();
            if (splitMessage[1] == "at")
            {
                bool     successfulFormat = true;
                DateTime foundDate        = DateTime.UtcNow.Add(userTimeZone.BaseUtcOffset).Date;
                var      foundTimeSpan    = new TimeSpan();
                bool     didUserInputDate = false;
                bool     didUserInputTime = false;
                if (writtenTime.Length > 0 && writtenTime.Length <= 2)
                {
                    foreach (string item in writtenTime)
                    {
                        if (item.Contains(":") && !didUserInputTime)
                        {
                            try {
                                int[] splitDigits = item.Split(":").Select(s => int.Parse(s)).ToArray();
                                if (splitDigits.Length == 2)
                                {
                                    foundTimeSpan = new TimeSpan(splitDigits[0], splitDigits[1], 0);
                                }
                                else if (splitDigits.Length == 3)
                                {
                                    foundTimeSpan = new TimeSpan(splitDigits[0], splitDigits[1], splitDigits[2]);
                                }
                                else
                                {
                                    successfulFormat = false;
                                }
                            } catch (FormatException) {
                                successfulFormat = false;
                            }
                            didUserInputTime = true;
                        }
                        else if (item.Contains("/") && !didUserInputDate)
                        {
                            try {
                                int[] splitDigits = item.Split("/").Select(s => int.Parse(s)).ToArray();
                                if (splitDigits.Length == 2)
                                {
                                    foundDate = new DateTime(foundTime.Year, splitDigits[1], splitDigits[0]);
                                }
                                else if (splitDigits.Length == 3)
                                {
                                    if (splitDigits[2] < 100)
                                    {
                                        splitDigits[2] += 2000;                                         // Won't work when we hit 2100 but that shouldn't be hard to spot.
                                    }
                                    foundDate = new DateTime(splitDigits[2], splitDigits[1], splitDigits[0]);
                                }
                                else
                                {
                                    successfulFormat = false;
                                }
                            } catch (FormatException) {
                                successfulFormat = false;
                            }
                            didUserInputDate = true;
                        }
                        else
                        {
                            successfulFormat = false;
                        }
                    }
                    // Basically, interpet the date that the user wants, then factor the timezone to UTC.
                    foundTime = DateTime.SpecifyKind(foundDate + foundTimeSpan - userTimeZone.BaseUtcOffset, DateTimeKind.Utc);
                }
                else
                {
                    successfulFormat = false;
                }
                if (!successfulFormat)
                {
                    await BotMethods.SendMessage(this, new SendMessageEventArgs {
                        Message    = $"The date/time you input could not be parsed! See {"?help remind".Code()} for how to format your date/time!",
                        Channel    = e.Channel,
                        LogMessage = "ReminderErrorInvalidTime"
                    });

                    return;
                }
            }
            else if (splitMessage[1] == "in")
            {
                bool successfulFormat = true;
                if (writtenTime.Length == 1)
                {
                    try {
                        int[] splitDigits = writtenTime[0].Split(":").Select(s => int.Parse(s)).ToArray();
                        var   timespan    = new TimeSpan();
                        if (splitDigits.Length == 2)
                        {
                            timespan = new TimeSpan(0, splitDigits[0], splitDigits[1]);
                        }
                        else if (splitDigits.Length == 3)
                        {
                            timespan = new TimeSpan(splitDigits[0], splitDigits[1], splitDigits[2]);
                        }
                        else
                        {
                            successfulFormat = false;
                        }
                        if (successfulFormat)
                        {
                            foundTime += timespan;
                        }
                    } catch (FormatException) {
                        successfulFormat = false;
                    }
                }
                else
                {
                    successfulFormat = false;
                }
                if (!successfulFormat)
                {
                    await BotMethods.SendMessage(this, new SendMessageEventArgs {
                        Message    = $"The timespan you input could not be parsed! See {"?help remind".Code()} for how to format your timespan!",
                        Channel    = e.Channel,
                        LogMessage = "ReminderErrorInvalidTimespan"
                    });

                    return;
                }
            }
            else
            {
                await BotMethods.SendMessage(this, new SendMessageEventArgs {
                    Message    = "Incorrect syntax, make sure you use the word \"in\" or \"at\" to specify a time for the reminder!",
                    Channel    = e.Channel,
                    LogMessage = "ReminderErrorNoAt"
                });

                return;
            }
            if (foundTime < DateTime.UtcNow)
            {
                await BotMethods.SendMessage(this, new SendMessageEventArgs {
                    Message    = $"The time you input was parsed as {TimeZoneInfo.ConvertTime(foundTime, userTimeZone).ToString(TimeFormatString)} {UserTimeZone.UserTimeZone.ToShortString(userTimeZone)}, which is in the past! Make your time a little more specific!",
                    Channel    = e.Channel,
                    LogMessage = "ReminderErrorPastTime"
                });

                return;
            }
            // Finally extract the message.
            string message = string.Join(' ', splitMessage.Skip(toIndex + 1));

            // Make the reminder.
            var reminder = new Reminder(TimeZoneInfo.ConvertTimeToUtc(foundTime), message, e.Channel.Id, e.Author.Id);

            reminder.Activate(ReminderElapsed);
            OutstandingReminders.Add(reminder);
            SaveReminders();

            await BotMethods.SendMessage(this, new SendMessageEventArgs {
                Message    = $"Okay, I'll tell you this message at {TimeZoneInfo.ConvertTime(foundTime, userTimeZone).ToString(TimeFormatString)} {UserTimeZone.UserTimeZone.ToShortString(userTimeZone)}",
                Channel    = e.Channel,
                LogMessage = "ReminderConfirm"
            });
        }
Example #15
0
 public void UpdateReminder(Reminder rem)
 {
     this.rem = rem;
     LoadReminderData();
 }
Example #16
0
        public async Task PostReminder(Reminder reminder)
        {
            await _reminderTable.InsertAsync(reminder);

            InsertEvent?.Invoke(reminder);
        }
Example #17
0
        private void RemindMeImporter_Load(object sender, EventArgs e)
        {
            BLIO.Log("RemindmeImporter_load");
            this.MaximumSize = this.Size;


            if (!HasFileAccess(this.remindmeFile)) //Do not attempt to launch the importer form if we can't open the file
            {
                BLIO.Log("Error opening .remindme file, no rights");
                RemindMeBox.Show("Can not open this .remindme file from " + Path.GetDirectoryName(this.remindmeFile) + ". Insufficient rights.", RemindMeBoxReason.OK);
                this.Close();
            }
            else
            {
                try
                {
                    BLIO.Log("Deserializing reminders.....");
                    List <object> deSerializedReminders = BLReminder.DeserializeRemindersFromFile(remindmeFile);
                    BLIO.Log(deSerializedReminders.Count - 1 + " reminders deserialized!");
                    lblAmountOfReminders.Text = deSerializedReminders.Count - 1 + " Reminders"; //-1 because of country code
                    foreach (object rem in deSerializedReminders)
                    {
                        if (rem.GetType() == typeof(Reminder))
                        {
                            Reminder reminder = (Reminder)rem;
                            BLIO.Log(reminder.Name + " Loaded into RemindMeImporter from the .remindme file.");
                            remindersFromRemindMeFile.Add((Reminder)rem);
                        }
                        else
                        {
                            BLIO.Log("Language code" + languageCode + " read from the .remindme file!");
                            languageCode = rem.ToString(); //The language code stored in the .remindme file, "en-Us" for example
                        }
                    }

                    if (languageCode != "") //Don't need to do this when exporting.
                    {
                        BLIO.Log("Going through the reminder list once more....");
                        foreach (object rem in remindersFromRemindMeFile)
                        {
                            if (rem.GetType() == typeof(Reminder))
                            {
                                Reminder remm = (Reminder)rem;
                                //Fix the date if the .remindme file has a different time format than the current system
                                BLIO.Log("(" + remm.Name + ") Fixing the date to match the language code " + languageCode);
                                remm.Date = BLDateTime.ConvertDateTimeStringToCurrentCulture(remm.Date, languageCode);
                            }
                        }
                    }

                    if (remindersFromRemindMeFile != null)
                    {
                        BLIO.Log("Adding the reminders from the .remindme file to the listview....");
                        BLFormLogic.AddRemindersToListview(lvReminders, remindersFromRemindMeFile);
                        BLIO.Log("Done!");
                    }
                    else
                    {
                        BLIO.Log("Failed to load reminders.");
                        lblTitle.Text = "Failed to load reminders.";
                    }
                }
                catch (Exception ex)
                {
                    RemindMeBox.Show("Something has gone wrong loading reminders from this .remindme file.\r\nThe file might be corrupt", RemindMeBoxReason.OK);
                    BLIO.Log("Error loading reminders from .remindme file written to error log");
                    BLIO.WriteError(ex, "Error loading reminders from .remindme file");
                    Application.Exit();
                }
            }
            BLIO.Log("RemindmeImporter loaded !");
        }
Example #18
0
        public async Task DeleteReminder(Reminder reminder)
        {
            await _reminderTable.DeleteAsync(reminder);

            RemoveEvent?.Invoke(reminder);
        }
Example #19
0
        /// <summary>
        /// Gets the timer object from the KeyValuePair<Reminder, Timer>
        /// </summary>
        /// <returns></returns>
        private System.Windows.Forms.Timer GetTimer(Reminder rem)
        {
            var kvp = httpTimers.Where(r => r.Key.Id == rem.Id).FirstOrDefault();

            return(kvp.Value);
        }