Пример #1
0
        /// <summary>
        /// Takes a string from the passing method, and checks file existence, then uses <see cref="GetJson(string)"/> to retrieve
        /// saved JSON object. The JSON's email and password attributes are then decoded using <see cref="DecodePassword(string)"/>
        /// and used to send a MailMessage object using SmtpClient to the user, informing them of a posted match.
        /// </summary>
        /// <param name="result">Passed string for notification purposes.</param>
        /// <param name="url">Passed URL for ease of access</param>
        public void NotifyUser(List <string> result, List <string> url)
        {
            //Initialize helper class
            rcHelper rc = new rcHelper();

            //Confirms rcData.json exists
            if (!File.Exists(Path.Combine(Directory.GetCurrentDirectory().ToString() + jsonFilePath)))
            {
                rc.DebugLog(new Exception("JSON has not been created"));
                Environment.Exit(0);
            }

            //Retrieves json object from file path
            RCDetails json     = rc.GetJson(jsonFilePath);
            string    email    = rc.DecodePassword(json.email);
            string    password = rc.DecodePassword(json.ePass);

            //If credentials exist, continue.
            if (email != null && password != null)
            {
                //Send details of post to the user in an email.
                try
                {
                    //Initialize mail object & client
                    MailMessage mail       = new MailMessage();
                    SmtpClient  SmtpServer = new SmtpClient("smtp.gmail.com");

                    //Adds details to mail object
                    StringBuilder strMailContent = new StringBuilder();
                    mail.From = new MailAddress(email);
                    mail.To.Add(email);
                    mail.Subject = "New Reddit Post!";
                    for (int i = 0; i < result.Count(); i++)
                    {
                        strMailContent.Append(result[i] + "\n" + url[i] + "\n\n");
                    }
                    mail.Body = "The following posts were created " + DateTime.Now.ToShortDateString()
                                + ":\n\n" + strMailContent;
                    //Sets port, credentials, SSL, and sends mail object.
                    SmtpServer.Port        = 587;
                    SmtpServer.Credentials = new System.Net.NetworkCredential(email, password);
                    SmtpServer.EnableSsl   = true;
                    SmtpServer.Send(mail);
                    Console.WriteLine("mail Sent");
                    SmtpServer.Dispose();
                    mail.Dispose();
                }
                //Generic exception handling
                catch (Exception ex)
                {
                    rc.DebugLog(ex);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Method for confirming whether or not all fields of JSON object have been initialized
        /// </summary>
        /// <returns><c>true</c> if all fields are input, otherwise <c>false</c></returns>
        public bool ApplicationReady()
        {
            //Initialize helper class
            rcHelper rc = new rcHelper();

            //Initialize instance of RCDetails class
            RCDetails json = rc.GetJson(jsonFilePath);

            //If json retrieval fails, return false
            if (json == null)
            {
                return(false);
            }

            //If all fields of RCDetails class are valid, return true
            else if (json.email != null && json.ePass != null && json.sub != null && json.searchCriteria != null)
            {
                return(true);
            }

            //Return false by default
            return(false);
        }