Skip to content

Commit 7528446

Browse files
author
Tharindu Abeygunawardana
committed
Added real time updates support to map view using signalr
1 parent 266ecd5 commit 7528446

13 files changed

+2775
-122
lines changed

Ndot.Tests/app.config

+8
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@
3838
<assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" culture="neutral" />
3939
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
4040
</dependentAssembly>
41+
<dependentAssembly>
42+
<assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral" />
43+
<bindingRedirect oldVersion="0.0.0.0-2.0.2.0" newVersion="2.0.2.0" />
44+
</dependentAssembly>
45+
<dependentAssembly>
46+
<assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" culture="neutral" />
47+
<bindingRedirect oldVersion="0.0.0.0-2.0.2.0" newVersion="2.0.2.0" />
48+
</dependentAssembly>
4149
</assemblyBinding>
4250
</runtime>
4351
<appSettings>

Ndot/Content/Site.css

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
body {
88
background-color: #fff;
9-
border-top: solid 10px #000;
109
color: #333;
1110
font-size: .85em;
1211
font-family: "Segoe UI", Verdana, Helvetica, Sans-Serif;

Ndot/Controllers/HomeController.cs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Device.Location;
1+
using System.Configuration;
42
using System.Linq;
5-
using System.Web;
63
using System.Web.Mvc;
74
using MongoRepository;
85
using Ndot.Models;
@@ -20,6 +17,7 @@ public HomeController(IRepository<Sr1FormData> repository)
2017

2118
public ActionResult Index()
2219
{
20+
ViewBag.GoogleMapsApiKey = ConfigurationManager.AppSettings["GoogleMapsApiKey"];
2321
var results = _repository.Collection.FindAllAs<Sr1FormData>().ToList();
2422
return View(results);
2523
}

Ndot/Controllers/Sr1FormController.cs

+10-87
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
using System.Net;
88
using System.Net.Http;
99
using System.Web.Http;
10+
using Microsoft.AspNet.SignalR;
1011
using Microsoft.Practices.EnterpriseLibrary.Logging;
1112
using MongoDB.Bson;
1213
using MongoRepository;
1314
using Ndot.Helpers;
15+
using Ndot.Hubs;
1416
using Ndot.Models;
1517
using ZXing;
1618

@@ -29,15 +31,14 @@ public Sr1FormController(LogWriter logger, IRepository<Sr1FormData> repository,
2931
_apiAgent = apiAgent;
3032
}
3133

32-
[Authorize]
34+
[System.Web.Http.Authorize]
3335
public IEnumerable<Sr1FormData> Get()
3436
{
3537
var results = _repository.Collection.FindAllAs<Sr1FormData>().ToList();
36-
results.Add(GetTestForm());
3738
return results;
3839
}
3940

40-
[Authorize]
41+
[System.Web.Http.Authorize]
4142
public Sr1FormData Get(string id)
4243
{
4344
return _repository.Collection.FindOneByIdAs<Sr1FormData>(new ObjectId(id));
@@ -56,6 +57,8 @@ public HttpResponseMessage Post(Sr1ClientFormData clientFormData)
5657
Street = clientFormData.Street,
5758
City = clientFormData.City,
5859
County = clientFormData.County,
60+
Latitude = clientFormData.Latitude,
61+
Longitude = clientFormData.Longitude,
5962
CreatedDate = DateTime.Now,
6063
Actors = new List<Actor>()
6164
};
@@ -116,6 +119,10 @@ public HttpResponseMessage Post(Sr1ClientFormData clientFormData)
116119
}
117120

118121
_repository.Add(form);
122+
123+
var hubContext = GlobalHost.ConnectionManager.GetHubContext<IncidentsHub>();
124+
hubContext.Clients.All.addNewMarkerToPage(form.Latitude, form.Longitude,
125+
form.Street, form.CreatedDate.ToString(), form.Actors.Count);
119126
}
120127
catch (Exception e)
121128
{
@@ -146,73 +153,6 @@ private void ValidateClientFormData(Sr1ClientFormData clientFormData)
146153
throw new HttpResponseException(HttpStatusCode.PreconditionFailed);
147154
}
148155

