diff --git a/Basic/Basic.csproj b/Basic/Basic.csproj index 4eea85df..0e5f686d 100644 --- a/Basic/Basic.csproj +++ b/Basic/Basic.csproj @@ -56,7 +56,10 @@ + + + diff --git a/Basic/Enums/OutboundCommPriority.cs b/Basic/Enums/OutboundCommPriority.cs new file mode 100644 index 00000000..6a8a3dad --- /dev/null +++ b/Basic/Enums/OutboundCommPriority.cs @@ -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, + /// + /// Priority 1 of 7 (highest). + /// + Highest = 32, + /// + /// Priority 2 of 7 (second highest). + /// + High = 64, + /// + /// Priority 3 of 7 (just above normal priority). + /// + Elevated = 96, + /// + /// Priority 4 of 7 (normal and default). + /// + Normal = 128, + /// + /// Priority 5 of 7 (just below normal priority). + /// + Lowered = 160, + /// + /// Priority 6 of 7 (second lowest). + /// + Low = 192, + /// + /// Priority 7 of 7 (lowest). + /// + Lowest = 224 + } +} diff --git a/Basic/Types/Communications/BasicOutboundComm.cs b/Basic/Types/Communications/BasicOutboundComm.cs new file mode 100644 index 00000000..1ab7aff0 --- /dev/null +++ b/Basic/Types/Communications/BasicOutboundComm.cs @@ -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 + } +} diff --git a/Basic/Types/Communications/BasicOutboundCommRecipient.cs b/Basic/Types/Communications/BasicOutboundCommRecipient.cs new file mode 100644 index 00000000..06a0a6d9 --- /dev/null +++ b/Basic/Types/Communications/BasicOutboundCommRecipient.cs @@ -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 + } +} diff --git a/Database/Database-Constructors.cs b/Database/Database-Constructors.cs index bd41e4d0..38f2df6e 100644 --- a/Database/Database-Constructors.cs +++ b/Database/Database-Constructors.cs @@ -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)]