diff --git a/SecretSantaHelper/MainWindow.xaml b/SecretSantaHelper/MainWindow.xaml
index efca1b2..8a99eae 100644
--- a/SecretSantaHelper/MainWindow.xaml
+++ b/SecretSantaHelper/MainWindow.xaml
@@ -22,5 +22,7 @@
+
+
diff --git a/SecretSantaHelper/MainWindow.xaml.cs b/SecretSantaHelper/MainWindow.xaml.cs
index 05de749..3f339a0 100644
--- a/SecretSantaHelper/MainWindow.xaml.cs
+++ b/SecretSantaHelper/MainWindow.xaml.cs
@@ -6,6 +6,7 @@
using System.Text;
using System.Windows;
using System.Windows.Forms;
+using Application = System.Windows.Forms.Application;
using MessageBox = System.Windows.Forms.MessageBox;
namespace SecretSantaHelper
@@ -15,7 +16,7 @@ namespace SecretSantaHelper
///
public partial class MainWindow : Window
{
-
+
private bool addClicked = false;
private Participant selectedParticipant;
private SantaSack santaSack;
@@ -23,6 +24,7 @@ public partial class MainWindow : Window
public MainWindow()
{
InitializeComponent();
+ lblVersion.Content = string.Format("Version: {0}", System.Reflection.Assembly.GetExecutingAssembly().GetName().Version);
santaSack = SantaSackSerializer.Deserialize();
lstParticipants.ItemsSource = from participant in santaSack.Participants select participant.DisplayValue();
}
@@ -38,6 +40,11 @@ private void btnImport_Click(object sender, RoutedEventArgs e)
if (filePicker.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
+ if (MessageBox.Show("Do You Want To Clear Previous Items Before Importing?", "Clear Previous?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
+ {
+ santaSack.Participants.Clear();
+ }
+
try
{
var dataRead = File.ReadLines(filePicker.FileName);
@@ -60,6 +67,7 @@ private void btnImport_Click(object sender, RoutedEventArgs e)
MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
}
}
+ SantaSackSerializer.Serialize(santaSack);
}
private void btnExport_Click(object sender, RoutedEventArgs e)
@@ -85,7 +93,7 @@ private void btnExport_Click(object sender, RoutedEventArgs e)
private void btnSave_Click(object sender, RoutedEventArgs e)
{
var emailHelper = new RegexUtilities();
- if(!emailHelper.IsValidEmail(txtEmail.Text))
+ if (!emailHelper.IsValidEmail(txtEmail.Text))
{
MessageBox.Show("That is an invalid email address!");
return;
@@ -136,6 +144,7 @@ private void btnSave_Click(object sender, RoutedEventArgs e)
lstParticipants.ItemsSource = null;
lstParticipants.ItemsSource = from participant in santaSack.Participants select participant.DisplayValue();
+ SantaSackSerializer.Serialize(santaSack);
}
private void btnCancel_Click(object sender, RoutedEventArgs e)
@@ -206,16 +215,19 @@ private void btnRemove_Click(object sender, RoutedEventArgs e)
lstParticipants.ItemsSource = null;
lstParticipants.ItemsSource = from participant in santaSack.Participants select participant.DisplayValue();
}
+ SantaSackSerializer.Serialize(santaSack);
}
private void btnGo_Click(object sender, RoutedEventArgs e)
{
+ SantaSackSerializer.Serialize(santaSack);
+
if (santaSack.Participants.Count < 3)
{
MessageBox.Show("You Haven't Got Enough People!");
return;
}
-
+
if (string.IsNullOrWhiteSpace(santaSack.Template.FromAddress))
{
MessageBox.Show("You Haven't Entered A From Address!");
@@ -267,7 +279,7 @@ private void btnGo_Click(object sender, RoutedEventArgs e)
var participantsToPair = (from p in santaSack.Participants select p).ToList();
var participantsToAssign = (from p in santaSack.Participants select p).ToList();
var participantsToSend = new List();
- var randomGenerator = new Random();
+ var randomGenerator = new Random((int)DateTime.UtcNow.Ticks);
while (participantsToPair.Count > 0)
{
@@ -318,31 +330,58 @@ private void btnGo_Click(object sender, RoutedEventArgs e)
}
- foreach (var pairedParticipant in participantsToSend)
+ while (participantsToSend.Any(x => x.Sent == false))
{
- var message = new MailMessage();
- message.From = new MailAddress(santaSack.Template.FromAddress);
- message.To.Add(new MailAddress(pairedParticipant.EmailAddress));
- message.Subject = santaSack.Template.Subject;
- message.Body = santaSack.Template.Content
- .Replace("{{GiftFromName}}", pairedParticipant.Name)
- .Replace("{{GiftFromEmail}}", pairedParticipant.EmailAddress)
- .Replace("{{GiftForName}}", pairedParticipant.PairedWith.Name)
- .Replace("{{GiftForEmail}}", pairedParticipant.PairedWith.EmailAddress);
- var client = new SmtpClient();
- client.Host = santaSack.Template.Host;
- int port;
- if (!int.TryParse(santaSack.Template.Port, out port))
+ if(participantsToSend.Any(x=>x.SendAttempts > 5))
+ {
+ foreach (var tooManyAttemptParticipant in participantsToSend.Where(x=>x.SendAttempts>5))
+ {
+ MessageBox.Show(
+ string.Format("Couldn't Send Email To {0}, They Drew {1}",
+ tooManyAttemptParticipant.EmailAddress,
+ tooManyAttemptParticipant.PairedWith.EmailAddress), "Couldn't Send",
+ MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
+ }
+ }
+
+ foreach (var pairedParticipant in participantsToSend.Where(x => x.Sent == false))
{
- port = 25;
+ var message = new MailMessage();
+ message.From = new MailAddress(santaSack.Template.FromAddress);
+ message.To.Add(!string.IsNullOrWhiteSpace(santaSack.Template.DiagnosticDeliveryAddress)
+ ? new MailAddress(santaSack.Template.DiagnosticDeliveryAddress)
+ : new MailAddress(pairedParticipant.EmailAddress));
+
+ message.Subject = santaSack.Template.Subject;
+ message.Body = santaSack.Template.Content
+ .Replace("{{GiftFromName}}", pairedParticipant.Name)
+ .Replace("{{GiftFromEmail}}", pairedParticipant.EmailAddress)
+ .Replace("{{GiftForName}}", pairedParticipant.PairedWith.Name)
+ .Replace("{{GiftForEmail}}", pairedParticipant.PairedWith.EmailAddress);
+ var client = new SmtpClient();
+ client.Host = santaSack.Template.Host;
+ int port;
+ if (!int.TryParse(santaSack.Template.Port, out port))
+ {
+ port = 25;
+ }
+ client.Port = port;
+ try
+ {
+ client.Send(message);
+ pairedParticipant.Sent = true;
+ }
+ catch (Exception)
+ {
+ pairedParticipant.Sent = false;
+ pairedParticipant.SendAttempts++;
+ }
}
- client.Port = port;
- client.Send(message);
}
MessageBox.Show("All Emails Have Been Sent!");
}
-
+
private void btnSendDetails_Click(object sender, RoutedEventArgs e)
{
var sendDetails = new SendDetails(ref santaSack);
@@ -353,5 +392,10 @@ private void Window_Closed(object sender, EventArgs e)
{
SantaSackSerializer.Serialize(santaSack);
}
+
+ private void Window_Loaded(object sender, RoutedEventArgs e)
+ {
+
+ }
}
}
diff --git a/SecretSantaHelper/PairedParticipant.cs b/SecretSantaHelper/PairedParticipant.cs
index 9b7d26d..606fa95 100644
--- a/SecretSantaHelper/PairedParticipant.cs
+++ b/SecretSantaHelper/PairedParticipant.cs
@@ -8,5 +8,7 @@ namespace SecretSantaHelper
public class PairedParticipant : Participant
{
public Participant PairedWith { get; set; }
+ public bool Sent { get; set; }
+ public int SendAttempts { get; set; }
}
}
diff --git a/SecretSantaHelper/Properties/AssemblyInfo.cs b/SecretSantaHelper/Properties/AssemblyInfo.cs
index 7eb9c78..51b03ee 100644
--- a/SecretSantaHelper/Properties/AssemblyInfo.cs
+++ b/SecretSantaHelper/Properties/AssemblyInfo.cs
@@ -51,5 +51,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("0.0.2.0")]
-[assembly: AssemblyFileVersion("0.0.2.0")]
+[assembly: AssemblyVersion("0.0.3.0")]
+[assembly: AssemblyFileVersion("0.0.3.0")]
diff --git a/SecretSantaHelper/SecretSantaHelper.suo b/SecretSantaHelper/SecretSantaHelper.suo
index 2d16f59..fd7c597 100644
Binary files a/SecretSantaHelper/SecretSantaHelper.suo and b/SecretSantaHelper/SecretSantaHelper.suo differ
diff --git a/SecretSantaHelper/SendDetails.xaml b/SecretSantaHelper/SendDetails.xaml
index f58e56e..2356d49 100644
--- a/SecretSantaHelper/SendDetails.xaml
+++ b/SecretSantaHelper/SendDetails.xaml
@@ -1,19 +1,25 @@
-
+ Title="Secret Santa Helper Template Editor" Height="425" Width="409" Closed="Window_Closed" Icon="/SecretSantaHelper;component/santa.ico" WindowStyle="SingleBorderWindow">
+
+
+
+
+
-
-
-
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
diff --git a/SecretSantaHelper/SendDetails.xaml.cs b/SecretSantaHelper/SendDetails.xaml.cs
index 9ae548b..c9b4476 100644
--- a/SecretSantaHelper/SendDetails.xaml.cs
+++ b/SecretSantaHelper/SendDetails.xaml.cs
@@ -7,17 +7,18 @@ namespace SecretSantaHelper
///
public partial class SendDetails : Window
{
- private readonly SantaSack templateDetails;
+ private readonly SantaSack santaSack;
- public SendDetails(ref SantaSack templateDetails)
+ public SendDetails(ref SantaSack santaSack)
{
- this.templateDetails = templateDetails;
+ this.santaSack = santaSack;
InitializeComponent();
- txtSMTP.Text = templateDetails.Template.Host;
- txtPort.Text = templateDetails.Template.Port;
- txtFrom.Text = templateDetails.Template.FromAddress;
- txtSubject.Text = templateDetails.Template.Subject;
- txtContent.Text = templateDetails.Template.Content;
+ txtSMTP.Text = santaSack.Template.Host;
+ txtPort.Text = santaSack.Template.Port;
+ txtFrom.Text = santaSack.Template.FromAddress;
+ txtSubject.Text = santaSack.Template.Subject;
+ txtContent.Text = santaSack.Template.Content;
+ txtDiagnostic.Text = santaSack.Template.DiagnosticDeliveryAddress;
btnDone.IsEnabled = true;
}
@@ -35,16 +36,22 @@ private void btnDone_Click(object sender, RoutedEventArgs e)
MessageBox.Show("That is an invalid from email address!");
return;
}
+ if (!string.IsNullOrWhiteSpace(txtDiagnostic.Text) && !emailHelper.IsValidEmail(txtDiagnostic.Text))
+ {
+ MessageBox.Show("That is an invalid diagnostic email address!");
+ return;
+ }
Close();
}
private void Window_Closed(object sender, System.EventArgs e)
{
- templateDetails.Template.Host = txtSMTP.Text;
- templateDetails.Template.Port = txtPort.Text;
- templateDetails.Template.FromAddress = txtFrom.Text;
- templateDetails.Template.Subject = txtSubject.Text;
- templateDetails.Template.Content = txtContent.Text;
+ santaSack.Template.Host = txtSMTP.Text;
+ santaSack.Template.Port = txtPort.Text;
+ santaSack.Template.FromAddress = txtFrom.Text;
+ santaSack.Template.Subject = txtSubject.Text;
+ santaSack.Template.Content = txtContent.Text;
+ santaSack.Template.DiagnosticDeliveryAddress = txtDiagnostic.Text;
}
}
}
diff --git a/SecretSantaHelper/Template.cs b/SecretSantaHelper/Template.cs
index 9e65610..86dcf1c 100644
--- a/SecretSantaHelper/Template.cs
+++ b/SecretSantaHelper/Template.cs
@@ -11,6 +11,7 @@ public class Template
public string Host { get; set; }
public string Port { get; set; }
public string FromAddress { get; set; }
+ public string DiagnosticDeliveryAddress { get; set; }
public string Subject { get; set; }
public string Content { get; set; }
@@ -21,6 +22,7 @@ public Template()
FromAddress = string.Empty;
Subject = string.Empty;
Content = string.Empty;
+ DiagnosticDeliveryAddress = string.Empty;
}
}
}