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 // You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.2.0516.1941")] [assembly: AssemblyVersion("1.2.0516.2018")]
[assembly: AssemblyFileVersion("1.2.0516.1941")] [assembly: AssemblyFileVersion("1.2.0516.2018")]
+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 // You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.2.0516.1941")] [assembly: AssemblyVersion("1.2.0516.2018")]
[assembly: AssemblyFileVersion("1.2.0516.1941")] [assembly: AssemblyFileVersion("1.2.0516.2018")]
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers // You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.2.0516.1941")] [assembly: AssemblyVersion("1.2.0516.2018")]
[assembly: AssemblyFileVersion("1.2.0516.1941")] [assembly: AssemblyFileVersion("1.2.0516.2018")]
+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 // You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.2.0516.1941")] [assembly: AssemblyVersion("1.2.0516.2018")]
[assembly: AssemblyFileVersion("1.2.0516.1941")] [assembly: AssemblyFileVersion("1.2.0516.2018")]
@@ -8,6 +8,7 @@ using System.Reactive.Subjects;
using System.Data.Entity.Infrastructure; using System.Data.Entity.Infrastructure;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Data.Objects; using System.Data.Objects;
using Disco.Models.Repository;
namespace Disco.Data.Repository.Monitor namespace Disco.Data.Repository.Monitor
{ {
@@ -76,7 +77,7 @@ namespace Disco.Data.Repository.Monitor
if (monitorEvent.EventType == RepositoryMonitorEventType.Added) if (monitorEvent.EventType == RepositoryMonitorEventType.Added)
{ {
// Update Entity Key for Added Events // 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; RepositoryMonitorEventType eventType;
string[] modifiedProperties = null; string[] modifiedProperties = null;
object[] entityKey = null; Dictionary<string, object> entityKey = null;
Type entityType; Type entityType;
switch (entryState.State) switch (entryState.State)
@@ -118,7 +119,7 @@ namespace Disco.Data.Repository.Monitor
// Don't pass entity key when entity newly added // Don't pass entity key when entity newly added
if (eventType != RepositoryMonitorEventType.Added) if (eventType != RepositoryMonitorEventType.Added)
entityKey = entryState.EntityKey.EntityKeyValues.Select(kv => kv.Value).ToArray(); entityKey = DetermineEntityKey(entryState);
return new RepositoryMonitorEvent() return new RepositoryMonitorEvent()
{ {
@@ -132,5 +133,45 @@ namespace Disco.Data.Repository.Monitor
objectEntryState = entryState 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] [JsonIgnore]
public object Entity { get; set; } public object Entity { get; set; }
public object[] EntityKey { get; set; } public Dictionary<string, object> EntityKey { get; set; }
public string[] ModifiedProperties { get; set; } public string[] ModifiedProperties { get; set; }
+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 // You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.2.0516.1941")] [assembly: AssemblyVersion("1.2.0516.2018")]
[assembly: AssemblyFileVersion("1.2.0516.1941")] [assembly: AssemblyFileVersion("1.2.0516.2018")]
+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 // You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.2.0516.1941")] [assembly: AssemblyVersion("1.2.0516.2018")]
[assembly: AssemblyFileVersion("1.2.0516.1941")] [assembly: AssemblyFileVersion("1.2.0516.2018")]
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers // You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.2.0516.1941")] [assembly: AssemblyVersion("1.2.0516.2018")]
[assembly: AssemblyFileVersion("1.2.0516.1941")] [assembly: AssemblyFileVersion("1.2.0516.2018")]
+2 -2
View File
@@ -31,5 +31,5 @@ using System.Runtime.InteropServices;
// //
// You can specify all the values or you can default the Revision and Build Numbers // You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
[assembly: AssemblyVersion("1.2.0516.1941")] [assembly: AssemblyVersion("1.2.0516.2018")]
[assembly: AssemblyFileVersion("1.2.0516.1941")] [assembly: AssemblyFileVersion("1.2.0516.2018")]
+40 -31
View File
@@ -164,20 +164,22 @@
return false; return false;
} }
function loadLiveComment(id) { function loadLiveComment(key) {
$.ajax({ if (key.JobId == jobId) {
url: '@Url.Action(MVC.API.Job.Comment())', $.ajax({
dataType: 'json', url: '@Url.Action(MVC.API.Job.Comment())',
data: { id: id }, dataType: 'json',
success: function (d) { data: { id: key.Id },
if (d && d.JobId == jobId) { success: function (d) {
addComment(d, false); if (d && d.JobId == jobId) {
addComment(d, false);
}
},
error: function (jqXHR, textStatus, errorThrown) {
alert('Unable to load live comment ' + id + ': ' + textStatus);
} }
}, });
error: function (jqXHR, textStatus, errorThrown) { }
alert('Unable to load live comment ' + id + ': ' + textStatus);
}
});
} }
function addComment(c, quick) { function addComment(c, quick) {
var e = $('<div><span class="author" /><span class="remove" /><span class="timestamp" /><span class="comment" /></div>'); var e = $('<div><span class="author" /><span class="remove" /><span class="timestamp" /><span class="comment" /></div>');
@@ -263,11 +265,13 @@
onLoadNavigation = navigationPath; onLoadNavigation = navigationPath;
} }
}; };
function addAttachment(id, quick) { function addAttachment(key, quick) {
var data = { id: id };
$.ajax({ if (key.JobId == jobId) {
url: '@Url.Action(MVC.API.Job.Attachment())', var data = { id: key.Id };
$.ajax({
url: '@Url.Action(MVC.API.Job.Attachment())',
dataType: 'json', dataType: 'json',
data: data, data: data,
success: function (d) { success: function (d) {
@@ -300,14 +304,17 @@
} }
}); });
} }
function removeAttachment(id) { }
var $element = $attachmentOutput.find('a[data-attachmentid="' + id + '"]'); function removeAttachment(key) {
if ($element.length > 0) { if (key.JobId == jobId) {
$element.hide(300).delay(300).queue(function () { var $element = $attachmentOutput.find('a[data-attachmentid="' + key.Id + '"]');
if ($element.attr('data-mimetype').toLowerCase().indexOf('image/') == 0) if ($element.length > 0) {
Shadowbox.removeCache(this); $element.hide(300).delay(300).queue(function () {
$element.remove(); if ($element.attr('data-mimetype').toLowerCase().indexOf('image/') == 0)
}); Shadowbox.removeCache(this);
$element.remove();
});
}
} }
} }
@@ -376,22 +383,24 @@
case 'JobAttachment': case 'JobAttachment':
switch (d.EventType) { switch (d.EventType) {
case 0: // Added case 0: // Added
addAttachment(d.EntityKey[0], false); addAttachment(d.EntityKey, false);
break; break;
case 1: // Removed case 1: // Removed
removeAttachment(d.EntityKey[0]); removeAttachment(d.EntityKey);
break; break;
} }
break; break;
case 'JobLog': case 'JobLog':
switch (d.EventType) { switch (d.EventType) {
case 0: // Added case 0: // Added
loadLiveComment(d.EntityKey[0]); loadLiveComment(d.EntityKey);
break; break;
case 1: // Removed case 1: // Removed
$CommentOutput.children('div[data-logid="' + d.EntityKey[0] + '"]').slideUp(300).delay(300).queue(function () { if (d.EntityKey.JobId == jobId) {
$(this).remove(); $CommentOutput.children('div[data-logid="' + d.EntityKey.Id + '"]').slideUp(300).delay(300).queue(function () {
}); $(this).remove();
});
}
break; break;
} }
break; break;
@@ -519,29 +519,31 @@ WriteLiteral(@"',
return false; return false;
} }
function loadLiveComment(id) { function loadLiveComment(key) {
$.ajax({ if (key.JobId == jobId) {
url: '"); $.ajax({
url: '");
#line 169 "..\..\Views\Job\JobParts\Resources.cshtml" #line 170 "..\..\Views\Job\JobParts\Resources.cshtml"
Write(Url.Action(MVC.API.Job.Comment())); Write(Url.Action(MVC.API.Job.Comment()));
#line default #line default
#line hidden #line hidden
WriteLiteral(@"', WriteLiteral(@"',
dataType: 'json', dataType: 'json',
data: { id: id }, data: { id: key.Id },
success: function (d) { success: function (d) {
if (d && d.JobId == jobId) { if (d && d.JobId == jobId) {
addComment(d, false); addComment(d, false);
}
},
error: function (jqXHR, textStatus, errorThrown) {
alert('Unable to load live comment ' + id + ': ' + textStatus);
} }
}, });
error: function (jqXHR, textStatus, errorThrown) { }
alert('Unable to load live comment ' + id + ': ' + textStatus);
}
});
} }
function addComment(c, quick) { function addComment(c, quick) {
var e = $('<div><span class=""author"" /><span class=""remove"" /><span class=""timestamp"" /><span class=""comment"" /></div>'); var e = $('<div><span class=""author"" /><span class=""remove"" /><span class=""timestamp"" /><span class=""comment"" /></div>');
@@ -554,7 +556,7 @@ WriteLiteral(@"',
commentHtml = commentHtml.replace(/\#(\d+)/g, '<a href="""); commentHtml = commentHtml.replace(/\#(\d+)/g, '<a href=""");
#line 190 "..\..\Views\Job\JobParts\Resources.cshtml" #line 192 "..\..\Views\Job\JobParts\Resources.cshtml"
Write(Url.Action(MVC.Job.Show(null))); Write(Url.Action(MVC.Job.Show(null)));
@@ -594,7 +596,7 @@ WriteLiteral(@"?id=$1"">#$1</a>');
'"); '");
#line 221 "..\..\Views\Job\JobParts\Resources.cshtml" #line 223 "..\..\Views\Job\JobParts\Resources.cshtml"
Write(Links.ClientBin.Disco_Silverlight_AttachmentUpload_xap); Write(Links.ClientBin.Disco_Silverlight_AttachmentUpload_xap);
@@ -615,7 +617,7 @@ WriteLiteral(@"',
'UploadUrl="); 'UploadUrl=");
#line 233 "..\..\Views\Job\JobParts\Resources.cshtml" #line 235 "..\..\Views\Job\JobParts\Resources.cshtml"
Write(Url.Action(MVC.API.Job.AttachmentUpload(Model.Job.Id, null))); Write(Url.Action(MVC.API.Job.AttachmentUpload(Model.Job.Id, null)));
@@ -654,15 +656,17 @@ WriteLiteral(@"'
onLoadNavigation = navigationPath; onLoadNavigation = navigationPath;
} }
}; };
function addAttachment(id, quick) { function addAttachment(key, quick) {
var data = { id: id };
$.ajax({ if (key.JobId == jobId) {
url: '"); var data = { id: key.Id };
$.ajax({
url: '");
#line 270 "..\..\Views\Job\JobParts\Resources.cshtml" #line 274 "..\..\Views\Job\JobParts\Resources.cshtml"
Write(Url.Action(MVC.API.Job.Attachment())); Write(Url.Action(MVC.API.Job.Attachment()));
#line default #line default
@@ -680,7 +684,7 @@ WriteLiteral(@"',
e.attr('data-attachmentid', a.Id).attr('data-mimetype', a.MimeType).attr('href', '"); e.attr('data-attachmentid', a.Id).attr('data-mimetype', a.MimeType).attr('href', '");
#line 280 "..\..\Views\Job\JobParts\Resources.cshtml" #line 284 "..\..\Views\Job\JobParts\Resources.cshtml"
Write(Url.Action(MVC.API.Job.AttachmentDownload())); Write(Url.Action(MVC.API.Job.AttachmentDownload()));
@@ -689,7 +693,7 @@ WriteLiteral(@"',
WriteLiteral("/\' + a.Id);\r\n e.find(\'.icon img\').attr(\'src\', \'"); WriteLiteral("/\' + a.Id);\r\n e.find(\'.icon img\').attr(\'src\', \'");
#line 281 "..\..\Views\Job\JobParts\Resources.cshtml" #line 285 "..\..\Views\Job\JobParts\Resources.cshtml"
Write(Url.Action(MVC.API.Job.AttachmentThumbnail())); Write(Url.Action(MVC.API.Job.AttachmentThumbnail()));
@@ -709,26 +713,27 @@ WriteLiteral("/\' + a.Id);\r\n e.find(\'.comments
" alert(\'Unable to add attachment: \' + d.Result);\r\n }\r\n " + " alert(\'Unable to add attachment: \' + d.Result);\r\n }\r\n " +
" },\r\n error: function (jqXHR, textStatus, e" + " },\r\n error: function (jqXHR, textStatus, e" +
"rrorThrown) {\r\n alert(\'Unable to add attachment: \' + text" + "rrorThrown) {\r\n alert(\'Unable to add attachment: \' + text" +
"Status);\r\n }\r\n });\r\n }\r\n fun" + "Status);\r\n }\r\n });\r\n }\r\n }\r\n" +
"ction removeAttachment(id) {\r\n var $element = $attachmentOutput.find(" + " function removeAttachment(key) {\r\n if (key.JobId == jobId) {\r" +
"\'a[data-attachmentid=\"\' + id + \'\"]\');\r\n if ($element.length > 0) {\r\n " + "\n var $element = $attachmentOutput.find(\'a[data-attachmentid=\"\' +" +
" $element.hide(300).delay(300).queue(function () {\r\n " + " key.Id + \'\"]\');\r\n if ($element.length > 0) {\r\n " +
" if ($element.attr(\'data-mimetype\').toLowerCase().indexOf(\'image/\') == 0)\r\n" + " $element.hide(300).delay(300).queue(function () {\r\n if " +
" Shadowbox.removeCache(this);\r\n $eleme" + "($element.attr(\'data-mimetype\').toLowerCase().indexOf(\'image/\') == 0)\r\n " +
"nt.remove();\r\n });\r\n }\r\n }\r\n\r\n function " + " Shadowbox.removeCache(this);\r\n $elemen" +
"removeLocalAttachment() {\r\n $this = $(this).closest(\'a\');\r\n\r\n " + "t.remove();\r\n });\r\n }\r\n }\r\n " +
" var data = { id: $this.attr(\'data-attachmentid\') };\r\n\r\n if (!$dia" + "}\r\n\r\n function removeLocalAttachment() {\r\n $this = $(this).clo" +
"logRemoveAttachment) {\r\n $dialogRemoveAttachment = $(\'#dialogRemo" + "sest(\'a\');\r\n\r\n var data = { id: $this.attr(\'data-attachmentid\') };\r\n\r" +
"veAttachment\').dialog({\r\n resizable: false,\r\n " + "\n if (!$dialogRemoveAttachment) {\r\n $dialogRemoveAttac" +
" height: 140,\r\n modal: true,\r\n autoOpen" + "hment = $(\'#dialogRemoveAttachment\').dialog({\r\n resizable: fa" +
": false\r\n });\r\n }\r\n\r\n $dialogRemoveAttachme" + "lse,\r\n height: 140,\r\n modal: true,\r\n " +
"nt.dialog(\"enable\").dialog(\'option\', \'buttons\', {\r\n \"Remove\": fun" + " autoOpen: false\r\n });\r\n }\r\n\r\n " +
"ction () {\r\n $dialogRemoveAttachment.dialog(\"disable\");\r\n " + " $dialogRemoveAttachment.dialog(\"enable\").dialog(\'option\', \'buttons\', {\r\n " +
" $dialogRemoveAttachment.dialog(\"option\", \"buttons\", null);\r\n " + " \"Remove\": function () {\r\n $dialogRemoveAttachment.di" +
" $.ajax({\r\n url: \'"); "alog(\"disable\");\r\n $dialogRemoveAttachment.dialog(\"option\", \"" +
"buttons\", null);\r\n $.ajax({\r\n url: \'");
#line 333 "..\..\Views\Job\JobParts\Resources.cshtml" #line 340 "..\..\Views\Job\JobParts\Resources.cshtml"
Write(Url.Action(MVC.API.Job.AttachmentRemove())); Write(Url.Action(MVC.API.Job.AttachmentRemove()));
@@ -760,24 +765,25 @@ WriteLiteral("\',\r\n dataType: \'json\',\r\n
" window.setTimeout(function () {\r\n switch (d.En" + " window.setTimeout(function () {\r\n switch (d.En" +
"tityTypeName) {\r\n case \'JobAttachment\':\r\n " + "tityTypeName) {\r\n case \'JobAttachment\':\r\n " +
" switch (d.EventType) {\r\n case 0: // A" + " switch (d.EventType) {\r\n case 0: // A" +
"dded\r\n addAttachment(d.EntityKey[0], false);\r" + "dded\r\n addAttachment(d.EntityKey, false);\r\n " +
"\n break;\r\n cas" + " break;\r\n case 1" +
"e 1: // Removed\r\n removeAttachment(d.EntityKe" + ": // Removed\r\n removeAttachment(d.EntityKey);" +
"y[0]);\r\n break;\r\n " + "\r\n break;\r\n }\r\n " +
"}\r\n break;\r\n case \'JobLog\':\r\n " + " break;\r\n case \'JobLog\':\r\n " +
" switch (d.EventType) {\r\n " + " switch (d.EventType) {\r\n cas" +
" case 0: // Added\r\n loadLiveComment(d.Entit" + "e 0: // Added\r\n loadLiveComment(d.EntityKey);" +
"yKey[0]);\r\n break;\r\n " + "\r\n break;\r\n ca" +
" case 1: // Removed\r\n $CommentOutput.ch" + "se 1: // Removed\r\n if (d.EntityKey.JobId == j" +
"ildren(\'div[data-logid=\"\' + d.EntityKey[0] + \'\"]\').slideUp(300).delay(300).queue" + "obId) {\r\n $CommentOutput.children(\'div[da" +
"(function () {\r\n $(this).remove();\r\n " + "ta-logid=\"\' + d.EntityKey.Id + \'\"]\').slideUp(300).delay(300).queue(function () {" +
" });\r\n break;\r\n" + "\r\n $(this).remove();\r\n " +
" }\r\n break;\r\n " + " });\r\n }\r\n " +
" }\r\n }, 100);\r\n }\r\n }\r\n var liveMe" + " break;\r\n }\r\n " +
"ssagesConnection = $.connection(\'"); " break;\r\n }\r\n }, 100);\r\n " +
" }\r\n }\r\n var liveMessagesConnection = $.connection(\'");
#line 402 "..\..\Views\Job\JobParts\Resources.cshtml" #line 411 "..\..\Views\Job\JobParts\Resources.cshtml"
Write(Url.Content("~/API/Repository/Notifications")); Write(Url.Content("~/API/Repository/Notifications"));