JLChen
2020-06-04 6d55af8792cf8fbef0055e677b900fc352dba9a2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
using System;
using System.Collections.Generic;
using System.Text;
using Shared;
using Shared.SimpleControl.R;
using System.Xml;
using Shared.SimpleControl.Phone;
using Shared.SimpleControl;
 
namespace SmartHome.UI.SimpleControl.Phone.Music
{
    class A31UserLogin : FrameLayout
    {
        /// <summary>
        /// 用户名
        /// </summary>
        EditText username;
        /// <summary>
        /// 密码
        /// </summary>
        EditText password;
        A31MusicModel currentMusiceA31;
        public void show (A31MusicModel a31, string TextUserName, string TextPasswrod)
        {
            currentMusiceA31 = a31;
            AddChidren (new Button {
                Height = Application.GetRealHeight (36),
                BackgroundColor = SkinStyle.Current.MusicTopFrameLayout,
            });
 
            var topFrameLayout = new FrameLayout {
                Height = Application.GetRealHeight (100),
                Y = Application.GetRealHeight (36),
                BackgroundColor = SkinStyle.Current.MusicTopFrameLayout,
            };
            AddChidren (topFrameLayout);
 
            var RadiolistName = new Button {
                TextID = MyInternationalizationString.PANDORA,
                TextColor = SkinStyle.Current.MusicTextColor,
            };
            topFrameLayout.AddChidren (RadiolistName);
 
            var hdl = new Button {
               Width = Application.GetRealWidth (154),
                Height = Application.GetRealHeight (90),
                X = Application.GetRealWidth (486),
                Gravity = Gravity.CenterVertical,
                UnSelectedImagePath = MainPage.LogoString,
            };
            topFrameLayout.AddChidren (hdl);
 
            var back = new Button {
                Width = Application.GetRealWidth (82),
                Height = Application.GetRealHeight (89),
                X = Application.GetRealWidth (10),
                Gravity = Gravity.CenterVertical,
                UnSelectedImagePath = "MusicIcon/HomepageBack.png",
            };
            topFrameLayout.AddChidren (back);
            back.MouseDownEventHandler += (sender, e) => {
                RemoveFromParent ();
            };
 
            var frameLayout = new FrameLayout {
                Height = Application.GetRealHeight (Application.DesignHeight - 136),
                Y = Application.GetRealHeight (136),
                //BackgroundColor = 0xff2F2F2F,
                BackgroundColor=SkinStyle.Current.MusicVerticalScrolViewLayout,
            };
            AddChidren (frameLayout);
 
            var tologin = new Button {
                Height = Application.GetRealHeight (100),
                TextID = MyInternationalizationString.Tologin,
                TextAlignment = TextAlignment.CenterLeft,
                X = Application.GetRealWidth (25),
                Y = Application.GetRealHeight (10),
                TextColor = SkinStyle.Current.MusicTextColor,
            };
            frameLayout.AddChidren (tologin);
 
            //用户名
            username = new EditText {
                Width = Application.GetRealWidth (590),
                Height = Application.GetRealHeight (80),
                X = Application.GetRealWidth (25),
                Y = Application.GetRealHeight (130),
                TextAlignment = TextAlignment.Center,
                Text = TextUserName,
                //Radius = (uint)Application.GetRealHeight(6),
                BackgroundColor =SkinStyle.Current.MusicEditTextBackgroundColor,
                PlaceholderText = Language.StringByID (MyInternationalizationString.Youremail),
                PlaceholderTextColor =SkinStyle.Current.MusicEditTextPlaceholderTextColor,
                TextColor = SkinStyle.Current.MusicTextColor,
                Radius=2,
                BorderWidth=2,
                BorderColor=SkinStyle.Current.MusicEditBorderColor,
            };
            frameLayout.AddChidren (username);
 
            //密码
            password = new EditText {
                Width = Application.GetRealWidth (590),
                Height = Application.GetRealHeight (80),
                X = Application.GetRealWidth (25),
                Y = Application.GetRealHeight (230),
                TextAlignment = TextAlignment.Center,
                Text = TextPasswrod,
                SecureTextEntry = true,
                //Radius = (uint)Application.GetRealHeight(6),
                BackgroundColor = SkinStyle.Current.MusicEditTextBackgroundColor,
                PlaceholderText = Language.StringByID (MyInternationalizationString.yourpassword),
                TextColor = SkinStyle.Current.MusicTextColor,
                Radius = 2,
                BorderWidth = 2,
                BorderColor = SkinStyle.Current.MusicEditBorderColor,
            };
            frameLayout.AddChidren (password);
 
            var notologin = new Button {
                Height = Application.GetRealHeight (100),
                TextID = MyInternationalizationString.Toregister,
                TextAlignment = TextAlignment.CenterLeft,
                X = Application.GetRealWidth (25),
                Y = Application.GetRealHeight (350),
                TextColor = SkinStyle.Current.MusicTextColor,
            };
            frameLayout.AddChidren (notologin);
 
            //登录
            var login = new Button {
                Width = Application.GetRealWidth (590),
                Height = Application.GetRealHeight (100),
                TextID = MyInternationalizationString.login,
                TextSize = 18,
                X = Application.GetRealWidth (25),
                Y = Application.GetRealHeight (450),
                BackgroundColor = 0xff656565,
                //Radius = (uint)Application.GetRealHeight(6),
            };
            frameLayout.AddChidren (login);
 
            login.MouseUpEventHandler += (sender, e) => {
                login.BackgroundColor = 0xff656565;
                if (username.Text.Trim () == "" || password.Text.Trim () == "") {
                    new Alert (Language.StringByID (MyInternationalizationString.Tip),
                              Language.StringByID (MyInternationalizationString.TipPleaseEnterTheCorrectData),
                              Language.StringByID (MyInternationalizationString.Close)).Show ();
                    return;
                }
                MainPage.Loading.Start ("Loging...");
 
                var tempusername = username.Text;
                var temppassword = password.Text;
 
                System.Threading.Tasks.Task.Run (() => {
                    try {
                        var dd = Login (tempusername, temppassword);
                        if (dd == null) {
                            return;
                        }
                        int number = 3;
                        System.DateTime dateTime = DateTime.Now;
                        while ((DateTime.Now - dateTime).TotalMilliseconds < 9 * 1000) {
                            System.Threading.Thread.Sleep (500);
                            var pandoraString = readList ();
                            if (pandoraString == null) {
                                continue;
                            }
                            pandoraString = pandoraString.Replace ("&amp;", "&").Replace ("&lt;", "<").Replace ("&gt;", ">").Replace ("&quot;", "\"").Replace ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", "").Replace ("&lt", "").Replace ("&gt", "").Replace ("&amp;", "").Replace ("&quot;", "");
                            int startIndex5 = pandoraString.IndexOf ("<PlayList>");
                            int endIndex = pandoraString.IndexOf ("</PlayList>") + "</PlayList>".Length;
                            if (endIndex <= startIndex5) {
                                continue;
                            }
                            var ss = pandoraString.Substring (startIndex5, endIndex - startIndex5);
                            XmlDocument xml = new XmlDocument ();
                            xml.LoadXml (ss);
 
                            var playList = xml.SelectSingleNode ("PlayList");
 
                            var listNameP = playList.SelectSingleNode ("ListName").InnerText;
 
                            var listInfo = playList.SelectSingleNode ("ListInfo");
 
                            number = int.Parse (listInfo.SelectSingleNode ("MarkSearch").InnerText);
                            if (number == 1) {
                                break;
                            }
                        }
                        if (number == 1) {
                            var pandoraListString = PandoraList ();
                            if (pandoraListString == null) {
                                return;
                            }
 
                            pandoraListString = pandoraListString.Replace ("&amp;", "&").Replace ("&lt;", "<").Replace ("&gt;", ">").Replace ("&quot;", "\"").Replace ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", "").Replace ("&lt", "").Replace ("&gt", "").Replace ("&amp;", "").Replace ("&quot;", "");
                            int startIndex1 = pandoraListString.IndexOf ("<PlayQueue>");
                            int endIndex1 = pandoraListString.IndexOf ("</PlayQueue>") + "</PlayQueue>".Length;
                            var aa = pandoraListString.Substring (startIndex1, endIndex1 - startIndex1);
                            if (endIndex1 <= startIndex1) {
                                return;
                            }
                            XmlDocument xml1 = new XmlDocument ();
                            xml1.LoadXml (aa);
                            var pandoraList = xml1.SelectSingleNode ("PlayQueue");
 
                            int number1 = int.Parse (pandoraList.SelectSingleNode ("TotalQueue").InnerText);
 
                            var playListInfo = pandoraList.SelectSingleNode ("PlayListInfo");
 
                            a31.PanRadioInfoList.Clear ();
                            for (int i = 1; i <= number1; i++) {
                                var list = playListInfo.SelectSingleNode ("List" + i);
 
                                MusicInfo musicInfo = new MusicInfo ();
                                musicInfo.Title = list.SelectSingleNode ("Name").InnerText;
                                var ListInfo = list.SelectSingleNode ("ListInfo");
 
                                foreach (XmlNode childNode in ListInfo.ChildNodes) {
                                    switch (childNode.Name) {
                                    case "SearchUrl":
                                        musicInfo.URL = childNode.InnerText;
                                        break;
                                    case "StationID":
                                        musicInfo.ID = childNode.InnerText;
                                        break;
                                    case "PicUrl":
                                        #region 初始化网络图片路径
                                        string path = "";
                                        if (Shared.Application.IsPad) {
                                            path = "Pad/" + "MusicImage/";
                                        } else {
                                            path = "Phone/" + "MusicImage/";
                                        }
                                        path = System.IO.Path.Combine (Shared.IO.FileUtils.RootPath, path + childNode.InnerText.Replace ('/', '_').Replace ('\\', '_').Replace (':', '_').Replace ('*', '_').Replace ('?', '_').Replace ('"', '_').Replace ('<', '_').Replace ('>', '_').Replace ('|', '_'));
                                        musicInfo.Image = path;
                                        #endregion
                                        Shared.IO.FileUtils.DownLoadImage (musicInfo.Image, childNode.InnerText);
                                        //musicInfo.Image = childNode.InnerText;
                                        break;
                                    }
                                }
                                if (musicInfo.ID == null) {
                                    continue;
                                }
                                currentMusiceA31.PanRadioInfoList.Add (musicInfo);
                            }
 
                            var pandoraConfigBytes = System.Text.Encoding.UTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (new PandoraConfig { UserName = tempusername, Passwrod = temppassword }));
                            Shared.IO.FileUtils.WriteFileByBytes (PandoraConfig.FileName, pandoraConfigBytes);
 
 
                            Application.RunOnMainThread (() => {
                                MainPage.Loading.Hide ();
                                MainPage.AddTip (Language.StringByID (MyInternationalizationString.successful), 1000);
                                this.Parent.RemoveAt (Parent.ChildrenCount - 2);
                                this.RemoveFromParent ();
                                A31PandoraList a31Pandoralist = new A31PandoraList ();
                                MainPage.MainFrameLayout.AddChidren (a31Pandoralist);
                                a31Pandoralist.show (a31, username.Text, password.Text);
                            });
                        } else if (number == 3) {
                            Application.RunOnMainThread (() => {
                                MainPage.Loading.Hide ();
                                new Alert (Language.StringByID (MyInternationalizationString.Tip),
                                                                       Language.StringByID (MyInternationalizationString.Accountorpassworderro),
                                                                       Language.StringByID (MyInternationalizationString.Close)).Show ();
                            });
                        } else {
                            Application.RunOnMainThread (() => {
                                MainPage.Loading.Hide ();
                                new Alert (Language.StringByID (MyInternationalizationString.Tip),
                                                                                          Language.StringByID (MyInternationalizationString.networkerrors),
                                                                                          Language.StringByID (MyInternationalizationString.Close)).Show ();
                            });
                        }
                    } catch { }
                });
            };
            login.MouseDownEventHandler += (sender, e) => {
                login.BackgroundColor = 0xffFE5E00;
            };
        }
 
 
 
