Update: Repository Monitor Entity Key Additions

'Custom' additions to the entity key so subscribers can deal with
notifications more efficiently.
This commit is contained in:
Gary Sharp
2013-05-16 20:20:41 +10:00
parent 2eac245d3c
commit 837f3df3a7
12 changed files with 167 additions and 111 deletions
+2 -2
View File
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.2.0516.1941")]
[assembly: AssemblyFileVersion("1.2.0516.1941")]
[assembly: AssemblyVersion("1.2.0516.2018")]
[assembly: AssemblyFileVersion("1.2.0516.2018")]
@@ -8,6 +8,7 @@ using System.Reactive.Subjects;
using System.Data.Entity.Infrastructure;
using System.Collections.Concurrent;
using System.Data.Objects;
using Disco.Models.Repository;
namespace Disco.Data.Repository.Monitor
{
@@ -76,7 +77,7 @@ namespace Disco.Data.Repository.Monitor
if (monitorEvent.EventType == RepositoryMonitorEventType.Added)
{
// Update Entity Key for Added Events
monitorEvent.EntityKey = monitorEvent.objectEntryState.EntityKey.EntityKeyValues.Select(kv => kv.Value).ToArray();
monitorEvent.EntityKey = DetermineEntityKey(monitorEvent.objectEntryState);
}
}
@@ -84,7 +85,7 @@ namespace Disco.Data.Repository.Monitor
{
RepositoryMonitorEventType eventType;
string[] modifiedProperties = null;
object[] entityKey = null;
Dictionary<string, object> entityKey = null;
Type entityType;
switch (entryState.State)
@@ -118,7 +119,7 @@ namespace Disco.Data.Repository.Monitor
// Don't pass entity key when entity newly added
if (eventType != RepositoryMonitorEventType.Added)
entityKey = entryState.EntityKey.EntityKeyValues.Select(kv => kv.Value).ToArray();
entityKey = DetermineEntityKey(entryState);
return new RepositoryMonitorEvent()
{
@@ -132,5 +133,45 @@ namespace Disco.Data.Repository.Monitor
objectEntryState = entryState
};
}
internal static Dictionary<string, object> DetermineEntityKey(ObjectStateEntry entryState)
{
Dictionary<string, object> key = entryState.EntityKey.EntityKeyValues.ToDictionary(kv => kv.Key, kv => kv.Value);
if (entryState.Entity is DeviceAttachment)
{
key["DeviceSerialNumber"] = ((DeviceAttachment)entryState.Entity).DeviceSerialNumber;
}
if (entryState.Entity is DeviceCertificate)
{
key["DeviceSerialNumber"] = ((DeviceCertificate)entryState.Entity).DeviceSerialNumber;
}
if (entryState.Entity is DeviceComponent)
{
key["DeviceModelId"] = ((DeviceComponent)entryState.Entity).DeviceModelId;
}
if (entryState.Entity is DeviceUserAssignment)
{
key["AssignedUserId"] = ((DeviceUserAssignment)entryState.Entity).AssignedUserId;
}
if (entryState.Entity is JobAttachment)
{
key["JobId"] = ((JobAttachment)entryState.Entity).JobId;
}
if (entryState.Entity is JobComponent)
{
key["JobId"] = ((JobComponent)entryState.Entity).JobId;
}
if (entryState.Entity is JobLog)
{
key["JobId"] = ((JobLog)entryState.Entity).JobId;
}
if (entryState.Entity is UserAttachment)
{
key["UserId"] = ((UserAttachment)entryState.Entity).UserId;
}
return key;
}
}
}
@@ -37,7 +37,7 @@ namespace Disco.Data.Repository.Monitor
[JsonIgnore]
public object Entity { get; set; }
public object[] EntityKey { get; set; }
public Dictionary<string, object> EntityKey { get; set; }
public string[] ModifiedProperties { get; set; }