// 系统参数设置 public static void SetSystemSettingParaService(CmsSystemSetting obj) { var channel = new Channel(GrpcChannelAddress, ChannelCredentials.Insecure); var client = new gRPCClient(channel); foreach (PropertyInfo p in obj.GetType().GetProperties()) { object value = p.GetValue(obj); // 处理是否 if (value != null && p.PropertyType == typeof(string)) { if (value.ToString().Equals("是")) { value = 1; } else if (value.ToString().Equals("否")) { value = 0; } SystemPara systemPara = new SystemPara(); systemPara.ParaName = p.Name; systemPara.ParaValue = value.ToString(); ControlResult result = client.setSystemSettingPara(systemPara); // 日志输出 if (result.Result.Equals("1")) { log.Info($"参数设置成功:{systemPara.ParaName},{systemPara.ParaValue}"); } else { log.Info($"参数设置失败:{systemPara.ParaName},{systemPara.ParaValue}"); } } } }
// 设备指令发送 public static ControlResult DeviceControlService(ControlModel model) { ControlResult result = new ControlResult(); var channel = new Channel(GrpcChannelAddress, ChannelCredentials.Insecure); var client = new gRPCClient(channel); switch (model.Name) { case "TurnOnLoopValve01": result = client.TurnOnLoopValve01(model.WriteCommand); break; case "TurnOffLoopValve01": result = client.TurnOffLoopValve01(model.WriteCommand); break; case "TurnOnLoopValve02": result = client.TurnOnLoopValve02(model.WriteCommand); break; case "TurnOffLoopValve02": result = client.TurnOffLoopValve02(model.WriteCommand); break; case "TurnOnOutValve01": result = client.TurnOnOutValve01(model.WriteCommand); break; case "TurnOffOutValve01": result = client.TurnOffOutValve01(model.WriteCommand); break; case "TurnOnOutValve02": result = client.TurnOnOutValve02(model.WriteCommand); break; case "TurnOffOutValve02": result = client.TurnOffOutValve02(model.WriteCommand); break; case "TurnOnPump01": result = client.TurnOnPump01(model.WriteCommand); break; case "TurnOffPump01": result = client.TurnOffPump01(model.WriteCommand); break; case "TurnOnPump02": result = client.TurnOnPump02(model.WriteCommand); break; case "TurnOffPump02": result = client.TurnOffPump02(model.WriteCommand); break; case "OperateDevice": result = client.OperateDevice(model.WriteCommand); break; default: break; } return(result); }