Skip to content

Instantly share code, notes, and snippets.

View dbarkol's full-sized avatar
💭
poppin and lockin

David Barkol dbarkol

💭
poppin and lockin
View GitHub Profile
[
{
"id" : "1000"
}
]
@dbarkol
dbarkol / GridEventsHub.cs
Created March 14, 2018 05:03
Grid Events Hub
using Microsoft.AspNetCore.SignalR;
namespace viewer.Hubs
{
public class GridEventsHub: Hub
{
public GridEventsHub()
{
}
}
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
// Awwww yeah!
services.AddSignalR();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
// other configuration ...
// Add SignalR hub routes
app.UseSignalR(routes =>
{
routes.MapHub<GridEventsHub>("/hubs/gridevents");
});
using System;
namespace viewer.Models
{
public class GridEvent<T> where T: class
{
public string Id { get; set;}
public string EventType { get; set;}
public string Subject {get; set;}
public DateTime EventTime { get; set; }
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Threading.Tasks;
using System.Net;
using System.Text;
using System.Net.Http;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Threading.Tasks;
using System.Net;
using System.Text;
using System.Net.Http;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
private bool EventTypeSubcriptionValidation
=> HttpContext.Request.Headers["aeg-event-type"].FirstOrDefault() ==
"SubscriptionValidation";
private bool EventTypeNotification
=> HttpContext.Request.Headers["aeg-event-type"].FirstOrDefault() ==
"Notification";
var details = JsonConvert.DeserializeObject<GridEvent<dynamic>>(e.ToString());
await this.HubContext.Clients.All.SendAsync(
"gridupdate",
details.Id,
details.EventType,
details.Subject,
details.EventTime.ToLongTimeString(),
e.ToString());
<table id="grid-events" class="table table-striped">
<thead>
<th>&nbsp;</th>
<th>Event Type</th>
<th>Subject</th>
</thead>
<tbody id="grid-event-details"></tbody>
</table>
<script id="event-template" type="text/x-handlebars-template">