Ready for testing creating first OutboundComm
This commit is contained in:
@@ -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());
|
||||
}
|
||||
|
||||
@@ -25,6 +25,8 @@ namespace Swarmops.Logic.Communications
|
||||
SenderName,
|
||||
SenderMail,
|
||||
Subject,
|
||||
Body
|
||||
BodyText,
|
||||
BodyHtml,
|
||||
BodyImages
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<Person> 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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<NotificationPayload>
|
||||
public class NotificationPayload: PayloadBase<NotificationPayload>, 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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user