Exemplo n.º 1
0
 public void DeleteMongoPlantsArea(MongoPlantsArea mongoPlantsArea)
 {
     IMongoCollection<BsonDocument> plantsAreasCollection = GetMongoCollection("plantsareas");
     FilterDefinition<BsonDocument> filter = Builders<BsonDocument>.Filter.Eq("_id", mongoPlantsArea.objId);
     plantsAreasCollection.DeleteOneAsync(filter);
 }
Exemplo n.º 2
0
        public void UpdateCollections()
        {
            DbMapper dbMapper = DbMapper.GetMySqlDbMapper();
            //IPlantsAreaMappingRepository plantsAreaMappingRepository = new PlantsAreaMappingRepository();
            //ISensorMappingRepository sensorMappingRepository = new SensorMappingRepository();
            MySqlPlantsAreaMappingRepository sqlPlantsAreaMappingRepository = new MySqlPlantsAreaMappingRepository();
            MySqlSensorMappingRepository sqlSensorMappingRepository = new MySqlSensorMappingRepository();

            ParameterServicesInfo.SetBaseParameters();
            List<PlantsAreaMapping> plantsAreaMappings = sqlPlantsAreaMappingRepository.GetAll();

            List<MongoPlantsArea> mongoPlantsAreas = new List<MongoPlantsArea>();
            List<MongoSensor> mongoSensors = new List<MongoSensor>();

            PlantsAreas pas = new PlantsAreas();
            plantsAreaMappings.ForEach(p => pas.AddPlantsArea(dbMapper.RestorePlantArea(p)));

            foreach (PlantsArea area in pas.Areas)
            {
                sqlSensorMappingRepository.GetAll(sm => sm.PlantsAreaId == area.Id)
                    .ForEach(sensorMapping => dbMapper.RestoreSensor(sensorMapping, area));
            }
   
            foreach (PlantsArea area in pas.Areas)
            {
                MongoPlantsArea mongoPlantsArea = new MongoPlantsArea(area);

                mongoPlantsAreas.Add(mongoPlantsArea);
                
                mongoSensors.AddRange(area.Sensors.Select(sensor => new MongoSensor(sensor)));
             }

            DeleteCollectionData("messages");
            DeleteCollectionData("notifications");

            IMongoCollection<BsonDocument> sensorsCollection = GetMongoCollection("sensors");
            IMongoCollection<BsonDocument> plantsAreasCollection = GetMongoCollection("plantsareas");

            sensorsCollection.DeleteMany(new BsonDocument());
            plantsAreasCollection.DeleteMany(new BsonDocument());
            
            IEnumerable<BsonDocument> docsSensor = mongoSensors.ConvertAll(input => input.ToBsonDocument());
            IEnumerable<BsonDocument> docsPlantsArea = mongoPlantsAreas.ConvertAll(input => input.ToBsonDocument());

            sensorsCollection.InsertMany(docsSensor);
            plantsAreasCollection.InsertMany(docsPlantsArea);
        }
Exemplo n.º 3
0
 public void SaveMongoPlantsArea(MongoPlantsArea mongoPlantsArea)
 {
     IMongoCollection<BsonDocument> plantsAreasCollection = GetMongoCollection("plantsareas");
     plantsAreasCollection.ReplaceOneAsync(bsonDocument => bsonDocument["_id"] == mongoPlantsArea.objId,
         mongoPlantsArea.ToBsonDocument(), new UpdateOptions {IsUpsert = true});
 }