Work checkpoint

This commit is contained in:
Rick Falkvinge
2017-01-03 17:48:49 +01:00
parent 480b84c3af
commit 38d8c29065
9 changed files with 113 additions and 22 deletions
+61 -12
View File
@@ -4,6 +4,8 @@ using Swarmops.Logic.Communications.Payload;
using Swarmops.Logic.Communications.Resolution;
using Swarmops.Utility.Communications;
using System.Reflection;
using Swarmops.Logic.Structure;
using Swarmops.Logic.Swarm;
namespace Swarmops.Backend
{
@@ -17,21 +19,29 @@ namespace Swarmops.Backend
{
if (!comm.Resolved)
{
// Resolve recipients
ResolverEnvelope resolverEnvelope = ResolverEnvelope.FromXml(comm.ResolverDataXml);
// Create the resolver via reflection of the static FromXml method
Assembly assembly = typeof(ResolverEnvelope).Assembly;
Type payloadType = assembly.GetType(resolverEnvelope.ResolverClass);
var methodInfo = payloadType.GetMethod("FromXml", BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy);
ICommsResolver resolver = (ICommsResolver)(methodInfo.Invoke(null, new object[] { resolverEnvelope.ResolverDataXml }));
ICommsResolver resolver = FindResolver(comm);
resolver.Resolve(comm);
comm.Resolved = true;
if (comm.Recipients.Count > 1)
{
// "Your message has been queued for delivery and the recipients have been resolved.
// Your mail will be sent to, or be attempted to sent to, [RecipientCount] people in [Geography] in [OrganizationName]."
NotificationStrings notifyStrings = new NotificationStrings();
NotificationCustomStrings customStrings = new NotificationCustomStrings();
notifyStrings[NotificationString.OrganizationName] = Organization.FromIdentity(comm.OrganizationId).Name;
customStrings["RecipientCount"] = comm.Recipients.Count.ToString("N0");
if (resolver is IHasGeography)
{
customStrings["GeographyName"] = ((IHasGeography) resolver).Geography.Name;
}
OutboundComm.CreateNotification(Organization.FromIdentity(comm.OrganizationId),
NotificationResource.OutboundComm_Resolved, notifyStrings,
People.FromSingle(Person.FromIdentity(comm.SenderPersonId)));
}
continue; // continue is not strictly necessary; could continue processing the same OutboundComm after resolution
}
@@ -61,7 +71,46 @@ namespace Swarmops.Backend
}
comm.Open = false;
if (comm.RecipientsFail + comm.RecipientsSuccess > 1)
{
ICommsResolver resolver = FindResolver(comm);
// "Your message to[GeographyName] has been sent to all scheduled recipients.Of the[RecipientCount] planned recipients, [RecipientsSuccess] succeeded
// from Swarmops' horizon. (These can fail later for a number of reasons, from broken computers to hospitalized recipients.)
// Time spent transmitting: [TransmissionTime]."
// TODO: CONTINUE HERE
NotificationStrings notifyStrings = new NotificationStrings();
NotificationCustomStrings customStrings = new NotificationCustomStrings();
notifyStrings[NotificationString.OrganizationName] = Organization.FromIdentity(comm.OrganizationId).Name;
customStrings["RecipientCount"] = comm.Recipients.Count.ToString("N0");
if (resolver is IHasGeography)
{
customStrings["Geography"] = ((IHasGeography)resolver).Geography.Name;
}
OutboundComm.CreateNotification(Organization.FromIdentity(comm.OrganizationId),
NotificationResource.OutboundComm_Resolved, notifyStrings,
People.FromSingle(Person.FromIdentity(comm.SenderPersonId)));
}
}
}
internal static ICommsResolver FindResolver(OutboundComm comm)
{
// Resolve recipients
ResolverEnvelope resolverEnvelope = ResolverEnvelope.FromXml(comm.ResolverDataXml);
// Create the resolver via reflection of the static FromXml method
Assembly assembly = typeof(ResolverEnvelope).Assembly;
Type payloadType = assembly.GetType(resolverEnvelope.ResolverClass);
var methodInfo = payloadType.GetMethod("FromXml", BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy);
return (ICommsResolver)(methodInfo.Invoke(null, new object[] { resolverEnvelope.ResolverDataXml }));
}
}
}
@@ -29,7 +29,7 @@ namespace Swarmops.Basic.Types.Communications
ClosedDateTime = closedDateTime;
RecipientCount = recipientCount;
RecipientsSuccess = recipientsSuccess;
RecipeintsFail = recipientsFail;
RecipientsFail = recipientsFail;
}
@@ -39,7 +39,7 @@ namespace Swarmops.Basic.Types.Communications
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)
original.RecipientsSuccess, original.RecipientsFail)
{
// copy ctor
}
@@ -62,7 +62,7 @@ namespace Swarmops.Basic.Types.Communications
public DateTime ClosedDateTime { get; protected set; }
public int RecipientCount { get; protected set; }
public int RecipientsSuccess { get; protected set; }
public int RecipeintsFail { get; protected set; }
public int RecipientsFail { get; protected set; }
#region Implementation of IHasIdentity
+17 -2
View File
@@ -142,7 +142,7 @@ namespace Swarmops.Logic.Communications
List<Person> recipients = People.FromSingle (participation.Person);
OutboundComm comm = OutboundComm.Create (null, null, participation.Organization,
null, null,
null /* resolver */, null /*recipientdata*/,
CommTransmitterClass.CommsTransmitterMail,
new PayloadEnvelope (new ParticipantMailPayload (mailType, participation, actingPerson)).ToXml(),
OutboundCommPriority.Low);
@@ -158,6 +158,21 @@ namespace Swarmops.Logic.Communications
}
public static OutboundComm CreateParticipantMail(string customSubject, string customBody, Person sender, Person from,
Organization organization, Geography geography)
{
ParticipantResolver resolver = new ParticipantResolver(organization, geography);
OutboundComm comm = OutboundComm.Create (sender, from, organization,
resolver, null /*recipientdata*/,
CommTransmitterClass.CommsTransmitterMail,
new PayloadEnvelope(new ParticipantMailPayload(customSubject, customBody, organization, sender)).ToXml(),
OutboundCommPriority.Low);
return comm;
}
public static OutboundComm CreateParticipantMail(string customSubject, string customBody, Participation participation,
Person actingPerson)
{
@@ -234,7 +249,7 @@ namespace Swarmops.Logic.Communications
if (organization != null)
{
strings[NotificationString.OrganizationName] = organization.Name; // since we're sending the org anyway, kind of pointless to require callers to set this
strings[NotificationString.OrganizationName] = organization.Name;
//strings[NotificationString.OrganizationMailPrefix] = organization.MailPrefix; // TODO
// TODO: Change to org admins
@@ -192,7 +192,9 @@ namespace Swarmops.Logic.Communications.Payload
BitcoinPayoutAddress_Changed,
Salary_MonthlyStatement,
Salary_Paid,
Salary_LastYearSummary
Salary_LastYearSummary,
OutboundComm_Resolved,
OutboundComm_Sent
}
// ReSharper restore InconsistentNaming
@@ -6,6 +6,7 @@ using System.Text;
using System.Threading.Tasks;
//using Swarmops.Basic.Types.Common;
using Swarmops.Logic.Security;
using Swarmops.Logic.Structure;
using Swarmops.Logic.Swarm;
using Swarmops.Logic.Support;
@@ -64,6 +65,18 @@ namespace Swarmops.Logic.Communications.Payload
}
public ParticipantMailPayload(string customSubject, string customBody, Organization organization,
Person actingPerson)
{
Strings = new SerializableDictionary<MailPayloadString, string>();
SubjectTemplate = customSubject;
BodyTemplate = customBody;
Strings[MailPayloadString.ActingPerson] = actingPerson.Name;
Strings[MailPayloadString.OrganizationName] = organization.Name;
}
public RenderedComm RenderComm (Person person)
{
string body = BodyTemplate;
@@ -6,11 +6,12 @@ using System.Threading.Tasks;
using Swarmops.Logic.Support;
using Swarmops.Logic.Swarm;
using Swarmops.Logic.Structure;
using System.Xml.Serialization;
namespace Swarmops.Logic.Communications.Resolution
{
[Serializable]
public class ParticipantResolver: PayloadBase<ParticipantResolver>, ICommsResolver
public class ParticipantResolver: PayloadBase<ParticipantResolver>, ICommsResolver, IHasGeography
{
[Obsolete("The parameterless ctor is provided for serializability and must not be called directly.", true)]
public ParticipantResolver()
@@ -18,6 +19,13 @@ namespace Swarmops.Logic.Communications.Resolution
// Required for serialization. Never call directly.
}
public ParticipantResolver(Organization organization, Geography geography, bool includeSuborganizations = true)
{
this.IncludeSuborganizations = includeSuborganizations;
this.GeographyId = geography.Identity;
this.OrganizationId = organization.Identity;
}
public void Resolve(OutboundComm comm)
{
Organization organization = Organization.FromIdentity (OrganizationId);
@@ -36,5 +44,8 @@ namespace Swarmops.Logic.Communications.Resolution
public bool IncludeSuborganizations { get; set; }
public int OrganizationId { get; set; }
public int GeographyId { get; set; }
[XmlIgnore]
public Geography Geography { get { return Geography.FromIdentity(this.GeographyId); } }
}
}
+1
View File
@@ -112,6 +112,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Communications\IHasGeography.cs" />
<Compile Include="Communications\Resolution\ParticipantResolver.cs" />
<Compile Include="Communications\Resolution\ResolverEnvelope.cs" />
<Compile Include="Financial\BitcoinTransactionInput.cs" />
@@ -1,7 +1,7 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.34209
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
@@ -554,7 +554,7 @@ namespace Swarmops.Logic.Resources {
}
/// <summary>
/// Looks up a localized string similar to Your message has been queued for delivery and the recipients have been resolved. Your mail will be sent to, or be attempted to sent to, [RecipientCount] people in [Geography] in [OrganizationName]..
/// Looks up a localized string similar to Your message has been queued for delivery and the recipients have been resolved. Your mail will be sent to, or be attempted to sent to, [RecipientCount] people in [GeographyName] in [OrganizationName]..
/// </summary>
internal static string OutboundComm_Resolved_Body {
get {
@@ -320,7 +320,7 @@ Please log on to [InstallationName] at [ExternalUrl]Financial/AttestCosts to att
This mail was sent to [Addressee] from [OrganizationName]. If you do not desire to receive these notifications in the future, please log on to [InstallationName] at [ExternalUrl] and modify your notification settings.</value>
</data>
<data name="OutboundComm_Resolved_Body" xml:space="preserve">
<value>Your message has been queued for delivery and the recipients have been resolved. Your mail will be sent to, or be attempted to sent to, [RecipientCount] people in [Geography] in [OrganizationName].</value>
<value>Your message has been queued for delivery and the recipients have been resolved. Your mail will be sent to, or be attempted to sent to, [RecipientCount] people in [GeographyName] in [OrganizationName].</value>
</data>
<data name="OutboundComm_Resolved_Subject" xml:space="preserve">
<value>[[OrganizationName]] Comm recipients determined for [GeographyName]: [RecipientCount]</value>