Beispiel #1
0
        private XDocument retrieveXML(string type, string date, string venue, int raceno)
        {
            string xml;

            using (var webClient = new GZipWebClient())
            {
                webClient.QueryString.Add("type", type);
                webClient.QueryString.Add("date", date);
                webClient.QueryString.Add("venue", venue);

                if (type == "pooltot")
                {
                    webClient.QueryString.Add("raceno", raceno.ToString());
                }

                if (type == "jcbwracing_winplaodds")
                {
                    webClient.QueryString.Add("start", raceno.ToString());
                    webClient.QueryString.Add("end", raceno.ToString());
                }

                //webClient.Encoding = Encoding.UTF8;

                xml = webClient.DownloadString(BaseUrl);
                return(XDocument.Parse(xml));
            }
        }
        public void GetKnownRepositories(Action <ObservableCollection <string> > callback, bool forceUpdate = false)
        {
            if (_cache.Count > 0 && !forceUpdate)
            {
                callback(new ObservableCollection <string>(_cache));
                return;
            }

            Log.Info("Update Known Repositories " + Url);
            Task.Factory.StartNew(() =>
            {
                try
                {
                    using (var client = new GZipWebClient())
                    {
                        var repos   = client.DownloadString(Url);
                        var matches = Regex.Matches(repos, "<repo>(.*)</repo>");

                        _cache.Clear();
                        foreach (Match match in matches)
                        {
                            _cache.Add(match.Groups[1].ToString());
                        }

                        callback(new ObservableCollection <string>(_cache));
                    }
                }
                catch (Exception e)
                {
                    Log.Warn(e);
                }
            });
        }
Beispiel #3
0
        public XmlDocument GetXml(string url, string referer = null)
        {
            _logger.Info($"Getting XML from url: {url}");

            var client = new GZipWebClient();

            if (!string.IsNullOrEmpty(referer))
            {
                client.Headers.Add("Referer", referer);
            }

            var xmlDoc = new XmlDocument();

            try
            {
                var xml = client.DownloadString(url);
                xmlDoc.LoadXml(xml);
            }
            catch (Exception ex)
            {
                _logger.Error(ex);
            }

            return(xmlDoc);
        }
Beispiel #4
0
        void Btn_Scrape_Click(object sender, EventArgs e)
        {
            /*
             * HtmlWeb Hw = new HtmlWeb();
             * var Hd = Hw.Load(this.Txt_Url.Text);
             * var Links = Hd.DocumentNode.SelectNodes("//a");
             * foreach (var Item_Link in Links)
             * {
             *  if (Item_Link.Attributes.Contains("href"))
             *  {
             *      if (Item_Link.Attributes["href"].Value.StartsWith(@"http://mangafox.me/manga/"))
             *      { Debug.WriteLine(Item_Link.Attributes["href"].Value); }
             *  }
             * }
             */

            String Url = this.Txt_Url.Text;
            String IPEndPoint_IPAddress = this.Txt_EndPointIPAddress.Text;

            String html;

            using (var wc = new GZipWebClient(IPEndPoint_IPAddress))
            { html = wc.DownloadString(Url); }

            this.Txt_Chapters.Text = html;
        }
Beispiel #5
0
 public dynamic Load(string url)
 {
     using (GZipWebClient client = new GZipWebClient())
     {
         return(client.DownloadString(url));
     }
 }
Beispiel #6
0
        /// <summary>
        /// Use this to get the whole page content
        /// </summary>
        /// <param name="pageURL"></param>
        /// <returns></returns>
        public static PageItem ProcessWebPage(String pageURL)
        {
            PageItem pageItem = null;

            try
            {
                // Setup the configuration to support document loading
                var config = Configuration.Default.WithDefaultLoader();
                // Load the names of all The Big Bang Theory episodes from Wikipedia
                using (GZipWebClient client = new GZipWebClient())
                {
                    client.Headers.Add("user-agent", Analyzer.Common.Configuration.ConfigurationManager.AppSettings.UserAgentOptions.GetRandom());
                    pageItem = new PageItem();
                    string webLocationContent = client.DownloadString(pageURL);
                    pageItem.Content = Analyzer.Common.HtmlRemoval.StripTagsCharArray(webLocationContent);
                    pageItem.Url     = pageURL;
                }
            }
            catch (Exception ex)
            {
                Analyzer.Common.Logger.ExceptionLoggingService.Instance.WriteError("Error in processing given wen URL: " + pageURL, ex);
                pageItem = null;
            }


            return(pageItem);
        }
Beispiel #7
0
        public XmlDocument GetXml(string url, string referer = null)
        {

            _logger.Info($"Getting XML from url: {url}");

            var client = new GZipWebClient();

            if (!string.IsNullOrEmpty(referer))
                client.Headers.Add("Referer", referer);

            var xmlDoc = new XmlDocument();

            try
            {
                var xml = client.DownloadString(url);
                xmlDoc.LoadXml(xml);
            }
            catch (Exception ex)
            {
                _logger.Error(ex);
            }

            return xmlDoc;

        }
