Working on mail resolution, part 1
This commit is contained in:
@@ -7,7 +7,7 @@ namespace Swarmops.Basic.Types.Communications
|
||||
public class BasicOutboundComm : IHasIdentity
|
||||
{
|
||||
public BasicOutboundComm (int outboundCommId, int senderPersonId, int fromPersonId, int organizationId,
|
||||
DateTime createdDateTime, string resolverClass, string recipientDataXml, bool resolved,
|
||||
DateTime createdDateTime, string resolverDataXml, string recipientDataXml, bool resolved,
|
||||
DateTime resolvedDateTime, OutboundCommPriority priority, string transmitterClass, string payloadXml,
|
||||
bool open, DateTime startTransmitDateTime, DateTime closedDateTime, int recipientCount,
|
||||
int recipientsSuccess, int recipientsFail)
|
||||
@@ -17,7 +17,7 @@ namespace Swarmops.Basic.Types.Communications
|
||||
FromPersonId = fromPersonId;
|
||||
OrganizationId = organizationId;
|
||||
CreatedDateTime = createdDateTime;
|
||||
ResolverClass = resolverClass;
|
||||
ResolverDataXml = resolverDataXml;
|
||||
RecipientDataXml = recipientDataXml;
|
||||
Resolved = resolved;
|
||||
ResolvedDateTime = resolvedDateTime;
|
||||
@@ -36,7 +36,7 @@ namespace Swarmops.Basic.Types.Communications
|
||||
public BasicOutboundComm (BasicOutboundComm original) :
|
||||
this (
|
||||
original.OutboundCommId, original.SenderPersonId, original.FromPersonId, original.OrganizationId,
|
||||
original.CreatedDateTime, original.ResolverClass, original.RecipientDataXml, original.Resolved,
|
||||
original.CreatedDateTime, original.ResolverDataXml, original.RecipientDataXml, original.Resolved,
|
||||
original.ResolvedDateTime, original.Priority, original.TransmitterClass, original.PayloadXml,
|
||||
original.Open, original.StartTransmitDateTime, original.ClosedDateTime, original.RecipientCount,
|
||||
original.RecipientsSuccess, original.RecipeintsFail)
|
||||
@@ -50,7 +50,7 @@ namespace Swarmops.Basic.Types.Communications
|
||||
public int FromPersonId { get; private set; }
|
||||
public int OrganizationId { get; private set; }
|
||||
public DateTime CreatedDateTime { get; private set; }
|
||||
public string ResolverClass { get; private set; }
|
||||
public string ResolverDataXml { get; private set; }
|
||||
public string RecipientDataXml { get; private set; }
|
||||
public bool Resolved { get; protected set; }
|
||||
public DateTime ResolvedDateTime { get; protected set; }
|
||||
|
||||
@@ -2,5 +2,6 @@
|
||||
{
|
||||
public interface ICommsResolver
|
||||
{
|
||||
string ToXml(); // implemented by PayloadBase
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ using Swarmops.Basic.Types.Communications;
|
||||
using Swarmops.Common.Enums;
|
||||
using Swarmops.Database;
|
||||
using Swarmops.Logic.Communications.Transmission;
|
||||
using Swarmops.Logic.Communications.Resolution;
|
||||
using Swarmops.Logic.Financial;
|
||||
using Swarmops.Logic.Structure;
|
||||
using Swarmops.Logic.Swarm;
|
||||
@@ -73,13 +74,13 @@ namespace Swarmops.Logic.Communications
|
||||
}
|
||||
|
||||
public static OutboundComm Create (Person sender, Person from, Organization organization,
|
||||
CommResolverClass resolverClass, string recipientDataXml, CommTransmitterClass transmitterClass,
|
||||
ICommsResolver resolver, string recipientDataXml, CommTransmitterClass transmitterClass,
|
||||
string payloadXml, OutboundCommPriority priority)
|
||||
{
|
||||
string resolverClassString = string.Empty;
|
||||
if (resolverClass != CommResolverClass.Unknown)
|
||||
string resolverDataXml = string.Empty;
|
||||
if (resolver != null)
|
||||
{
|
||||
resolverClassString = resolverClass.ToString();
|
||||
resolverDataXml = new ResolverEnvelope(resolver).ToXml();
|
||||
}
|
||||
|
||||
string transmitterClassString = string.Empty;
|
||||
@@ -88,17 +89,17 @@ namespace Swarmops.Logic.Communications
|
||||
transmitterClassString = "Swarmops.Utility.Communications." + transmitterClass;
|
||||
}
|
||||
|
||||
return Create (sender, from, organization, resolverClassString, recipientDataXml, transmitterClassString,
|
||||
return Create (sender, from, organization, resolverDataXml, recipientDataXml, transmitterClassString,
|
||||
payloadXml, priority);
|
||||
}
|
||||
|
||||
public static OutboundComm Create (Person sender, Person from, Organization organization,
|
||||
string resolverClassString, string recipientDataXml, string transmitterClassString, string payloadXml,
|
||||
private static OutboundComm Create (Person sender, Person from, Organization organization,
|
||||
string resolverDataXml, 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,
|
||||
organization != null ? organization.Identity : 0, resolverDataXml,
|
||||
recipientDataXml ?? string.Empty, transmitterClassString,
|
||||
payloadXml, priority);
|
||||
|
||||
@@ -141,7 +142,7 @@ namespace Swarmops.Logic.Communications
|
||||
List<Person> recipients = People.FromSingle (participation.Person);
|
||||
|
||||
OutboundComm comm = OutboundComm.Create (null, null, participation.Organization,
|
||||
CommResolverClass.Unknown, null,
|
||||
null, null,
|
||||
CommTransmitterClass.CommsTransmitterMail,
|
||||
new PayloadEnvelope (new ParticipantMailPayload (mailType, participation, actingPerson)).ToXml(),
|
||||
OutboundCommPriority.Low);
|
||||
@@ -163,7 +164,7 @@ namespace Swarmops.Logic.Communications
|
||||
List<Person> recipients = People.FromSingle(participation.Person);
|
||||
|
||||
OutboundComm comm = OutboundComm.Create(null, null, participation.Organization,
|
||||
CommResolverClass.Unknown, null,
|
||||
null /* resolver */, null,
|
||||
CommTransmitterClass.CommsTransmitterMail,
|
||||
new PayloadEnvelope(new ParticipantMailPayload(customSubject, customBody, participation, actingPerson)).ToXml(),
|
||||
OutboundCommPriority.Low);
|
||||
@@ -215,7 +216,7 @@ namespace Swarmops.Logic.Communications
|
||||
// TODO: Change to org admins
|
||||
}
|
||||
|
||||
OutboundComm comm = OutboundComm.Create (null, null, organization, CommResolverClass.Unknown, null,
|
||||
OutboundComm comm = OutboundComm.Create (null, null, organization, null, null,
|
||||
CommTransmitterClass.CommsTransmitterMail,
|
||||
new PayloadEnvelope (new NotificationPayload (notificationResourceString, strings, customStrings)).ToXml(),
|
||||
OutboundCommPriority.Low);
|
||||
@@ -248,7 +249,7 @@ namespace Swarmops.Logic.Communications
|
||||
payload.Strings[NotificationString.BudgetName] = budget.Name;
|
||||
payload.Strings[NotificationString.ConcernedPersonName] = concernedPerson.Canonical;
|
||||
|
||||
OutboundComm comm = OutboundComm.Create (null, null, budget.Organization, CommResolverClass.Unknown, null,
|
||||
OutboundComm comm = OutboundComm.Create (null, null, budget.Organization, null, null,
|
||||
CommTransmitterClass.CommsTransmitterMail,
|
||||
new PayloadEnvelope (payload).ToXml(),
|
||||
OutboundCommPriority.Low);
|
||||
@@ -278,7 +279,7 @@ namespace Swarmops.Logic.Communications
|
||||
payload.Strings[NotificationString.BudgetAmountFloat] =
|
||||
amountRequested.ToString("N2");
|
||||
|
||||
OutboundComm comm = OutboundComm.Create (null, null, organization, CommResolverClass.Unknown, null,
|
||||
OutboundComm comm = OutboundComm.Create (null, null, organization, null, null,
|
||||
CommTransmitterClass.CommsTransmitterMail,
|
||||
new PayloadEnvelope (payload).ToXml(),
|
||||
OutboundCommPriority.Low);
|
||||
@@ -309,7 +310,7 @@ namespace Swarmops.Logic.Communications
|
||||
payload.Strings[NotificationString.ConcernedPersonName] = concernedPerson.Canonical;
|
||||
payload.Strings[NotificationString.EmbeddedPreformattedText] = reasonGiven;
|
||||
|
||||
OutboundComm comm = OutboundComm.Create (null, null, budget.Organization, CommResolverClass.Unknown, null,
|
||||
OutboundComm comm = OutboundComm.Create (null, null, budget.Organization, null, null,
|
||||
CommTransmitterClass.CommsTransmitterMail,
|
||||
new PayloadEnvelope (payload).ToXml(),
|
||||
OutboundCommPriority.Low);
|
||||
@@ -325,7 +326,7 @@ namespace Swarmops.Logic.Communications
|
||||
private static OutboundComm CreateSingleRecipientNotification (NotificationPayload payload,
|
||||
Organization organization, Person addressee)
|
||||
{
|
||||
OutboundComm comm = OutboundComm.Create(null, null, organization, CommResolverClass.Unknown, null,
|
||||
OutboundComm comm = OutboundComm.Create(null, null, organization, null, null,
|
||||
CommTransmitterClass.CommsTransmitterMail, new PayloadEnvelope(payload).ToXml(),
|
||||
OutboundCommPriority.Low);
|
||||
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Swarmops.Logic.Support;
|
||||
using Swarmops.Logic.Communications.Transmission;
|
||||
|
||||
namespace Swarmops.Logic.Communications.Resolution
|
||||
{
|
||||
[Serializable]
|
||||
public class ResolverEnvelope : PayloadBase<ResolverEnvelope>
|
||||
{
|
||||
public ResolverEnvelope()
|
||||
{
|
||||
// default public ctor for serializability
|
||||
}
|
||||
|
||||
public ResolverEnvelope (ICommsResolver resolver)
|
||||
{
|
||||
PayloadClass = resolver.GetType().ToString();
|
||||
PayloadXml = resolver.ToXml();
|
||||
}
|
||||
|
||||
public string PayloadClass { get; set; }
|
||||
public string PayloadXml { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -5,9 +5,10 @@ using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using MySql.Data.MySqlClient.Properties;
|
||||
using Swarmops.Basic.Types.Common;
|
||||
//using Swarmops.Basic.Types.Common;
|
||||
using Swarmops.Logic.Security;
|
||||
using Swarmops.Logic.Swarm;
|
||||
using Swarmops.Logic.Support;
|
||||
|
||||
namespace Swarmops.Logic.Communications.Transmission
|
||||
{
|
||||
|
||||
+3
-1
@@ -118,6 +118,7 @@
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Communications\Resolution\ResolverEnvelope.cs" />
|
||||
<Compile Include="Financial\BitcoinTransactionInput.cs" />
|
||||
<Compile Include="Financial\BitcoinUtility.cs" />
|
||||
<Compile Include="Financial\HotBitcoinAddress.cs" />
|
||||
@@ -190,7 +191,7 @@
|
||||
<Compile Include="Communications\Transmission\ParticipantMailPayload.cs" />
|
||||
<Compile Include="Communications\Transmission\PayloadEnvelope.cs" />
|
||||
<Compile Include="Communications\Transmission\NotificationPayload.cs" />
|
||||
<Compile Include="Communications\Transmission\PayloadBase.cs" />
|
||||
<Compile Include="Support\PayloadBase.cs" />
|
||||
<Compile Include="Financial\BankDataReaders\SEPaymentsBankgiroReader.cs" />
|
||||
<Compile Include="Financial\Currencies.cs" />
|
||||
<Compile Include="Financial\ExchangeRateSnapshot.cs" />
|
||||
@@ -725,6 +726,7 @@
|
||||
<None Include="app.config" />
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
|
||||
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
|
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||
|
||||
@@ -1,53 +1,53 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Xml.Serialization;
|
||||
using Swarmops.Logic.Support;
|
||||
|
||||
namespace Swarmops.Logic.Communications.Transmission
|
||||
{
|
||||
[Serializable]
|
||||
public class PayloadBase<T> : IXmlPayload
|
||||
{
|
||||
public string ToXml()
|
||||
{
|
||||
XmlSerializer serializer = new XmlSerializer (typeof (T));
|
||||
|
||||
MemoryStream stream = new MemoryStream();
|
||||
serializer.Serialize (stream, this);
|
||||
|
||||
byte[] xmlBytes = stream.GetBuffer();
|
||||
string xml = Encoding.UTF8.GetString (xmlBytes);
|
||||
|
||||
xml = xml.Replace("�", "");
|
||||
xml = xml.Replace("\x00", "");
|
||||
|
||||
return xml;
|
||||
}
|
||||
|
||||
public static T FromXml (string xml)
|
||||
{
|
||||
// Compensate for stupid Mono encoding bugs
|
||||
|
||||
if (xml.StartsWith ("?"))
|
||||
{
|
||||
xml = xml.Substring (1);
|
||||
}
|
||||
|
||||
xml = xml.Replace ("�", "");
|
||||
xml = xml.Replace ("\x00", "");
|
||||
|
||||
XmlSerializer serializer = new XmlSerializer (typeof (T));
|
||||
|
||||
MemoryStream stream = new MemoryStream();
|
||||
byte[] xmlBytes = Encoding.UTF8.GetBytes (xml);
|
||||
stream.Write (xmlBytes, 0, xmlBytes.Length);
|
||||
|
||||
stream.Position = 0;
|
||||
T result = (T) serializer.Deserialize (stream);
|
||||
stream.Close();
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Xml.Serialization;
|
||||
using Swarmops.Logic.Support;
|
||||
|
||||
namespace Swarmops.Logic.Support
|
||||
{
|
||||
[Serializable]
|
||||
public class PayloadBase<T> : IXmlPayload
|
||||
{
|
||||
public string ToXml()
|
||||
{
|
||||
XmlSerializer serializer = new XmlSerializer (typeof (T));
|
||||
|
||||
MemoryStream stream = new MemoryStream();
|
||||
serializer.Serialize (stream, this);
|
||||
|
||||
byte[] xmlBytes = stream.GetBuffer();
|
||||
string xml = Encoding.UTF8.GetString (xmlBytes);
|
||||
|
||||
xml = xml.Replace("�", "");
|
||||
xml = xml.Replace("\x00", "");
|
||||
|
||||
return xml;
|
||||
}
|
||||
|
||||
public static T FromXml (string xml)
|
||||
{
|
||||
// Compensate for stupid Mono encoding bugs
|
||||
|
||||
if (xml.StartsWith ("?"))
|
||||
{
|
||||
xml = xml.Substring (1);
|
||||
}
|
||||
|
||||
xml = xml.Replace ("�", "");
|
||||
xml = xml.Replace ("\x00", "");
|
||||
|
||||
XmlSerializer serializer = new XmlSerializer (typeof (T));
|
||||
|
||||
MemoryStream stream = new MemoryStream();
|
||||
byte[] xmlBytes = Encoding.UTF8.GetBytes (xml);
|
||||
stream.Write (xmlBytes, 0, xmlBytes.Length);
|
||||
|
||||
stream.Position = 0;
|
||||
T result = (T) serializer.Deserialize (stream);
|
||||
stream.Close();
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user