Ejemplo n.º 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);
        }
Ejemplo n.º 2
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";
            }
        }