public async Task <MirrorStatus> RefreshCachedPOI(int poiId) { var mirrorStatus = await Task.Run <MirrorStatus>(() => { var dataModel = new OCMEntities(); var poiModel = dataModel.ChargePoints.FirstOrDefault(p => p.ID == poiId); var poiCollection = database.GetCollection <POIMongoDB>("poi"); var query = Query.EQ("ID", poiId); var removeResult = poiCollection.Remove(query); System.Diagnostics.Debug.WriteLine("POIs removed from cache [" + poiId + "]:" + removeResult.DocumentsAffected); if (poiModel != null) { var cachePOI = POIMongoDB.FromChargePoint(OCM.API.Common.Model.Extensions.ChargePoint.FromDataModel(poiModel)); if (cachePOI.AddressInfo != null) { cachePOI.SpatialPosition = new GeoJsonPoint <GeoJson2DGeographicCoordinates>(new GeoJson2DGeographicCoordinates(cachePOI.AddressInfo.Longitude, cachePOI.AddressInfo.Latitude)); } poiCollection.Insert <POIMongoDB>(cachePOI); } else { //poi not present in master DB, we've removed it from cache } long numPOIInMasterDB = dataModel.ChargePoints.LongCount(); return(RefreshMirrorStatus(poiCollection.Count(), 1, numPOIInMasterDB)); }); return(mirrorStatus); }
public void InsertAllPOI(List <OCM.API.Common.Model.ChargePoint> poiList, MongoCollection <POIMongoDB> poiCollection) { var mongoDBPoiList = new List <POIMongoDB>(); foreach (var poi in poiList) { var newPoi = POIMongoDB.FromChargePoint(poi); if (newPoi.AddressInfo != null) { newPoi.SpatialPosition = new GeoJsonPoint <GeoJson2DGeographicCoordinates>(new GeoJson2DGeographicCoordinates(newPoi.AddressInfo.Longitude, newPoi.AddressInfo.Latitude)); } mongoDBPoiList.Add(newPoi); } poiCollection.InsertBatch(mongoDBPoiList); }
public void InsertAllPOI(List <OCM.API.Common.Model.ChargePoint> poiList, MongoCollection <POIMongoDB> poiCollection) { using (server.RequestStart(database)) { foreach (var poi in poiList) { var newPoi = POIMongoDB.FromChargePoint(poi); if (newPoi.AddressInfo != null) { newPoi.SpatialPosition = new GeoJsonPoint <GeoJson2DGeographicCoordinates>(new GeoJson2DGeographicCoordinates(newPoi.AddressInfo.Longitude, newPoi.AddressInfo.Latitude)); } poiCollection.Insert(newPoi); } } }