Higher-level GeographyUpdates added

This commit is contained in:
Rick Falkvinge
2014-12-22 15:54:10 +01:00
parent dd1896140c
commit 4792cc9f5a
5 changed files with 113 additions and 2 deletions
@@ -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; } }
}
}
+28
View File
@@ -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<BasicGeographyUpdate> result = new List<BasicGeographyUpdate>();
+2
View File
@@ -236,6 +236,8 @@
<Compile Include="Governance\MotionAmendment.cs" />
<Compile Include="Governance\MotionAmendments.cs" />
<Compile Include="Governance\Motions.cs" />
<Compile Include="Structure\GeographyUpdate.cs" />
<Compile Include="Structure\GeographyUpdates.cs" />
<Compile Include="Structure\OrganizationParameters.cs" />
<Compile Include="Structure\PostalCode.cs" />
<Compile Include="Structure\PostalCodes.cs" />
+54
View File
@@ -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
}
}
}
+24
View File
@@ -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<GeographyUpdates,GeographyUpdate,BasicGeographyUpdate>
{
static public GeographyUpdates GetUnprocessed()
{
return FromArray (SwarmDb.GetDatabaseForReading().GetUnprocessedGeographyUpdates());
}
static public GeographyUpdates GetCreatedSince (DateTime dateTimeSince)
{
return FromArray (SwarmDb.GetDatabaseForReading().GetGeographyUpdatesSince (dateTimeSince));
}
}
}