Skip to content

Instantly share code, notes, and snippets.

public class ClientLocation
{
public Guid Id { get; set; }
public Guid ClientId { get; set; }
public GeoJsonPoint<GeoJson2DGeographicCoordinates> Coordinates { get; set; }
public DateTime CurrentTimeStamp { get; set; }
}
public async Task<LocationResponse> RetrieveLocations(Guid clientId, DateTime? startDate = null,
DateTime? endDate = null)
{
var list = new List<FilterDefinition<ClientLocation>>();
list.Add(Builders<ClientLocation>.Filter.Where(a => a.ClientId == clientId));
if (startDate.HasValue)
{
list.Add(Builders<ClientLocation>.Filter.Where(a => a.CurrentTimeStamp >= startDate.Value));
public async Task UpdateLocation(LocationRequest request)
{
var clientLocation = new ClientLocation
{
Id = Guid.NewGuid(),
ClientId = request.ClientId,
CurrentTimeStamp = request.CurrentTimeStamp,
Coordinates =
GeoJson.Point(new GeoJsonObjectArgs<GeoJson2DGeographicCoordinates>(),
new GeoJson2DGeographicCoordinates(request.Longitude, request.Latitude))
public class LocationManager : ILocationManager
{
private readonly MongoClient _client;
public LocationManager()
{
_client = new MongoClient("mongodb://localhost:27017");
}
public interface ILocationManager
{
Task UpdateLocation(LocationRequest request);
Task<LocationResponse> RetrieveLocations(Guid clientId, DateTime? startDate = null,
DateTime? endDate = null);
}
public class ClientLocation
{
public Guid Id { get; set; }
public Guid ClientId { get; set; }
public double Latitude { get; set; }
public double Longitude { get; set; }
public class LocationResponse
{
public Guid ClientId { get; set; }
public LocationData[] Datas { get; set; }
}
public class LocationData
{
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 LocationRequest
{
public double Latitude { get; set; }
public double Longitude { get; set; }
public Guid ClientId { get; set; }
}
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