Example #1
0
        public ServiceProvider(ISender<MeasuringMessage> sender, PlantsAreas plantsAreas)
        {
            Sender = sender;
            
            //subscribing
            sender.MessageSending += RecieveMessage;

            PlantsAreas = plantsAreas;
            _timer = new Timer(1000);
            _timer.Elapsed += ServiceTimer_Tick;
            _timer.AutoReset = true;
            _timer.Enabled = true;
        }
Example #2
0
 public DbDataModifier(PlantsAreas plantsAreas, SensorsCollection sensorsCollection,
     IMeasurableParameterMappingRepository measurableParameterMappingRepository,
     IPlantMappingRepository plantMappingRepository, ISensorMappingRepository sensorMappingRepository,
     IPlantsAreaMappingRepository plantsAreaMappingRepository, 
     IServiceScheduleMappingRepository serviceScheduleMappingRepository)
 {
     _plantsAreas = plantsAreas;
     _sensorsCollection = sensorsCollection;
     _measurableParameterMappingRepository = measurableParameterMappingRepository;
     _plantMappingRepository = plantMappingRepository;
     _sensorMappingRepository = sensorMappingRepository;
     _plantsAreaMappingRepository = plantsAreaMappingRepository;
     _serviceScheduleMappingRepository = serviceScheduleMappingRepository;
     _dbMapper = new DbMapper(_plantMappingRepository,
         _measurableParameterMappingRepository, _serviceScheduleMappingRepository);
 }
Example #3
0
 public MySqlDbDataModifier(MySqlMeasurableParameterMappingRepository sqlMeasurableParameterMappingRepository,
     MySqlPlantMappingRepository sqlPlantMappingRepository,
     MySqlPlantsAreaMappingRepository sqlPlantsAreaMappingRepository,
     MySqlSensorMappingRepository sqlSensorMappingRepository,
     MySqlServiceScheduleMappingRepository sqlServiceScheduleMappingRepository,
     MySqlMeasuringMessageMappingRepository sqlMeasuringMessageMappingRepository,
     SensorsCollection sensorsCollection, PlantsAreas plantsAreas)
 {
     _sqlMeasurableParameterMappingRepository = sqlMeasurableParameterMappingRepository;
     _sqlPlantMappingRepository = sqlPlantMappingRepository;
     _sqlPlantsAreaMappingRepository = sqlPlantsAreaMappingRepository;
     _sqlServiceScheduleMappingRepository = sqlServiceScheduleMappingRepository;
     _sqlMeasuringMessageMappingRepository = sqlMeasuringMessageMappingRepository;
     _sensorsCollection = sensorsCollection;
     _plantsAreas = plantsAreas;
     _sqlSensorMappingRepository = sqlSensorMappingRepository;
     _dbMapper = new DbMapper(_sqlPlantMappingRepository,
         _sqlMeasurableParameterMappingRepository, _sqlServiceScheduleMappingRepository);
 }
Example #4
0
        public void Initialize()
        {
            //IPlantMappingRepository plantRepository = new PlantMappingRepository();
            //IPlantsAreaMappingRepository plantsAreaRepository = new PlantsAreaMappingRepository();
            //IMeasurableParameterMappingRepository measurableParameterRepository =
            //    new MeasurableParameterMappingRepository();
            //ISensorMappingRepository sensorRepository = new SensorMappingRepository();
            //IServiceScheduleMappingRepository serviceScheduleMappingRepository = new ServiceScheduleMappingRepository();

            MySqlMeasurableParameterMappingRepository sqlMeasurableParameterMappingRepository = new MySqlMeasurableParameterMappingRepository();
            MySqlPlantMappingRepository sqlPlantMappingRepository = new MySqlPlantMappingRepository();
            MySqlPlantsAreaMappingRepository sqlPlantsAreaMappingRepository = new MySqlPlantsAreaMappingRepository();
            MySqlSensorMappingRepository sqlSensorMappingRepository = new MySqlSensorMappingRepository();
            MySqlServiceScheduleMappingRepository sqlServiceScheduleMappingRepository = new MySqlServiceScheduleMappingRepository();

            _dbMapper = new DbMapper(sqlPlantMappingRepository,
                sqlMeasurableParameterMappingRepository, sqlServiceScheduleMappingRepository);

            _mongoDbAccessor = new MongoDbAccessor();

            List<PlantsAreaMapping> plantsAreaMappings = new List<PlantsAreaMapping>();

            if (_user != null)
            {
                plantsAreaMappings = sqlPlantsAreaMappingRepository.GetAll(mapping => mapping.UserId == new Guid(_user.Id));
            }

            _plantsAreas = new PlantsAreas();
                
            plantsAreaMappings.ForEach(p => _plantsAreas.AddPlantsArea(_dbMapper.RestorePlantArea(p)));

            _sensorsCollection = new SensorsCollection();

            foreach (PlantsArea area in _plantsAreas.Areas)
            {
                foreach (SensorMapping sensorMapping in sqlSensorMappingRepository.GetAll(sm => sm.PlantsAreaId == area.Id))
                {
                    Sensor sensor = _dbMapper.RestoreSensor(sensorMapping, area);
                    if (sensor != null)
                    {
                        _sensorsCollection.AddSensor(sensor);
                        sensor.IsOn = true;
                    }
                }
            }

            foreach (PlantsArea area in _plantsAreas.Areas)
            {
                //if custom sensor
                foreach (Sensor source in area.Sensors.Where(s => s.IsCustom))
                {
                    ServiceState serviceState = new ServiceState(source.MeasurableType, true);
                    area.PlantServicesStates.AddServiceState(serviceState);
                }
            }

            _sensorsMeasuringsProvider = new SensorsMeasuringsProvider(_sensorsCollection);

            _observer = new Observer(_sensorsMeasuringsProvider, _plantsAreas);

            _mongoMessagesListener = new MongoMessagesListener(_observer);

            _serviceProvider = new ServiceProvider(_observer, _plantsAreas);

            //_dbDataModifier = new DbDataModifier(_plantsAreas, _sensorsCollection, measurableParameterRepository,
            //    plantRepository, sensorRepository, plantsAreaRepository, serviceScheduleMappingRepository);

            _mySqlDbDataModifier = new MySqlDbDataModifier(sqlMeasurableParameterMappingRepository,
                sqlPlantMappingRepository, sqlPlantsAreaMappingRepository, sqlSensorMappingRepository,
                sqlServiceScheduleMappingRepository, new MySqlMeasuringMessageMappingRepository(), _sensorsCollection,
                _plantsAreas);
            //new MySqlMeasurableParameterMappingRepository(),
            //               new MySqlPlantMappingRepository(), new MySqlPlantsAreaMappingRepository(),
            //               new MySqlSensorMappingRepository(), new MySqlServiceScheduleMappingRepository(), new MySqlMeasuringMessageMappingRepository(), new SensorsCollection(), new PlantsAreas());
        }
Example #5
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);
        }