Beispiel #8
0
        private static string getWeb(string url)
        {
            GZipWebClient webClient = new GZipWebClient();

            webClient.Encoding = System.Text.Encoding.UTF8;

            return(webClient.DownloadString(url));
        }
Beispiel #9
0
        public void Check(Action <UpdateResponse> callback)
        {
            var leagueMd5 = Utility.Md5Checksum(Config.Instance.LeagueOfLegendsExePath);
            var coreMd5   = Utility.Md5Checksum(Directories.CoreFilePath);

            if (Config.Instance.DeveloperSettings.IgnoreUpdate)
            {
                Log.Info("Ignore Update");
                callback(new UpdateResponse {
                    State = UpdateState.UpToDate
                });
                return;
            }

            Task.Factory.StartNew(() =>
            {
                try
                {
                    using (var client = new GZipWebClient {
                        Timeout = 4000
                    })
                    {
                        var info = JsonConvert.DeserializeObject <UpdateInfo>(client.DownloadString(Url + leagueMd5));

                        if (info.Version == "0")
                        {
                            Log.Info("League Version not Supported " + leagueMd5);
                            callback(new UpdateResponse {
                                State = UpdateState.VersionNotSupported
                            });
                            return;
                        }

                        if (info.Version != coreMd5 && WhiteList.Any(s => info.Url.StartsWith(s)))
                        {
                            Log.Info("Update available for " + leagueMd5);
                            callback(new UpdateResponse {
                                State = UpdateState.UpdateAvailable, Info = info
                            });
                            return;
                        }

                        Log.Info("League Version is up to date " + leagueMd5);
                        callback(new UpdateResponse {
                            State = UpdateState.UpToDate
                        });
                    }
                }
                catch (Exception e)
                {
                    Log.Warn(e);
                    callback(new UpdateResponse {
                        State = UpdateState.UpdateError
                    });
                }
            });
        }
        public ObservableCollection <CafeResult> GetCafeResults(CityResult cityResult)
        {
            var cafeResults = new ObservableCollection <CafeResult>();
            var theForkURL  = getUrl(cityResult);

            var wc = new GZipWebClient();

            wc.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36 Edg/87.0.664.60");
            wc.Headers.Add("Accept-Language", "en-US,en;q=0.9");
            wc.Headers.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9");
            wc.Headers.Add("Accept-Encoding", "gzip");
            var test = wc.DownloadString(theForkURL);

            var htmlDoc = new HtmlDocument();

            htmlDoc.LoadHtml(test);

            string typeXpath     = "//span[@class = 'enrzupw0 css-1ujxl3z ejesmtr0']";
            string nameXpath     = "//div[@class = 'css-aycukd e6vs4hd0']/div/h2/a";
            string addressExpath = "//p[@class = 'css-axj1nn ejesmtr0']";
            string avPriceXpath  = "//p[@class = 'css-a7e1wa ejesmtr0']/span[2]";
            string rateXpath     = "//span[@class = 'css-17f8ytt e1l48fgb0']/span[1]";

            try
            {
                for (int i = 0; i < 5; i++) // what if there are less than 5?
                {
                    var    type         = htmlDoc.DocumentNode.SelectNodes(typeXpath)[i].InnerText;
                    var    name         = htmlDoc.DocumentNode.SelectNodes(nameXpath)[i].InnerText;
                    var    address      = htmlDoc.DocumentNode.SelectNodes(addressExpath)[i].InnerText;
                    string averagePrice = "";
                    if (htmlDoc.DocumentNode.SelectNodes(avPriceXpath).Count > 1)
                    {
                        averagePrice = htmlDoc.DocumentNode.SelectNodes(avPriceXpath)[i].InnerText;
                    }
                    string rate = "";
                    if (htmlDoc.DocumentNode.SelectNodes(rateXpath).Count > i)
                    {
                        rate = htmlDoc.DocumentNode.SelectNodes(rateXpath)[i].InnerText;   //not all cafes have ratings!
                    }
                    cafeResults.Add(new CafeResult(type, name, address, averagePrice, rate));
                }
            }
            catch (Exception e)
            {
                Utils.Log.LogExceptions(e.Message);
            }

            //var link = htmlDoc.DocumentNode.SelectSingleNode("//span[@class = 'enrzupw0 css-1ujxl3z ejesmtr0']").InnerText;

            return(cafeResults);
        }
