From 4e343aa2d3bba9e1dc5519afa2564a230c556496 Mon Sep 17 00:00:00 2001
From: 陈嘉乐 <cjl@hdlchina.com.cn>
Date: 星期五, 05 二月 2021 15:13:14 +0800
Subject: [PATCH] 2021-2-5-1

---
 Crabtree/SmartHome/UI/SimpleControl/Phone/Schedule/Send.cs |  209 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 209 insertions(+), 0 deletions(-)

diff --git a/Crabtree/SmartHome/UI/SimpleControl/Phone/Schedule/Send.cs b/Crabtree/SmartHome/UI/SimpleControl/Phone/Schedule/Send.cs
new file mode 100644
index 0000000..52da91d
--- /dev/null
+++ b/Crabtree/SmartHome/UI/SimpleControl/Phone/Schedule/Send.cs
@@ -0,0 +1,209 @@
+锘縰sing System;
+using System.Collections.Generic;
+using Newtonsoft.Json.Linq;
+using Shared;
+using Shared.SimpleControl.R;
+
+namespace SmartHome
+{
+    public class Send
+    {
+        #region 璁℃椂鍣ㄧ殑鍛戒护鏂规硶
+        /// <summary>
+        /// 鑾峰彇璁℃椂鍣ㄥ垪琛�
+        /// </summary>
+        /// <returns></returns>
+        public static ResponsePackNew GetTimerList ()
+        {
+            var jObject = new JObject { }; 
+            jObject.Add ("gatewayId", Int64.Parse (GatewayId));
+            jObject.Add ("homeId", Int64.Parse (HomeId));
+            var responsePackNew = RequestServerhomeId (jObject, API.GetTimerList);
+            return responsePackNew;
+        }
+        /// <summary>
+        /// 娣诲姞璁℃椂鍣ㄥ懡浠� 
+        /// </summary>
+        /// <param name="timer"></param>
+        /// <returns></returns>
+        public static ResponsePackNew AddTimer (Timer timer) 
+        {
+            ResponsePackNew responsePackNew = null;
+            try {
+                var jArray = new JArray { };
+                foreach (var dic in timer.whichDay) {
+                    jArray.Add (dic);
+                }
+
+                var deviceDateJObject = new JObject { };
+                deviceDateJObject.Add ("gatewayId", Int64.Parse (GatewayId));
+                deviceDateJObject.Add ("homeId", Int64.Parse (HomeId));
+                var funjArray = new JArray { };
+                for (int i = 0; i < timer.controlData.actions.Count; i++) {
+                    var fun = timer.controlData.actions [i];
+                    var funJObject = new JObject { };
+                    funJObject.Add ("deviceId", fun.deviceId);
+                    funJObject.Add ("spk", fun.spk);
+
+                    var attributesJArray = new JArray { };
+                    for (int i1 = 0; i1 < fun.attributes.Count; i1++) {
+                        var attributes = fun.attributes [i1];
+                        var attributesJObject = new JObject { };
+                        attributesJObject.Add ("key", attributes.key);
+                        attributesJObject.Add ("value", attributes.value);
+                        attributesJArray.Add (attributesJObject);
+                    }
+                    funJObject.Add ("attributes", attributesJArray);
+
+                    var busJObject = new JObject { };
+                    busJObject.Add ("addresses", fun.bus.addresses);
+                    busJObject.Add ("loopId", fun.bus.loopId);
+                    funJObject.Add ("bus", busJObject);
+                    funjArray.Add (funJObject);
+                }
+                deviceDateJObject.Add ("actions", funjArray);
+                
+                var jObject = new JObject { };
+                jObject.Add ("gatewayId", Int64.Parse (GatewayId)); 
+                jObject.Add ("homeId", Int64.Parse (HomeId));
+                jObject.Add ("timerName", timer.timerName);
+                jObject.Add ("isEnable", timer.isEnable);
+                jObject.Add ("executeUtcTime", Method.GetUtcTime (timer.executeUtcTime));
+                jObject.Add ("controlData", deviceDateJObject);
+                jObject.Add ("timerType", timer.timerType.GetHashCode());
+                jObject.Add ("whichDay", jArray);
+                responsePackNew = RequestServerhomeId (jObject, API.AddTimer);
+              
+            } catch (Exception e) {
+                var dd = e.Message;
+            }
+            return responsePackNew;
+        }
+        /// <summary>
+        /// 缂栬緫鏇存柊
+        /// </summary>
+        /// <param name="timer"></param>
+        /// <returns></returns>
+        public static ResponsePackNew UpdateTimer (Timer timer)
+        {
+            ResponsePackNew responsePackNew = null;
+            try {
+                var jArray = new JArray { };
+                foreach (var dic in timer.whichDay) {
+                    jArray.Add (dic);
+                }
+
+                var deviceDateJObject = new JObject { };
+                deviceDateJObject.Add ("gatewayId", Int64.Parse (GatewayId));
+                deviceDateJObject.Add ("homeId", Int64.Parse (HomeId));
+                var funjArray = new JArray { };
+                for (int i = 0; i < timer.controlData.actions.Count; i++) {
+                    var fun = timer.controlData.actions [i];
+                    var funJObject = new JObject { };
+                    funJObject.Add ("deviceId", fun.deviceId);
+                    funJObject.Add ("spk", fun.spk);
+
+                    var attributesJArray = new JArray { };
+                    for (int i1 = 0; i1 < fun.attributes.Count; i1++) {
+                        var attributes = fun.attributes [i1];
+                        var attributesJObject = new JObject { };
+                        attributesJObject.Add ("key", attributes.key);
+                        attributesJObject.Add ("value", attributes.value);
+                        attributesJArray.Add (attributesJObject);
+                    }
+                    funJObject.Add ("attributes", attributesJArray);
+
+                    var busJObject = new JObject { };
+                    busJObject.Add ("addresses", fun.bus.addresses);
+                    busJObject.Add ("loopId", fun.bus.loopId);
+                    funJObject.Add ("bus", busJObject);
+                    funjArray.Add (funJObject);
+                }
+                deviceDateJObject.Add ("actions", funjArray);
+
+                var jObject = new JObject { };
+                jObject.Add ("gatewayId", Int64.Parse (GatewayId));
+                jObject.Add ("homeId", Int64.Parse (HomeId));
+                jObject.Add ("id", timer.id);
+                jObject.Add ("timerName", timer.timerName);
+                jObject.Add ("isEnable", timer.isEnable);
+                jObject.Add ("executeUtcTime", Method.GetUtcTime (timer.executeUtcTime));
+                jObject.Add ("controlData", deviceDateJObject);
+                jObject.Add ("timerType", timer.timerType.GetHashCode ());
+                jObject.Add ("whichDay", jArray);
+                responsePackNew = RequestServerhomeId (jObject, API.EditTimer);
+
+            } catch (Exception e) {
+                var dd = e.Message;
+            }
+            return responsePackNew;
+        }
+        /// <summary>
+        /// 鍒犻櫎
+        /// </summary>
+        /// <returns></returns>
+        public static ResponsePackNew DelTimer (string id)
+        {
+            var jObject = new JObject { };
+            jObject.Add ("id", Int64.Parse (id));
+            jObject.Add ("gatewayId", Int64.Parse (GatewayId));
+            jObject.Add ("homeId", Int64.Parse (HomeId));
+            var responsePackNew = RequestServerhomeId (jObject, API.DeleteTimer);
+            return responsePackNew;
+        }
+        /// <summary> 
+        /// 寮�鍏�
+        /// </summary>
+        /// <returns></returns>
+        public static ResponsePackNew SwitchTimer (Timer timer)
+        {
+           
+            var jObject = new JObject { };
+            jObject.Add ("id", timer.id);
+            jObject.Add ("gatewayId", Int64.Parse (GatewayId));
+            jObject.Add ("homeId", Int64.Parse (HomeId));
+            var responsePackNew = RequestServerhomeId (jObject, API.IsEnableTimer);
+            return responsePackNew;
+        }
+        #endregion
+        /// <summary>
+        /// 缃戝叧ID
+        /// </summary>
+        public static string GatewayId {
+            get {
+                return UserConfig.Instance.HomeGateway.gatewayId;
+            }
+        }
+        /// <summary>
+        /// 浣忓畢ID
+        /// </summary>
+        public static string HomeId {
+            get {
+                return UserConfig.Instance.CurrentRegion.Id;
+            }
+        }
+      
+        /// <summary>
+        ///璇锋眰鏈嶅姟鍣紙涓庝綇瀹呮湁鍏�:渚嬪锛沨omeId锛� 
+        /// </summary>
+        /// <returns></returns>
+        public static ResponsePackNew RequestServerhomeId (object o, string api_Url, int mTimeout = 3)
+        {
+            var requestJson = HttpUtil.GetSignRequestJson (o);
+            return HttpUtil.RequestHttpsPostFroHome (api_Url, requestJson, mTimeout);
+
+        }
+        /// <summary>
+        /// 璇锋眰鏈嶅姟鍣�
+        /// </summary>
+        /// <returns></returns>
+        public static ResponsePackNew RequestServer (object o, string api_Url)
+        {
+            var requestJson = HttpUtil.GetSignRequestJson (o);
+            return HttpUtil.RequestHttpsPost (api_Url, requestJson);
+
+        }
+        
+
+    }
+}

--
Gitblit v1.8.0