Committing work in general

This commit is contained in:
Rick Falkvinge
2013-07-15 07:38:16 +00:00
parent 0b3d062227
commit c75bca7f3a
7 changed files with 151 additions and 2 deletions
+1 -1
View File
@@ -109,7 +109,7 @@ namespace Swarmops.Database
}
}
public void CreateSwarmopsLogEntryAffectedObject (int swarmopsLogEntryId, string affectedObjectType, string affectedObjectId)
public void CreateSwarmopsLogEntryAffectedObject (int swarmopsLogEntryId, string affectedObjectType, int affectedObjectId)
{
using (DbConnection connection = GetMySqlDbConnection())
{
+4
View File
@@ -193,6 +193,9 @@
<Compile Include="Support\DatabaseMaintenance.cs" />
<Compile Include="Support\Imagery.cs" />
<Compile Include="Support\IXmlPayload.cs" />
<Compile Include="Support\LogEntries\CashAdvanceAttestedLogEntry.cs" />
<Compile Include="Support\LogEntries\CashAdvanceRequestedLogEntry.cs" />
<Compile Include="Support\LogEntries\FinancialActionBase.cs" />
<Compile Include="Support\LogEntries\LogEntryBase.cs" />
<Compile Include="Support\ObjectOptionalData.cs" />
<Compile Include="Support\PluralBase.cs" />
@@ -234,6 +237,7 @@
<Compile Include="Support\SerializableDictionary.cs" />
<Compile Include="Support\SingularFactory.cs" />
<Compile Include="Support\SwarmopsLog.cs" />
<Compile Include="Support\SwarmopsLogEntry.cs" />
<Compile Include="Support\TemporaryIdentity.cs" />
<Compile Include="Support\UrlTranslations.cs" />
<Compile Include="Swarm\Activists.cs" />
@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Swarmops.Logic.Financial;
using Swarmops.Logic.Swarm;
namespace Swarmops.Logic.Support.LogEntries
{
class CashAdvanceAttestedLogEntry: CashAdvanceRequestedLogEntry
{
// Identical class
CashAdvanceAttestedLogEntry(Person attestingPerson, double amount, FinancialAccount budget, string reason)
:base (attestingPerson, amount, budget, reason)
{
}
}
}
@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Swarmops.Logic.Financial;
using Swarmops.Logic.Swarm;
namespace Swarmops.Logic.Support.LogEntries
{
[Serializable]
public class CashAdvanceRequestedLogEntry: FinancialActionBase
{
public CashAdvanceRequestedLogEntry()
{
// empty ctor needed for serialize
}
public CashAdvanceRequestedLogEntry(Person requestingPerson, double amount, FinancialAccount budget, string reason)
{
this.Amount = amount;
this.Currency = budget.Organization.Currency.Code;
this.DateTime = DateTime.UtcNow;
this.Description = reason;
this.FinancialAccountId = budget.Identity;
this.FinancialAccountName = budget.Name; // redundancy in case of future name changes
this.OwnerPersonId = budget.OwnerPersonId;
this.OwnerPersonName = budget.Owner.Name;
this.PersonId = requestingPerson.Identity; // do not save name for data retention reasons
}
}
}
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Swarmops.Logic.Support.Log;
namespace Swarmops.Logic.Support.LogEntries
{
[Serializable]
public class FinancialActionBase: LogEntryBase<FinancialActionBase>
{
public FinancialActionBase()
{
// necessary for serialization
}
public int FinancialAccountId { get; set; }
public string FinancialAccountName { get; set; }
public int PersonId { get; set; }
public double Amount { get; set; }
public string Currency { get; set; }
public string Description { get; set; }
public int OwnerPersonId { get; set; }
public string OwnerPersonName { get; set; }
public DateTime DateTime { get; set; }
}
}
+17 -1
View File
@@ -2,10 +2,26 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Swarmops.Database;
using Swarmops.Logic.Swarm;
namespace Swarmops.Logic.Support
{
class SwarmopsLog
public class SwarmopsLog
{
public static SwarmopsLogEntry CreateEntry (Person person, IXmlPayload logEntry)
{
string logEntryClass = logEntry.GetType().ToString();
if (logEntryClass.StartsWith("Swarmops.Logic.Support.Logentries."))
{
logEntryClass = logEntryClass.Substring("Swarmops.Logic.Support.Logentries.".Length);
}
int logEntryId = SwarmDb.GetDatabaseForWriting().CreateSwarmopsLogEntry(
person != null ? person.Identity : 0, logEntryClass, logEntry.ToXml());
return SwarmopsLogEntry.FromIdentityAggressive(logEntryId);
}
}
}
+51
View File
@@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Swarmops.Basic.Interfaces;
using Swarmops.Basic.Types;
using Swarmops.Database;
using Swarmops.Logic.Swarm;
namespace Swarmops.Logic.Support
{
public class SwarmopsLogEntry: BasicSwarmopsLogEntry
{
private SwarmopsLogEntry (BasicSwarmopsLogEntry basic):
base (basic)
{
// private ctor
}
public static SwarmopsLogEntry FromBasic (BasicSwarmopsLogEntry basic)
{
return new SwarmopsLogEntry(basic);
}
public static SwarmopsLogEntry FromIdentity (int swarmopsLogEntryId)
{
return FromBasic(SwarmDb.GetDatabaseForReading().GetSwarmopsLogEntry(swarmopsLogEntryId));
}
public static SwarmopsLogEntry FromIdentityAggressive (int swarmopsLogEntryId)
{
return FromBasic(SwarmDb.GetDatabaseForWriting().GetSwarmopsLogEntry(swarmopsLogEntryId)); // Writing intentional
}
public static SwarmopsLogEntry Create (Person person, IXmlPayload logEntry)
{
return SwarmopsLog.CreateEntry(person, logEntry);
}
public void CreateAffectedObject (IHasIdentity affectedObject)
{
string className = affectedObject.GetType().ToString();
int dotIndex = className.LastIndexOf('.');
className = className.Substring(dotIndex); // assumes there's always at least one dot in a class name
SwarmDb.GetDatabaseForWriting().CreateSwarmopsLogEntryAffectedObject(this.Identity, className, affectedObject.Identity);
}
}
}