Ejemplo n.º 1
0
        private MirrorStatus RefreshMirrorStatus(long cachePOICollectionCount, long numPOIUpdated, long numPOIInMasterDB)
        {
            var statusCollection = database.GetCollection <MirrorStatus>("status");

            statusCollection.RemoveAll();

            //new status
            MirrorStatus status = new MirrorStatus();

            //status.ID = Guid.NewGuid().ToString();
            status.Description = "MongoDB Cache of Open Charge Map POI Database";
            status.LastUpdated = DateTime.UtcNow;

            status.TotalPOIInCache   = cachePOICollectionCount;
            status.TotalPOIInDB      = numPOIInMasterDB;
            status.StatusCode        = HttpStatusCode.OK;
            status.NumPOILastUpdated = numPOIUpdated;
            status.NumPOILastUpdated = 0;

            statusCollection.Insert(status);
            return(status);
        }
Ejemplo n.º 2
0
        public CacheProviderMongoDB()
        {
            try
            {
                if (!BsonClassMap.IsClassMapRegistered(typeof(POIMongoDB)))
                {
                    // register deserialization class map for ChargePoint
                    BsonClassMap.RegisterClassMap <POIMongoDB>(cm =>
                    {
                        cm.AutoMap();
                        cm.SetIgnoreExtraElements(true);
                    });
                }

                if (!BsonClassMap.IsClassMapRegistered(typeof(OCM.API.Common.Model.ChargePoint)))
                {
                    // register deserialization class map for ChargePoint
                    BsonClassMap.RegisterClassMap <OCM.API.Common.Model.ChargePoint>(cm =>
                    {
                        cm.AutoMap();
                        cm.SetIgnoreExtraElements(true);
                    });
                }
                if (!BsonClassMap.IsClassMapRegistered(typeof(OCM.API.Common.Model.CoreReferenceData)))
                {
                    // register deserialization class map for ChargePoint
                    BsonClassMap.RegisterClassMap <OCM.API.Common.Model.CoreReferenceData>(cm =>
                    {
                        cm.AutoMap();
                        cm.SetIgnoreExtraElements(true);
                    });
                }

                if (!BsonClassMap.IsClassMapRegistered(typeof(MirrorStatus)))
                {
                    // register deserialization class map for ChargePoint
                    BsonClassMap.RegisterClassMap <MirrorStatus>(cm =>
                    {
                        cm.AutoMap();
                        cm.SetIgnoreExtraElements(true);
                    });
                }

                if (!BsonClassMap.IsClassMapRegistered(typeof(CountryExtendedInfo)))
                {
                    // register deserialization class map for ChargePoint
                    BsonClassMap.RegisterClassMap <CountryExtendedInfo>(cm =>
                    {
                        cm.AutoMap();
                        cm.SetIgnoreExtraElements(true);
                    });
                }
            }
            catch (Exception)
            {
                ;;
            }

            var connectionString = ConfigurationManager.AppSettings["MongoDB_ConnectionString"].ToString();

            client   = new MongoClient(connectionString);
            server   = client.GetServer();
            database = server.GetDatabase(ConfigurationManager.AppSettings["MongoDB_Database"]);

            /*if (BsonSerializer.LookupSerializer(typeof(DateTime)) == null)
             * {
             *  BsonSerializer.RegisterSerializer(typeof(DateTime),
             *   new DateTimeSerializer(DateTimeSerializationOptions.LocalInstance));
             * }*/
            status = GetMirrorStatus(false, false);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Perform full or partial repopulation of POI Mirror in MongoDB
        /// </summary>
        /// <returns></returns>
        public async Task <MirrorStatus> PopulatePOIMirror(CacheUpdateStrategy updateStrategy)
        {
            if (!database.CollectionExists("poi"))
            {
                database.CreateCollection("poi");
            }

            if (updateStrategy != CacheUpdateStrategy.All)
            {
                CoreReferenceData coreRefData = new ReferenceDataManager().GetCoreReferenceData();
                if (!database.CollectionExists("reference"))
                {
                    database.CreateCollection("reference");
                }
                if (!database.CollectionExists("status"))
                {
                    database.CreateCollection("status");
                }

                if (coreRefData != null)
                {
                    var reference = database.GetCollection <CoreReferenceData>("reference");
                    reference.RemoveAll();
                    reference.Insert(coreRefData);
                }
            }

            var poiList       = GetPOIListToUpdate(updateStrategy);
            var poiCollection = database.GetCollection <POIMongoDB>("poi");

            if (poiList != null && poiList.Any())
            {
                if (updateStrategy == CacheUpdateStrategy.All)
                {
                    poiCollection.RemoveAll();
                }

                RemoveAllPOI(poiList, poiCollection);
                Thread.Sleep(300);
                InsertAllPOI(poiList, poiCollection);

                poiCollection.CreateIndex(IndexKeys <POIMongoDB> .GeoSpatialSpherical(x => x.SpatialPosition));
                poiCollection.CreateIndex(IndexKeys <POIMongoDB> .Descending(x => x.DateLastStatusUpdate));
                poiCollection.CreateIndex(IndexKeys <POIMongoDB> .Descending(x => x.DateCreated));
            }

            var statusCollection = database.GetCollection <MirrorStatus>("status");

            statusCollection.RemoveAll();

            //new status
            MirrorStatus status = new MirrorStatus();

            //status.ID = Guid.NewGuid().ToString();
            status.Description = "MongoDB Cache of Open Charge Map POI Database";
            status.LastUpdated = DateTime.UtcNow;

            status.TotalPOI   = poiCollection.Count();
            status.StatusCode = HttpStatusCode.OK;
            if (poiList != null)
            {
                status.NumPOILastUpdated = poiList.Count;
            }
            else
            {
                status.NumPOILastUpdated = 0;
            }

            statusCollection.Insert(status);
            return(status);
        }