Ejemplo n.º 1
0
        public object ModifyDtuRemoteConfigRequest([FromUri] int dtuId, [FromBody] DtuConfig dtuConfig)
        {
            // ET通信
            ILog log = LogManager.GetLogger("DtuRemoteConfig");

            log.DebugFormat("Instant DTU remote config: DTU={0}, dtuConfig={1}", dtuId, dtuConfig);
            // 设置消息头
            Guid            guid   = Guid.NewGuid();
            FsMessageHeader header = new FsMessageHeader
            {
                S = "WebClient",
                A = "GET",
                R = "/et/dtu/instant/at", // request url.
                U = guid,
                T = Guid.NewGuid()
            };
            // 设置部分消息体
            RemoteConfig rc = new RemoteConfig
            {
                Count        = 2,
                Ip1          = dtuConfig.Ip,
                Port1        = dtuConfig.Port,
                Ip2          = dtuConfig.Ip2,
                Port2        = dtuConfig.Port2,
                Mode         = dtuConfig.DtuMode.ToUpper(),
                ByteInterval = dtuConfig.PacketInterval,
                Retry        = dtuConfig.ReconnectionCount
            };
            List <CommandConfig> listCmd = RemoteConfigService.GetCommand(rc);

            FsMessage msg = new FsMessage
            {
                Header = header,
                Body   = new { dtuId, cmds = listCmd }
            };

            // return msg.Body;
            WebClientService.SendToET(msg); // 向ET Push DTU远程配置消息

            using (var entity = new SecureCloud_Entities())
            {
                var strGuid = guid.ToString();
                var query   = from ti in entity.T_TASK_INSTANT
                              where ti.MSG_ID == strGuid
                              select new
                {
                    msgid = ti.MSG_ID
                };
                var result = true;
                var list   = query.ToList();
                if (list.Count == 0)
                {
                    result = false;
                }
                var json = new JObject(
                    new JProperty("msgid", guid),
                    new JProperty("result", result));
                return(json);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 更新DTU远程配置
        /// </summary>
        /// <param name="dtuEntity"></param>
        /// <param name="jObj"></param>
        /// <param name="dtuConfig"></param>
        public static void UpdateDtuConfig(T_DIM_REMOTE_DTU dtuEntity, JObject jObj, DtuConfig dtuConfig)
        {
            // JToken tokenDtuId = jObj["dtuId"];
            var cmds = from cmd in jObj["cmds"].Children()
                       select new { cmd = (string)cmd["cmd"], result = (string)cmd["result"] };

            foreach (var cmd in cmds)
            {
                switch (cmd.cmd)
                {
                case "setCount":
                    if (cmd.result != "OK")
                    {
                        return;
                    }
                    break;

                case "setIP1":
                    if (cmd.result == "OK" && dtuConfig.Ip != default(string) && dtuConfig.Ip != dtuEntity.DTU_IP)
                    {
                        dtuEntity.DTU_IP = dtuConfig.Ip;
                    }
                    break;

                case "setPort1":
                    if (cmd.result == "OK" && dtuConfig.Port != default(int?) && dtuConfig.Port != dtuEntity.DTU_PORT)
                    {
                        dtuEntity.DTU_PORT = dtuConfig.Port;
                    }
                    break;

                case "setIP2":
                    if (cmd.result == "OK" && dtuConfig.Ip2 != default(string) && dtuConfig.Ip2 != dtuEntity.DtuIp2)
                    {
                        dtuEntity.DtuIp2 = dtuConfig.Ip2;
                    }
                    break;

                case "setPort2":
                    if (cmd.result == "OK" && dtuConfig.Port2 != default(int?) && dtuConfig.Port2 != dtuEntity.DtuPort2)
                    {
                        dtuEntity.DtuPort2 = dtuConfig.Port2;
                    }
                    break;

                case "setMode":
                    if (cmd.result == "OK" && dtuConfig.DtuMode != default(string) && dtuConfig.DtuMode.ToUpper() != dtuEntity.DtuMode)
                    {
                        dtuEntity.DtuMode = dtuConfig.DtuMode.ToUpper();
                    }
                    break;

                case "setByteInterval":
                    if (cmd.result == "OK" && dtuConfig.PacketInterval != default(int?) && dtuConfig.PacketInterval != dtuEntity.PacketInterval)
                    {
                        dtuEntity.PacketInterval = dtuConfig.PacketInterval;
                    }
                    break;

                case "setRetry":
                    if (cmd.result == "OK" && dtuConfig.ReconnectionCount != default(int?) && dtuConfig.ReconnectionCount != dtuEntity.ReconnectionCount)
                    {
                        dtuEntity.ReconnectionCount = dtuConfig.ReconnectionCount;
                    }
                    break;

                default:
                    break;
                }
            }
        }
Ejemplo n.º 3
0
        public object ModifyDtuRemoteConfig([FromUri] string messageId, [FromUri] int dtuId, [FromBody] DtuConfig dtuConfig)
        {
            // 查询 T_TASK_INSTANT 表获取数据:
            using (var entity = new SecureCloud_Entities())
            {
                var dtuEntity = entity.T_DIM_REMOTE_DTU.FirstOrDefault(d => d.ID == dtuId);
                if (dtuEntity == null || dtuEntity.REMOTE_DTU_STATE == false)
                {
                    return(ConstructJobject(dtuId, "DTU不存在或已禁用", HttpStatusCode.BadRequest));
                }

                var query = from ti in entity.T_TASK_INSTANT
                            where ti.MSG_ID == messageId
                            select new
                {
                    dtuId  = ti.DTU_ID,
                    data   = ti.RESULT_JSON,
                    time   = ti.FINISHED,
                    status = ti.RESULT_MSG
                };
                var list = query.ToList();
                if (list.Count == 0)
                {
                    return(null); // 200: OK
                }
                if (list.Select(s => s.dtuId).FirstOrDefault() != dtuId)
                {
                    return(ConstructJobject(dtuId, "任务中DTU和当前DTU不匹配", HttpStatusCode.BadRequest));
                }

                var strData = list.Select(s => s.data).FirstOrDefault();
                if (strData == null || strData.Trim() == "")
                {
                    return(list.Select(s => new { result = JsonConvert.DeserializeObject(""), s.time, s.status }).FirstOrDefault());
                }

                JObject jObj = list.Select(s => JObject.Parse(s.data)).FirstOrDefault();
                DtuConfig.UpdateDtuConfig(dtuEntity, jObj, dtuConfig);

                #region 日志信息

                this.Request.Properties["ActionParameter"] = JsonConvert.SerializeObject(dtuConfig);

                var dtuNo = entity.T_DIM_REMOTE_DTU.Where(w => w.ID == dtuId).Select(s => s.REMOTE_DTU_NUMBER).FirstOrDefault();
                this.Request.Properties["ActionParameterShow"] =
                    string.Format("DTU编号:{0},主中心ip:{1},主中心端口:{2},副中心2ip:{3},副中心2端口:{4}," +
                                  "DTU工作模式:{5},封包间隔时间:{6},重连次数:{7}",
                                  dtuNo,
                                  dtuConfig.Ip ?? string.Empty,
                                  dtuConfig.Port,
                                  dtuConfig.Ip2 ?? string.Empty,
                                  dtuConfig.Port2,
                                  string.IsNullOrEmpty(dtuConfig.DtuMode) ? string.Empty : dtuConfig.DtuMode,
                                  dtuConfig.PacketInterval,
                                  dtuConfig.ReconnectionCount
                                  );

                #endregion

                try
                {
                    entity.SaveChanges();
                    return(list.Select(s => new { result = JsonConvert.DeserializeObject(s.data), s.time, s.status }).FirstOrDefault());
                }
                catch (Exception ex)
                {
                    return(ConstructJobject(dtuId, "DTU信息修改失败", HttpStatusCode.BadRequest));
                }
            }
        }