Skip to content

Instantly share code, notes, and snippets.

@developingtoday
developingtoday / Startup.cs
Created November 14, 2016 18:35
initial plumbing of location service
public class Startup
{
public void Configuration(IAppBuilder builder)
{
var config = new HttpConfiguration();
//Add json media formatter CamelCase
config.Formatters.Clear();
config.Formatters.Add(new JsonMediaTypeFormatter());
config.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
config.MapHttpAttributeRoutes();
@developingtoday
developingtoday / ExceptionFilter.cs
Created November 14, 2016 18:44
Basic exception filter on a web api
public class ExceptionFilter: ExceptionFilterAttribute
{
public override void OnException(HttpActionExecutedContext actionExecutedContext)
{
Debug.WriteLine(actionExecutedContext.Exception);
Console.WriteLine(actionExecutedContext.Exception);
actionExecutedContext.Response = new System.Net.Http.HttpResponseMessage(System.Net.HttpStatusCode.InternalServerError);
}
}
@developingtoday
developingtoday / LocationService.cs
Created November 14, 2016 18:55
starting stoping the location service angular.
public class LocationService
{
private IDisposable _disposable;
public void Start()
{
var adress = @"http://localhost:10280/locationserv"; //todo add a config key
_disposable = WebApp.Start(adress);
Console.WriteLine("Web application started on:{0}",adress);
}
static void Main(string[] args)
{
var location=new LocationService();
location.Start();
Console.ReadKey();
}
@developingtoday
developingtoday / LocationControllerV1.cs
Created November 14, 2016 19:05
first version of location controller.
public class LocationController:ApiController
{
[Route("api/v1/ping")]
[HttpGet]
public HttpResponseMessage Ping()
{
return Request.CreateResponse(HttpStatusCode.OK, new {Result = "pong"});
}
@developingtoday
developingtoday / packagesLocationService.config
Created November 14, 2016 19:13
location service nuget pacakges.
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.AspNet.Cors" version="5.0.0" targetFramework="net452" />
<package id="Microsoft.AspNet.SignalR.Core" version="2.2.1" targetFramework="net452" />
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="net452" />
<package id="Microsoft.AspNet.WebApi.Core" version="5.2.3" targetFramework="net452" />
<package id="Microsoft.AspNet.WebApi.Owin" version="5.2.3" targetFramework="net452" />
<package id="Microsoft.AspNet.WebApi.OwinSelfHost" version="5.2.3" targetFramework="net452" />
<package id="Microsoft.Owin" version="3.0.1" targetFramework="net452" />
<package id="Microsoft.Owin.Cors" version="3.0.1" targetFramework="net452" />
static void Main(string[] args)
{
HostFactory.Run(x =>
{
x.Service<LocationService>(s =>
{
s.ConstructUsing(name => new LocationService());
//create the class that hosts service logic
s.WhenStarted(a => a.Start()); //start method
s.WhenStopped(a => a.Stop()); //stop method
public class LocationRequest
{
public double Latitude { get; set; }
public double Longitude { get; set; }
public Guid ClientId { get; set; }
}
public class LocationRequest
{
public double Latitude { get; set; }
public double Longitude { get; set; }
public Guid ClientId { get; set; }
public DateTime CurrentTimeStamp { get; set; }
public class LocationResponse
{
public Guid ClientId { get; set; }
public LocationData[] Datas { get; set; }
}
public class LocationData
{