private PumpStateModel1Model GetPumpStateModel1(PumpConnectionData pumpConnection)
        {
            var query     = $"select * from {pumpConnection.DatabaseNaming} where DateAndTime < (select max(DateAndTime) from {pumpConnection.DatabaseNaming})";
            var stateData = SQLHelper.Query(pumpConnection.ConnectionString, query).Tables[0];

            if (stateData.Rows.Count > 0)
            {
                var dr        = stateData.Rows[0];
                var pumpState = new PumpStateModel1Model();
                pumpState.PumpId         = pumpConnection.PumpId;
                pumpState.DateAndTime    = SQLHelper.TryGetValue <DateTime>(dr, "DateAndTime");
                pumpState.IndexNo        = SQLHelper.TryGetValue <int>(dr, "INDEX");
                pumpState.StatusGen      = SQLHelper.TryGetValue <bool?>(dr, "Status_Gen");
                pumpState.StatusMotor    = SQLHelper.TryGetValue <bool?>(dr, "Status_Motor");
                pumpState.StatusBarGen   = SQLHelper.TryGetValue <int?>(dr, "Status_Bar_Gen");
                pumpState.LEDGen         = SQLHelper.TryGetValue <bool?>(dr, "LED_Gen");
                pumpState.StatusBarMotor = SQLHelper.TryGetValue <int?>(dr, "Status_Bar_Motor");
                pumpState.LEDMotor       = SQLHelper.TryGetValue <bool?>(dr, "LED_Motor");
                pumpState.L1NGen         = SQLHelper.TryGetValue <double?>(dr, "L1_N_Gen");
                pumpState.L2NGen         = SQLHelper.TryGetValue <double?>(dr, "L2_N_Gen");
                pumpState.L3NGen         = SQLHelper.TryGetValue <double?>(dr, "L3_N_Gen");
                pumpState.TempGen        = SQLHelper.TryGetValue <double?>(dr, "Temp_Gen");
                pumpState.L1L2Gen        = SQLHelper.TryGetValue <double?>(dr, "L1_L2_Gen");
                pumpState.L2L3Gen        = SQLHelper.TryGetValue <double?>(dr, "L2_L3_Gen");
                pumpState.L3L1Gen        = SQLHelper.TryGetValue <double?>(dr, "L3_L1_Gen");
                pumpState.SpeedGen       = SQLHelper.TryGetValue <double?>(dr, "Speed_Gen");
                pumpState.Fuel           = SQLHelper.TryGetValue <double?>(dr, "Fuel");
                pumpState.Battery        = SQLHelper.TryGetValue <double?>(dr, "Battery");
                pumpState.Oil            = SQLHelper.TryGetValue <double?>(dr, "Oil");
                pumpState.Charge         = SQLHelper.TryGetValue <double?>(dr, "Charge");
                pumpState.FrequencyGen   = SQLHelper.TryGetValue <double?>(dr, "Frequency_Gen");
                pumpState.KWHGen         = SQLHelper.TryGetValue <double?>(dr, "kWh_Gen");
                pumpState.P1NMotor       = SQLHelper.TryGetValue <double?>(dr, "P1_N_Motor");
                pumpState.P2NMotor       = SQLHelper.TryGetValue <double?>(dr, "P2_N_Motor");
                pumpState.P3NMotor       = SQLHelper.TryGetValue <double?>(dr, "P3_N_Motor");
                pumpState.TempMotor      = SQLHelper.TryGetValue <double?>(dr, "Temp_Motor");
                pumpState.AmpL1          = SQLHelper.TryGetValue <double?>(dr, "Amp_L1");
                pumpState.AmpL2          = SQLHelper.TryGetValue <double?>(dr, "Amp_L2");
                pumpState.AmpL3          = SQLHelper.TryGetValue <double?>(dr, "Amp_L3");
                pumpState.SpeedMotor     = SQLHelper.TryGetValue <double?>(dr, "Speed_Motor");
                pumpState.Pressure       = SQLHelper.TryGetValue <double?>(dr, "Pressure");
                pumpState.Vibration      = SQLHelper.TryGetValue <double?>(dr, "Vibration");
                pumpState.Flow           = SQLHelper.TryGetValue <double?>(dr, "Flow");
                pumpState.FrequencyMotor = SQLHelper.TryGetValue <double?>(dr, "Frequency_Motor");
                pumpState.KWHMotor       = SQLHelper.TryGetValue <double?>(dr, "kWh_Motor");
                pumpState.TimeMTNHour    = SQLHelper.TryGetValue <double?>(dr, "Time_MTN_Hour");
                pumpState.TimeMTNMin     = SQLHelper.TryGetValue <double?>(dr, "Time_MTN_Min");
                pumpState.TimeMTNSec     = SQLHelper.TryGetValue <double?>(dr, "Time_MTN_Sec");
                pumpState.LEDIDELRate    = SQLHelper.TryGetValue <int?>(dr, "LED_IDEL_RATE");
                pumpState.KW1            = SQLHelper.TryGetValue <double?>(dr, "kW1");
                pumpState.KW2            = SQLHelper.TryGetValue <double?>(dr, "kW2");
                pumpState.KW3            = SQLHelper.TryGetValue <double?>(dr, "kW3");
                return(pumpState);
            }
            else
            {
                return(new PumpStateModel1Model());
            }
        }
        private PumpStateModel1Model GetPumpStateModel1(Pump pump)
        {
            var mongoDB    = new ControlRoomMongoContext().GetDatabase();
            var collection = mongoDB.GetCollection <PumpStateModel1Mongo>();
            var state      = collection.Find(t => t.PumpId == pump.Id.ToString())
                             .SortByDescending(t => t.DateAndTime).FirstOrDefault();

            if (state == null)
            {
                return(new PumpStateModel1Model());
            }

            var result = new PumpStateModel1Model();

            result.PumpId         = Guid.Parse(state.PumpId);
            result.IndexNo        = (int)state.IndexNo;
            result.DateAndTime    = state.DateAndTime;
            result.StatusGen      = state.StatusGen;
            result.StatusMotor    = state.StatusMotor;
            result.StatusBarGen   = (int?)state.StatusBarGen;
            result.LEDGen         = state.LEDGen;
            result.StatusBarMotor = (int?)state.StatusBarMotor;
            result.LEDMotor       = state.LEDMotor;
            result.L1NGen         = state.L1NGen;
            result.L2NGen         = state.L2NGen;
            result.L3NGen         = state.L3NGen;
            result.TempGen        = state.TempGen;
            result.L1L2Gen        = state.L1L2Gen;
            result.L2L3Gen        = state.L2L3Gen;
            result.L3L1Gen        = state.L3L1Gen;
            result.SpeedGen       = state.SpeedGen;
            result.Fuel           = state.Fuel;
            result.Battery        = state.Battery;
            result.Oil            = state.Oil;
            result.Charge         = state.Charge;
            result.FrequencyGen   = state.FrequencyGen;
            result.KWHGen         = state.KWHGen;
            result.P1NMotor       = state.P1NMotor;
            result.P2NMotor       = state.P2NMotor;
            result.P3NMotor       = state.P3NMotor;
            result.TempMotor      = state.TempMotor;
            result.AmpL1          = state.AmpL1;
            result.AmpL2          = state.AmpL2;
            result.AmpL3          = state.AmpL3;
            result.SpeedMotor     = state.SpeedMotor;
            result.Pressure       = state.Pressure;
            result.Vibration      = state.Vibration;
            result.Flow           = state.Flow;
            result.FrequencyMotor = state.FrequencyMotor;
            result.KWHMotor       = state.KWHMotor;
            result.TimeMTNHour    = state.TimeMTNHour;
            result.TimeMTNMin     = state.TimeMTNMin;
            result.TimeMTNSec     = state.TimeMTNSec;
            result.LEDIDELRate    = (int?)state.LEDIDELRate;
            result.KW1            = state.KW1;
            result.KW2            = state.KW2;
            result.KW3            = state.KW3;
            return(result);
        }
