コード例 #1
0
        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);
        }
コード例 #2
0
        public static POIMongoDB FromChargePoint(OCM.API.Common.Model.ChargePoint cp, POIMongoDB poi = null)
        {
            if (poi == null)
            {
                poi = new POIMongoDB();
            }

            poi.AddressInfo            = cp.AddressInfo;
            poi.Chargers               = cp.Chargers;
            poi.Connections            = cp.Connections;
            poi.DataProvider           = cp.DataProvider;
            poi.DataProviderID         = cp.DataProviderID;
            poi.DataProvidersReference = cp.DataProvidersReference;
            poi.DataQualityLevel       = cp.DataQualityLevel;

            if (cp.DateCreated != null)
            {
                poi.DateCreated = (DateTime?)DateTime.SpecifyKind(cp.DateCreated.Value, DateTimeKind.Utc);
            }
            if (cp.DateLastConfirmed != null)
            {
                poi.DateLastConfirmed = (DateTime?)DateTime.SpecifyKind(cp.DateLastConfirmed.Value, DateTimeKind.Utc);
            }
            if (cp.DateLastStatusUpdate != null)
            {
                poi.DateLastStatusUpdate = (DateTime?)DateTime.SpecifyKind(cp.DateLastStatusUpdate.Value, DateTimeKind.Utc);
            }
            if (cp.DatePlanned != null)
            {
                poi.DatePlanned = (DateTime?)DateTime.SpecifyKind(cp.DatePlanned.Value, DateTimeKind.Utc);
            }

            poi.GeneralComments = cp.GeneralComments;
            poi.ID                     = cp.ID;
            poi.MediaItems             = cp.MediaItems;
            poi.MetadataTags           = cp.MetadataTags;
            poi.MetadataValues         = cp.MetadataValues;
            poi.NumberOfPoints         = cp.NumberOfPoints;
            poi.NumberOfPoints         = cp.NumberOfPoints;
            poi.OperatorID             = cp.OperatorID;
            poi.OperatorInfo           = cp.OperatorInfo;
            poi.OperatorsReference     = cp.OperatorsReference;
            poi.ParentChargePointID    = cp.ParentChargePointID;
            poi.StatusType             = cp.StatusType;
            poi.StatusTypeID           = cp.StatusTypeID;
            poi.SubmissionStatus       = cp.SubmissionStatus;
            poi.SubmissionStatusTypeID = cp.SubmissionStatusTypeID;
            poi.UsageCost              = cp.UsageCost;
            poi.UsageType              = cp.UsageType;
            poi.UsageTypeID            = cp.UsageTypeID;
            poi.UserComments           = cp.UserComments;
            poi.LevelOfDetail          = cp.LevelOfDetail;
            poi.UUID                   = cp.UUID;
            return(poi);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
 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);
         }
     }
 }