Example #1
0
        Response postRequest(string url_from, string parameters, string Referer = null, CookieContainer cookies = null)
        {
            try
            {
                ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
                using (var client = new BetterWebClient(cookies == null ? CookieContainer : cookies))
                {
                    client.Headers[HttpRequestHeader.UserAgent] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:65.0) Gecko/20100101 Firefox/65.0";
                    if (!string.IsNullOrWhiteSpace(Referer))
                    {
                        client.Headers[HttpRequestHeader.Referer] = Referer;
                    }
                    client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";

                    string response = client.UploadString(url_from, parameters);
                    extractCookies(client.ResponseHeaders["Set-Cookie"]);
                    return(new Response {
                        Page = response, Location = client.Location, StatusCode = client.StatusCode, ResponseUri = client.ResponseUri
                    });
                }
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
Example #2
0
        public static void Init(string path)
        {
            try
            {
                var data = new BetterWebClient(null).DownloadString("https://raw.github.com/" + path + "/Properties/AssemblyInfo.cs");
                foreach (var line in data.Split('\n'))
                {
                    if (line.StartsWith("//"))
                    {
                        continue;
                    }

                    if (line.StartsWith("[assembly: AssemblyVersion"))
                    {
                        var serverVersion = new System.Version(line.Substring(28, (line.Length - 4) - 28 + 1));
                        if (serverVersion > Version)
                        {
                            Config.ShowNotification(
                                "Update avalible: " + Version + " => " + serverVersion, System.Drawing.Color.Red, 10000);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            Config.ShowNotification("No Update avalible: " + Version, System.Drawing.Color.GreenYellow, 5000);
        }
Example #3
0
        public async Task DownloadAsync(string downloadUrl, string sdf)
        {
            string downloadLocation = "";

            using (var client = new BetterWebClient(this.cookieContainer, false))
            {
                string downloadPage = await client.DownloadStringTaskAsync(downloadUrl);

                CQ  downloadPageDom     = CQ.Create(downloadPage);
                var downloadInputButton = downloadPageDom.Find("#optionsPage input");
                downloadLocation = downloadInputButton.Attr("onClick");

                // e.g. window.location='https://earthexplorer.usgs.gov/download/4220/ASTGDEMV2_0N51W004/STANDARD/INVSVC'
                downloadLocation = downloadLocation.Replace("window.location", "");
                downloadLocation = downloadLocation.Replace("=", "");
                downloadLocation = downloadLocation.Trim('\'');
            }

            if (!String.IsNullOrEmpty(downloadLocation))
            {
                using (var client = new BetterWebClient(this.cookieContainer, false))
                {
                    string nextPage = await client.DownloadStringTaskAsync(downloadLocation);

                    CQ nextPageDom = CQ.Create(nextPage);

                    string nextPageLower = nextPage.ToLower();

                    if (nextPageLower.Contains("agree to") && nextPageLower.Contains("end user license"))
                    {
                        await this.AcceptDownloadLicenseAgreement(client, downloadLocation, nextPageDom);
                    }
                }
            }
        }
Example #4
0
        public Requestera(EnumHttpProvider httpProvider)
        {
            this.HttpProvider = httpProvider;

            if (httpProvider == EnumHttpProvider.AngleSharp)
            {
                this.angleSharpClient = AngleSharp.BrowsingContext.New();
            }
            else if (httpProvider == EnumHttpProvider.BetterWebClient)
            {
                this.betterWebClient = new BetterWebClient();
            }
            else if (httpProvider == EnumHttpProvider.ChromeHeadless)
            {
                this.chromeHeadlessClient = new ChromeClient(true);
            }
            else if (httpProvider == EnumHttpProvider.ChromeHeadlessPersistent)
            {
                this.chromeHeadlessPersistentClient = new ChromePersistentClient(true);
            }
            else if (httpProvider == EnumHttpProvider.HttpClient)
            {
                this.httpClient = new System.Net.Http.HttpClient();
            }
            else if (httpProvider == EnumHttpProvider.WebClient)
            {
                this.webClient = new WebClient();
            }
            else
            {
                throw new ArgumentNullException("httpProvider");
            }
        }
Example #5
0
        private async Task AcceptDownloadLicenseAgreement(BetterWebClient client, string pageUrl, CQ licencePageDom)
        {
            var mainContentForm = licencePageDom.Find("#maincontent form");
            var licenseCode     = mainContentForm.Find("input[name='licenseCode']").Val();


            var postParams = new NameValueCollection();

            postParams.Add("licenseCode", licenseCode);

            client.Headers.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
            client.Headers.Add("Accept-Encoding", "gzip, deflate");
            client.Headers.Add("Accept-Language", "en-US,en;q=0.5");
            client.Headers.Add("Cache-Control", "no-cache");
            client.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
            client.Headers.Add("Pragma", "no-cache");
            client.Headers.Add("User-Agent", AeroSceneryManager.Instance.Settings.UserAgent);
            client.Headers.Add("Referer", pageUrl);


            await client.UploadValuesTaskAsync(pageUrl, "POST", postParams);

            //string responsebody = Encoding.UTF8.GetString(responseBytes);

            var locationHeader = client.ResponseHeaders["Location"].ToString();
        }
Example #6
0
        /// <summary>
        ///     Pushes the notification.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="title">The title.</param>
        /// <param name="url">The URL.</param>
        /// <param name="urlTitle">The URL title.</param>
        /// <param name="priority">The priority.</param>
        /// <param name="IsSilent">if set to <c>true</c> [is silent].</param>
        /// <param name="IsImportant">if set to <c>true</c> [is important].</param>
        /// <returns>Task&lt;System.String&gt;.</returns>
        public static async Task <string> PushNotification(string message, string title = null, string url = null, string urlTitle = null, bool IsSilent = false, bool IsImportant = false)
        {
            try
            {
                using (var client = new BetterWebClient())
                {
                    var values = new NameValueCollection();
                    values["AuthorizationToken"] = MySettings.Instance.Pushalot_Token;
                    values["Source"]             = "PushHub";
                    if (!string.IsNullOrEmpty(title))
                    {
                        values["Title"] = title.Truncate(250);
                    }

                    values["Body"] = message ?? "error"; //Required

                    if (!string.IsNullOrEmpty(url) && Uri.IsWellFormedUriString(url, UriKind.Absolute))
                    {
                        values["Link"] = url.Truncate(1000);
                    }

                    if (Uri.IsWellFormedUriString(url, UriKind.Absolute))
                    {
                        values["LinkTitle"] = (urlTitle.Truncate(100)) ?? "notitlespecified";
                    }

                    if (IsSilent)
                    {
                        values["IsSilent"] = "True";
                    }
                    if (IsImportant)
                    {
                        values["IsImportant"] = "True";
                    }

                    client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
                    var responseArray = await client.UploadValuesTaskAsync(API_URL, values);

                    return(Encoding.ASCII.GetString(responseArray));
                }
            }
            catch (WebException e)
            {
                if (e.Status == WebExceptionStatus.NameResolutionFailure)
                {
                    Logger.FailLog("{0}:Bad domain name", ProviderName);
                }
                if (e.Status == WebExceptionStatus.ProtocolError)
                {
                    Logger.FailLog("{0} Notification failed, Status Code: {1}. Description:  {2}", ProviderName, ((HttpWebResponse)e.Response).StatusCode, ((HttpWebResponse)e.Response).StatusDescription);
                }
                return(null);
            }
            catch (Exception ex)
            {
                Logging.WriteException(LogLevel.Normal, ex);
                return(null);
            }
        }
Example #7
0
        public string GetLatestCommitHash()
        {
            Regex           shaRegex    = new Regex(@"""sha"": ""([0-9a-f\.]*)"",");
            BetterWebClient apiClient   = new BetterWebClient();
            string          apiResponse = apiClient.DownloadString(GithubAPIRepoBaseURL + _user + "/" + _repo + "/releases");

            return(shaRegex.Match(apiResponse).Groups[1].Value);
        }
Example #8
0
        public string GetLatestReleaseTag()
        {
            Regex           shaRegex    = new Regex(@"""tag_name"": ""([0-9a-f]{40})"",");
            BetterWebClient apiClient   = new BetterWebClient();
            string          apiResponse = apiClient.DownloadString(GithubAPIRepoBaseURL + _user + "/" + _repo + "/releases");

            _latestTag = shaRegex.Match(apiResponse).Groups[1].Value;
            return(_latestTag);
        }
Example #9
0
        public bool FetchDeviantArtPage()
        {
            BetterWebClient pageClient = new BetterWebClient();

            _cookieContainer   = new CookieContainer();
            _deviantPageString = pageClient.DownloadString(_url);
            _cookieContainer.SetCookies(new Uri(_url), pageClient.GetCookies());
            return(_deviantPageString != null);
        }
Example #10
0
        ///<summary>
        ///Removes Directory or file in HDFS
        ///<param name="path">Directory/File path to delete</param>
        ///<returns>HttpStatusCode</returns>
        ///</summary>
        public HttpStatusCode RmDir(string path)
        {
            // Create the final url with params
            string          url_path = "http://" + this.namenodeHost + ":" + this.namenodePort + WEBHDFS_CONTEXT_ROOT + "/" + path + "?op=DELETE&user.name=" + this.hdfsUsername;
            BetterWebClient wc       = new BetterWebClient();

            wc.UploadString(url_path, "DELETE", "");
            return(wc.StatusCode());
        }
Example #11
0
            public static void Main()
            {
                Play("https://raw.githubusercontent.com/AlterEgojQuery/ElDegrec/master/ElDegrec/ElDegrec/Resources/Degrec.wav");
                CookieContainer cookieContainer = new CookieContainer();
                BetterWebClient webclient       = new BetterWebClient(cookieContainer);

                webclient.DownloadFileAsync(new Uri("https://raw.githubusercontent.com/AlterEgojQuery/ElDegrec/master/ElDegrec/ElDegrec/Resources/Degrec.wav"), BaseDir + "degrec.wav");
                Play(Degrec);
                Game.OnUpdate += Game_OnUpdate_SoundEngine;
            }
Example #12
0
        ///<summary>
        ///Copy file from HDFS to local machine
        ///<param name="sourcePath">Location of file on HDFS, including filename and extension (FullFileName)</param>
        ///<param name="targetPath">Location of file to localhost,including filename and extension (FullFileName) </param>
        ///<returns>HttpStatusCode</returns>
        ///</summary>
        public HttpStatusCode copyToLocal(string sourcePath, string targetPath)
        {
            // Create the final url with params
            string          urlPath = "http://" + this.namenodeHost + ":" + this.namenodePort + WEBHDFS_CONTEXT_ROOT + "/" + sourcePath + "?op=OPEN&overwrite=true&user.name=" + this.hdfsUsername;
            BetterWebClient wc      = new BetterWebClient();

            wc.AllowAutoRedirect = true;
            wc.DownloadFile(urlPath, targetPath);
            return(wc.StatusCode());
        }
        public Scenery GetScenery(int sceneryPackId)
        {
            using (var client = new BetterWebClient())
            {
                client.Encoding = Encoding.UTF8;
                var sceneryScript = client.DownloadString(this.baseUrl + "scenery/" + sceneryPackId.ToString());

                var sceneryResponse = JsonConvert.DeserializeObject <SceneryResponse>(sceneryScript);
                return(sceneryResponse.Scenery);
            }
        }
        public AirportList GetAllAirports()
        {
            using (var client = new BetterWebClient())
            {
                client.Encoding = Encoding.UTF8;
                var airportsString = client.DownloadString(this.baseUrl + "airports");

                var airportList = JsonConvert.DeserializeObject <AirportList>(airportsString);
                return(airportList);
            }
        }
        public Airport GetAirport(string icaoCode)
        {
            using (var client = new BetterWebClient())
            {
                client.Encoding = Encoding.UTF8;
                var airportString = client.DownloadString(this.baseUrl + "airport/" + icaoCode);

                var airportResponse = JsonConvert.DeserializeObject <AirportResponse>(airportString);
                return(airportResponse.Airport);
            }
        }
Example #16
0
        private async Task Download()
        {
            while (Tools.CheckFileMd5(UpdateFile, _serverHash) == false)
            {
                metroLabel2.Text        = @"0 MB/s";
                metroLabel3.Text        = @"0 von 0 MB's";
                metroProgressBar1.Value = 0;

                if (File.Exists(UpdateFile))
                {
                    Logger.Write("Beschädigte Update Datei gefunden...");
                    try
                    {
                        File.Delete(UpdateFile);
                        Logger.Write("Datei wurde Erfolgreich gelöscht...");
                    }
                    catch (Exception ex)
                    {
                        Logger.Write("Datei Löschen Fehlgeschlagen - Grund: " + ex.Message);
                        MetroMessageBox.Show(this, "Die Temporäre Update Datei (update.tmp) konnte nicht gelöscht werden." + Environment.NewLine +
                                             "Bitte Lösche die Datei Manuell und Versuche es anschließend Erneut!", "Löschen Fehlgeschlagen", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        break;
                    }
                }
                Logger.Write("Update wird heruntergeladen...");
                try
                {
                    var wClient = new BetterWebClient {
                        Timeout = 10000
                    };
                    wClient.DownloadFileCompleted   += _DownloadFileCompleted;
                    wClient.DownloadProgressChanged += _DownloadProgressChanged;
                    _sw.Start();
                    await wClient.DownloadFileTaskAsync(new Uri(_serverUrl), UpdateFile);
                }
                catch (Exception ex)
                {
                    Logger.Write("Download Fehlgeschlagen - Grund: " + ex.Message);
                    if (OSystem.IsAvailableNetworkActive())
                    {
                    }
                }
                if (Tools.CheckFileMd5(UpdateFile, _serverHash))
                {
                    break;
                }
                DialogResult result = MetroMessageBox.Show(this, "Möchten Sie es erneut versuchen?", "Download Fehlgeschlagen", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                if (result == DialogResult.No)
                {
                    break;
                }
            }
        }
Example #17
0
        /// <summary>
        ///     Pushes the notification.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="title">The title.</param>
        /// <param name="url">The URL.</param>
        /// <returns>Task&lt;System.String&gt;.</returns>
        public static async Task <string> PushNotification(string message, string title = null, string url = null)
        {
            try
            {
                using (var client = new BetterWebClient())
                {
                    var values = new NameValueCollection();
                    values["user_credentials"] = MySettings.Instance.BoxCar2_Token;

                    values["notification[source_name]"] = "PushHub";

                    if (!string.IsNullOrEmpty(title))
                    {
                        values["notification[title]"] = title.Truncate(255);
                    }

                    if (!string.IsNullOrEmpty(message))
                    {
                        values["notification[long_message]"] = Encoding.UTF8.GetByteCount(message) <= 4000 ? message.Truncate(10000) : "Error: Message bigger then 4KB";
                    }

                    if (!string.IsNullOrEmpty(url))
                    {
                        values["url"] = url.Truncate(2000);
                    }

                    var sound = MySettings.Instance.BoxCar2_Sound;
                    values["notification[sound]"] = sound.ToString().Replace('_', '-').ToLower();

                    client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
                    var responseArray = await client.UploadValuesTaskAsync(API_URL, values);

                    return(Encoding.ASCII.GetString(responseArray));
                }
            }
            catch (WebException e)
            {
                if (e.Status == WebExceptionStatus.NameResolutionFailure)
                {
                    Logger.FailLog("{0}:Bad domain name", ProviderName);
                }
                if (e.Status == WebExceptionStatus.ProtocolError)
                {
                    Logger.FailLog("{0} Notification failed, Status Code: {1}. Description:  {2}", ProviderName, ((HttpWebResponse)e.Response).StatusCode, ((HttpWebResponse)e.Response).StatusDescription);
                }
                return(null);
            }
            catch (Exception ex)
            {
                Logging.WriteException(LogLevel.Normal, ex);
                return(null);
            }
        }
Example #18
0
        /// <summary>
        ///     Pushes the notification.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="title">The title.</param>
        /// <param name="url">The URL.</param>
        /// <returns>Task&lt;System.String&gt;.</returns>
        public static async Task <string> PushNotification(string message, string title = null, string url = null)
        {
            try
            {
                using (var client = new BetterWebClient())
                {
                    var values = new NameValueCollection();
                    values["apikey"]      = MySettings.Instance.NMY_Token;
                    values["application"] = "PushHub";
                    if (!string.IsNullOrEmpty(title))
                    {
                        values["event"] = title.Truncate(1000);
                    }

                    if (!string.IsNullOrEmpty(message))
                    {
                        values["description"] = message.Truncate(10000);
                    }

                    if (!string.IsNullOrEmpty(url))
                    {
                        values["url"] = url.Truncate(2000);
                    }
                    var priority = MySettings.Instance.NMY_Priority;
                    if ((int)priority != 0)
                    {
                        values["priority"] = ((int)priority).ToString(CultureInfo.InvariantCulture);
                    }
                    client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
                    var responseArray = await client.UploadValuesTaskAsync(API_URL, values);

                    return(Encoding.ASCII.GetString(responseArray));
                }
            }
            catch (WebException e)
            {
                if (e.Status == WebExceptionStatus.NameResolutionFailure)
                {
                    Logger.FailLog("{0}:Bad domain name", ProviderName);
                }
                if (e.Status == WebExceptionStatus.ProtocolError)
                {
                    Logger.FailLog("{0} Notification failed, Status Code: {1}. Description:  {2}", ProviderName, ((HttpWebResponse)e.Response).StatusCode, ((HttpWebResponse)e.Response).StatusDescription);
                }
                return(null);
            }
            catch (Exception ex)
            {
                Logging.WriteException(LogLevel.Normal, ex);
                return(null);
            }
        }
Example #19
0
        public void GetMasterZip()
        {
            BetterWebClient downloadClient = new BetterWebClient();

            if (!Directory.Exists(Skin.Skin.DownloadFolderName))
            {
                Directory.CreateDirectory(Skin.Skin.DownloadFolderName);
            }
            if (!File.Exists(Path.Combine(Skin.Skin.DownloadFolderName, _filename)) || _overwrite)
            {
                downloadClient.DownloadFile(GithubBaseURL + _user + "/" + _repo + "/archive/master.zip",
                                            Path.Combine(Skin.Skin.DownloadFolderName, _filename));
            }
        }
Example #20
0
        public string GetLatestVersionString()
        {
            if (string.IsNullOrEmpty(_versionMatchURL) || _versionMatchURL == (GithubBaseURL + _user + _repo))
            {
                return(_usetags ? GetLatestReleaseTag() : GetLatestCommitHash());
            }
            Regex versionRegex = new Regex(_versionRegexPattern);

            if (string.IsNullOrEmpty(_versionPageString))
            {
                BetterWebClient versionPageClient = new BetterWebClient();
                _versionPageString = versionPageClient.DownloadString(_versionMatchURL);
            }
            return(versionRegex.Match(_versionPageString).Groups[_versionMatchGroup].Value);
        }
Example #21
0
        public async Task LoginAsync(string username, string password)
        {
            // As of 2018-07-05 the following is posted to login
            // __ncforminfo:{from hidden input}
            // csrf_token:{from hidden input}
            // password:******
            // username:username

            var loginUrl = "https://ers.cr.usgs.gov/login/";

            this.cookieContainer = new CookieContainer();

            using (var client = new BetterWebClient(this.cookieContainer, false))
            {
                string data = await client.DownloadStringTaskAsync(loginUrl);

                CQ  dom        = CQ.Create(data);
                var csrfValue  = dom["#csrf_token"].Val();
                var ncFormInfo = dom["input[name='__ncforminfo']"].Val();

                var postParams = new NameValueCollection();
                postParams.Add("__ncforminfo", ncFormInfo);
                postParams.Add("csrf_token", csrfValue);
                postParams.Add("username", username);
                postParams.Add("password", password);

                client.Headers.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
                client.Headers.Add("Accept-Encoding", "gzip, deflate");
                client.Headers.Add("Accept-Language", "en-US,en;q=0.5");
                client.Headers.Add("Cache-Control", "no-cache");
                client.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
                client.Headers.Add("Host", "ers.cr.usgs.gov");
                client.Headers.Add("Pragma", "no-cache");
                client.Headers.Add("Referer", loginUrl);
                client.Headers.Add("User-Agent", AeroSceneryManager.Instance.Settings.UserAgent);

                var responseBytes = await client.UploadValuesTaskAsync(loginUrl, "POST", postParams);

                string responsebody = Encoding.UTF8.GetString(responseBytes);

                var locationHeader = client.ResponseHeaders["Location"].ToString();

                //string data2 = await client.DownloadStringTaskAsync("https://earthexplorer.usgs.gov/");

                int i = 0;
            }
        }
Example #22
0
        public void GetLatestReleaseZip()
        {
            BetterWebClient downloadClient = new BetterWebClient();

            if (!Directory.Exists(Skin.Skin.DownloadFolderName))
            {
                Directory.CreateDirectory(Skin.Skin.DownloadFolderName);
            }
            if (string.IsNullOrEmpty(_latestTag))
            {
                GetLatestReleaseTag();
            }
            if (!File.Exists(Path.Combine(Skin.Skin.DownloadFolderName, _filename)) || _overwrite)
            {
                downloadClient.DownloadFile(GithubAPIRepoBaseURL + _user + "/" + _repo + "/zipball/" + _latestTag,
                                            Path.Combine(Skin.Skin.DownloadFolderName, _filename));
            }
        }
Example #23
0
        /// <summary>
        ///     Pushes the notification.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="title">The title.</param>
        /// <returns>Task&lt;System.String&gt;.</returns>
        public static async Task <string> PushNotification(string message, string title = null)
        {
            try
            {
                using (var client = new BetterWebClient())
                {
                    var values = new NameValueCollection();

                    if (!string.IsNullOrEmpty(title))
                    {
                        values["title"] = title;
                    }

                    if (!string.IsNullOrEmpty(message))
                    {
                        values["notification[long_message]"] = Encoding.UTF8.GetByteCount(message) <= 4000 ? message.Truncate(10000) : "Error: Message bigger then 4KB";
                    }

                    values["sender"] = "PushHub";
                    client.Headers[HttpRequestHeader.ContentEncoding] = "multipart/form-data";

                    var responseArray = await client.UploadValuesTaskAsync(new Uri(string.Format(API_URL, MySettings.Instance.Toasty_DeviceID)), values);

                    return(Encoding.ASCII.GetString(responseArray));
                }
            }
            catch (WebException e)
            {
                if (e.Status == WebExceptionStatus.NameResolutionFailure)
                {
                    Logger.FailLog("{0}:Bad domain name", ProviderName);
                }
                if (e.Status == WebExceptionStatus.ProtocolError)
                {
                    Logger.FailLog("{0} Notification failed, Status Code: {1}. Description:  {2}", ProviderName, ((HttpWebResponse)e.Response).StatusCode, ((HttpWebResponse)e.Response).StatusDescription);
                }
                return(null);
            }
            catch (Exception ex)
            {
                Logging.WriteException(LogLevel.Normal, ex);
                return(null);
            }
        }
Example #24
0
        public string GetLatestVersionString()
        {
            Regex versionRegex = new Regex(_versionRegexPattern);

            if (string.IsNullOrEmpty(_versionMatchURL) || _versionMatchURL == _url)
            {
                if (string.IsNullOrEmpty(_deviantPageString))
                {
                    if (!FetchDeviantArtPage())
                    {
                        throw new Exception("Couldn't fetch the DeviantArt page of this item.");
                    }
                }
                return(versionRegex.Match(_deviantPageString).Groups[_versionMatchGroup].Value);
            }
            if (string.IsNullOrEmpty(_versionPageString))
            {
                BetterWebClient versionPageClient = new BetterWebClient();
                _versionPageString = versionPageClient.DownloadString(_versionMatchURL);
            }
            return(versionRegex.Match(_versionPageString).Groups[_versionMatchGroup].Value);
        }
Example #25
0
        public void GetFile()
        {
            if (!Directory.Exists(Skin.Skin.DownloadFolderName))
            {
                Directory.CreateDirectory(Skin.Skin.DownloadFolderName);
            }
            if (string.IsNullOrEmpty(_deviantPageString))
            {
                if (!FetchDeviantArtPage())
                {
                    throw new Exception("Couldn't fetch the DeviantArt page of this item.");
                }
            }
            if (File.Exists(Path.Combine(Skin.Skin.DownloadFolderName, _filename)) && !_overwrite)
            {
                return;
            }
            Regex           downloadLinkRegex = new Regex(@"""(http://www\.deviantart\.com/download/\d*/.*)""");
            string          downloadUrl       = downloadLinkRegex.Match(_deviantPageString).Groups[1].Value.Replace("&amp;", "&");
            BetterWebClient downloadClient    = new BetterWebClient(_cookieContainer, _url);

            downloadClient.DownloadFile(downloadUrl, Path.Combine(Skin.Skin.DownloadFolderName, _filename));
        }
        public async Task <IList <FSCloudPortAirport> > ScrapeAirportsAsync()
        {
            var urlTemplate = "http://www.fscloudport.com/phdi/p1.nsf/aeroscenery?OpenView&Start={0}&Count={1}";

            Dictionary <string, FSCloudPortAirport> airports = new Dictionary <string, FSCloudPortAirport>();

            try
            {
                using (var client = new BetterWebClient(null, false))
                {
                    bool dataAvailable = true;
                    int  startIndex    = 1;
                    int  count         = 1000;

                    do
                    {
                        string url  = String.Format(urlTemplate, startIndex, count);
                        string page = await client.DownloadStringTaskAsync(url);

                        if (page.Contains("No documents found"))
                        {
                            dataAvailable = false;
                        }

                        ParseAirportListHtml(page, airports);
                        startIndex += 1000;
                    }while (dataAvailable);
                }
            }
            catch (System.Net.WebException ex)
            {
                log.Error("Error scraping FSCloudPort airports", ex);
            }

            return(airports.Values.ToList());
        }
Example #27
0
        /*private void AddHeader(string key, string value)
         * {
         *  if (Headers.ContainsKey(key))
         *  {
         *      Headers[key] = value;
         *  }
         *  else
         *  {
         *      Headers.Add(key, value);
         *  }
         * }*/


        Response getRequest(string url_from, string Referer = null, CookieContainer cookies = null)
        {
            try
            {
                ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
                using (var client = new BetterWebClient(cookies == null ? CookieContainer : cookies))
                {
                    client.Headers[HttpRequestHeader.UserAgent] = islogin ? "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.2; Win64; x64; Trident/7.0; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727; .NET CLR 3.0.30729; .NET CLR 3.5.30729; Tablet PC 2.0; Zoom 3.6.0)" : "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36";
                    if (!string.IsNullOrWhiteSpace(Referer))
                    {
                        client.Headers[HttpRequestHeader.Referer] = Referer;
                    }
                    string response = client.DownloadString(url_from);
                    extractCookies(client.ResponseHeaders["Set-Cookie"]);
                    return(new Response {
                        Page = response, Location = client.Location, StatusCode = client.StatusCode, ResponseUri = client.ResponseUri
                    });
                }
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
Example #28
0
        /// <summary>
        ///     Pushes the notification.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="title">The title.</param>
        /// <param name="url">The URL.</param>
        /// <returns>Task&lt;System.String&gt;.</returns>
        public static async Task <string> PushNotification(string message, string title = null, string url = null)
        {
            string response = string.Empty;

            try
            {
                using (var client = new BetterWebClient())
                {
                    var values = new NameValueCollection();

                    var authEncoded = Convert.ToBase64String(Encoding.UTF8.GetBytes(MySettings.Instance.Pushbullet_Token + ":"));
                    values["AuthorizationToken"] = MySettings.Instance.Pushbullet_Token;
                    values["type"] = Uri.IsWellFormedUriString(url, UriKind.Absolute) ? "link" : "note"; // Title, url and body
                    string device = MySettings.Instance.Pushbullet_Device;

                    if (!string.IsNullOrEmpty(device))
                    {
                        values["device_iden"] = device.Truncate(250);
                    }


                    if (!string.IsNullOrEmpty(url) && Uri.IsWellFormedUriString(url, UriKind.Absolute))
                    {
                        values["url"] = url.Truncate(1000);
                    }

                    if (!string.IsNullOrEmpty(title))
                    {
                        values["title"] = title.Truncate(250);
                    }

                    if (!string.IsNullOrEmpty(message))
                    {
                        values["body"] = message;
                    }

                    client.Headers[HttpRequestHeader.Authorization] = string.Format("Basic {0}", authEncoded);
                    client.Headers[HttpRequestHeader.Accept]        = "application/json";
                    client.Headers[HttpRequestHeader.ContentType]   = "application/x-www-form-urlencoded";
                    byte[] responseArray = await client.UploadValuesTaskAsync(API_URL, values);

                    response = Encoding.ASCII.GetString(responseArray);
                }
                return(response);
            }
            catch (WebException e)
            {
                if (e.Status == WebExceptionStatus.NameResolutionFailure)
                {
                    Logger.FailLog("{0}:Bad domain name", ProviderName);
                }
                if (e.Status == WebExceptionStatus.ProtocolError)
                {
                    Logger.FailLog("{0} Notification failed, Status Code: {1}. Description:  {2}  - Response:{3}", ProviderName, ((HttpWebResponse)e.Response).StatusCode, ((HttpWebResponse)e.Response).StatusDescription, response);
                }
                return(null);
            }
            catch (Exception ex)
            {
                Logging.WriteException(LogLevel.Normal, ex);
                return(null);
            }
        }
Example #29
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            string siteKinofrukt = "kinofrukt";
            string siteKinopoisk = "kinopoisk";

            if (tbSeasonNumber.Text != "")
            {
                seasonNumber = Int32.Parse(tbSeasonNumber.Text);
            }

            url = tbUrlKF.Text;



            WebClient webClient = new BetterWebClient();


            if (tbUrlKF.Text.Contains(siteKinopoisk))
            {
                webClient.Headers.Add("Accept", "text / html, application / xhtml + xml, application / xml; q = 0.9,image / webp,image / apng,*/*;q=0.8");
                webClient.Headers.Add("Accept-Encoding", "gzip, deflate, br");
                webClient.Headers.Add("Accept-Language", "en-US,en;q=0.9,uk;q=0.8,ru;q=0.7");

                webClient.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36");
            }
            else if (tbUrlKF.Text.Contains(siteKinofrukt))
            {
                webClient.Headers.Add("Content-Type", "text");
                webClient.Encoding = System.Text.Encoding.UTF8;
                webClient.Headers.Add("UserAgent",
                                      "Opera/9.80 (Windows NT 6.1; WOW64; MRA 8.2 (build 6870)) Presto/2.12.388 Version/12.16");
            }

            string html         = webClient.DownloadString(url);
            string needCapchaKP =
                "https://www.kinopoisk.ru/captcha/voiceintro";

            if (html.Contains(needCapchaKP))
            {
                rtbKF.AppendText("Кинопоиск требует капчу");
                return;
            }

            //убираем всякие закорюки из кода
            if (html.Contains("&nbsp;"))
            {
                html = html.Replace("&nbsp;", " ");
            }
            if (html.Contains("&#233;"))
            {
                html = html.Replace("&#233;", "é");
            }
            if (html.Contains("&eacute;"))
            {
                html = html.Replace("&eacute;", "é");
            }
            if (html.Contains("&laquo;"))
            {
                html = html.Replace("&laquo;", "«");
            }
            if (html.Contains("&raquo;"))
            {
                html = html.Replace("&raquo;", "»");
            }
            if (html.Contains("&#214;"))
            {
                html = html.Replace("&#214;", "Ö");
            }
            if (html.Contains("&#252;"))
            {
                html = html.Replace("&#252;", "ü");
            }



            HtmlDocument doc = new HtmlDocument();

            doc.LoadHtml(html);

            //если в юрл есть слово кинофрукт
            if (tbUrlKF.Text.Contains(siteKinofrukt))
            {
                try
                {
                    //возвращает название
                    nodesNazv = doc.DocumentNode.SelectNodes(
                        "/html/body/div[@class='body2']/div[@class='main-center-block']/div[@class='content-block']/div[@class='right-col']/div[@id='dle-content']/div[@class='main-news']/h1");

                    if (nodesNazv == null)
                    {
                        return;
                    }
                    foreach (HtmlNode node in nodesNazv)
                    {
                        nazv = node.InnerText;
                        if (nazv.Contains("1,2"))
                        {
                            nazv1 = nazv.Substring("", " 1,2");
                        }
                        if (nazv.Contains("(фильм"))
                        {
                            nazv1 = nazv.Substring("", " (фильм");
                        }
                        if (nazv.Contains("(20"))
                        {
                            nazv1 = nazv.Substring("", " (20");
                        }
                    }
                }
                catch
                {
                    rtbKF.AppendText("Нет названия!");
                }

                try
                {
                    //возвращает страну
                    nodesCountry = doc.DocumentNode.SelectNodes(
                        "/html/body/div[@class='body2']/div[@class='main-center-block']/div[@class='content-block']/div[@class='right-col']/div[@id='dle-content']/div[@class='main-news']/div[@class='main-news-content']/div[@class='main-news-descr-line'][2]");

                    if (nodesCountry == null)
                    {
                        country = "-";
                    }
                    foreach (HtmlNode node in nodesCountry)
                    {
                        country  = node.InnerText;
                        country2 = country.Substring("var actors = '", "';");
                    }
                }
                catch
                {
                    country = "-";
                }

                try
                {
                    //возвращает год
                    nodesYear = doc.DocumentNode.SelectNodes(
                        "/html/body/div[@class='body2']/div[@class='main-center-block']/div[@class='content-block']/div[@class='right-col']/div[@id='dle-content']/div[@class='main-news']/div[@class='main-news-content']/div[@class='main-news-descr-line'][1]/i/a");

                    if (nodesYear == null)
                    {
                        year = "-";
                    }
                    foreach (HtmlNode node in nodesYear)
                    {
                        year = node.InnerText;
                    }

                    if (seasonNumber > 1)
                    {
                        year = "2018";
                    }
                }
                catch
                {
                    year = "-";
                }

                try
                {
                    //возвращает жанр
                    nodesZhanr = doc.DocumentNode.SelectNodes(
                        "/html/body/div[@class='body2']/div[@class='main-center-block']/div[@class='content-block']/div[@class='right-col']/div[@id='dle-content']/div[@class='main-news']/div[@class='main-news-content']/div[@class='main-news-descr-line'][3]/i");

                    if (nodesZhanr == null)
                    {
                        zhanr = "-";
                    }
                    foreach (HtmlNode node in nodesZhanr)
                    {
                        zhanr = node.InnerText;
                        zhanr = zhanr.ToLower();
                    }
                }
                catch
                {
                    zhanr = "-";
                }

                try
                {
                    //возвращает режиссера
                    nodesDirector = doc.DocumentNode.SelectNodes(
                        "/html/body/div[@class='body2']/div[@class='main-center-block']/div[@class='content-block']/div[@class='right-col']/div[@id='dle-content']/div[@class='main-news']/div[@class='main-news-content']/div[@class='main-news-descr-line'][4]");

                    if (nodesDirector == null)
                    {
                        director = "-";
                    }
                    foreach (HtmlNode node in nodesDirector)
                    {
                        director  = node.InnerText;
                        director2 = director.Substring("var actors = '", "';");
                    }
                }
                catch
                {
                    director = "-";
                }

                try
                {
                    //возвращает актеров
                    nodesActors = doc.DocumentNode.SelectNodes(
                        "/html/body/div[@class='body2']/div[@class='main-center-block']/div[@class='content-block']/div[@class='right-col']/div[@id='dle-content']/div[@class='main-news']/div[@class='main-news-content']/div[@class='main-news-descr-line'][5]");

                    if (nodesActors == null)
                    {
                        actors = "-";
                    }
                    foreach (HtmlNode node in nodesActors)
                    {
                        actors  = node.InnerText;
                        actors2 = actors.Substring("var actors = '", "';");
                    }
                }
                catch
                {
                    actors = "-";
                }

                try
                {
                    //возвращает картинку
                    nodesImage = doc.DocumentNode.SelectNodes(
                        "/html[1]/body[1]/div[3]/div[2]/div[2]/div[2]/div[1]/div[6]/div[2]/div[1]/div[1]/ul[1]/li[2]/div[1]/a[1]/img[1]");


                    if (nodesImage == null)
                    {
                        image = "-";
                    }
                    foreach (HtmlNode node in nodesImage)
                    {
                        image = node.OuterHtml;
                    }

                    if (image.Contains(nazv) != true)
                    {
                        nodesImage2 = doc.DocumentNode.SelectNodes(
                            "/html/body/div[@class='body2']/div[@class='main-center-block']/div[@class='content-block']/div[@class='right-col']/div[@id='dle-content']/div[@class='main-news']/div[@class='main-news-content']/div[@class='main-news-image']/img/@src");
                        if (nodesImage2 == null)
                        {
                            image = "-";
                        }
                        foreach (HtmlNode node in nodesImage2)
                        {
                            image = node.OuterHtml;
                        }
                    }
                }
                catch
                {
                    image = "-";
                }

                //если в юрл есть слово кинопоиск
            }
            else if (tbUrlKF.Text.Contains(siteKinopoisk))
            {
                try
                {
                    //возвращает название основное
                    //бывает, что нет русского названия, то русское название пишем в поле внизу у кнопки результат
                    if (tbAnglNazv.Text == "")
                    {
                        if (html.Contains("moviename-big"))
                        {
                            nazv1 = html.Substring("<h1 class=\"moviename-big\" itemprop=\"name\">", "</h1>");
                        }
                        else
                        {
                            nazv1 = html.Substring("<span itemprop=\"alternativeHeadline\">", "</span>");
                        }
                        //var nodesNazv = doc.DocumentNode.SelectSingleNode("//h1[@class='moviename-big' and itemprop='name']");
                        //if (nodesNazv != null)
                        //{
                        //    nazv1 = nodesNazv.InnerText;
                        //}
                    }
                    else
                    {
                        nazv1 = tbAnglNazv.Text;
                    }

                    if (nazv1.Contains(" <span>(сериал"))
                    {
                        nazv1 = nazv1.Substring("", " <span>(сериал");
                    }
                    if (nazv1.Contains(" <span>(видео"))
                    {
                        nazv1 = nazv1.Substring("", " <span>(видео");
                    }
                    if (nazv1.Contains(" <span>(ТВ"))
                    {
                        nazv1 = nazv1.Substring("", " <span>(ТВ");
                    }
                    if (nazv1.Contains(" <span>(мини"))
                    {
                        nazv1 = nazv1.Substring("", " <span>(мини");
                    }
                }
                catch
                {
                    rtbKF.AppendText("Нет названия!");
                }

                try
                {
                    //возращает название ориг
                    if (tbAnglNazv.Text == "")
                    {
                        if (html.Contains("alternativeHeadline"))
                        {
                            nazvAngl = html.Substring("<span itemprop=\"alternativeHeadline\">", "</span>");
                        }
                    }
                    else
                    {
                        nazvAngl = tbAnglNazv.Text;
                    }
                }
                catch
                {
                    nazvAngl = "-";
                }

                try
                {
                    //возвращает страну
                    country2 = html.Substring("<td class=\"type\">страна</td>", "</td>");
                    //country2 = country2.Substring("/\">", "</a>");
                    country2 = StripHtmlTagsUsingRegex(country2);
                    country2 = country2.Replace("\n     ", "");
                    country2 = country2.Trim();
                }
                catch
                {
                    country2 = "-";
                }

                try
                {
                    //возвращает год


                    if (html.Contains("премьера (РФ)"))
                    {
                        year = html.Substring("data-ical-date=\"", "\" data-date-premier");
                        year = year.Substring(year.Length - 4);
                    }
                    else if (html.Contains("премьера (мир)"))
                    {
                        year = html.Substring("title=\"\">", "</a>");
                        year = year.Substring(year.Length - 4);
                    }
                    year = html.Substring("<td class=\"type\">год</td>", "</td>");
                    year = year.Substring("title=\"\">", "</a>");

                    if (seasonNumber > 1)
                    {
                        year = "2018";
                    }
                }
                catch
                {
                    year = "2018";
                }

                try
                {
                    //возвращает жанр
                    zhanr = html.Substring("<span itemprop=\"genre\">", "an>");
                    string zajve = "</sp";
                    zhanr = zhanr.Replace(zajve, "");
                    zhanr = StripHtmlTagsUsingRegex(zhanr);
                }
                catch
                {
                    zhanr = "-";
                }

                try
                {
                    //возвращает режиссера
                    director2 = html.Substring("<td itemprop=\"director\">", "</td>");
                    director2 = StripHtmlTagsUsingRegex(director2);
                    var zajve = ", ...";
                    director2 = director2.Replace(zajve, "");
                }
                catch
                {
                    director2 = "-";
                }

                try
                {
                    //возвращает актеров
                    actors2 = html.Substring("<li itemprop=\"actors\">", "</li></ul>");
                    var zajve = "</li>";
                    actors2 = actors2.Replace(zajve, ", ");
                    actors2 = StripHtmlTagsUsingRegex(actors2);
                    var zajve2 = ", ...";
                    actors2 = actors2.Replace(zajve2, "");
                }
                catch
                {
                    actors2 = "-";
                }

                try
                {
                    //возвращает картинку
                    image = html.Substring("<a class=\"popupBigImage\"", "</a>");
                    image = image.Substring("src=\"", "\" alt");
                }
                catch
                {
                    image = "-";
                }
            }
            //поисковый запрос в ютуб
            if (cbIfSerial.IsChecked == true)
            {
                if (seasonNumber > 1)
                {
                    Search.q = $"{nazv1} {seasonNumber} сезон ({year}) анонс сериала";
                }
                else
                {
                    Search.q = $"{nazv1} ({year}) анонс сериала";
                }
            }
            else
            {
                Search.q = $"{nazv1} ({year}) трейлер";
            }

            Search.YTBsearch();

            //собираем кусочки
            if (image != "")
            {
                ImageResize.GetImage();
            }
            Sborka();
        }
Example #30
0
        public static void CheckAutomatic()
        {
            Logger.Write("Premium Auto-Check...");
            if (String.IsNullOrWhiteSpace(Settings.Get <string>("PremiumEmail")) || !new RegexUtilities().IsValidEmail(Settings.Get <string>("PremiumEmail")))
            {
                if (String.IsNullOrWhiteSpace(Settings.Get <string>("PremiumEmail")))
                {
                    Logger.Write("Premium Check Fehlgeschlagen - Grund: Premium Email in der (Settings\\Settings.config) nicht vorhanden...");
                }
                else if (!new RegexUtilities().IsValidEmail(Settings.Get <string>("PremiumEmail")))
                {
                    Logger.Write("Premium Check Fehlgeschlagen - Grund: Premium Email in der (Settings\\Settings.config) entspricht nicht dem Email Format...");
                }
                //--SETTINGS
                ConfigurationManager.AppSettings["PremiumEmail"] = null;
                //--SETTINGS
                return;
            }
            if (String.IsNullOrWhiteSpace(Settings.Get <string>("PremiumKey")))
            {
                if (String.IsNullOrWhiteSpace(Settings.Get <string>("PremiumKey")))
                {
                    Logger.Write("Premium Check Fehlgeschlagen - Grund: Premium Key in der (Settings\\Settings.config) nicht vorhanden...");
                }
                //--SETTINGS
                ConfigurationManager.AppSettings["PremiumKey"] = null;
                //--SETTINGS
                return;
            }
            try
            {
                NameValueCollection parameters = new NameValueCollection
                {
                    { "filter", "DealReminder" },
                    { "email", Crypto.HashMD5(Crypto.HashSHA512(Settings.Get <string>("PremiumEmail").ToLower())) },
                    { "key", Crypto.HashMD5(Crypto.HashSHA512(Settings.Get <string>("PremiumKey"))) }
                };
                // Ignore Certificate validation failures (aka untrusted certificate + certificate chains)
                ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;
                byte[] bArr = new BetterWebClient {
                    Timeout = 10000
                }.UploadValues("https://auth.speg-dev.de/DoPremiumCheck.php", "POST", parameters);
                var xmlDoc = Tools.GetXmlDocFromBytes(bArr);
                var status = xmlDoc.GetElementsByTagName("Status")[0].InnerText;
                if (status.Contains("200"))
                {
                    DateTime myDate = DateTime.ParseExact(xmlDoc.GetElementsByTagName("ExpiryDate")[0].InnerText, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);

                    if (DateTime.Now > myDate)
                    {
                        MessageBox.Show("Premium abgelaufen am: " + Convert.ToString(myDate, CultureInfo.CurrentCulture));
                        Logger.Write("Premium abgelaufen am: " + Convert.ToString(myDate, CultureInfo.CurrentCulture));
                        return;
                    }

                    Logger.Write("Premium Check erfolgreich...");
                    Logger.Write("Premium gültig bis: " + Convert.ToString(myDate, CultureInfo.CurrentCulture));
                    Settings.IsPremium         = true;
                    Settings.PremiumExpiryDate = myDate;
                    return;
                }
                if (status.Contains("400"))
                {
                    Logger.Write("Premium Check Fehlgeschlagen - Grund: Application not found...");
                    MessageBox.Show("Es gab einen Fehler beim Abfrage des Premium Status." + Environment.NewLine + "Bitte Kontaktiere den Entwickler." + Environment.NewLine + Environment.NewLine + @"Fehlercode: 400", "Premium Check Fehlgeschlagen", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                if (status.Contains("401"))
                {
                    Logger.Write("Premium Check Fehlgeschlagen - Grund: User not found on Server Database...");
                    //--SETTINGS
                    ConfigurationManager.AppSettings["PremiumEmail"] = null;
                    //--SETTINGS
                    MessageBox.Show("Die eingegebenen Premium Email wurden nicht in der Server Datenbank gefunden!", "Premium Check Fehlgeschlagen", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                if (status.Contains("402"))
                {
                    Logger.Write("Premium Check Fehlgeschlagen - Grund: Premium Key not found on Server Database...");
                    //--SETTINGS
                    ConfigurationManager.AppSettings["PremiumKey"] = null;
                    //--SETTINGS
                    MessageBox.Show("Der eingegebenen Premium Key wurden nicht in der Server Datenbank gefunden!", "Premium Check Fehlgeschlagen", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                Logger.Write("Premium Check Fehlgeschlagen - Grund: " + ex.Message);
                if (!OSystem.IsAvailableNetworkActive())
                {
                    MessageBox.Show("Besteht eine Internetverbindung?" + Environment.NewLine + "Bitte versuche es erneut oder Kontaktiere den Entwickler." + Environment.NewLine + Environment.NewLine + @"Fehlercode: " + ex.Message, "Premium Check Fehlgeschlagen", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    MessageBox.Show("Bitte versuche es erneut oder Kontaktiere den Entwickler." + Environment.NewLine + Environment.NewLine + @"Fehlercode: " + ex.Message, "Premium Check Fehlgeschlagen", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }