Exemplo n.º 1
0
        /// <summary>
        /// 查询平台中设备,并保存到数据库中
        /// </summary>
        /// <param name="buildID">区域编码</param>
        /// <param name="queryDevicesMode">设备信息</param>
        /// <returns></returns>
        public static int SaveDevices(string buildID, QueryDevicesMode queryDevicesMode)
        {
            int reslut = 0;

            foreach (var item in queryDevicesMode.devices)
            {
                //数据插入表:T_DC_DevicesInfo
                string SQLString = @"IF EXISTS (SELECT 1 FROM T_DC_DevicesInfo WHERE F_DeviceId= '" + item.deviceId + @"') 
                                            UPDATE T_DC_DevicesInfo SET F_GatewayId = '" + item.gatewayId + @"', F_NodeType = '" + item.nodeType +
                                   @"', F_LastModifiedTime = '" + item.lastModifiedTime + @"', F_NodeId = '" + item.deviceInfo.nodeId +
                                   @"', F_Description = '" + item.deviceInfo.description + @"', F_ManufacturerName = '" + item.deviceInfo.manufacturerName +
                                   @"', F_Mac = '" + item.deviceInfo.mac + @"', F_DeviceType = '" + item.deviceInfo.deviceType +
                                   @"', F_ProtocolType = '" + item.deviceInfo.protocolType + @"', F_Status = '" + item.deviceInfo.status +
                                   @"' WHERE F_DeviceId = '" + item.deviceId + @"'
                                        ELSE
                                            INSERT INTO T_DC_DevicesInfo
                                            (F_BuildID, F_DeviceId, F_GatewayId, F_NodeType, F_CreateTime, F_LastModifiedTime, F_NodeId, F_Name, 
                                             F_Description, F_ManufacturerId, F_ManufacturerName, F_Mac, F_DeviceType, F_Model, F_ProtocolType, F_Status  ) VALUES
                                               ( '" + buildID + @"','" + item.deviceId + @"','" + item.gatewayId + @"','" + item.nodeType + @"','" + item.createTime +
                                   @"','" + item.lastModifiedTime + @"','" + item.deviceInfo.nodeId + @"','" + item.deviceInfo.name + @"','" + item.deviceInfo.description +
                                   @"','" + item.deviceInfo.manufacturerId + @"','" + item.deviceInfo.manufacturerName + @"','" + item.deviceInfo.mac + @"','" + item.deviceInfo.deviceType +
                                   @"','" + item.deviceInfo.model + @"','" + item.deviceInfo.protocolType + @"','" + item.deviceInfo.status +
                                   @"')";

                reslut = reslut + SQLHelper.ExecuteSql(SQLString);
            }
            return(reslut);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 定时查询刷新Token
        /// </summary>
        public static void getNewTokenFromAPI()
        {
            int loginNGCount = 0;

            while (Runtime.m_IsRefreshToken)
            {
                try
                {
                    // 调用封装北向接口的功能 API
                    if (AuthenticationServer.Login())
                    {
                        loginNGCount = 0;
                        LogHelper.log.Info("*** 刷新 Token成功 *** accessToken:" + AuthenticationServer.Auth.AccessToken);
                        Runtime.ShowLog("*** 刷新 Token成功 ***");


                        long pageNo   = 0;
                        long pageSize = 50;
                        //获取当天0时0分0秒UTC时间(当天0时0分0秒),
                        DateTime utcNow      = DateTime.UtcNow.AddHours(-DateTime.UtcNow.Hour).AddMinutes(-DateTime.UtcNow.Minute).AddSeconds(-DateTime.UtcNow.Second);
                        string   QueryResult = DataCollectionServer.QueryDevice(pageNo, pageSize, utcNow.ToString("yyyyMMddTHHmmssZ"));

                        JObject          jObj         = JObject.Parse(QueryResult);
                        QueryDevicesMode queryDevices = new QueryDevicesMode();
                        queryDevices = Newtonsoft.Json.JsonConvert.DeserializeObject <QueryDevicesMode>(QueryResult);
                        LogHelper.log.Info("查询当前平台中设备返回内容:" + jObj.ToString());
                        //Runtime.ShowLog("查询当前平台中设备:" + jObj.ToString());
                        if (queryDevices.totalCount > 0)
                        {
                            int reslut = DataCollectionDAL.SaveDevices(queryDevices);
                            LogHelper.log.Info(" 查询到的设备 存入数据库,总共:" + reslut + "设备");
                            Runtime.ShowLog(" 查询到的设备 存入数据库,总共:" + reslut + "设备");
                        }

                        //间隔20分钟刷新一次Token
                        System.Threading.Thread.Sleep(1200000);
                    }
                    else
                    {
                        Runtime.ShowLog("!!!刷新 Token失败失败 !!!,准备再次尝试登录...");
                        LogHelper.log.Error("!!! 刷新 Token失败失败 !!!,准备再次尝试登录...");
                        //登录失败,则1分钟刷新一次Token
                        System.Threading.Thread.Sleep(60000);
                    }



                    continue;
                }
                catch (Exception ex)
                {
                    Runtime.ShowLog("!!! 刷新 Token失败失败 !!!,准备再次尝试登录...  详细:" + ex.Message);
                    LogHelper.log.Error("!!! 刷新 Token失败失败 !!!,准备再次尝试登录...  详细:" + ex.Message);
                    System.Threading.Thread.Sleep(30000);
                    continue;
                }
            }
        }