Esempio n. 1
0
        private void btnSend_Click(object sender, EventArgs e)
        {
            try
            {
                BLIO.Log("Attempting to send a message to the RemindMe developer..");

                //Don't do anything if there's no text
                if (string.IsNullOrWhiteSpace(tbNote.Text))
                {
                    return;
                }

                //Don't do anything without internet
                if (!BLIO.HasInternetAccess())
                {
                    RemindMeMessageFormManager.MakeMessagePopup("You do not currently have an active internet connection", 3);
                    return;
                }

                string email   = tbEmail.Text;
                string subject = tbSubject.Text;
                string note    = tbNote.Text;

                BLOnlineDatabase.InsertEmailAttempt(File.ReadAllText(IOVariables.uniqueString), note, subject, email);
                RemindMeMessageFormManager.MakeMessagePopup("Feedback Sent. Thank you!", 5);
                tbEmail.Text   = "";
                tbSubject.Text = "";
                tbNote.Text    = "";
                BLIO.Log("Message sent!");
            }
            catch
            {
                RemindMeMessageFormManager.MakeMessagePopup("Something went wrong. Could not send the e-mail", 3);
            }
        }
Esempio n. 2
0
        private void btnSend_Click(object sender, EventArgs e)
        {
            BLIO.Log("(UCSupport)btnSend_Click");
            try
            {
                BLIO.Log("Attempting to send a message to the RemindMe developer..");

                //Don't do anything if there's no text
                if (string.IsNullOrWhiteSpace(tbNote.Text) || tbNote.Text == "Type your message here...")
                {
                    return;
                }

                //Don't do anything without internet
                if (!BLIO.HasInternetAccess())
                {
                    RemindMeMessageFormManager.MakeMessagePopup("You do not currently have an active internet connection", 3);
                    return;
                }

                string email   = tbEmail.Text;
                string subject = tbSubject.Text;
                string note    = tbNote.Text;

                BLOnlineDatabase.InsertEmailAttempt(BLLocalDatabase.Setting.Settings.UniqueString, note, subject, email);
                RemindMeMessageFormManager.MakeMessagePopup("Feedback Sent. Thank you!", 5);
                tbEmail.Text   = "";
                tbSubject.Text = "";
                tbNote.Text    = "";
                label3.Focus();
                BLIO.Log("Message sent!");
            }
            catch (Exception ex)
            {
                BLIO.Log("Error in UCSUpport.btnSend_Click. Could not send the message! Exception type: " + ex.GetType().ToString() + "   Stacktrace:\r\n" + ex.StackTrace);
                RemindMeMessageFormManager.MakeMessagePopup("Something went wrong. Could not send the e-mail", 3);
            }
        }
Esempio n. 3
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());
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Transforms the part of the textbox string "API{url,data}" to the data from the API
        /// </summary>
        /// <param name="reminderText">The reminder text</param>
        /// <returns>The reminder text with the API{} replaced with the actual API value</returns>
        private async void TransformAPITextToValue(string color, string reminderText, float previewSize = 0)
        {
            float size = previewSize == 0 ? BLLocalDatabase.PopupDimension.GetPopupDimensions().FontNoteSize : previewSize;

            if (!reminderText.Contains("API{"))
            {
                return;
            }

            try
            {
                int retryCount = 0;
                htmlLblText.Text = "<p style=\"color: " + color + "; font-size: " + Math.Round(size * 1.28) + "px;\">Loading...</p>";
                new Thread(async() =>
                {
                    startMethod:



                    try
                    {
                        //if !hasinternetaccess Thread.Sleep(250); , 8 times, then error

                        if (!BLIO.HasInternetAccess())
                        {
                            retryCount++;

                            if (retryCount <= 8)
                            {
                                Thread.Sleep(250);
                                goto startMethod;
                            }
                            else
                            {
                                htmlLblText.Invoke((MethodInvoker)(() =>
                                {
                                    htmlLblText.Text = "An error occured." + rem.Note;
                                }));

                                return;
                            }
                        }

                        retryCount = 0;

                        //Interner access!

                        int startIndex = reminderText.IndexOf("API{");
                        int endIndex   = -1;

                        bool found = false;
                        int count  = 1;
                        while (!found)
                        {
                            if (reminderText[startIndex + count] == '}')
                            {
                                endIndex = startIndex + count;
                                found    = true;
                            }
                            else
                            {
                                count++;
                            }
                        }

                        //[url, dataToPick]
                        string[] data    = (reminderText.Substring(startIndex + 4, endIndex - (startIndex + 4))).Split(',');
                        JObject response = await BLIO.HttpRequest("GET", data[0]);

                        //This is the API value the user is requesting. Replace API{url,data} with this.
                        string value = response.SelectTokens(data[1]).Select(t => t.Value <string>()).ToList()[0];

                        StringBuilder stringBuilder = new StringBuilder(reminderText);
                        stringBuilder.Remove(startIndex, endIndex - (startIndex) + 1);
                        stringBuilder.Insert(startIndex, value);
                        reminderText = stringBuilder.ToString();

                        //TODO if response.status != 200   stringBuilder.Insert(startIndex, "Error occured");
                        //Bitcoin: $60,001
                        //Superfarm: Error
                        //Reef: $0,04
                        //

                        //Still contains another API{} ? again...
                        if (reminderText.Contains("API{"))
                        {
                            goto startMethod;
                        }

                        htmlLblText.Invoke((MethodInvoker)(() =>
                        {
                            htmlLblText.Text = "<p style=\"color: " + color + "; font-size: " + Math.Round(size * 1.28) + "px;\">" + reminderText + "</p>";
                        }));
                        //return reminderText;
                    }
                    catch (Exception ex)
                    {
                        retryCount++;

                        if (retryCount <= 8)
                        {
                            Thread.Sleep(250);
                            goto startMethod;
                        }
                        else
                        {
                            htmlLblText.Text = "An error occured. (" + ex.GetType().ToString() + ")\r\n" + rem.Note;
                        }
                    }
                }).Start();
            }
            catch (Exception ex)
            {
                BLIO.WriteError(ex, "TransformAPITextToValue() failed with " + ex.GetType().ToString());
                //return reminderText;
            }
        }