Beispiel #11
0
        /// <summary>
        /// Search for PersonaId based on Username
        /// </summary>
        /// <param name="searchTerm">Username to search for (be specific)</param>
        /// <param name="user">Result user (if any)</param>
        /// <param name="status">Status of the search</param>
        /// <returns>Success/Fail</returns>
        public bool SearchPersonaId(string searchTerm, out AtomUser user, out UserSearchStatus status)
        {
            userClient.AuthToken = OriginToken;
            var result   = userClient.DownloadString($"{API}/xsearch/users?userId={_myself.pid.pidId}&searchTerm={searchTerm}");
            var personas = JsonConvert.DeserializeObject <Personas>(result);

            user = null;
            //if (personas.totalCount > 20) {
            //    status = UserSearchStatus.TOO_MANY_RESULTS;
            //    return false;
            //}
            //else if (personas.totalCount <= 0) {
            //    status = UserSearchStatus.NO_MATCHES;
            //    return false;
            //}
            if (personas.totalCount <= 0)
            {
                status = UserSearchStatus.NO_MATCHES;
                return(false);
            }

            //result = userClient.DownloadString($"{API}/atom/users?userIds={string.Join(",", personas.infoList.Select(x => x.friendUserId))}");
            //var atomUsers = new XMLSerializer().Deserialize<AtomUsers>(result);
            // Apparently 5 at a time is a max
            var atomUsers = GetAtomUsers(personas.infoList);

            user = atomUsers.Users.FirstOrDefault(x => x.EAID.Equals(searchTerm, StringComparison.OrdinalIgnoreCase));
            if (user != null)
            {
                status      = UserSearchStatus.SUCCESS;
                user.Avatar = GetAvatar(user.UserId);
                return(true);
            }
            else
            {
                status = UserSearchStatus.PARTIAL_MATCHES;
                return(false);
            }
        }
Beispiel #12
0
        void GetChapters(String Url, String IPEndPoint_IPAddress)
        {
            //HtmlWeb Hw = new HtmlWeb();
            //var Hd = Hw.Load(Url);

            String html;

            using (var wc = new GZipWebClient(IPEndPoint_IPAddress))
            { html = wc.DownloadString(Url); }

            HtmlAgilityPack.HtmlDocument Hd = new HtmlAgilityPack.HtmlDocument();
            Hd.LoadHtml(html);

            var Nodes         = Hd.DocumentNode.SelectNodes("//div");
            var Node_Chapters =
                Nodes.FirstOrDefault(O =>
                                     O.Attributes.Contains("id") &&
                                     O.Attributes["id"].Value == "chapters");

            List <String> List_Links = new List <String>();
            //var Links = Hd.DocumentNode.SelectNodes("//a");
            var Links = Node_Chapters.SelectNodes(".//a");

            foreach (var Item_Link in Links)
            {
                if (Item_Link.Attributes.Contains("href"))
                {
                    if (Item_Link.Attributes["href"].Value.StartsWith(@"http://mangafox.me/manga/") ||
                        Item_Link.Attributes["href"].Value.StartsWith(@"/mangafox.me/manga/"))
                    {
                        if (Item_Link.Attributes["href"].Value.StartsWith(@"http://mangafox.me/manga/"))
                        {
                            List_Links.Add(Item_Link.Attributes["href"].Value);
                            Debug.WriteLine(Item_Link.Attributes["href"].Value);
                        }
                        else
                        {
                            Uri Uri_Source = new Uri(Url);
                            List_Links.Add("http://" + Uri_Source.Host + Item_Link.Attributes["href"].Value);
                            Debug.WriteLine("http://" + Uri_Source.Host + Item_Link.Attributes["href"].Value);
                        }
                    }
                }
            }

            StringBuilder Sb_Links = new StringBuilder();

            List_Links.OrderBy(O => O).ToList().ForEach(O => Sb_Links.AppendLine(O));

            this.Txt_Chapters.Text = Sb_Links.ToString().Trim();
        }
Beispiel #13
0
        public static PageItem ProcessWebPage(String pageURL, String cssSelector)
        {
            PageItem pageItem = null;

            try
            {
                // Setup the configuration to support document loading
                var config = Configuration.Default.WithDefaultLoader();
                // Load the names of all The Big Bang Theory episodes from Wikipedia
                using (GZipWebClient client = new GZipWebClient())
                {
                    client.Headers.Add("user-agent", Analyzer.Common.Configuration.ConfigurationManager.AppSettings.UserAgentOptions.GetRandom());
                    string webLocationContent = client.DownloadString(pageURL);
                    var    parser             = new HtmlParser();
                    var    document           = parser.Parse(webLocationContent);
                    // This CSS selector gets the desired content
                    var cellSelector = cssSelector;
                    // Perform the query to get all cells with the content
                    var cells = document.QuerySelectorAll(cellSelector);
                    // We are only interested in the text - select it with LINQ
                    var pageContent = cells.Select(m => m.TextContent);
                    if (pageContent != null && pageContent.Count() > 0)
                    {
                        pageItem = new PageItem();
                        StringBuilder sb = new StringBuilder();
                        foreach (var pageContentElement in pageContent)
                        {
                            sb.AppendLine(pageContentElement);
                        }

                        pageItem.Content = Analyzer.Common.HtmlRemoval.StripTagsCharArray(sb.ToString());
                        pageItem.Url     = pageURL;
                    }
                }
            }
            catch (Exception ex)
            {
                Analyzer.Common.Logger.ExceptionLoggingService.Instance.WriteError("Error in processing given wen URL: " + pageURL, ex);
                pageItem = null;
            }


            return(pageItem);
        }
