diff --git a/Database/Database-OutboundCommRecipients.cs b/Database/Database-OutboundCommRecipients.cs index 622c47db..f5abbf6b 100644 --- a/Database/Database-OutboundCommRecipients.cs +++ b/Database/Database-OutboundCommRecipients.cs @@ -141,7 +141,7 @@ namespace Swarmops.Database #region Creation and manipulation -- stored procedures - public int CreateOutboundCommRecipient(int senderPersonId, int fromPersonId, int organizationId, string resolverClass, string recipientDataXml, string transmitterClass, string payloadXml, OutboundCommPriority priority) + public int CreateOutboundCommRecipient(int outboundCommId, int personId) { using (DbConnection connection = GetMySqlDbConnection()) { @@ -150,8 +150,8 @@ namespace Swarmops.Database DbCommand command = GetDbCommand("CreateOutboundCommRecipient", connection); command.CommandType = CommandType.StoredProcedure; - AddParameterWithName(command, "outboundCommId", senderPersonId); - AddParameterWithName(command, "personId", fromPersonId); + AddParameterWithName(command, "outboundCommId", outboundCommId); + AddParameterWithName(command, "personId", personId); return Convert.ToInt32(command.ExecuteScalar()); } diff --git a/Logic/Communications/ICommsRenderer.cs b/Logic/Communications/ICommsRenderer.cs index 7baaf806..8b3e0f4d 100644 --- a/Logic/Communications/ICommsRenderer.cs +++ b/Logic/Communications/ICommsRenderer.cs @@ -25,6 +25,8 @@ namespace Swarmops.Logic.Communications SenderName, SenderMail, Subject, - Body + BodyText, + BodyHtml, + BodyImages } } diff --git a/Logic/Communications/OutboundComm.cs b/Logic/Communications/OutboundComm.cs index c5a687df..ac259aef 100644 --- a/Logic/Communications/OutboundComm.cs +++ b/Logic/Communications/OutboundComm.cs @@ -2,8 +2,10 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using Swarmops.Basic.Enums; using Swarmops.Basic.Types.Communications; using Swarmops.Database; +using Swarmops.Logic.Communications.Transmission; using Swarmops.Logic.Structure; using Swarmops.Logic.Swarm; @@ -21,32 +23,101 @@ namespace Swarmops.Logic.Communications return new OutboundComm(basic); } - public static OutboundComm FromIdentity (int outboundCommId) + public static OutboundComm FromIdentity(int outboundCommId) { return FromBasic(SwarmDb.GetDatabaseForReading().GetOutboundComm(outboundCommId)); } - public static OutboundComm Create(Person sender, Person from, Organization organization) + public static OutboundComm FromIdentityAggressive(int outboundCommId) { - return null; + return FromBasic(SwarmDb.GetDatabaseForWriting().GetOutboundComm(outboundCommId)); + } + + public static OutboundComm Create(Person sender, Person from, Organization organization, CommResolverClass resolverClass, string recipientDataXml, CommTransmitterClass transmitterClass, string payloadXml, OutboundCommPriority priority) + { + string resolverClassString = string.Empty; + if (resolverClass != CommResolverClass.Unknown) + { + resolverClassString = resolverClass.ToString(); + } + + string transmitterClassString = string.Empty; + if (transmitterClass != CommTransmitterClass.Unknown) + { + transmitterClassString = "Swarmops.Utility.Communications." + transmitterClass.ToString(); + } + + return Create(sender, from, organization, resolverClassString, recipientDataXml, transmitterClassString, + payloadXml, priority); + } + + public static OutboundComm Create(Person sender, Person from, Organization organization, string resolverClassString, string recipientDataXml, string transmitterClassString, string payloadXml, OutboundCommPriority priority) + { + int newId = SwarmDb.GetDatabaseForWriting().CreateOutboundComm(sender != null? sender.Identity: 0, from != null? from.Identity: 0, + organization != null? organization.Identity: 0, resolverClassString, + recipientDataXml ?? string.Empty, transmitterClassString, + payloadXml, priority); + + return FromIdentityAggressive(newId); } + public static OutboundComm CreateNotification (Organization organization, NotificationResource notification) + { + return CreateNotification(organization, notification.ToString()); + } + public static OutboundComm CreateNotification (Organization organization, string notificationResourceString) + { + List recipients = People.FromSingle(Person.FromIdentity(1)); // Initial Admin recipient + + if (organization != null) + { + // TODO: Change to org admins + } + + OutboundComm comm = OutboundComm.Create(null, null, organization, CommResolverClass.Unknown, null, + CommTransmitterClass.CommsTransmitterMail, + new NotificationPayload(notificationResourceString).ToXml(), + OutboundCommPriority.Low); + + foreach (Person person in recipients) + { + comm.AddRecipient(person); + } + + comm.Resolved = true; + + return comm; + } + + // public static OutboundComm CreateNotification (FinancialAccount budget, string notificationResource) + + + + public void AddRecipient (Person person) + { + if (person == null) + { + throw new ArgumentNullException("Recipient cannot be null."); + } + + SwarmDb.GetDatabaseForWriting().CreateOutboundCommRecipient(this.Identity, person.Identity); + } } - public enum CommResolverClasses + public enum CommResolverClass { Unknown = 0, Test_Foo_Bar } - public enum CommTransmitterClasses + public enum CommTransmitterClass { Unknown = 0, - + CommsTransmitterMail } } diff --git a/Logic/Communications/Transmission/NotificationPayload.cs b/Logic/Communications/Transmission/NotificationPayload.cs index bd08759d..a3612006 100644 --- a/Logic/Communications/Transmission/NotificationPayload.cs +++ b/Logic/Communications/Transmission/NotificationPayload.cs @@ -4,11 +4,12 @@ using System.Linq; using System.Resources; using System.Text; using System.Globalization; +using Swarmops.Logic.Swarm; namespace Swarmops.Logic.Communications.Transmission { [Serializable] - public class NotificationPayload: PayloadBase + public class NotificationPayload: PayloadBase, ICommsRenderer { public NotificationPayload() { @@ -45,5 +46,31 @@ namespace Swarmops.Logic.Communications.Transmission return resourceManager.GetString(this.BodyResource); } + + #region Implementation of ICommsRenderer + + public RenderedComms RenderComm(OutboundComm comm, Person person) + { + RenderedComms result = new RenderedComms(); + + result[CommsRenderPart.Subject] = GetSubject(); + result[CommsRenderPart.BodyText] = GetBody(); + result[CommsRenderPart.SenderName] = "Swarmops Administrative"; + result[CommsRenderPart.SenderMail] = "admin@swarmops.com"; + + return result; + } + + #endregion } + +// ReSharper disable InconsistentNaming + + public enum NotificationResource + { + Unknown = 0, + System_Startup + } + +// ReSharper restore InconsistentNaming }