Esempio n. 5
0
        public void UpdateRemindMe() //This is called within a Thread
        {
            try
            {
                //Don't do anything without internet
                if (hasUpdated || !BLIO.HasInternetAccess())
                {
                    return;
                }

                if (GetGithubVersion() > new Version(IOVariables.RemindMeVersion))
                {
                    BLIO.Log("New version of RemindMe on Github! Starting UpdateRemindMe()...");
                    DateTime dateNow = DateTime.UtcNow;
                    //Download the updated files
                    DownloadFile("https://github.com/Stefangansevles/RemindMe/raw/master/Update/UpdateFiles.zip", IOVariables.rootFolder + "UpdateFiles.zip");

                    ZipFile zip = new ZipFile(IOVariables.rootFolder + "UpdateFiles.zip");

                    if (zip == null || !ZipFile.IsZipFile(IOVariables.rootFolder + "UpdateFiles.zip"))
                    {
                        BLIO.Log("UpdateRemindMe ABORTED. Zip is null or invalid.");
                        return;
                    }

                    try
                    {
                        BLIO.Log("UpdateFiles.zip contains files for a new RemindMe version!");

                        //First, move the running files into an /old/ directory
                        MoveOldFiles();

                        //Now, move those updates files into the application directory, so that when the program starts the next time, RemindMe is updated! :)
                        zip.ExtractProgress += Zip_ExtractProgress;
                        BLIO.Log("Extracting zip...");
                        zip.ExtractAll(IOVariables.applicationFilesFolder, ExtractExistingFileAction.OverwriteSilently);

                        while (!extractCompleted)
                        {
                        }                             //Busy waiting, but we're in a thread anyway
                        BLIO.Log("UpdateRemindMe() took: " + (long)(DateTime.UtcNow - dateNow).TotalMilliseconds + " ms");

                        BLIO.Log("Attempting to remove UpdateFiles.zip...");
                        try { File.Delete(IOVariables.rootFolder + "UpdateFiles.zip"); } catch { }

                        if (restartRemindMe && !Form1.Instance.Visible)
                        {
                            BLIO.Log("Restarting RemindMe...");
                            Application.Restart();
                        }
                        else
                        {
                            BLIO.Log("Installation complete! restartRemindMe = " + restartRemindMe);
                            Form1.Instance.restartRemindMeUpdateToolStripMenuItem.Visible = true; //Give a "Restart" option on the RemindMe Icon
                        }

                        hasUpdated = true;
                    }
                    catch (Exception ex) //do rollback
                    {
                        BLIO.Log("Something went wrong during extraction in UpdateRemindMe(). Exception: " + ex.GetType().ToString() + "\r\nDoing rollback...");

                        //Roll the files in /old/ back to the original folder
                        foreach (string fl in Directory.GetFiles(IOVariables.applicationFilesFolder + "\\old"))
                        {
                            if (File.Exists(IOVariables.applicationFilesFolder + Path.GetFileName(fl)))
                            {
                                BLIO.Log(" - Deleting file: " + Path.GetFileName(fl));
                                File.Delete(IOVariables.applicationFilesFolder + Path.GetFileName(fl));
                            }

                            BLIO.Log(" - Restoring /old file: " + Path.GetFileName(fl));
                            File.Move(fl, IOVariables.applicationFilesFolder + Path.GetFileName(fl));
                        }
                        //Delete the /old
                        BLIO.Log("Deleting directory /old");
                        Directory.Delete(IOVariables.applicationFilesFolder + "\\old");
                    }
                }
                else if (BLIO.LastLogMessage != null && !BLIO.LastLogMessage.Contains("Updating user"))
                {
                    BLIO.Log("No new version of RemindMe on Github.");
                }
            }
            catch (Exception ex)
            {
                BLIO.Log("First part of UpdateRemindMe failed. Exception: " + ex.GetType().ToString());
            }
        }