Beispiel #14
0
        void DownloadChapter(String Url, String IPEndPoint_IPAdress)
        {
            String FilePath = this.DownloadChapter_FilePath;

            //Get Pages

            String html;

            using (var wc = new GZipWebClient(IPEndPoint_IPAdress))
            { html = wc.DownloadString(Url); }

            HtmlAgilityPack.HtmlDocument Hd = new HtmlAgilityPack.HtmlDocument();
            Hd.LoadHtml(html);

            //HtmlWeb Hw = new HtmlWeb();
            //var Hd = Hw.Load(Url);

            //var Nds = Hd.DocumentNode.SelectNodes("//form");
            //var Nd_Form = Nds.FirstOrDefault(O => O.Attributes.Contains("id") && O.Attributes["id"].Value == "top_bar");
            var   Nds_Script = Hd.DocumentNode.SelectNodes("//script");
            var   Nd_Script  = Nds_Script.FirstOrDefault(O => O.InnerText.Contains("var total_pages"));
            Regex R          = new Regex(@"var total_pages=[0-9]*;");
            var   Matches    = R.Matches(Nd_Script.InnerText);

            R = new Regex(@"=[0-9]*");
            Int32 Pages = Convert.ToInt32(R.Matches(Matches[0].Value)[0].Value.TrimStart('='));

            String Chapter_Url = Strings.Mid(Url, 1, Strings.InStrRev(Url, @"/"));

            String Tmp     = Strings.Mid(Chapter_Url, 1, Strings.InStrRev(Chapter_Url, @"/") - 1);
            String Chapter = Strings.Mid(Tmp, Strings.InStrRev(Tmp, @"/") + 1);

            this.mDownloadPage_Params = new DownloadPage_Params()
            {
                Chapter             = Chapter,
                Chapter_Url         = Chapter_Url,
                FilePath            = FilePath,
                Url                 = Url,
                IPEndPoint_IPAdress = IPEndPoint_IPAdress
            };

            Parallel.For(0, Pages, this.DownloadPage);
        }
Beispiel #15
0
        public static PageItem ProcessWordpressArticle(String pageURL)
        {
            PageItem pageItem = null;

            try
            {
                // Setup the configuration to support document loading
                var config = Configuration.Default.WithDefaultLoader();
                // Load the names of all The Big Bang Theory episodes from Wikipedia
                var address = pageURL;

                using (GZipWebClient client = new GZipWebClient())
                {
                    client.Headers.Add("user-agent", Analyzer.Common.Configuration.ConfigurationManager.AppSettings.UserAgentOptions.GetRandom());
                    string webLocationContent = client.DownloadString(pageURL);
                    var    parser             = new HtmlParser();
                    var    document           = parser.Parse(webLocationContent);
                    // Asynchronously get the document in a new context using the configuration
                    //var document = await BrowsingContext.New(config).OpenAsync(address);
                    var article = document.All.SingleOrDefault(o => o.LocalName == "article");
                    var title   = article.QuerySelectorAll("h1.entry-title");
                    var content = article.QuerySelectorAll("div.entry-content");



                    {
                        pageItem = new PageItem();


                        pageItem.Title   = title.First().TextContent;
                        pageItem.Content = Analyzer.Common.HtmlRemoval.StripTagsCharArray(content.First().TextContent);
                        pageItem.Url     = pageURL;
                    }
                }
            } catch (Exception ex)
            {
                Analyzer.Common.Logger.ExceptionLoggingService.Instance.WriteError("Error in processing given wen URL: " + pageURL, ex);
                pageItem = null;
            }


            return(pageItem);
        }
        public ObservableCollection <CafeResult> GetCafeResult(CityResult cityResult)
        {
            var cafeResult = new ObservableCollection <CafeResult>();
            var testURL    = getUrl(cityResult);

            // var testURL = getUrl(new CityResult() { Latitude = "48.220778", Longitude = "16.3100205" });
            var wc = new GZipWebClient();

            wc.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36 Edg/87.0.664.60");
            wc.Headers.Add("Accept-Language", "en-US,en;q=0.9");
            wc.Headers.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9");
            wc.Headers.Add("Accept-Encoding", "gzip");
            var test = wc.DownloadString(testURL);

            var htmlDoc = new HtmlDocument();

            htmlDoc.LoadHtml(test);

            string typeXpath = "//span[@class = 'enrzupw0 css-1ujxl3z ejesmtr0']";
            // string nameXpath = "//a[@class = 'css-1lxw1q9 ejesmtr0']";
            string nameXpath     = "//div[@class = 'css-aycukd e6vs4hd0']/div/h2/a";
            string addressExpath = "//p[@class = 'css-axj1nn ejesmtr0']";
            string avPriceXpath  = "//p[@class = 'css-a7e1wa ejesmtr0']/span[2]";
            string rateXpath     = "//span[@class = 'css-17f8ytt e1l48fgb0']/span[1]";

            for (int i = 0; i < 5; i++)
            {
                var type         = htmlDoc.DocumentNode.SelectNodes(typeXpath)[i].InnerText;
                var name         = htmlDoc.DocumentNode.SelectNodes(nameXpath)[i].InnerText;
                var address      = htmlDoc.DocumentNode.SelectNodes(addressExpath)[i].InnerText;
                var averagePrice = htmlDoc.DocumentNode.SelectNodes(avPriceXpath)[i].InnerText;
                var rate         = htmlDoc.DocumentNode.SelectNodes(rateXpath)[i].InnerText;

                cafeResult.Add(new CafeResult(type, name, address, averagePrice, rate));
            }

            //var link = htmlDoc.DocumentNode.SelectSingleNode("//span[@class = 'enrzupw0 css-1ujxl3z ejesmtr0']").InnerText;

            return(cafeResult);
        }
        private IHtmlDocument DownloadHTML(string url)
        {
            using (var client = new GZipWebClient())
            {
                client.Headers["User-Agent"] =
                    "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36";
                client.Headers["Accept"] =
                    "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8";
                client.Headers["Accept-Encoding"] = "gzip, deflate, br";
                client.Headers["Accept-Language"] = "en-US,en;q=0.9,az;q=0.8,ru;q=0.7";
                //client.Headers["Connection"] = "keep-alive";
                client.Headers["Cache-Control"]             = "no-cache";
                client.Headers["Pragma"]                    = "no-cache";
                client.Headers["Host"]                      = "www.leboncoin.fr";
                client.Headers["Upgrade-Insecure-Requests"] = "1";


                var html     = client.DownloadString(url);
                var parser   = new HtmlParser();
                var document = parser.ParseDocument(html);
                return(document);
            }
        }
Beispiel #18
0
        public void Login(string email, string password)
        {
            Email    = email;
            Password = password;

            try {
                // Initializing
                client.DownloadString("https://accounts.ea.com/connect/auth?response_type=code&client_id=ORIGIN_SPA_ID&display=originXWeb/login&locale=en_US&redirect_uri=https://www.origin.com/views/login.html");
                client.DownloadString(client.ResponseHeaders["Location"]);
                var loginRequestUrl = $"https://signin.ea.com{client.ResponseHeaders["Location"]}";
                client.DownloadString(loginRequestUrl); // Downloads the login page

                // Login
                var reqparm = new System.Collections.Specialized.NameValueCollection();
                reqparm.Add("email", email);
                reqparm.Add("password", password);
                reqparm.Add("_eventId", "submit");
                reqparm.Add("showAgeUp", "true");
                reqparm.Add("googleCaptchaResponse", "");
                reqparm.Add("_rememberMe", "on");
                reqparm.Add("rememberMe", "on");
                byte[] responsebytes = client.UploadValues(loginRequestUrl, "POST", reqparm);
                string responsebody  = Encoding.UTF8.GetString(responsebytes);

                var arr          = responsebody.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None).ToList();
                var nextLocation = arr.FirstOrDefault(x => x.Contains("window.location"));
                var startIndex   = nextLocation.IndexOf("\"");
                loginRequestUrl = nextLocation.Substring(startIndex + 1, nextLocation.Length - (startIndex + 2));

                // TODO: Check if these are even correct
                var endOrChallenge = client.DownloadString(loginRequestUrl);
                if (endOrChallenge.Contains("&_eventId=challenge"))
                {
                    LoginVerification(loginRequestUrl);
                }
                else if (endOrChallenge.Contains("&_eventId=end"))
                {
                    client.DownloadString(loginRequestUrl + "&_eventId=end");
                }

                // Finish login
                client.DownloadString(client.ResponseHeaders["Location"]);

                FetchOriginAccessToken();
                FetchCompanionAccessToken();
                FetchMyself();
            }
            catch (Exception e) {
                Debug.WriteLine($"Error: {e.Message}");
                throw new ApplicationException("Incorrect email or password!");
            }
        }
