Esempio n. 1
0
        public MainForm()
        {
            InitializeComponent();

            try
            {
                _smtp      = ConfigurationManager.AppSettings["smtp"];
                _smtpPort  = int.Parse(ConfigurationManager.AppSettings["smtp_port"]);
                _enableSsl = bool.Parse(ConfigurationManager.AppSettings["smtp_enable_ssl"]);
                _username  = ConfigurationManager.AppSettings["smtp_username"];
                _password  = ConfigurationManager.AppSettings["smtp_password"];

                _recentData = ReadRecentData();
                NewsletterUrlComboBox.DisplayMember = "Url";
                NewsletterUrlComboBox.ValueMember   = "Url";

                NewsletterSendToComboBox.DisplayMember = "Email";
                NewsletterSendToComboBox.ValueMember   = "Email";

                BindComboBoxes(_recentData);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error reading configuration: " + ex.ToString());
                Environment.Exit(1);
            }
        }
Esempio n. 2
0
        private void BindComboBoxes(RecentData data)
        {
            NewsletterUrlComboBox.Items.Clear();
            NewsletterUrlComboBox.Items.AddRange(data.RecentUrls.OrderByDescending(x => x.LastUsed).ToArray());

            NewsletterSendToComboBox.Items.Clear();
            NewsletterSendToComboBox.Items.AddRange(data.RecentEmails.OrderByDescending(x => x.LastUsed).ToArray());
        }
Esempio n. 3
0
        private void SaveRecentData(RecentData data)
        {
            var serializer = new XmlSerializer(typeof(RecentData));

            using (var writer = new StreamWriter("recent.xml", false))
            {
                serializer.Serialize(writer, data);
            }
        }
Esempio n. 4
0
        private void AddToRecentData(RecentData data, string url, string email)
        {
            var existingUrl = data.RecentUrls.FirstOrDefault(x => x.Url == url);

            if (existingUrl == null)
            {
                data.RecentUrls.Add(new RecentUrl
                {
                    Url      = url,
                    LastUsed = DateTime.Now
                });

                if (data.RecentUrls.Count > 10)
                {
                    var last = data.RecentUrls.OrderBy(x => x.LastUsed).First();
                    data.RecentUrls.Remove(last);
                }
            }
            else
            {
                existingUrl.LastUsed = DateTime.Now;
            }

            var existingEmail = data.RecentEmails.FirstOrDefault(x => x.Email == email);

            if (existingEmail == null)
            {
                data.RecentEmails.Add(new RecentEmail
                {
                    Email    = email,
                    LastUsed = DateTime.Now
                });

                if (data.RecentEmails.Count > 10)
                {
                    var last = data.RecentEmails.OrderBy(x => x.LastUsed).First();
                    data.RecentEmails.Remove(last);
                }
            }
            else
            {
                existingEmail.LastUsed = DateTime.Now;
            }

            SaveRecentData(data);
            BindComboBoxes(data);
        }