예제 #3
0
        public async Task SendPumpStateModel1(PumpStateModel1Model model)
        {
            var connectionId = Context.ConnectionId;

            if (!registeredSenders.ContainsKey(connectionId))
            {
                throw new UnauthorizedException();
            }
            var connectionIds = registeredRecievers.Where(t => t.Value == model.PumpId).Select(t => t.Key);
            await Clients.Clients(connectionIds).SendAsync("ReceiveState", model);
        }
        public PumpStateModel1Model GetPumpStateModel1(Guid pumpId)
        {
            var pump = pumpRepository.GetAll().Where(t => t.IsActive == true && t.Id == pumpId).FirstOrDefault();

            if (pump == null)
            {
                throw new DataValidationException("Pump not found or inactive.");
            }

            var mongoDB    = new ControlRoomMongoContext().GetDatabase();
            var collection = mongoDB.GetCollection <PumpStateModel1Mongo>();
            var state      = collection.Find(t => t.PumpId == pumpId.ToString())
                             .SortByDescending(t => t.DateAndTime).FirstOrDefault();

            if (state == null)
            {
                //throw new DataValidationException("State data not found");
                return(new PumpStateModel1Model());
            }

            var result = new PumpStateModel1Model();

            result.PumpId         = Guid.Parse(state.PumpId);
            result.IndexNo        = (int)state.IndexNo;
            result.DateAndTime    = state.DateAndTime;
            result.StatusGen      = state.StatusGen;
            result.StatusMotor    = state.StatusMotor;
            result.StatusBarGen   = (int?)state.StatusBarGen;
            result.LEDGen         = state.LEDGen;
            result.StatusBarMotor = (int?)state.StatusBarMotor;
            result.LEDMotor       = state.LEDMotor;
            result.L1NGen         = state.L1NGen;
            result.L2NGen         = state.L2NGen;
            result.L3NGen         = state.L3NGen;
            result.TempGen        = state.TempGen;
            result.L1L2Gen        = state.L1L2Gen;
            result.L2L3Gen        = state.L2L3Gen;
            result.L3L1Gen        = state.L3L1Gen;
            result.SpeedGen       = state.SpeedGen;
            result.Fuel           = state.Fuel;
            result.Battery        = state.Battery;
            result.Oil            = state.Oil;
            result.Charge         = state.Charge;
            result.FrequencyGen   = state.FrequencyGen;
            result.KWHGen         = state.KWHGen;
            result.P1NMotor       = state.P1NMotor;
            result.P2NMotor       = state.P2NMotor;
            result.P3NMotor       = state.P3NMotor;
            result.TempMotor      = state.TempMotor;
            result.AmpL1          = state.AmpL1;
            result.AmpL2          = state.AmpL2;
            result.AmpL3          = state.AmpL3;
            result.SpeedMotor     = state.SpeedMotor;
            result.Pressure       = state.Pressure;
            result.Vibration      = state.Vibration;
            result.Flow           = state.Flow;
            result.FrequencyMotor = state.FrequencyMotor;
            result.KWHMotor       = state.KWHMotor;
            result.TimeMTNHour    = state.TimeMTNHour;
            result.TimeMTNMin     = state.TimeMTNMin;
            result.TimeMTNSec     = state.TimeMTNSec;
            result.LEDIDELRate    = (int?)state.LEDIDELRate;
            result.KW1            = state.KW1;
            result.KW2            = state.KW2;
            result.KW3            = state.KW3;
            return(result);
        }