Beispiel #19
0
        void DownloadPage(Int32 Ct)
        {
            Int32   Try_Ct   = 0;
            Boolean Is_Error = false;

            do
            {
                Is_Error = false;
                try
                {
                    Int32 Page_Ct = Ct + 1;

                    String Url                 = this.mDownloadPage_Params.Url;
                    String Chapter_Url         = this.mDownloadPage_Params.Chapter_Url;
                    String FilePath            = this.mDownloadPage_Params.FilePath;
                    String Chapter             = this.mDownloadPage_Params.Chapter;
                    String IPEndPoint_IPAdress = this.mDownloadPage_Params.IPEndPoint_IPAdress;

                    //var Hw = new HtmlWeb();
                    //var Hd = Hw.Load(Chapter_Url + Page_Ct + @".html");

                    String html;
                    using (var wc = new GZipWebClient(IPEndPoint_IPAdress))
                    { html = wc.DownloadString(Chapter_Url + Page_Ct + @".html"); }

                    HtmlAgilityPack.HtmlDocument Hd = new HtmlAgilityPack.HtmlDocument();
                    Hd.LoadHtml(html);

                    var Nds       = Hd.DocumentNode.SelectNodes("//div");
                    var Nd_Viewer =
                        Nds.FirstOrDefault(O =>
                                           O.Attributes.Contains("id") &&
                                           O.Attributes["id"].Value == "viewer");

                    var Img_Url = Nd_Viewer.SelectSingleNode("//img").Attributes["src"].Value;

                    using (WebClient Wc = new WebClient())
                    {
                        Uri Uri_Source = new Uri(Url);

                        FileInfo Fi_Source = new FileInfo(Strings.Mid(Img_Url, Strings.InStrRev(Img_Url, @"/") + 1));
                        FileInfo Fi_Target = new FileInfo(FilePath.TrimEnd('\\') + @"\" + Chapter + @"\" + Fi_Source.Name);
                        if (!Fi_Target.Directory.Exists)
                        {
                            Fi_Target.Directory.Create();
                        }

                        //Wc.DownloadFile(@"http://" + Uri_Source.Host + @"/" + Img_Path, Fi_Target.FullName);
                        Wc.DownloadFile(Img_Url, Fi_Target.FullName);
                    }
                }
                catch (Exception Ex)
                {
                    Is_Error = true;
                    Try_Ct++;
                    if (Try_Ct > 10)
                    {
                        throw Ex;
                    }
                }
            }while (Is_Error);
        }
        public List <SiteRow> ParseAnonsLive()
        {
            string adress = GetApiAdress();

            WebClient wb = new GZipWebClient();

            wb.Encoding = Encoding.UTF8;
            var respone = wb.DownloadString($"https:{adress}/line/currentLine/ru/");

            var json = JObject.Parse(respone);

            var rezult = new List <SiteRow>();
            var events = json["events"].Where(x => x["level"].ToString() == "1").ToList();

            foreach (var ev in events)
            {
                if (ev["state"]?["willBeLive"]?.ToString() == "True")
                {
                }
                else
                {
                    continue;
                }
                SiteRow rw = new SiteRow();
                rw.Site      = ParserType.Fonbet;
                rw.TeamName  = ev["team1"].ToString();
                rw.TimeStart = UnixTimeStampToDateTime(SetDouble(ev["startTime"].ToString())).AddHours(3);
                var sport = json["sports"].Where(x => x["id"].ToString() == ev["sportId"].ToString()).ToList().First();
                rw.Groupe = sport["name"].ToString();

                rw.Sport = rw.Groupe.Split('.').First().Trim();
                rw.Match = $"{rw.TeamName} - {ev["team2"]}";

                rezult.Add(rw);

                var rw2 = rw.Clone();
                rw2.TeamName = ev["team2"].ToString();


                rezult.Add(rw2);
            }

            wb      = new GZipWebClient();
            respone = wb.DownloadString($"https:{adress}/live/currentLine/ru/");
            json    = JObject.Parse(respone);
            events  = json["events"].Where(x => x["level"].ToString() == "1").ToList();
            foreach (JToken ev in events)
            {
                SiteRow rw = new SiteRow();
                rw.Site      = ParserType.Fonbet;
                rw.TeamName  = ev["team1"].ToString();
                rw.TimeStart = UnixTimeStampToDateTime(SetDouble(ev["startTime"].ToString())).AddHours(3);
                var sport = json["sports"].Where(x => x["id"].ToString() == ev["sportId"].ToString()).ToList().First();
                rw.Groupe = sport["name"].ToString();

                rw.Sport = rw.Groupe.Split('.').First().Trim();
                rw.Match = $"{rw.TeamName} - {ev["team2"]}";

                rezult.Add(rw);

                var rw2 = rw.Clone();
                rw2.TeamName = ev["team2"].ToString();


                rezult.Add(rw2);
            }


            rezult = rezult.OrderBy(x => x.TimeStart).ToList();
            return(rezult);
        }
Beispiel #21
0
        public void Update(Action <UpdateResponse> callback, UpdateInfo info = null)
        {
            var leagueMd5 = Utility.Md5Checksum(Config.Instance.LeagueOfLegendsExePath);
            var coreMd5   = Utility.Md5Checksum(Directories.CoreFilePath);

            Task.Factory.StartNew(() =>
            {
                try
                {
                    using (var client = new GZipWebClient {
                        Timeout = 4000
                    })
                    {
                        if (info == null)
                        {
                            info = JsonConvert.DeserializeObject <UpdateInfo>(client.DownloadString(Url + leagueMd5));
                        }

                        if (info.Version != coreMd5 && WhiteList.Any(s => info.Url.StartsWith(s)))
                        {
                            Log.InfoFormat("Update Core from {0} to {1}", coreMd5, info.Version);
                            Messenger.Default.Send(new BalloonTipCoreUpdateMessage());
                            // TODO: implement balloontip service

                            try
                            {
                                client.DownloadFile(info.Url, UpdateZip);

                                using (var archive = ZipFile.OpenRead(UpdateZip))
                                {
                                    foreach (var entry in archive.Entries)
                                    {
                                        var file = Path.Combine(Directories.CoreDirectory, entry.FullName);
                                        Log.Info("Update " + file);
                                        entry.ExtractToFile(file, true);
                                    }
                                }

                                callback(new UpdateResponse {
                                    State = UpdateState.Updated
                                });
                            }
                            catch (Exception e)
                            {
                                Log.Warn("Core Download failed", e);
                                callback(new UpdateResponse {
                                    State = UpdateState.DownloadError
                                });
                            }
                            finally
                            {
                                if (File.Exists(UpdateZip))
                                {
                                    File.Delete(UpdateZip);
                                }
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Log.Warn(e);
                    callback(new UpdateResponse {
                        State = UpdateState.UpdateError
                    });
                }
            });
        }
Beispiel #22
0
        public void Check(Action <UpdateResponse> callback)
        {
            Task.Factory.StartNew(() =>
            {
                try
                {
                    using (var client = new GZipWebClient {
                        Timeout = 4000
                    })
                    {
                        var info          = JsonConvert.DeserializeObject <UpdateInfo>(client.DownloadString(Url));
                        var loaderVersion = System.Reflection.Assembly.GetEntryAssembly().GetName().Version;
                        var updateVersion = Version.Parse(info.Version);

                        if (updateVersion > loaderVersion && WhiteList.Any(s => info.Url.StartsWith(s)))
                        {
                            callback(new UpdateResponse {
                                State = UpdateState.UpdateAvailable, Info = info
                            });
                            return;
                        }

                        callback(new UpdateResponse {
                            State = UpdateState.UpToDate
                        });
                    }
                }
                catch (Exception e)
                {
                    Log.Warn(e);
                    callback(new UpdateResponse {
                        State = UpdateState.UpdateError
                    });
                }
            });
        }
Beispiel #23
0
        public void Update(Action <UpdateResponse> callback, UpdateInfo info = null)
        {
            Task.Factory.StartNew(() =>
            {
                try
                {
                    using (var client = new GZipWebClient {
                        Timeout = 4000
                    })
                    {
                        if (info == null)
                        {
                            info = JsonConvert.DeserializeObject <UpdateInfo>(client.DownloadString(Url));
                        }

                        var loaderVersion = System.Reflection.Assembly.GetEntryAssembly().GetName().Version;
                        var updateVersion = Version.Parse(info.Version);

                        if (updateVersion > loaderVersion && WhiteList.Any(s => info.Url.StartsWith(s)))
                        {
                            Log.InfoFormat("Update Loader from {0} to {1}", loaderVersion, updateVersion);
                            Messenger.Default.Send(new BalloonTipLoaderUpdateMessage());
                            // TODO: implement balloontip service

                            try
                            {
                                client.DownloadFile(info.Url, UpdateExe);

                                using (var archive = ZipFile.OpenRead(UpdateExe))
                                {
                                    foreach (var entry in archive.Entries)
                                    {
                                        var file = Path.Combine(Directories.CoreDirectory, entry.FullName);
                                        Log.Info("Update " + file);
                                        entry.ExtractToFile(file, true);
                                    }
                                }

                                callback(new UpdateResponse {
                                    State = UpdateState.Updated
                                });
                            }
                            catch (Exception e)
                            {
                                Log.Warn("Loader Download failed", e);
                                callback(new UpdateResponse {
                                    State = UpdateState.DownloadError
                                });
                            }
                            finally
                            {
                                if (File.Exists(UpdateExe))
                                {
                                    File.Delete(UpdateExe);
                                }
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Log.Warn(e);
                    callback(new UpdateResponse {
                        State = UpdateState.UpdateError
                    });
                }
            });
        }
Beispiel #24
0
        public LoginType Login(string email, string password)
        {
            var loginType = LoginType.ERROR;

            Email    = email;
            Password = password;

            try {
                if (_authCodeService != null && _authCodeService.TryGetSid(Email, out var sidCookie))
                {
                    var newCookie = new System.Net.Cookie(sidCookie.Name, sidCookie.Value, sidCookie.Path);
                    Uri uri       = new Uri("https://accounts.ea.com/connect");
                    client.CookieContainer.Add(uri, newCookie);
                    loginType = LoginType.TOKEN;
                }
                else
                {
                    // Initializing
                    client.DownloadString("https://accounts.ea.com/connect/auth?response_type=code&client_id=ORIGIN_SPA_ID&display=originXWeb/login&locale=en_US&release_type=prod");
                    var authUrl = client.ResponseHeaders["Location"];
                    var fid     = authUrl.Split("fid=")[1];
                    client.DownloadString(authUrl);
                    var loginRequestUrl = $"https://signin.ea.com{client.ResponseHeaders["Location"]}";
                    client.DownloadString(loginRequestUrl); // Downloads the login page

                    // Login
                    var reqparm = new System.Collections.Specialized.NameValueCollection();
                    reqparm.Add("email", email);
                    reqparm.Add("password", password);
                    reqparm.Add("_eventId", "submit");
                    reqparm.Add("showAgeUp", "true");
                    reqparm.Add("googleCaptchaResponse", "");
                    reqparm.Add("_rememberMe", "on");
                    reqparm.Add("rememberMe", "on");

                    //reqparm.Add("pn_text", "");
                    //reqparm.Add("passwordForPhone", "");
                    //reqparm.Add("country", "US");
                    //reqparm.Add("phoneNumber", "");
                    //reqparm.Add("_eventId", "submit");
                    //reqparm.Add("gCaptchaResponse", "");
                    //reqparm.Add("isPhoneNumberLogin", "false");
                    //reqparm.Add("isIncompletePhone", "");
                    //reqparm.Add("countryPrefixPhoneNumber", "");
                    byte[] responsebytes = client.UploadValues(loginRequestUrl, "POST", reqparm);
                    string responsebody  = Encoding.UTF8.GetString(responsebytes);

                    if (!string.IsNullOrEmpty(responsebody))
                    {
                        var arr          = responsebody.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None).ToList();
                        var nextLocation = arr.FirstOrDefault(x => x.Contains("window.location"));
                        var startIndex   = nextLocation.IndexOf("\"");
                        loginRequestUrl = nextLocation.Substring(startIndex + 1, nextLocation.Length - (startIndex + 2));

                        // TODO: Check if these are even correct
                        var endOrChallenge = client.DownloadString(loginRequestUrl);
                        if (endOrChallenge.Contains("&_eventId=challenge"))
                        {
                            LoginVerification(loginRequestUrl);
                        }
                        else if (endOrChallenge.Contains("&_eventId=end"))
                        {
                            client.DownloadString(loginRequestUrl + "&_eventId=end");
                        }

                        // Finish login
                        client.DownloadString(client.ResponseHeaders["Location"]);
                    }
                    else
                    {
                        if (client.ResponseHeaders.AllKeys.Contains("Location"))
                        {
                            throw new Exception($"Rate limit exceeded: {email}");
                        }
                        client.DownloadString($"https://accounts.ea.com/connect/auth?response_type=code&client_id=ORIGIN_SPA_ID&display=originXWeb%2Flogin&locale=en_US&release_type=prod&fid={fid}");
                    }

                    var cookies = client.CookieContainer.GetCookies(new Uri("https://accounts.ea.com/connect"));
                    var sid     = cookies["sid"];
                    _authCodeService?.AddOrRefresh(email, sid);

                    loginType = LoginType.CREDENTIALS;
                }

                FetchOriginAccessToken();
                FetchCompanionAccessToken();
                FetchMyself();
            }
            catch (Exception e) {
                Debug.WriteLine($"Error: {e.Message}");
                loginType = LoginType.ERROR;
                throw new ApplicationException($"Incorrect email or password for {email}");
            }

            return(loginType);
        }
        public void GetAssemblyDatabase(Action <ObservableCollection <LSharpDbAssembly> > callback,
                                        bool forceUpdate = false)
        {
            if (_cache.Count > 0 && !forceUpdate)
            {
                callback(new ObservableCollection <LSharpDbAssembly>(_cache));
                return;
            }

            Log.Info("Update Assembly Database " + Url);
            Task.Factory.StartNew(() =>
            {
                try
                {
                    using (var client = new GZipWebClient())
                    {
                        var data = JsonConvert.DeserializeObject <List <LSharpDbAssembly> >(client.DownloadString(Url));

                        _cache.Clear();
                        foreach (var assembly in data)
                        {
                            _cache.Add(assembly);
                        }

                        callback(new ObservableCollection <LSharpDbAssembly>(_cache));
                    }
                }
                catch (Exception e)
                {
                    Log.Warn(e);
                }
            });
        }