Added basic GeographyUpdate structures
This commit is contained in:
@@ -72,6 +72,7 @@
|
||||
<Compile Include="Types\Financial\BasicFinancialTransactionTagSetType.cs" />
|
||||
<Compile Include="Types\Financial\BasicFinancialTransactionTagType.cs" />
|
||||
<Compile Include="Types\Financial\BasicFinancialValidation.cs" />
|
||||
<Compile Include="Types\Structure\BasicGeographyUpdate.cs" />
|
||||
<Compile Include="Types\Structure\BasicPostalCode.cs" />
|
||||
<Compile Include="Types\Financial\BasicFinancialAccount.cs" />
|
||||
<Compile Include="Types\Governance\BasicMeeting.cs" />
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.Linq;
|
||||
using System.Reflection.Emit;
|
||||
using System.Text;
|
||||
|
||||
namespace Swarmops.Basic.Types.Structure
|
||||
{
|
||||
[Serializable]
|
||||
public class BasicGeographyUpdate
|
||||
{
|
||||
[Obsolete ("Do not call this ctor directly. It is intended for serialization.", true)]
|
||||
public BasicGeographyUpdate()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public BasicGeographyUpdate (int geographyUpdateId, string updateType, string updateSource, string guid,
|
||||
string countryCode, string changeDataXml, DateTime createdDateTime, DateTime effectiveDateTime,
|
||||
bool processed)
|
||||
{
|
||||
this.GeographyUpdateId = geographyUpdateId;
|
||||
this.UpdateType = updateType;
|
||||
this.UpdateSource = updateSource;
|
||||
this.Guid = guid;
|
||||
this.CountryCode = countryCode;
|
||||
this.ChangeDataXml = changeDataXml;
|
||||
this.CreatedDateTime = createdDateTime;
|
||||
this.EffectiveDateTime = effectiveDateTime;
|
||||
this.Processed = processed;
|
||||
}
|
||||
|
||||
public BasicGeographyUpdate (BasicGeographyUpdate original)
|
||||
: this (
|
||||
original.GeographyUpdateId, original.UpdateType, original.UpdateSource, original.Guid,
|
||||
original.CountryCode, original.ChangeDataXml, original.CreatedDateTime, original.EffectiveDateTime,
|
||||
original.Processed)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
public int GeographyUpdateId { get; private set; }
|
||||
public string UpdateType { get; private set; }
|
||||
public string UpdateSource { get; private set; }
|
||||
public string Guid { get; private set; }
|
||||
public string CountryCode { get; private set; }
|
||||
public string ChangeDataXml { get; private set; }
|
||||
public DateTime CreatedDateTime { get; private set; }
|
||||
public DateTime EffectiveDateTime { get; private set; }
|
||||
public bool Processed { get; protected set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,181 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using Swarmops.Basic.Enums;
|
||||
using Swarmops.Basic.Types;
|
||||
using Swarmops.Basic.Types.Structure;
|
||||
|
||||
namespace Swarmops.Database
|
||||
{
|
||||
public partial class SwarmDb
|
||||
{
|
||||
#region Field reading code
|
||||
|
||||
private const string geographyUpdateFieldSequence =
|
||||
" GeographyUpdates.GeographyUpdateId, GeographyUpdates.GeographyUpdateTypeId, " + // 0-1
|
||||
"GeographyUpdates.GeographyUpdateSourceId, GeographyUpdates.Guid, GeographyUpdates.CountryCode, " + // 2-4
|
||||
"GeographyUpdates.ChangeDataXml, GeographyUpdates.CreatedDateTime, " + // 5-6
|
||||
"GeographyUpdates.EffectiveDateTime,GeographyUpdates.Processed, " + // 7-8
|
||||
"GeographyUpdateTypes.Name AS GeographyUpdateType, " + // 9
|
||||
"GeographyUpdateSources.Name AS GeographyUpdateSource " + // 10
|
||||
"FROM GeographyUpdates " +
|
||||
"JOIN GeographyUpdateTypes ON (GeographyUpdateTypes.GeographyUpdateTypeId=GeographyUpdates.GeographyUpdateTypeId) " +
|
||||
"JOIN GeographyUpdateSources ON (GeographyUpdateSources.GeographyUpdateSourceId=GeographyUpdates.GeographyUpdateSourceId) ";
|
||||
|
||||
private static BasicGeographyUpdate ReadGeographyUpdateFromDataReader (DbDataReader reader)
|
||||
{
|
||||
int geographyUpdateId = reader.GetInt32 (0);
|
||||
// Fields# 1 and 2 are indexes into other tables, contents of which joined in #9 and #10 instead
|
||||
string guid = reader.GetString (3);
|
||||
string countryCode = reader.GetString (4);
|
||||
string changeDataXml = reader.GetString (5);
|
||||
DateTime createdDateTime = reader.GetDateTime (6);
|
||||
DateTime effectiveDateTime = reader.GetDateTime (7);
|
||||
bool processed = reader.GetBoolean (8);
|
||||
string updateType = reader.GetString (9);
|
||||
string updateSource = reader.GetString (10);
|
||||
|
||||
return new BasicGeographyUpdate (geographyUpdateId, updateType, updateSource, guid, countryCode,
|
||||
changeDataXml, createdDateTime, effectiveDateTime, processed);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public BasicGeographyUpdate[] GetAllGeographyUpdates()
|
||||
{
|
||||
List<BasicGeographyUpdate> result = new List<BasicGeographyUpdate>();
|
||||
|
||||
using (DbConnection connection = GetMySqlDbConnection())
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
DbCommand command =
|
||||
GetDbCommand (
|
||||
"SELECT " + geographyUpdateFieldSequence + " ORDER BY \"CreatedDateTime\"", connection);
|
||||
|
||||
using (DbDataReader reader = command.ExecuteReader())
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
result.Add (ReadGeographyUpdateFromDataReader (reader));
|
||||
}
|
||||
|
||||
return result.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public BasicGeographyUpdate[] GetGeographyUpdatesSince(DateTime since)
|
||||
{
|
||||
List<BasicGeographyUpdate> result = new List<BasicGeographyUpdate>();
|
||||
|
||||
using (DbConnection connection = GetMySqlDbConnection())
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
DbCommand command =
|
||||
GetDbCommand(
|
||||
"SELECT " + geographyUpdateFieldSequence + " WHERE CreatedDateTime >= @sinceDateTime", connection);
|
||||
AddParameterWithName(command, "@sinceDateTime", since);
|
||||
|
||||
using (DbDataReader reader = command.ExecuteReader())
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
result.Add(ReadGeographyUpdateFromDataReader(reader));
|
||||
}
|
||||
|
||||
return result.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public BasicGeographyUpdate[] GetUnprocessedGeographyUpdates()
|
||||
{
|
||||
List<BasicGeographyUpdate> result = new List<BasicGeographyUpdate>();
|
||||
|
||||
using (DbConnection connection = GetMySqlDbConnection())
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
DbCommand command =
|
||||
GetDbCommand(
|
||||
"SELECT " + geographyUpdateFieldSequence + " WHERE EffectiveDateTime >= @dateTimeNow AND Processed=0", connection);
|
||||
AddParameterWithName(command, "@dateTimeNow", DateTime.UtcNow);
|
||||
|
||||
using (DbDataReader reader = command.ExecuteReader())
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
result.Add(ReadGeographyUpdateFromDataReader(reader));
|
||||
}
|
||||
|
||||
return result.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public bool ExistGeographyUpdateWithGuid(string guid)
|
||||
{
|
||||
using (DbConnection connection = GetMySqlDbConnection())
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
DbCommand command =
|
||||
GetDbCommand(
|
||||
"SELECT Guid FROM GeographyUpdates WHERE Guid = @testGuid", connection);
|
||||
AddParameterWithName(command, "@testGuid", guid);
|
||||
|
||||
using (DbDataReader reader = command.ExecuteReader())
|
||||
{
|
||||
if (reader.Read())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public int CreateGeographyUpdate (string updateType, string updateSource, string guid, string countryCode, string changeDataXml, DateTime createdDateTime, DateTime effectiveDateTime)
|
||||
{
|
||||
using (DbConnection connection = GetMySqlDbConnection())
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
DbCommand command = GetDbCommand ("CreateGeographyUpdate", connection);
|
||||
command.CommandType = CommandType.StoredProcedure;
|
||||
|
||||
AddParameterWithName(command, "geographyUpdateType", updateType);
|
||||
AddParameterWithName(command, "geographyUpdateSource", updateSource);
|
||||
AddParameterWithName(command, "guid", guid);
|
||||
AddParameterWithName(command, "countryCode", countryCode);
|
||||
AddParameterWithName(command, "changeDataXml", changeDataXml);
|
||||
AddParameterWithName(command, "createdDateTime", createdDateTime);
|
||||
AddParameterWithName(command, "effectiveDateTime", effectiveDateTime);
|
||||
|
||||
return Convert.ToInt32 (command.ExecuteScalar());
|
||||
}
|
||||
}
|
||||
|
||||
public void SetGeographyUpdateProcessed (int geographyUpdateId)
|
||||
{
|
||||
using (DbConnection connection = GetMySqlDbConnection())
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
DbCommand command = GetDbCommand("SetGeographyUpdateProcessed", connection);
|
||||
command.CommandType = CommandType.StoredProcedure;
|
||||
|
||||
AddParameterWithName(command, "geographyUpdateId", geographyUpdateId);
|
||||
command.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -58,6 +58,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Configuration.cs" />
|
||||
<Compile Include="Database-GeographyUpdates.cs" />
|
||||
<Compile Include="Database-CashAdvances.cs" />
|
||||
<Compile Include="Database-Currencies.cs" />
|
||||
<Compile Include="Database-FinancialTransactionTags.cs" />
|
||||
@@ -142,4 +143,4 @@
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
|
||||
</Project>
|
||||
</Project>
|
||||
Reference in New Issue
Block a user