From 59c06c28ee5edee006a72c941079b9a87a75dd9e Mon Sep 17 00:00:00 2001 From: Rick Falkvinge Date: Wed, 12 Jun 2013 23:27:45 +0000 Subject: [PATCH] Committing work at EOD --- Database/Database-OutboundComms.cs | 5 +-- Logic/Communications/ICommsRenderer.cs | 30 ++++++++++++++++ Logic/Communications/ICommsResolver.cs | 11 ++++++ Logic/Communications/ICommsTransmitter.cs | 18 ++++++++++ Logic/Communications/OutboundComm.cs | 36 +++++++++++++++++++ .../OutboundCommTransmitException.cs | 25 +++++++++++++ Logic/Communications/Transmission/IPayload.cs | 12 +++++++ .../Transmission/MailMetaPayload.cs | 14 ++++++++ .../Transmission/PayloadBase.cs | 2 +- Logic/Logic.csproj | 6 ++++ .../Communications/CommsTransmitterMail.cs | 20 +++++++++++ Utility/Utility.csproj | 2 +- 12 files changed, 177 insertions(+), 4 deletions(-) create mode 100644 Logic/Communications/ICommsRenderer.cs create mode 100644 Logic/Communications/ICommsResolver.cs create mode 100644 Logic/Communications/ICommsTransmitter.cs create mode 100644 Logic/Communications/OutboundCommTransmitException.cs create mode 100644 Logic/Communications/Transmission/IPayload.cs create mode 100644 Logic/Communications/Transmission/MailMetaPayload.cs create mode 100644 Utility/Communications/CommsTransmitterMail.cs diff --git a/Database/Database-OutboundComms.cs b/Database/Database-OutboundComms.cs index 1057fd31..f86a3246 100644 --- a/Database/Database-OutboundComms.cs +++ b/Database/Database-OutboundComms.cs @@ -214,11 +214,12 @@ namespace Swarmops.Database AddParameterWithName(command, "senderPersonId", senderPersonId); AddParameterWithName(command, "fromPersonId", fromPersonId); AddParameterWithName(command, "organizationId", organizationId); - AddParameterWithName(command, "resolverClass", resolverClass); // Will be turned into ID by stored procedure - AddParameterWithName(command, "recipientDataXml", recipientDataXml); + AddParameterWithName(command, "resolverClass", String.IsNullOrEmpty(resolverClass)? "0": resolverClass); // Will be turned into ID by stored procedure + AddParameterWithName(command, "recipientDataXml", String.IsNullOrEmpty(recipientDataXml)? string.Empty: recipientDataXml); AddParameterWithName(command, "transmitterClass", transmitterClass); // Will be turned into ID by stored procedure AddParameterWithName(command, "payloadXml", payloadXml); AddParameterWithName(command, "priority", (int) priority); // convert enum to integerized priority; convert back on field read + AddParameterWithName(command, "createdDateTime", DateTime.UtcNow); return Convert.ToInt32(command.ExecuteScalar()); } diff --git a/Logic/Communications/ICommsRenderer.cs b/Logic/Communications/ICommsRenderer.cs new file mode 100644 index 00000000..7baaf806 --- /dev/null +++ b/Logic/Communications/ICommsRenderer.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Swarmops.Logic.Swarm; + +namespace Swarmops.Logic.Communications +{ + /// + /// Renders an OutboundComm for one specific type of comm and for the target person. + /// + public interface ICommsRenderer + { + RenderedComms RenderComm(OutboundComm comm, Person person); + } + + public class RenderedComms: Dictionary + { + // typeset for readability + } + + public enum CommsRenderPart + { + Unknown = 0, + SenderName, + SenderMail, + Subject, + Body + } +} diff --git a/Logic/Communications/ICommsResolver.cs b/Logic/Communications/ICommsResolver.cs new file mode 100644 index 00000000..c0269f41 --- /dev/null +++ b/Logic/Communications/ICommsResolver.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Swarmops.Logic.Communications +{ + public interface ICommsResolver + { + } +} diff --git a/Logic/Communications/ICommsTransmitter.cs b/Logic/Communications/ICommsTransmitter.cs new file mode 100644 index 00000000..7c1747ec --- /dev/null +++ b/Logic/Communications/ICommsTransmitter.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Swarmops.Logic.Swarm; + +namespace Swarmops.Logic.Communications +{ + public interface ICommsTransmitter + { + /// + /// This function transmits an outbound comm. If it fails, it must throw an OutboundCommTransmitException. It is expected to block until complete. + /// + /// The piece of communications to send. + /// The person to send to. + void Transmit(OutboundComm comm, Person person); + } +} diff --git a/Logic/Communications/OutboundComm.cs b/Logic/Communications/OutboundComm.cs index 0b843a32..c5a687df 100644 --- a/Logic/Communications/OutboundComm.cs +++ b/Logic/Communications/OutboundComm.cs @@ -3,6 +3,9 @@ using System.Collections.Generic; using System.Linq; using System.Text; using Swarmops.Basic.Types.Communications; +using Swarmops.Database; +using Swarmops.Logic.Structure; +using Swarmops.Logic.Swarm; namespace Swarmops.Logic.Communications { @@ -12,5 +15,38 @@ namespace Swarmops.Logic.Communications { // private ctor } + + public static OutboundComm FromBasic (BasicOutboundComm basic) + { + return new OutboundComm(basic); + } + + public static OutboundComm FromIdentity (int outboundCommId) + { + return FromBasic(SwarmDb.GetDatabaseForReading().GetOutboundComm(outboundCommId)); + } + + public static OutboundComm Create(Person sender, Person from, Organization organization) + { + return null; + } + + + + + + } + + public enum CommResolverClasses + { + Unknown = 0, + Test_Foo_Bar + + } + + public enum CommTransmitterClasses + { + Unknown = 0, + } } diff --git a/Logic/Communications/OutboundCommTransmitException.cs b/Logic/Communications/OutboundCommTransmitException.cs new file mode 100644 index 00000000..eabb9819 --- /dev/null +++ b/Logic/Communications/OutboundCommTransmitException.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Swarmops.Logic.Communications +{ + /// + /// This exception is thrown if transmission of an OutboundComm fails (for a specific person). The description should NOT contain personal data or anything that varies with person/time. + /// + public class OutboundCommTransmitException: Exception + { + public OutboundCommTransmitException (string description) : base (description) + { + Description = description; + } + + public OutboundCommTransmitException (string description, Exception innerException): base (description, innerException) + { + Description = description; + } + + public string Description { get; set; } + } +} diff --git a/Logic/Communications/Transmission/IPayload.cs b/Logic/Communications/Transmission/IPayload.cs new file mode 100644 index 00000000..9366b3e1 --- /dev/null +++ b/Logic/Communications/Transmission/IPayload.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Swarmops.Logic.Communications.Transmission +{ + public interface IPayload + { + string ToXml(); + } +} diff --git a/Logic/Communications/Transmission/MailMetaPayload.cs b/Logic/Communications/Transmission/MailMetaPayload.cs new file mode 100644 index 00000000..0c176f07 --- /dev/null +++ b/Logic/Communications/Transmission/MailMetaPayload.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Swarmops.Logic.Communications.Transmission +{ + [Serializable] + public class MailMetaPayload: PayloadBase + { + public string PayloadClass { get; set; } + public string PayloadXml { get; set; } + } +} diff --git a/Logic/Communications/Transmission/PayloadBase.cs b/Logic/Communications/Transmission/PayloadBase.cs index 4886653e..a9a362e4 100644 --- a/Logic/Communications/Transmission/PayloadBase.cs +++ b/Logic/Communications/Transmission/PayloadBase.cs @@ -8,7 +8,7 @@ using System.Xml.Serialization; namespace Swarmops.Logic.Communications.Transmission { [Serializable] - public class PayloadBase + public class PayloadBase: IPayload { public string ToXml() { diff --git a/Logic/Logic.csproj b/Logic/Logic.csproj index e42ab197..732a8573 100644 --- a/Logic/Logic.csproj +++ b/Logic/Logic.csproj @@ -64,10 +64,16 @@ + + + + + + diff --git a/Utility/Communications/CommsTransmitterMail.cs b/Utility/Communications/CommsTransmitterMail.cs new file mode 100644 index 00000000..d1228a4c --- /dev/null +++ b/Utility/Communications/CommsTransmitterMail.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Swarmops.Logic.Communications; +using Swarmops.Logic.Swarm; + +namespace Swarmops.Utility.Communications +{ + public class CommsTransmitterMail: ICommsTransmitter + { + // To be implemented + + public void Transmit(OutboundComm comm, Person person) + { + throw new NotImplementedException(); + } + + } +} diff --git a/Utility/Utility.csproj b/Utility/Utility.csproj index 428e36fd..1d4fa86c 100644 --- a/Utility/Utility.csproj +++ b/Utility/Utility.csproj @@ -95,6 +95,7 @@ + @@ -145,7 +146,6 @@ -