wxr
2020-03-13 171bf03f3664226eeff2b20ee9bd2e914b63a17d
HDL_ON/DAL/Net/CommonPage.cs
@@ -15,7 +15,8 @@
        public static Action RefreshAir;
        public static string FindGatewayChilrenIPAddress = new NetWiFi ().BroadcastIpAddress.ToString ();
        private static string ip = "0.0.0.0";
        public static System.Net.IPEndPoint EndPoint {
        public static System.Net.IPEndPoint EndPoint
        {
            get
            {
                try
@@ -32,7 +33,8 @@
        ///保存设备备注才用gb2312,其他情况用utf8
        public static Encoding MyEncodingUTF8 = Encoding.UTF8;//Get
        public static Encoding MyEncodingGB2312 {
        public static Encoding MyEncodingGB2312
        {
            get
            {
                try
@@ -59,7 +61,8 @@
        //public static byte currentSubnetID = 0;
        public static void InitHttpListener ()
        {
            if (isHttpListenerStart) {
            if (isHttpListenerStart)
            {
                return;
            }
            HttpListener.Start (new NetWiFi ().IpAddress, 6001);
@@ -99,7 +102,7 @@
                {
                    case Command.ReadLightSingleLoopBrightnessACK:
                    case Command.SetSingleLightACK:
                        foreach (var function in DB_ResidenceData.residenceData.functions.lights)
                        foreach (var function in DB_ResidenceData.residenceData.functionList.lights)
                        {
                            if (function.GetBusId() == subnetID + "_" + deviceID + "_" + receiveBytes[0])
                            {
@@ -119,7 +122,6 @@
                                        var relay = function as Light;
                                        relay.state = receiveBytes[2] == 0 ? 0 : 1;
                                        HomePage.UpdataLightView(relay);
                                        //RoomPage.
                                    }
                                    else if (function.functionType == "brightness")
                                    {
@@ -137,7 +139,8 @@
                        break;
                }
            }
            catch (Exception ex) {
            catch (Exception ex)
            {
                MainPage.Log($"Bus Rev Erorr : {ex.Message}");
            }
        }
@@ -149,7 +152,8 @@
        public static string byteToHex16 (byte b)
        {
            string s = Convert.ToString (b, 16).ToUpper (); 
            if (s.Length <= 1) {
            if (s.Length <= 1)
            {
                return "0" + s;
            }
            return s;//
@@ -157,16 +161,22 @@
        static void httpListener_EventHandler (System.Collections.Specialized.NameValueCollection nameValueCollection, System.IO.Stream outputStream, System.IO.Stream inputStream)
        {
            try {
                if (nameValueCollection ["Command"] != null && nameValueCollection ["Command"].StartsWith ("Get")) {
            try
            {
                if (nameValueCollection["Command"] != null && nameValueCollection["Command"].StartsWith("Get"))
                {
                    string tempFileName = nameValueCollection ["Command"].Replace ("Get", "");
                    if ("AllFiles" == tempFileName) {
                    if ("AllFiles" == tempFileName)
                    {
                        byte [] bytes = System.Text.Encoding.UTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (FileUtils.ReadFiles ()));
                        outputStream.Write (bytes, 0, bytes.Length);
                        outputStream.Flush ();
                    } else {
                    }
                    else
                    {
                        byte [] bytes;
                        if (!FileUtils.Exists (tempFileName)) {
                        if (!FileUtils.Exists(tempFileName))
                        {
                            bytes = System.Text.Encoding.UTF8.GetBytes ("文件名不存在!");
                            outputStream.Write (bytes, 0, bytes.Length);
                            outputStream.Flush ();
@@ -179,15 +189,21 @@
                        outputStream.Write (bytes, 0, bytes.Length);
                        outputStream.Flush ();
                    }
                } else if (nameValueCollection ["Command"].StartsWith ("Upload")) {
                }
                else if (nameValueCollection["Command"].StartsWith("Upload"))
                {
                    string path = Application.RootPath + nameValueCollection ["Command"].Replace ("Upload", "");
                    string dePath = nameValueCollection ["Command"].Replace ("Upload", "");
                } else {
                }
                else
                {
                    byte [] bytes = System.Text.Encoding.UTF8.GetBytes ("请求命令无效!");
                    outputStream.Write (bytes, 0, bytes.Length);
                    outputStream.Flush ();
                }
            } catch (Exception ex) {
            }
            catch (Exception ex)
            {
                MainPage.Log ("httpListener_EventHandler" + ex.ToString ());
            }
        }
@@ -198,19 +214,25 @@
        public static int Port = 5555;
        static void httpListener_EventHandler (string rawUrl, System.IO.Stream outputStream, System.IO.Stream inputStream)
        {
            foreach (var musicInfo in MusicInfo.MusicInfoList) {
                if ("audio-item-" + musicInfo.ID == rawUrl.TrimStart ('/')) {
            foreach (var musicInfo in MusicInfo.MusicInfoList)
            {
                if ("audio-item-" + musicInfo.ID == rawUrl.TrimStart('/'))
                {
                    var file = new System.IO.FileStream (musicInfo.Data, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                    byte [] bytes = new byte [1024];
                    try {
                        while (file.CanRead) {
                    try
                    {
                        while (file.CanRead)
                        {
                            int len = file.Read (bytes, 0, bytes.Length);
                            if (len == 0) {
                            if (len == 0)
                            {
                                break;
                            }
                            outputStream.Write (bytes, 0, len);
                        }
                    } catch { }
                    }
                    catch { }
                    file.Close ();
                    break;
                }