Example #1
0
 public static async Task<string> GetVerifyString(this S1WebClient client)
 {
     string verify = "";
     
     //use DownloadString will just return cached data, which is not what i want
     //post dummy data to disable cache
     var privacyPage = await client.PostDataTaskAsync(new Uri(UserAction.PrivacyUrl)); 
     var root = new HtmlDoc(privacyPage).RootElement;
     var input = root.FindFirst("input", (e) => e.Attributes["name"] == "verify");
     if (input != null)
         verify = input.Attributes["value"];
     else
     {
         throw new S1UserException(ErrorParser.Parse(root));
     }
     return verify;
 }
Example #2
0
 public DataParser(string s)
 {
     HtmlPage = new HtmlDoc(s).RootElement;
 }
Example #3
0
 public DataParser(Stream s)
 {
     HtmlPage = new HtmlDoc(s).RootElement;
 }
Example #4
0
        private void GenerateXml()
        {
            FileStream sourcePage = new FileStream("Data/face.htm", FileMode.Open);
            FileStream rankPage = new FileStream("Data/faceRank.htm", FileMode.Open);
            EmotionParser.Init(sourcePage);
            XDocument doc = new XDocument();
            XElement root = new XElement("Root");
            doc.Add(root);

            var ranks = new HtmlDoc(rankPage).RootElement.Descendants("img");
            foreach (var image in ranks)
            {
                XElement e = null;
                foreach (var item in EmotionParser.EmotionList)
                {
                    if (image.Attributes["src"] == item.Value.Path)
                    {
                        e = new XElement("img");
                        XAttribute id = new XAttribute("Id", item.Value.Id);
                        XAttribute Path = new XAttribute("Path", item.Value.Path);
                        e.Add(id);
                        e.Add(Path);
                        System.Diagnostics.Debug.WriteLine(item.Value.Path);
                        break;
                    }
                }
                if (e != null) root.Add(e);
            }
            var writer = XmlWriter.Create("emotion_list.xml", 
                new XmlWriterSettings {
                    Indent = true,
                    NewLineOnAttributes = false
            });

            doc.WriteTo(writer);
            writer.Flush();

            WelcomeTitle = "Done";
        }
Example #5
0
 public async void TestServer()
 {
     Status = "Connecting";
     try{
         client = new S1WebClient();
         var result = await client.DownloadStringTaskAsync(Addr + path); 
         Status = "Wrong Data";
         if (result.Length > 0)
         {
             var root = new HtmlDoc(result).RootElement;
             var serverDownTitle = ServerListViewModel.ServerDownTitle;
             if (serverDownTitle != null &&
                 root.FindFirst("title").InnerHtml.Contains(serverDownTitle))
             {
                 Status = "Server Down";
                 if (NotifySuccess != null) NotifySuccess();
             }
             else
             {
                 if (NotifySuccess != null) NotifySuccess();
                 Status = "Success";
             }
         }
     }
     catch (TaskCanceledException)
     {
         Status = "Cancled";
     }
     catch(Exception)
     {
         Status = "Failed";
     }
 }