149-
private static Sr1FormData GetTestForm()
150-
{
151-
return new Sr1FormData
152-
{
153-
Id = "1232323",
154-
Street = "123 Elm Street",
155-
City = "Las Vegas",
156-
County = "Clark",
157-
CreatedDate = DateTime.Now,
158-
Actors = new List<Actor>
159-
{
160-
new Actor
161-
{
162-
Type = "Driver",
163-
Driver = new DriverInfo
164-
{
165-
FirstName = "John",
166-
MiddleName = "Z",
167-
LastName = "Xamarin",
168-
Street = "331 Main St.",
169-
City = "Las Vegas",
170-
State = "NV",
171-
Zip = "89129",
172-
DriverLicenseNumber = "124234422",
173-
DriverLicenseState = "NV",
174-
Dob = new DateTime(1990, 12, 3),
175-
LicensePlateNumber = "883GWN",
176-
LicensePlateState = "NV",
177-
Year = "2002",
178-
Make = "Nissan Sentra",
179-
BodyType = "Car",
180-
Vin = "231XJKJ9934KKJKJDKFJ"
181-
},
182-
Owner = new OwnerInfo
183-
{
184-
FirstName = "Bon",
185-
MiddleName = "Z",
186-
LastName = "Jonas",
187-
Street = "423 Zebas St.",
188-
City = "Las Vegas",
189-
State = "NV",
190-
Zip="89123",
191-
DriverLicenseNumber = "J2KJ2KJ3K",
192-
DriverLicenseState = "NV",
193-
Dob = new DateTime (1949, 4, 2)
194-
}
195-
},
196-
new Actor
197-
{
198-
Type = "Pedestrian",
199-
OwnerSameAsDriver = true,
200-
Driver = new DriverInfo
201-
{
202-
FirstName = "Jenny",
203-
MiddleName = "Z",
204-
LastName = "Xamarin",
205-
Street = "331 Main St.",
206-
City = "Las Vegas",
207-
State = "NV",
208-
Zip = "89129",
209-
Dob = new DateTime(1990, 12, 3),
210-
}
211-
}
212-
}
213-
};
214-
}
215-
216156
private static OwnerInfo GetOwnerInfoFromDlData(DlBarCodeData dlData)
217157
{
218158
return new OwnerInfo
@@ -230,23 +170,6 @@ private static OwnerInfo GetOwnerInfoFromDlData(DlBarCodeData dlData)
230170
};
231171
}
232172

233-
private static OwnerInfo CopyDriverInfoToOwnerInfo(Actor actor)
234-
{
235-
return new OwnerInfo
236-
{
237-
FirstName = actor.Driver.FirstName,
238-
MiddleName = actor.Driver.MiddleName,
239-
LastName = actor.Driver.LastName,
240-
Street = actor.Driver.Street,
241-
City = actor.Driver.City,
242-
State = actor.Driver.State,
243-
Zip = actor.Driver.Zip,
244-
DriverLicenseNumber = actor.Driver.DriverLicenseNumber,
245-
DriverLicenseState = actor.Driver.DriverLicenseState,
246-
Dob = actor.Driver.Dob
247-
};
248-
}
249-
250173
private static DriverInfo GetDriverInfoFromDlData(DlBarCodeData dlData, ClientActor clientActor)
251174
{
252175
return new DriverInfo

Ndot/Hubs/IncidentsHub.cs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Web;
5+
using Microsoft.AspNet.SignalR;
6+
7+
namespace Ndot.Hubs
8+
{
9+
public class IncidentsHub : Hub
10+
{
11+
12+
}
13+
}

Ndot/Models/DomainObjects.cs

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ public class Sr1ClientFormData
1010
public string Street { get; set; }
1111
public string City { get; set; }
1212
public string County { get; set; }
13+
public double Latitude { get; set; }
14+
public double Longitude { get; set; }
1315
public List<ClientActor> Actors { get; set; }
1416
}
1517

Ndot/Ndot.csproj