        /// <summary>
        /// 登录信息
        /// </summary>
        /// <param name="username">用户名</param>
        /// <param name="password">密码</param>
        /// <returns></returns>
        string Login (string username, string password)
        {
            StringBuilder getPlayList = new StringBuilder ();
            getPlayList.AppendLine ("<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>");
            getPlayList.AppendLine ("<s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">");
            getPlayList.AppendLine ("<s:Body>");
            getPlayList.AppendLine ("<u:BackUpQueue xmlns:u=\"urn:schemas-wiimu-com:service:PlayQueue:1\">");
            getPlayList.AppendLine ("<QueueContext>");
            getPlayList.AppendLine ("&lt;?xml version=&quot;1.0&quot;?&gt;");
            getPlayList.AppendLine ("&lt;PlayList&gt;");
            getPlayList.AppendLine ("&lt;ListName&gt;Pandora&lt;/ListName&gt;");
            getPlayList.AppendLine ("&lt;ListInfo&gt;");
            getPlayList.AppendLine ("&lt;TrackNumber&gt;0&lt;/TrackNumber&gt;");
            getPlayList.AppendLine ("&lt;SearchUrl&gt;tuner.pandora.com&lt;/SearchUrl&gt;");
            getPlayList.AppendLine ("&lt;Quality&gt;0&lt;/Quality&gt;");
            getPlayList.AppendLine ("&lt;UpdateTime&gt;0&lt;/UpdateTime&gt;");
            getPlayList.AppendLine ("&lt;Http_proxy&gt;&lt;/Http_proxy&gt;");
            getPlayList.AppendLine ("&lt;Login_username&gt;" + username + "&lt;/Login_username&gt;");//2532767200@qq.com
            getPlayList.AppendLine ("&lt;Login_password&gt;" + password + "&lt;/Login_password&gt;");//85521566
            getPlayList.AppendLine ("&lt;/ListInfo&gt;");
            getPlayList.AppendLine ("&lt;/PlayList&gt;");
            getPlayList.AppendLine ("</QueueContext>");
            getPlayList.AppendLine ("</u:BackUpQueue>");
            getPlayList.AppendLine ("</s:Body>");
            getPlayList.AppendLine ("</s:Envelope>");
 
            Shared.Net.MyWebClient webClient = new Shared.Net.MyWebClient ();
            webClient.Headers.Add ("SOAPACTION", "\"urn:schemas-wiimu-com:service:PlayQueue:1#BackUpQueue\"");
            webClient.Headers.Add ("CONTENT-TYPE", "text/xml;charset=\"utf-8\"");
            try {
                byte [] recevieBytes = webClient.UploadData (new Uri ("http://" + currentMusiceA31.IPAddress + ":" + currentMusiceA31.Port + "/upnp/control/PlayQueue1"), "POST", System.Text.Encoding.UTF8.GetBytes (getPlayList.ToString ()));
                return System.Text.Encoding.UTF8.GetString (recevieBytes, 0, recevieBytes.Length);
            } catch (Exception e) {
                return null;
            }
        }
        /// <summary>
        /// 登录成功
        /// </summary>
        /// <returns></returns>
        string readList ()
        {
            StringBuilder ss = new StringBuilder ();
            ss.AppendLine ("<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>");
            ss.AppendLine ("<s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">");
            ss.AppendLine ("<s:Body>");
            ss.AppendLine ("<u:BrowseQueue xmlns:u=\"urn:schemas-wiimu-com:service:PlayQueue:1\">");
            ss.AppendLine ("<QueueName>Pandora</QueueName>");
            ss.AppendLine ("</u:BrowseQueue>");
            ss.AppendLine ("</s:Body>");
            ss.AppendLine ("</s:Envelope>");
 
            Shared.Net.MyWebClient webClient = new Shared.Net.MyWebClient ();
            webClient.Proxy = null;
            webClient.Headers.Add ("CONTENT-TYPE", "text/xml;charset=\"utf-8\"");
            webClient.Headers.Add ("SOAPACTION", "\"urn:schemas-wiimu-com:service:PlayQueue:1#BrowseQueue\"");
            try {
                byte [] recevieBytes = webClient.UploadData (new Uri ("http://" + currentMusiceA31.IPAddress + ":" + currentMusiceA31.Port + "/upnp/control/PlayQueue1"), "POST", System.Text.Encoding.UTF8.GetBytes (ss.ToString ()));
                return System.Text.Encoding.UTF8.GetString (recevieBytes, 0, recevieBytes.Length);
            } catch (Exception e) {
                return null;
            }
        }
        /// <summary>
        /// 获取电台列表信息
        /// </summary>
        /// <param name="listname">列表名</param>
        /// <returns></returns>
        string PandoraList ()
        {
            StringBuilder stringList = new StringBuilder ();
 
            stringList.AppendLine ("<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>");
            stringList.AppendLine ("<s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">");
            stringList.AppendLine ("<s:Body>");
            stringList.AppendLine ("<u:BrowseQueue xmlns:u=\"urn:schemas-wiimu-com:service:PlayQueue:1\">");
            stringList.AppendLine ("<QueueName>TotalQueue</QueueName>");
            stringList.AppendLine ("</u:BrowseQueue>");
            stringList.AppendLine ("</s:Body>");
            stringList.AppendLine ("</s:Envelope>");
 
            Shared.Net.MyWebClient webClient = new Shared.Net.MyWebClient ();
            webClient.Proxy = null;
            webClient.Headers.Add ("CONTENT-TYPE", "text/xml;charset=\"utf-8\"");
            webClient.Headers.Add ("SOAPACTION", "\"urn:schemas-wiimu-com:service:PlayQueue:1#BrowseQueue\"");
            try {
                byte [] recevieBytes = webClient.UploadData (new Uri ("http://" + currentMusiceA31.IPAddress + ":" + currentMusiceA31.Port + "/upnp/control/PlayQueue1"), "POST", System.Text.Encoding.UTF8.GetBytes (stringList.ToString ()));
                return System.Text.Encoding.UTF8.GetString (recevieBytes, 0, recevieBytes.Length);
            } catch (Exception e) {
                return null;
            }
        }
    }
}