Moved mail transmission to backend's actual loop. Fingers crossed...
This commit is contained in:
@@ -64,6 +64,7 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="CommsTransmitter.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Swarmops.Logic.Communications;
|
||||
using Swarmops.Logic.Communications.Transmission;
|
||||
|
||||
namespace Swarmops.Backend
|
||||
{
|
||||
internal class CommsTransmitter
|
||||
{
|
||||
static internal void Run()
|
||||
{
|
||||
OutboundComms comms = OutboundComms.GetOpen();
|
||||
|
||||
foreach (OutboundComm comm in comms)
|
||||
{
|
||||
// TODO: RESOLVE RECIPIENTS
|
||||
|
||||
if (!comm.Resolved)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (comm.TransmitterClass != "Swarmops.Utility.Communications.CommsTransmitterMail")
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
ICommsTransmitter transmitter = new Swarmops.Utility.Communications.CommsTransmitterMail();
|
||||
|
||||
OutboundCommRecipients recipients = comm.Recipients;
|
||||
PayloadEnvelope envelope = PayloadEnvelope.FromXml(comm.PayloadXml);
|
||||
|
||||
comm.StartTransmission();
|
||||
|
||||
foreach (OutboundCommRecipient recipient in recipients)
|
||||
{
|
||||
try
|
||||
{
|
||||
transmitter.Transmit(envelope, recipient.Person);
|
||||
recipient.CloseSuccess();
|
||||
}
|
||||
catch (OutboundCommTransmitException e)
|
||||
{
|
||||
recipient.CloseFailed(e.Description);
|
||||
}
|
||||
}
|
||||
|
||||
comm.Open = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -271,6 +271,8 @@ namespace Swarmops.Backend
|
||||
{
|
||||
BotLog.Write(0, "MainCycle", "Ten-second entry");
|
||||
|
||||
CommsTransmitter.Run();
|
||||
|
||||
try
|
||||
{
|
||||
/*TestTrace("Running EventProcessor.Run()...");
|
||||
|
||||
@@ -157,6 +157,40 @@ namespace Swarmops.Database
|
||||
}
|
||||
}
|
||||
|
||||
public void SetOutboundCommRecipientClosed (int outboundCommRecipientId)
|
||||
{
|
||||
using (DbConnection connection = GetMySqlDbConnection())
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
DbCommand command = GetDbCommand("SetOutboundCommRecipientClosed", connection);
|
||||
command.CommandType = CommandType.StoredProcedure;
|
||||
|
||||
AddParameterWithName(command, "outboundCommRecipientId", outboundCommRecipientId);
|
||||
AddParameterWithName(command, "dateTime", DateTime.UtcNow);
|
||||
|
||||
command.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
|
||||
public int SetOutboundCommRecipientFailed(int outboundCommRecipientId, string failReason)
|
||||
{
|
||||
using (DbConnection connection = GetMySqlDbConnection())
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
DbCommand command = GetDbCommand("SetOutboundCommRecipientFailed", connection);
|
||||
command.CommandType = CommandType.StoredProcedure;
|
||||
|
||||
AddParameterWithName(command, "outboundCommId", outboundCommRecipientId);
|
||||
AddParameterWithName(command, "dateTime", DateTime.UtcNow);
|
||||
AddParameterWithName(command, "failReason", failReason);
|
||||
|
||||
|
||||
return Convert.ToInt32(command.ExecuteScalar());
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
@@ -241,6 +241,38 @@ namespace Swarmops.Database
|
||||
}
|
||||
}
|
||||
|
||||
public void SetOutboundCommTransmissionStart(int outboundCommId)
|
||||
{
|
||||
using (DbConnection connection = GetMySqlDbConnection())
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
DbCommand command = GetDbCommand("SetOutboundCommTransmissionStart", connection);
|
||||
command.CommandType = CommandType.StoredProcedure;
|
||||
|
||||
AddParameterWithName(command, "outboundCommId", outboundCommId);
|
||||
AddParameterWithName(command, "dateTime", DateTime.UtcNow);
|
||||
|
||||
command.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
|
||||
public void SetOutboundCommClosed(int outboundCommId)
|
||||
{
|
||||
using (DbConnection connection = GetMySqlDbConnection())
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
DbCommand command = GetDbCommand("SetOutboundCommClosed", connection);
|
||||
command.CommandType = CommandType.StoredProcedure;
|
||||
|
||||
AddParameterWithName(command, "outboundCommId", outboundCommId);
|
||||
AddParameterWithName(command, "dateTime", DateTime.UtcNow);
|
||||
|
||||
command.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
@@ -128,6 +128,28 @@ namespace Swarmops.Logic.Communications
|
||||
get { return OutboundCommRecipients.ForOutboundComm(this); }
|
||||
}
|
||||
|
||||
public new bool Open
|
||||
{
|
||||
get { return base.Open; }
|
||||
set
|
||||
{
|
||||
if (base.Open && value == false)
|
||||
{
|
||||
SwarmDb.GetDatabaseForWriting().SetOutboundCommClosed(this.Identity);
|
||||
base.Open = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InvalidOperationException("Can only change OutboundComms.Open from true to false");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void StartTransmission()
|
||||
{
|
||||
SwarmDb.GetDatabaseForWriting().SetOutboundCommTransmissionStart(this.Identity);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public enum CommResolverClass
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Swarmops.Basic.Types.Communications;
|
||||
using Swarmops.Database;
|
||||
using Swarmops.Logic.Swarm;
|
||||
|
||||
namespace Swarmops.Logic.Communications
|
||||
@@ -24,6 +25,22 @@ namespace Swarmops.Logic.Communications
|
||||
get { return Person.FromIdentity(base.PersonId); }
|
||||
}
|
||||
|
||||
public void CloseSuccess()
|
||||
{
|
||||
SwarmDb.GetDatabaseForWriting().SetOutboundCommRecipientClosed(this.Identity);
|
||||
|
||||
base.Success = true;
|
||||
base.Open = false;
|
||||
}
|
||||
|
||||
public void CloseFailed(string failReason)
|
||||
{
|
||||
SwarmDb.GetDatabaseForWriting().SetOutboundCommRecipientFailed(this.Identity, failReason);
|
||||
|
||||
base.Success = false;
|
||||
base.Open = false;
|
||||
}
|
||||
|
||||
// TODO: CloseSuccess, CloseFail
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user