Checking in types for BasicOutboundComms / -Recipients

This commit is contained in:
Rick Falkvinge
2013-06-10 20:32:42 +00:00
parent cafb5e924c
commit f15425920a
5 changed files with 154 additions and 118 deletions
+3
View File
@@ -56,7 +56,10 @@
<Compile Include="Enums\CommunicationType.cs" />
<Compile Include="Enums\ExternalActivityType.cs" />
<Compile Include="Enums\OrganizationFinancialAccountType.cs" />
<Compile Include="Enums\OutboundCommPriority.cs" />
<Compile Include="Types\BasicBallot.cs" />
<Compile Include="Types\Communications\BasicOutboundComm.cs" />
<Compile Include="Types\Communications\BasicOutboundCommRecipient.cs" />
<Compile Include="Types\Financial\BasicCashAdvance.cs" />
<Compile Include="Types\BasicCommunicationTurnaround.cs" />
<Compile Include="Types\BasicElection.cs" />
+40
View File
@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Swarmops.Basic.Enums
{
public enum OutboundCommPriority
{
Unknown = 0,
/// <summary>
/// Priority 1 of 7 (highest).
/// </summary>
Highest = 32,
/// <summary>
/// Priority 2 of 7 (second highest).
/// </summary>
High = 64,
/// <summary>
/// Priority 3 of 7 (just above normal priority).
/// </summary>
Elevated = 96,
/// <summary>
/// Priority 4 of 7 (normal and default).
/// </summary>
Normal = 128,
/// <summary>
/// Priority 5 of 7 (just below normal priority).
/// </summary>
Lowered = 160,
/// <summary>
/// Priority 6 of 7 (second lowest).
/// </summary>
Low = 192,
/// <summary>
/// Priority 7 of 7 (lowest).
/// </summary>
Lowest = 224
}
}
@@ -0,0 +1,73 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Swarmops.Basic.Enums;
using Swarmops.Basic.Interfaces;
namespace Swarmops.Basic.Types.Communications
{
public class BasicOutboundComm: IHasIdentity
{
public BasicOutboundComm (int outboundCommId, int senderPersonId, int organizationId, DateTime createdDateTime, string resolverClass, string recipientDataXml, bool resolved, DateTime resolvedDateTime, OutboundCommPriority priority, string transmitterClass, string payloadXml,
bool open, DateTime startTransmitDateTime, DateTime closedDateTime, int recipientCount, int recipientsSuccess, int recipientsFail)
{
this.OutboundCommId = outboundCommId;
this.SenderPersonId = senderPersonId; // should we include a "fromPersonId" in basedata too, when deputies are sending on behalf of avatars?
this.OrganizationId = organizationId;
this.CreatedDateTime = createdDateTime;
this.ResolverClass = resolverClass;
this.RecipientDataXml = recipientDataXml;
this.Resolved = resolved;
this.ResolvedDateTime = resolvedDateTime;
this.Priority = priority;
this.TransmitterClass = transmitterClass;
this.PayloadXml = payloadXml;
this.Open = open;
this.StartTransmitDateTime = startTransmitDateTime;
this.ClosedDateTime = closedDateTime;
this.RecipientCount = recipientCount;
this.RecipientsSuccess = recipientsSuccess;
this.RecipeintsFail = recipientsFail;
}
public BasicOutboundComm (BasicOutboundComm original) :
this (original.OutboundCommId, original.SenderPersonId, original.OrganizationId, original.CreatedDateTime, original.ResolverClass, original.RecipientDataXml, original.Resolved, original.ResolvedDateTime, original.Priority, original.TransmitterClass, original.PayloadXml,
original.Open, original.StartTransmitDateTime, original.ClosedDateTime, original.RecipientCount, original.RecipientsSuccess, original.RecipeintsFail)
{
// copy ctor
}
public int OutboundCommId { get; private set; }
public int SenderPersonId { get; private set; }
public int OrganizationId { get; private set; }
public DateTime CreatedDateTime { get; private set; }
public string ResolverClass { get; private set; }
public string RecipientDataXml { get; private set; }
public bool Resolved { get; protected set; }
public DateTime ResolvedDateTime { get; protected set; }
public OutboundCommPriority Priority { get; private set; }
public string TransmitterClass { get; private set; }
public string PayloadXml { get; private set; }
public bool Open { get; protected set; }
public DateTime StartTransmitDateTime { get; protected set; }
public DateTime ClosedDateTime { get; protected set; }
public int RecipientCount { get; protected set; }
public int RecipientsSuccess { get; protected set; }
public int RecipeintsFail { get; protected set; }
#region Implementation of IHasIdentity
public int Identity
{
get { return this.OutboundCommId; }
}
#endregion
}
}
@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Swarmops.Basic.Interfaces;
namespace Swarmops.Basic.Types.Communications
{
public class BasicOutboundCommRecipient: IHasIdentity
{
public BasicOutboundCommRecipient (int outboundCommRecipientId, int outboundCommId, int personId, bool open, bool success, string failReason)
{
this.OutboundCommRecipientId = outboundCommRecipientId;
this.OutboundCommId = outboundCommId;
this.PersonId = personId;
this.Open = open;
this.Success = success;
this.FailReason = failReason;
}
public int OutboundCommRecipientId { get; private set; }
public int OutboundCommId { get; private set; }
public int PersonId { get; private set; }
public bool Open { get; protected set; }
public bool Success { get; protected set; }
public string FailReason { get; protected set; }
#region Implementation of IHasIdentity
public int Identity
{
get { return this.OutboundCommRecipientId; }
}
#endregion
}
}
+1 -118
View File
@@ -40,124 +40,7 @@ namespace Swarmops.Database
[Obsolete ("Do not use. Use SwarmDb.GetDatabaseForReading(), ...ForWriting() or ...ForAdmin().", true)]
public static SwarmDb GetDatabase()
{
Console.WriteLine("Entering GetDatabase()");
// First, check if a previous invocation has put anything in the cashe.
string connectionString = _cachedConnectionString;
// During a cacheless invocation, the app/web config has priority.
if (connectionString == null && ConfigurationManager.ConnectionStrings["Activizr"] != null)
{
Console.WriteLine("Initing from ConfigManager");
connectionString = ConfigurationManager.ConnectionStrings["Activizr"].ConnectionString;
Logging.LogInformation(LogSource.PirateDb,
"SwarmDb initialized from Config ConnectionString: [" + connectionString +
"]");
}
// If the app/web config is empty, check the database config file on disk
if (connectionString == null)
{
Console.WriteLine("Point 2");
try
{
if (Path.DirectorySeparatorChar == '/' && HttpContext.Current == null)
{
Console.WriteLine("Attempting to initialize using MonoConfigFile, which is " + MonoConfigFile);
// We are running under mono in a backend environment
using (StreamReader reader = new StreamReader(MonoConfigFile))
{
connectionString = reader.ReadLine();
Logging.LogInformation(LogSource.PirateDb,
"SwarmDb initialized for Linux: [" + connectionString + "]");
}
}
else if (HttpContext.Current != null)
{
Console.WriteLine("Point 3");
// We are running a web application, under Mono (production) or Windows (development)
using (StreamReader reader = new StreamReader(HttpContext.Current.Server.MapPath(WebConfigFile))
)
{
connectionString = reader.ReadLine();
Logging.LogInformation(LogSource.PirateDb,
"SwarmDb initialized for web: [" + connectionString + "]");
}
}
else
{
Console.WriteLine("Point 4");
// We are running an application, presumably directly from Visual Studio.
// If so, the current working directory is "PirateWeb/30/Console/bin".
using (StreamReader reader = new StreamReader(AppConfigFile))
{
connectionString = reader.ReadLine();
Logging.LogInformation(LogSource.PirateDb,
"SwarmDb initialized for application: [" + connectionString +
"]");
}
}
}
catch (Exception)
{
Logging.LogWarning(LogSource.PirateDb, "Unable to read Database.Config - defaulting");
// Ignore if we can't read the Database.config
}
// To simplify future checks
if (connectionString != null && connectionString.Length == 0)
{
connectionString = null;
}
}
// If we still have nothing, and we're running from web, then assume we have a dev environment and use the hostname as db, user, and pass.
if (connectionString == null)
{
Console.WriteLine("Point 5");
if (HttpContext.Current != null)
{
string hostName = HttpContext.Current.Request.Url.Host;
connectionString = "server=peregrine;database=" + hostName + ";user=" + hostName + ";password=" + hostName; // TODO: Replace "peregrine" with "localhost"
}
else
{
throw new InvalidOperationException("No database connection string found -- write a connect string on one line into a file named database.config; see connectionstrings.com for examples"); // TODO: Replace with custom exception to present config screen
}
}
// Now write the correct data to the cache, for faster lookup next time.
if (_cachedConnectionString == null)
{
_cachedConnectionString = connectionString;
}
SwarmDb db = null;
try
{
db = new SwarmDb(DbProviderFactories.GetFactory(DefaultProviderName), connectionString);
}
catch (Exception e)
{
throw new Exception(
"Unable to initalize SwarmDb using connection string \"" + connectionString + "\"", e); // TODO: REMOVE ON PRODUCTION -- CREDENTIALS LEAKAGE
}
return db;
throw new NotImplementedException("GetDatabase() is obsolete and has been deleted.");
}
[Obsolete ("Do not use. Use GetDatabaseForAdmin().", true)]