public MongoMessagesListener(ISender<MeasuringMessage> sender)
        {
            Sender = sender;
            //subscribing
            sender.MessageSending += RecieveMessage;

            MongoDbAccessor = new MongoDbAccessor();
        }
Exemple #2
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());
        }
Exemple #3
0
 public void Execute(IJobExecutionContext context)
 {
     MongoDbAccessor mongoDbAccessor = new MongoDbAccessor();
     mongoDbAccessor.UpdateCollections();
 }