public void Reload(string accountsXmlDoc) { Users.Clear(); try { _accountsDoc.Load(Utils.StartupLocation + @"\Accounts.xml"); _accountsDs.Reset(); _accountsDs.ReadXml(_accountsDoc.ToXmlReader()); AccountsDataGrid.ItemsSource = _accountsDs.Tables[0].DefaultView; foreach (XmlNode node in _accountsDoc.DocumentElement) { if (node.Name == "Account") { string email = "", tagsLoaded = ""; foreach (XmlNode child in node.ChildNodes) { switch (child.Name) { case "Email": email = child.InnerText; break; case "Tags": tagsLoaded = child.InnerText; break; default: break; } } if (email != "") { var tags = tagsLoaded.Split(' '); var user = new User(email, tagsLoaded); Users.Add(user); } } } } catch (Exception ex) { _accountsDs.Reset(); _accountsDoc.LoadXml( "<Accounts>\r\n <Account>\r\n <Email>[email protected]</Email>\r\n <Tags>Please insert your tags here with a space in between each</Tags>\r\n </Account>\r\n</Accounts>"); _accountsDs.ReadXml(_accountsDoc.ToXmlReader()); AccountsDataGrid.ItemsSource = _accountsDs.Tables[0].DefaultView; Save(); _mainForm.LogException(ex); } }
private void ProcessRequest(User user) { Logger.CurrentLogger.Log($"Emailing {user.Email} with {user.DealsForUser.Count} Deals.", LogType.DebugLog); var message = new MailMessage(); var address = new MailAddress(_mainForm.Settings.Email); message.From = address; message.To.Add(user.Email); string body = "", subject = _mainForm.Settings.EmailSubject; subject = user.TriggerTags.Aggregate(subject, (current, tag) => current + $"[{tag}]"); body = user.DealsForUser.Aggregate(body, (current, deal) => current + $"\r\n{deal.Title}\r\n{deal.Url}\r\n"); message.Body = body; message.Subject = subject; var client = new SmtpClient { Host = _mainForm.Settings.SmtpHost, Port = _mainForm.Settings.Port, EnableSsl = true, DeliveryMethod = SmtpDeliveryMethod.Network, UseDefaultCredentials = false, Credentials = new NetworkCredential(_mainForm.Settings.Email, _mainForm.Settings.Password) }; try { client.Send(message); } catch (Exception ex) { Logger.CurrentLogger.Log($"Failed to send a message to {user.Email}", LogType.Error); _mainForm.LogException(ex); } user.TriggerTags.Clear(); user.DealsForUser.Clear(); }