Esempio n. 1
0
        public IDeviceOperations GetOperations(ModbusDevice device)
        {
            Type type = device.GetType();

            if (type == typeof(MonitorBox))
            {
                this._logger.LogInformation("Creating MonitorBoxOperations");
                return(new MonitorBoxOperations((MonitorBox)device,
                                                this._serviceProvider.GetRequiredService <FacilityContext>(),
                                                this._serviceProvider.GetRequiredService <IAddMonitorBoxReading>(),
                                                this._serviceProvider.GetRequiredService <ILogger <IMonitorBoxOperations> >(),
                                                this._serviceProvider.GetRequiredService <IMediator>()));
            }
            else if (type == typeof(H2Generator))
            {
                this._logger.LogInformation("Creating GeneratorOperations");
                return(new GeneratorOperations((H2Generator)device, this._serviceProvider.GetRequiredService <IAddGeneratorReading>(), this._serviceProvider.GetRequiredService <ILogger <IGeneratorOperations> >()));
            }
            else if (type == typeof(TankScale))
            {
                this._logger.LogInformation("Creating TankScaleOperations");
                return(new TankScaleOperations((TankScale)device, this._serviceProvider.GetRequiredService <IAddTankScaleReading>(), this._serviceProvider.GetRequiredService <ILogger <ITankScaleOperations> >()));
            }
            else
            {
                return(null);
            }
        }
        public bool AddReading(ModbusDevice device)
        {
            Type type = device.GetType();

            if (type == typeof(MonitorBox))
            {
                return(this._addMonitorBoxReading.AddReading((MonitorBox)device));
            }
            else if (type == typeof(H2Generator))
            {
                return(this._addGenReading.AddReading((H2Generator)device));
            }
            else if (type == typeof(TankScale))
            {
                return(this._addNHReading.AddReading((TankScale)device));
            }
            else
            {
                return(false);
            }
        }
        public static IDeviceOperations OperationFactory(FacilityContext context, ModbusDevice device)
        {
            Type type = device.GetType();

            if (type == typeof(GenericMonitorBox))
            {
                return(new MonitorBoxController(context.GetMonitorBox(device.Identifier, false)));
            }
            else if (type == typeof(H2Generator))
            {
                return(new GeneratorController(context.GetGenerator(device.Identifier, false)));
            }
            else if (type == typeof(AmmoniaController))
            {
                return(new NH3Controller(context.GetNHController(device.Identifier, false)));
            }
            else
            {
                return(null);
            }
        }
        public bool AddReading(ModbusDevice device)
        {
            Type type = device.GetType();

            if (type == typeof(GenericMonitorBox))
            {
                return(this._addMonitorBoxReading.AddReading((GenericMonitorBox)device));
            }
            else if (type == typeof(H2Generator))
            {
                return(this._addGenReading.AddReading((H2Generator)device));
            }
            else if (type == typeof(AmmoniaController))
            {
                return(this._addNHReading.AddReading((AmmoniaController)device));
            }
            else
            {
                return(false);
            }
        }