+25-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,22 @@
4242
<Reference Include="Elmah">
4343
<HintPath>..\packages\elmah.corelibrary.1.2.2\lib\Elmah.dll</HintPath>
4444
</Reference>
45+
<Reference Include="Microsoft.AspNet.SignalR.Core">
46+
<HintPath>..\packages\Microsoft.AspNet.SignalR.Core.2.0.1\lib\net45\Microsoft.AspNet.SignalR.Core.dll</HintPath>
47+
</Reference>
48+
<Reference Include="Microsoft.AspNet.SignalR.SystemWeb">
49+
<HintPath>..\packages\Microsoft.AspNet.SignalR.SystemWeb.2.0.1\lib\net45\Microsoft.AspNet.SignalR.SystemWeb.dll</HintPath>
50+
</Reference>
4551
<Reference Include="Microsoft.CSharp" />
52+
<Reference Include="Microsoft.Owin">
53+
<HintPath>..\packages\Microsoft.Owin.2.0.2\lib\net45\Microsoft.Owin.dll</HintPath>
54+
</Reference>
55+
<Reference Include="Microsoft.Owin.Host.SystemWeb">
56+
<HintPath>..\packages\Microsoft.Owin.Host.SystemWeb.2.0.2\lib\net45\Microsoft.Owin.Host.SystemWeb.dll</HintPath>
57+
</Reference>
58+
<Reference Include="Microsoft.Owin.Security">
59+
<HintPath>..\packages\Microsoft.Owin.Security.2.0.2\lib\net45\Microsoft.Owin.Security.dll</HintPath>
60+
</Reference>
4661
<Reference Include="Microsoft.Practices.EnterpriseLibrary.Common">
4762
<HintPath>..\packages\EnterpriseLibrary.Common.6.0.1304.0\lib\NET45\Microsoft.Practices.EnterpriseLibrary.Common.dll</HintPath>
4863
</Reference>
@@ -71,6 +86,12 @@
7186
<Reference Include="Moq">
7287
<HintPath>..\packages\Moq.4.1.1309.1617\lib\net40\Moq.dll</HintPath>
7388
</Reference>
89+
<Reference Include="Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
90+
<HintPath>..\packages\Newtonsoft.Json.5.0.8\lib\net45\Newtonsoft.Json.dll</HintPath>
91+
</Reference>
92+
<Reference Include="Owin">
93+
<HintPath>..\packages\Owin.1.0\lib\net40\Owin.dll</HintPath>
94+
</Reference>
7495
<Reference Include="System" />
7596
<Reference Include="System.Data" />
7697
<Reference Include="System.Data.Entity" />
@@ -98,9 +119,6 @@
98119
<Private>True</Private>
99120
<HintPath>..\packages\Microsoft.AspNet.Mvc.FixedDisplayModes.1.0.0\lib\net40\Microsoft.Web.Mvc.FixedDisplayModes.dll</HintPath>
100121
</Reference>
101-
<Reference Include="Newtonsoft.Json">
102-
<HintPath>..\packages\Newtonsoft.Json.4.5.11\lib\net40\Newtonsoft.Json.dll</HintPath>
103-
</Reference>
104122
<Reference Include="System.Net.Http">
105123
</Reference>
106124
<Reference Include="System.Net.Http.Formatting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
@@ -216,9 +234,11 @@
216234
<Compile Include="Helpers\DlBarCodeParser.cs" />
217235
<Compile Include="Helpers\IEdmundsApiAgent.cs" />
218236
<Compile Include="Helpers\ILogger.cs" />
237+
<Compile Include="Hubs\IncidentsHub.cs" />
219238
<Compile Include="MessageHandlers\BasicAuthMessageHandler.cs" />
220239
<Compile Include="Models\DomainObjects.cs" />
221240
<Compile Include="Properties\AssemblyInfo.cs" />
241+
<Compile Include="Startup.cs" />
222242
</ItemGroup>
223243
<ItemGroup>
224244
<Content Include="App_Readme\Elmah.txt" />
@@ -297,6 +317,8 @@
297317
<None Include="Scripts\jquery.validate-vsdoc.js" />
298318
<Content Include="Scripts\jquery-ui-1.8.24.js" />
299319
<Content Include="Scripts\jquery-ui-1.8.24.min.js" />
320+
<Content Include="Scripts\jquery.signalR-2.0.1.js" />
321+
<Content Include="Scripts\jquery.signalR-2.0.1.min.js" />
300322
<Content Include="Scripts\jquery.unobtrusive-ajax.js" />
301323
<Content Include="Scripts\jquery.unobtrusive-ajax.min.js" />
302324
<Content Include="Scripts\jquery.validate.js" />

0 commit comments

Comments
 (0)