Added CommsTransmitterMail
This commit is contained in:
@@ -11,15 +11,15 @@ namespace Swarmops.Logic.Communications
|
||||
/// </summary>
|
||||
public interface ICommsRenderer
|
||||
{
|
||||
RenderedComms RenderComm(OutboundComm comm, Person person);
|
||||
RenderedComm RenderComm(Person person);
|
||||
}
|
||||
|
||||
public class RenderedComms: Dictionary<CommsRenderPart,string>
|
||||
public class RenderedComm: Dictionary<CommRenderPart,string>
|
||||
{
|
||||
// typeset for readability
|
||||
}
|
||||
|
||||
public enum CommsRenderPart
|
||||
public enum CommRenderPart
|
||||
{
|
||||
Unknown = 0,
|
||||
SenderName,
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Swarmops.Logic.Communications.Transmission;
|
||||
using Swarmops.Logic.Swarm;
|
||||
|
||||
namespace Swarmops.Logic.Communications
|
||||
@@ -13,6 +14,6 @@ namespace Swarmops.Logic.Communications
|
||||
/// </summary>
|
||||
/// <param name="comm">The piece of communications to send.</param>
|
||||
/// <param name="person">The person to send to.</param>
|
||||
void Transmit(OutboundComm comm, Person person);
|
||||
void Transmit(PayloadEnvelope envelope, Person person);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,14 +62,14 @@ namespace Swarmops.Logic.Communications.Transmission
|
||||
|
||||
#region Implementation of ICommsRenderer
|
||||
|
||||
public RenderedComms RenderComm(OutboundComm comm, Person person)
|
||||
public RenderedComm RenderComm(Person person)
|
||||
{
|
||||
RenderedComms result = new RenderedComms();
|
||||
RenderedComm result = new RenderedComm();
|
||||
|
||||
result[CommsRenderPart.Subject] = GetSubject();
|
||||
result[CommsRenderPart.BodyText] = GetBody();
|
||||
result[CommsRenderPart.SenderName] = "Swarmops Administrative";
|
||||
result[CommsRenderPart.SenderMail] = "admin@swarmops.com";
|
||||
result[CommRenderPart.Subject] = GetSubject();
|
||||
result[CommRenderPart.BodyText] = GetBody();
|
||||
result[CommRenderPart.SenderName] = "Swarmops Administrative";
|
||||
result[CommRenderPart.SenderMail] = "admin@swarmops.com";
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace Swarmops.Logic.Communications.Transmission
|
||||
return Encoding.Default.GetString(xmlBytes);
|
||||
}
|
||||
|
||||
static T FromXml (string xml)
|
||||
public static T FromXml (string xml)
|
||||
{
|
||||
var serializer = new XmlSerializer(typeof(T));
|
||||
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Mail;
|
||||
using System.Text;
|
||||
using Swarmops.Logic.Communications;
|
||||
using Swarmops.Logic.Communications.Transmission;
|
||||
using Swarmops.Logic.Swarm;
|
||||
|
||||
namespace Swarmops.Utility.Communications
|
||||
@@ -11,9 +13,39 @@ namespace Swarmops.Utility.Communications
|
||||
{
|
||||
// To be implemented
|
||||
|
||||
public void Transmit(OutboundComm comm, Person person)
|
||||
public void Transmit(PayloadEnvelope envelope, Person person)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
if (envelope.PayloadClass != "Swarmops.Logic.Communications.Transmission.NotificationPayload")
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
ICommsRenderer renderer = NotificationPayload.FromXml(envelope.PayloadXml);
|
||||
|
||||
RenderedComm comm = renderer.RenderComm(person);
|
||||
|
||||
MailMessage mail = new MailMessage();
|
||||
|
||||
// This is a rather simple mail (no images or stuff like that)
|
||||
|
||||
mail.From = new MailAddress(comm[CommRenderPart.SenderMail], comm[CommRenderPart.SenderMail], Encoding.UTF8);
|
||||
mail.To.Add(new MailAddress(person.Email, person.Name));
|
||||
|
||||
mail.Subject = comm[CommRenderPart.Subject];
|
||||
mail.Body = comm[CommRenderPart.Subject];
|
||||
mail.SubjectEncoding = Encoding.UTF8;
|
||||
mail.BodyEncoding = Encoding.UTF8;
|
||||
|
||||
SmtpClient mailClient = new SmtpClient("192.168.80.204"); // Fix this - for development use only
|
||||
|
||||
try
|
||||
{
|
||||
mailClient.Send(mail);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new OutboundCommTransmitException("Cannot send mail to " + person.Email, e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user