public override object ProcessHandel(X1ReceiveObj receviceObj)
 {
     if (string.Equals(receviceObj.header.@namespace, "AliGenie.Iot.Device.Query", StringComparison.OrdinalIgnoreCase))
     {
         return(null);
     }
     else
     {
         if (nextHandle != null)
         {
             return(nextHandle.ProcessHandel(receviceObj));
         }
         else
         {
             return(null);
         }
     }
 }
Example #2
0
 public override object ProcessHandel(X1ReceiveObj receviceObj)
 {
     /*
      * {"header":{"namespace":"AliGenie.Iot.Device.Control","name":"TurnOn","payLoadVersion":1,"messageId":"e64170d7-d064-4972-bcee-c4fd8cd032f8"},"payload":{"accessToken":"m3rj-r06xPyLLda55Ze-lPP3YkDZBJcwdKm4DWiHeaq4PYS7jCF3-TpLNbDXwZpdX3xOMlN8KI5nouiA8bUp-SL5tkIypiBCiOgJ80Uyagqdx_Y8A6drdqJL42rao1q0eeuVZgxHC0GidnevjaSTkI1T6rpAiB_uo4u__YB5p893HDQiEduNj6HkqVQ7vwerPeSKdp9Mx4LdjGU6U6QeJfC11D47slu41r1R42Ce3yQ","deviceId":"000b57fffed27bac11","deviceType":"switch","attribute":"powerstate","value":"on","extensions":null}}
      */
     if (string.Equals(receviceObj.header.@namespace, "AliGenie.Iot.Device.Control", StringComparison.OrdinalIgnoreCase))
     {
         return(new DevControl().DealDevControl(receviceObj));
     }
     else
     {
         if (nextHandle != null)
         {
             return(nextHandle.ProcessHandel(receviceObj));
         }
         else
         {
             return(null);
         }
     }
 }
Example #3
0
        /// <summary>
        /// 天猫指令入口
        /// </summary>
        /// <param name="receiveObj"></param>
        /// <returns></returns>
        public async Task <ActionResult> TestReceive([FromBody] X1ReceiveObj receiveObj)
        {
            ToolHelper.FunctionHelper.writeLog("receiveObj", JsonConvert.SerializeObject(receiveObj), "TestReceive");
            object res = null;

            //直接来判断具体应该怎么操作,不走原来的流程。。

            if ([email protected]("AliGenie.Iot.Device.Discovery"))
            {//查询设备列表
                res = new DevDiscover().DiscoverDev(receiveObj);
            }
            else
            { //控制设备
                await Task.Run(() => {
                    res = new DevControl().DealDevControl(receiveObj);
                    ToolHelper.FunctionHelper.writeLog("success", JsonConvert.SerializeObject(res), "TestReceive");
                });
            }


            return(Content(JsonConvert.SerializeObject(res), "application/json"));
        }
Example #4
0
        public object DealDevControl(X1ReceiveObj receviceObj)
        {
            var    cacheModel = CacheData.GetAccessTokenCache(receviceObj.payload.accessToken);
            string hostId     = cacheModel.HostId;// CloudApi.Providers.OpenAuthorizationCodeProvider.GetHostIdByTicket(receviceObj.payload.accessToken);


            if (string.IsNullOrEmpty(hostId))
            {
                X1ReturnDeviceControlPayload tempRes = new X1ReturnDeviceControlPayload();

                tempRes.header       = receviceObj.header;
                tempRes.header.name += "Response";

                tempRes.payload = new X1ReturnDeviceOperErrorPayload()
                {
                    deviceId = receviceObj.payload.deviceId, errorCode = "ACCESS_TOKEN_INVALIDATE", message = "access_token is invalidate"
                };

                return(tempRes);
            }

            DeviceHandleThread.DeviceOperQueue.Enqueue(receviceObj);

            var res = new X1ReturnDeviceControlPayload()
            {
                header  = receviceObj.header,
                payload = new X1ReturnDeviceOperSuccesspPayload()
                {
                    deviceId = receviceObj.payload.deviceId
                }
            };

            res.header.name += "Response";

            return(res);
        }
Example #5
0
 public DealHead(X1ReceiveObj receiveObj)
 {
     ReceiveObj = receiveObj;
 }
Example #6
0
        public object DiscoverDev(X1ReceiveObj receiveObj)
        {
            X1ReturnDeviceDiscoverModel res = new X1ReturnDeviceDiscoverModel();

            res.header       = receiveObj.header;
            res.header.name += "Response";
            res.payload      = new DeviceDiscoverPayload();
            var devices = new List <X1ReturnDeviceModel>();



            var cacheModel = CacheData.GetAccessTokenCache(receiveObj.payload.accessToken);


            string hostId = cacheModel.HostId;


            if (string.IsNullOrEmpty(hostId))
            {
                X1ReturnDeviceOperErrorPayload payload = new X1ReturnDeviceOperErrorPayload()
                {
                    errorCode = "ACCESS_TOKEN_INVALIDATE",
                    message   = "access_token is invalidate"
                };

                res.payload = payload;
                return(res);
            }


            string tempIcoUrl = System.Configuration.ConfigurationManager.AppSettings["serverUrl"];


            var hostType = cacheModel.ClientId;

            if (!string.IsNullOrEmpty(hostType))
            {
                tempIcoUrl += "/" + hostType + "_ico.ico";
            }
            else
            {
                tempIcoUrl += "/yourIco.ico";
            }



            string resultStr = string.Empty;


            try
            {
                /*
                 * 获取设备列表具体代码位置
                 * 获取完之后,自行处理成天猫协议对应的类
                 */
                devices = new List <X1ReturnDeviceModel>();
            }
            catch (NullReferenceException ex)
            {
                FunctionHelper.writeLog("GetDevice error:", ex.Message + "   " + ex.StackTrace, "DeviceDiscoverHandleError");
            }
            catch (Exception ex)
            {
                try
                {
                    devices = GetDevListFromCache(hostId);
                }
                catch (Exception)
                {
                    FunctionHelper.writeLog("GetDevice error:", ex.Message + "   " + ex.StackTrace, "DeviceDiscoverHandleError");
                }
            }
            res.payload = new { devices = devices };

            return(res);
        }
Example #7
0
 public abstract object ProcessHandel(X1ReceiveObj receviceObj);