示例#1
0
 private void login_processing(string data)
 {
     try
     {
         account = new Account();
         XmlDocument doc = new XmlDocument();
         doc.LoadXml(data);
         XmlNodeList list = doc.GetElementsByTagName("response");
         for (int i = 0; i < list.Count; i++)
         {
             account.sid = doc.GetElementsByTagName("sid")[i].InnerText;
             account.sid_name = doc.GetElementsByTagName("sid_name")[i].InnerText;
             DateTime t = ConvertFromUnixTimestamp(Convert.ToDouble(doc.GetElementsByTagName("servertime")[i].InnerText));
             DateTime d = new DateTime();
             d = DateTime.Now;
             time = Math.Round((d - t).TotalHours);
         }
         XmlNodeList alist = doc.GetElementsByTagName("account");
         for (int i = 0; i < alist.Count; i++)
         {
             account.login = doc.GetElementsByTagName("login")[i].InnerText;
             account.balance = doc.GetElementsByTagName("balance")[i].InnerText;
         }
         List<Service> ls = new List<Service>();
         XmlNodeList ilist = doc.GetElementsByTagName("item");
         for (int i = 0; i < ilist.Count; i++)
         {
             try
             {
                 Service s = new Service();
                 s.id = doc.GetElementsByTagName("id")[i].InnerText;
                 s.type = doc.GetElementsByTagName("type")[i].InnerText;
                 s.name = doc.GetElementsByTagName("name")[i].InnerText;
                 s.expire = doc.GetElementsByTagName("expire")[i].InnerText;
                 ls.Add(s);
             }
             catch (Exception) { }
         }
         account.services = ls;
     }
     catch (Exception ex)
     {
         throw new System.InvalidOperationException("Login processing error");
     }
 }
示例#2
0
 public async void LogOut()
 {
     if (account.login == null) throw new System.InvalidOperationException("Error to log out. You are not logged");
     try
     {
         HttpWebRequest request2 = (HttpWebRequest)WebRequest.Create(@"http://api.sovok.tv/v2.0/xml/logout?" + account.sid_name + "=" + account.sid);
         WebResponse responseAsync = await request2.GetResponseAsync();
         WebResponse webResponse = responseAsync;
         Stream responseStream = webResponse.GetResponseStream();
         using (responseStream)
         {
             using (StreamReader streamReader = new StreamReader(responseStream))
             {
                 string endAsync = await streamReader.ReadToEndAsync();
                 string str = endAsync;
             }
         }
         account = null;
     }
     catch (Exception) { throw new System.InvalidOperationException("Error to logout"); }
 }