diff --git a/Basic/Types/Structure/BasicGeographyUpdate.cs b/Basic/Types/Structure/BasicGeographyUpdate.cs index 9ed3f05f..3ce04f0a 100644 --- a/Basic/Types/Structure/BasicGeographyUpdate.cs +++ b/Basic/Types/Structure/BasicGeographyUpdate.cs @@ -4,11 +4,12 @@ using System.Collections.Specialized; using System.Linq; using System.Reflection.Emit; using System.Text; +using Swarmops.Basic.Interfaces; namespace Swarmops.Basic.Types.Structure { [Serializable] - public class BasicGeographyUpdate + public class BasicGeographyUpdate: IHasIdentity { [Obsolete ("Do not call this ctor directly. It is intended for serialization.", true)] public BasicGeographyUpdate() @@ -37,7 +38,7 @@ namespace Swarmops.Basic.Types.Structure original.CountryCode, original.ChangeDataXml, original.CreatedDateTime, original.EffectiveDateTime, original.Processed) { - + // copy ctor - empty } @@ -50,5 +51,7 @@ namespace Swarmops.Basic.Types.Structure public DateTime CreatedDateTime { get; private set; } public DateTime EffectiveDateTime { get; private set; } public bool Processed { get; protected set; } + + public int Identity { get { return GeographyUpdateId; } } } } diff --git a/Database/Database-GeographyUpdates.cs b/Database/Database-GeographyUpdates.cs index 19c6539b..ffd91782 100644 --- a/Database/Database-GeographyUpdates.cs +++ b/Database/Database-GeographyUpdates.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Data; using System.Data.Common; +using System.Globalization; using Swarmops.Basic.Enums; using Swarmops.Basic.Types; using Swarmops.Basic.Types.Structure; @@ -42,6 +43,33 @@ namespace Swarmops.Database #endregion + + public BasicGeographyUpdate GetGeographyUpdate(int identity) + { + using (DbConnection connection = GetMySqlDbConnection()) + { + connection.Open(); + + DbCommand command = + GetDbCommand( + "SELECT " + geographyUpdateFieldSequence + " WHERE GeographyUpdateId=" + identity.ToString(CultureInfo.InvariantCulture), connection); + + using (DbDataReader reader = command.ExecuteReader()) + { + if (reader.Read()) + { + return ReadGeographyUpdateFromDataReader(reader); + } + + throw new ArgumentException ("No such GeographyUpdate: " + + identity.ToString (CultureInfo.InvariantCulture)); + } + } + } + + + + public BasicGeographyUpdate[] GetAllGeographyUpdates() { List result = new List(); diff --git a/Logic/Logic.csproj b/Logic/Logic.csproj index f63d8617..69ec7784 100644 --- a/Logic/Logic.csproj +++ b/Logic/Logic.csproj @@ -236,6 +236,8 @@ + + diff --git a/Logic/Structure/GeographyUpdate.cs b/Logic/Structure/GeographyUpdate.cs new file mode 100644 index 00000000..95b55075 --- /dev/null +++ b/Logic/Structure/GeographyUpdate.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.CompilerServices; +using System.Text; +using System.Threading.Tasks; +using Swarmops.Basic.Types.Structure; +using Swarmops.Database; + +namespace Swarmops.Logic.Structure +{ + [Serializable] + public class GeographyUpdate : BasicGeographyUpdate + { + [Obsolete("Do not call this ctor directly. It is intended for serialization use only.", true)] + public GeographyUpdate() + { + + } + + private GeographyUpdate (BasicGeographyUpdate basic) + : base (basic) + { + // private ctor + } + + public static GeographyUpdate FromBasic(BasicGeographyUpdate basic) + { + return new GeographyUpdate(basic); + } + + public Country Country + { + get + { + if (string.IsNullOrEmpty (base.CountryCode)) + { + return null; + } + + return Country.FromCode (base.CountryCode); + } + } + + public static GeographyUpdate Create (string updateType, string updateSource, string guid, string countryCode, string changeDataXml, DateTime effectiveDateTime) + { + int identity = SwarmDb.GetDatabaseForWriting() + .CreateGeographyUpdate (updateType, updateSource, guid, countryCode, changeDataXml, DateTime.UtcNow, + effectiveDateTime); + return FromBasic (SwarmDb.GetDatabaseForWriting().GetGeographyUpdate (identity)); // "ForWriting" intentional to avoid db replication race conditions + } + + } +} diff --git a/Logic/Structure/GeographyUpdates.cs b/Logic/Structure/GeographyUpdates.cs new file mode 100644 index 00000000..d0d45439 --- /dev/null +++ b/Logic/Structure/GeographyUpdates.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Swarmops.Basic.Types.Structure; +using Swarmops.Database; +using Swarmops.Logic.Support; + +namespace Swarmops.Logic.Structure +{ + public class GeographyUpdates:PluralBase + { + static public GeographyUpdates GetUnprocessed() + { + return FromArray (SwarmDb.GetDatabaseForReading().GetUnprocessedGeographyUpdates()); + } + + static public GeographyUpdates GetCreatedSince (DateTime dateTimeSince) + { + return FromArray (SwarmDb.GetDatabaseForReading().GetGeographyUpdatesSince (dateTimeSince)); + } + } +}