コード例 #1
0
ファイル: InstallPanel.cs プロジェクト: Sheeyre/BBDInstaller
        private async Task <int> DownloadBd(string installationPath)
        {
            var channel = $"https://github.com/{repo}/BetterDiscordApp/archive/{branch}.zip";
            var dest    = $"{installationPath}\\resources\\BetterDiscord.zip";

            Append("Downloading BandagedBD package");

            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12 | SecurityProtocolType.Ssl3;


            using (var wc = new TimedWebClient()) {
                wc.DownloadProgressChanged += (sender, args) => {
                    setProgress(args.ProgressPercentage / 2);
                };

                Append($"Using channel: {channel}", true);
                Append($"Downloading to: {dest}", true);

                try {
                    await wc.DownloadFileTaskAsync(channel, dest);
                }
                catch (WebException e) {
                    Append("Download error: " + e.Message, true);
                    return(0);
                }
            }

            Append("Finished downloading BandagedBD package");

            return(ExtractBd(dest, $"{installationPath}\\resources"));
        }
コード例 #2
0
        public static async Task <T> ExecuteGet <T>(string url)
        {
            using (var wc = new TimedWebClient()) {
                var str = await wc.DownloadStringTaskAsync(new Uri(url));

                return(JsonConvert.DeserializeObject <T>(str));
            }
        }
コード例 #3
0
        public static T ExecuteGetSync <T>(string url)
        {
            using (var wc = new TimedWebClient()) {
                var str = wc.DownloadString(new Uri(url));

                return(JsonConvert.DeserializeObject <T>(str));
            }
        }
コード例 #4
0
        public static string ExecutePostSyncToString <T>(string url, string parameters)
        {
            using (var wc = new TimedWebClient()) {
                wc.Timeout = 30000;
                wc.Headers[HttpRequestHeader.ContentType] = "application/json; charset=utf-8";
                string HtmlResult = wc.UploadString(new Uri(url), parameters);

                return(HtmlResult);
            }
        }
コード例 #5
0
 public static string ExecuteGetAsStringSync(string url, int?timeOut = null)
 {
     using (var wc = new TimedWebClient()) {
         if (timeOut.HasValue)
         {
             wc.Timeout = timeOut.Value;
         }
         return(wc.DownloadString(new Uri(url)));
     }
 }
コード例 #6
0
        public static async Task <T> ExecutePost <T>(string url, string parameters)
        {
            using (var wc = new TimedWebClient()) {
                wc.Timeout = 30000;
                wc.Headers[HttpRequestHeader.ContentType] = "application/json; charset=utf-8";
                string HtmlResult = await wc.UploadStringTaskAsync(new Uri(url), parameters);

                return(JsonConvert.DeserializeObject <T>(HtmlResult));
            }
        }
コード例 #7
0
        public static T ExecutePutSync <T>(string url, string parameters, int timeout = 30000)
        {
            using (var wc = new TimedWebClient()) {
                wc.Timeout = timeout;
                wc.Headers[HttpRequestHeader.ContentType] = "application/json; charset=utf-8";
                string HtmlResult = wc.UploadString(new Uri(url), "PUT", parameters);

                return(JsonConvert.DeserializeObject <T>(HtmlResult));
            }
        }
コード例 #8
0
ファイル: GithubTracker.cs プロジェクト: bsamuels453/Pikatwo
        void QueueNewAnnouncement(HtmlNodeCollection repoNodes)
        {
            string title            = repoNodes["title"].InnerText;
            var    separator        = title.IndexOf('/');
            var    repoName         = title.Substring(separator + 1);
            var    author           = repoNodes["author"].ChildNodes["name"].InnerText;
            var    publishTime      = repoNodes["published"].InnerText;
            var    rawLink          = repoNodes["link"].Attributes["href"].Value;
            var    compareSeparator = rawLink.LastIndexOf('/');
            var    link             = rawLink.Substring(0, compareSeparator + 1);
            var    beginCommit      = rawLink.Substring(compareSeparator + 1, 10);
            var    endCommit        = rawLink.Substring(compareSeparator + 1 + 10 + 3, 10);
            var    timestamp        = new DateTime
                                      (
                int.Parse(publishTime.Substring(0, 4)),
                int.Parse(publishTime.Substring(5, 2)),
                int.Parse(publishTime.Substring(8, 2)),
                int.Parse(publishTime.Substring(11, 2)),
                int.Parse(publishTime.Substring(14, 2)),
                int.Parse(publishTime.Substring(17, 2))
                                      );

            var client     = new TimedWebClient();
            var commitPage = client.DownloadString(rawLink);
            var doc        = new HtmlDocument();

            doc.LoadHtml(commitPage);
            client.Dispose();

            var entry         = doc.DocumentNode.SelectNodes("//span[@class=\"num\"]");
            var rawNumCommits = entry[0].InnerText;

            rawNumCommits = new string(rawNumCommits.Where(char.IsDigit).ToArray());
            int numCommits = int.Parse(rawNumCommits);


            if (_subscribedProjects.Contains(repoName))
            {
                lock (_queuedAnnouncements){
                    _queuedAnnouncements.Add
                        (new QueuedAnnouncement
                        (
                            author,
                            link,
                            repoName,
                            timestamp,
                            beginCommit,
                            endCommit,
                            numCommits
                        )
                        );
                }
            }
        }
コード例 #9
0
    public string sendSMS(string MobileNo, string smsText)
    {
        string SmsStatusMsg = string.Empty;

        try
        {
            WebClient     client = new WebClient();
            StringBuilder sb     = new StringBuilder();

            sb.Append(_settings.SmsBegin);

            sb.Append(_settings.SmsUserName);
            sb.Append(_settings.SmsSecond);
            sb.Append(_settings.SmsPassword);
            sb.Append(_settings.SmsThird);
            sb.Append(_settings.SmsSenderIDPromotional);
            sb.Append(_settings.SmsFouth);
            sb.Append(_settings.SmsRoutePro);
            sb.Append(_settings.SmsFifth);
            sb.Append(MobileNo);

            sb.Append(_settings.SmsLast);
            sb.Append(smsText);

            string URL = sb.ToString();
            SmsStatusMsg = new TimedWebClient {
                Timeout = 600000
            }.DownloadString(URL);

            string datetime = DateTime.Now.ToString("yyyyMMdd");

            DataTable dt = new DataTable();
            dt.Columns.AddRange(new DataColumn[5] {
                new DataColumn("sms_Broadcast_id"), new DataColumn("sms_Status"), new DataColumn("sms_mobileNo"), new DataColumn("sms_text"), new DataColumn("sms_dateFormat")
            });
            string   sentsmsList = MobileNo;
            string[] words       = sentsmsList.Split(',');
            foreach (string MObileNo in words)
            {
                dt.Rows.Add("sss", null, MObileNo, smsText, datetime);
            }

            return("Message Sent Successful.");
        }
        catch (WebException e1)
        {
            return(e1.Message + " " + "WebException" + " " + e1.InnerException);
        }
        catch (Exception e2)
        {
            return(e2.Message + " " + "WebException" + " " + e2.InnerException);
        }
    }
コード例 #10
0
 private string DownloadFileFromCache(Uri uri, string destinationpath)
 {
     if (IsFileExpired(destinationpath, this.DefaultTTL))
     {
         using (var w = new TimedWebClient(this.Timeout))
         {
             w.CachePolicy = this.CachePolicy;
             w.Credentials = this.Credentials;
             w.Proxy       = this.Proxy;
             w.Headers.Add(HttpRequestHeader.UserAgent, USERAGENT);
             w.DownloadFile(uri, destinationpath);
         }
     }
     return(destinationpath);
 }
コード例 #11
0
        public static int GetUniqueID()
        {
            string commentForCodeLurkers = "This is to find the public IPv4 address of the client to use it as unique ID for Analytics";

            try
            {
                var client    = new TimedWebClient();
                var ipAddress = client.DownloadString(ipService);
                ipAddress = Regex.Match(ipAddress, @"([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})").Groups[1].Value;

                return(BitConverter.ToInt32(IPAddress.Parse(ipAddress).GetAddressBytes(), 0));
            }
            catch
            {
                Random rnd = new Random();
                return(rnd.Next(int.MinValue, int.MaxValue));
            }
        }
コード例 #12
0
    private static void setProxies()
    {
        //Set our proxy information
        string   fullproxyaddress = "http://localhost:8888";
        WebProxy myProxy          = new WebProxy(fullproxyaddress);

        myProxy.Credentials = new NetworkCredential("1", "1");
        try
        {
            //Initialize our object using the created proxy
            //Make the request
            string html = new TimedWebClient {
                Timeout = 360000, Proxy = myProxy
            }.DownloadString("http://www.google.com");
            html = HttpUtility.HtmlDecode(html);
            Console.Write(html);
        }
        catch { Console.Write("Error!"); }
    }
コード例 #13
0
        private async Task <string> GetResponse(string url)
        {
            using (var client = new TimedWebClient(10000))
            {
                client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");

                try
                {
                    return(client.DownloadString(url));
                }
                catch (WebException ex)
                {
                    await _log.WriteInfoAsync(nameof(GetResponse),
                                              $"erl: {url}",
                                              $"Error. Status Code: {ex.Status}. Stack: {ex.ToString()}");

                    return(null);
                }
            }
        }
コード例 #14
0
ファイル: GithubTracker.cs プロジェクト: bsamuels453/Pikatwo
        void RefreshRepos()
        {
            var client = new TimedWebClient();
            var rssStr = client.DownloadString(_rssUrl);

            client.Dispose();

            var rssDocument = new HtmlDocument();

            rssDocument.LoadHtml(rssStr);

            var entries = rssDocument.DocumentNode.SelectNodes("//entry");

            foreach (var entry in entries)
            {
                var childNodes = entry.ChildNodes;
                if (childNodes["id"].InnerText.Contains("PushEvent"))
                {
                    QueueNewAnnouncement(childNodes);
                }
            }
        }
コード例 #15
0
        internal static Tuple <int, string> CheckAvailability(string url, string prefix)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(url) ||
                    !Uri.TryCreate(url, UriKind.Absolute, out var uri) ||
                    !Url.IsValid(url))
                {
                    return(new Tuple <int, string>(02_0005, url)); // Invalid url
                }

                if (!PingHost(uri.Host, out var time))
                {
                    return(new Tuple <int, string>(02_0006, url)); // cannot ping
                }
                using (var client = new TimedWebClient())
                {
                    try
                    {
                        var s = client.DownloadString(Url.Combine(url, prefix, ""));
                        if (!s.StartsWith("Milvaneth Api Service"))
                        {
                            return(new Tuple <int, string>(02_0004, url)); // not valid service
                        }
                    }
                    catch
                    {
                        return(new Tuple <int, string>(02_0004, url));
                    }
                }

                return(new Tuple <int, string>(time, url));
            }
            catch
            {
                return(new Tuple <int, string>(02_0001, url)); // other exception
            }
        }
コード例 #16
0
 private string DownloadFileFromCache(Uri uri, string destinationpath)
 {
     if (IsFileExpired(destinationpath, this.DefaultTTL))
     {
         using (var w = new TimedWebClient(this.Timeout))
         {
             w.CachePolicy = this.CachePolicy;
             w.Credentials = this.Credentials;
             w.Proxy = this.Proxy;
             w.Headers.Add(HttpRequestHeader.UserAgent, USERAGENT);
             w.DownloadFile(uri, destinationpath);
         }
     }
     return destinationpath;
 }
コード例 #17
0
ファイル: GithubTracker.cs プロジェクト: bsamuels453/Pikatwo
        void RefreshRepos()
        {
            var client = new TimedWebClient();
            var rssStr = client.DownloadString(_rssUrl);
            client.Dispose();

            var rssDocument = new HtmlDocument();
            rssDocument.LoadHtml(rssStr);

            var entries = rssDocument.DocumentNode.SelectNodes("//entry");

            foreach (var entry in entries){
                var childNodes = entry.ChildNodes;
                if (childNodes["id"].InnerText.Contains("PushEvent")){
                    QueueNewAnnouncement(childNodes);
                }
            }
        }
コード例 #18
0
ファイル: GithubTracker.cs プロジェクト: bsamuels453/Pikatwo
        void QueueNewAnnouncement(HtmlNodeCollection repoNodes)
        {
            string title = repoNodes["title"].InnerText;
            var separator = title.IndexOf('/');
            var repoName = title.Substring(separator + 1);
            var author = repoNodes["author"].ChildNodes["name"].InnerText;
            var publishTime = repoNodes["published"].InnerText;
            var rawLink = repoNodes["link"].Attributes["href"].Value;
            var compareSeparator = rawLink.LastIndexOf('/');
            var link = rawLink.Substring(0, compareSeparator + 1);
            var beginCommit = rawLink.Substring(compareSeparator + 1, 10);
            var endCommit = rawLink.Substring(compareSeparator + 1 + 10 + 3, 10);
            var timestamp = new DateTime
                (
                int.Parse(publishTime.Substring(0, 4)),
                int.Parse(publishTime.Substring(5, 2)),
                int.Parse(publishTime.Substring(8, 2)),
                int.Parse(publishTime.Substring(11, 2)),
                int.Parse(publishTime.Substring(14, 2)),
                int.Parse(publishTime.Substring(17, 2))
                );

            var client = new TimedWebClient();
            var commitPage = client.DownloadString(rawLink);
            var doc = new HtmlDocument();
            doc.LoadHtml(commitPage);
            client.Dispose();

            var entry = doc.DocumentNode.SelectNodes("//span[@class=\"num\"]");
            var rawNumCommits = entry[0].InnerText;
            rawNumCommits = new string(rawNumCommits.Where(char.IsDigit).ToArray());
            int numCommits = int.Parse(rawNumCommits);

            if (_subscribedProjects.Contains(repoName)){
                lock (_queuedAnnouncements){
                    _queuedAnnouncements.Add
                        (new QueuedAnnouncement
                            (
                            author,
                            link,
                            repoName,
                            timestamp,
                            beginCommit,
                            endCommit,
                            numCommits
                            )
                        );
                }
            }
        }
コード例 #19
0
        private void bitcoinDE_run()
        {
            try
            {
                string json;
                string newToolTip = "Buy: 0.00€ Sell: 0.00€ ~Price: 0.00€ (" + DateTime.Now.Hour.ToString() + ":" + DateTime.Now.Minute.ToString() + ":" + DateTime.Now.Second.ToString() + "h)";
                string importentMessage = "";
                string importentLink = "";
                string old_importentMessage = "";
                string old_importentLink = "";
                double buyPrice = 0;
                double sellPrice = 0;
                double averagePrice = 0;
                double old_averagePrice = 0;

                while (true)
                {
                    json = new TimedWebClient { Timeout = 20000 }.DownloadString("http://miner-control.de/bitcoin_de.json");
                    if (json != "")
                    {
                        dynamic dynJSON = JsonConvert.DeserializeObject(json);
                        buyPrice = ((dynJSON.buyPrice != null && dynJSON.buyPrice != "") ? Convert.ToDouble(dynJSON.buyPrice) : 0);
                        sellPrice = ((dynJSON.sellPrice != null && dynJSON.sellPrice != "") ? Convert.ToDouble(dynJSON.sellPrice) : 0);
                        averagePrice = ((dynJSON.averagePrice != null && dynJSON.averagePrice != "") ? Convert.ToDouble(dynJSON.averagePrice) : 0);
                        old_averagePrice = ((dynJSON.averagePrice_3h != null && dynJSON.averagePrice_3h != "") ? Convert.ToDouble(dynJSON.averagePrice_3h) : 0);

                        newToolTip = "Buy: " + string.Format("{0:N2}", buyPrice) + "€ Sell: " + string.Format("{0:N2}", sellPrice) + "€ ~Price: " + string.Format("{0:N2}", averagePrice) + "€ (" + ((dynJSON.lastUpdateTime != null && dynJSON.lastUpdateTime != "") ? dynJSON.lastUpdateTime : "xx:xx:xx") + "h)";
                        importentMessage = ((dynJSON.importentMessage != null && dynJSON.importentMessage != "") ? dynJSON.importentMessage : "");
                        importentLink = ((dynJSON.importentLink != null && dynJSON.importentLink != "") ? dynJSON.importentLink : "");
                    }
                    if (averagePrice > old_averagePrice)
                    {
                        bitcoinIcon.Icon = new Icon(GetType(), "bitcoin_green.ico");
                    }
                    else if (averagePrice < old_averagePrice)
                    {
                        bitcoinIcon.Icon = new Icon(GetType(), "bitcoin_red.ico");
                    }
                    else
                    {
                        bitcoinIcon.Icon = new Icon(GetType(), "bitcoin.ico");
                    }
                    old_averagePrice = averagePrice;

                    //Info Ballon
                    if (importentMessage != old_importentMessage && importentLink != old_importentLink && importentLink != "" && importentMessage != "")
                    {
                        bitcoinIcon.BalloonTipText = importentMessage + " : Click here to open.";
                        bitcoinIcon.ShowBalloonTip(5000);
                    }

                    //Set all Infos to bar
                    bitcoinIcon.BalloonTipText = bitcoinIcon.Text = newToolTip;

                    if (importentMessage != "")
                    {
                        importentToolStripMenuItem.Text = importentMessage;
                        importentToolStripMenuItem.Tag = importentLink;
                        importentToolStripMenuItem.Visible = true;
                    }
                    else
                    {
                        importentToolStripMenuItem.Visible = false;
                    }

                    //Wait 1 min
                    Thread.Sleep(60000); //60000 = 1 min
                    json = "";
                    old_importentMessage = importentMessage;
                    old_importentLink = importentLink;
                }
            }
            catch (Exception e)
            {
                //MessageBox.Show("Fatal Error: " + e.Message);
                bitcoinDE_run();
            }
        }
コード例 #20
0
ファイル: LogCastClient.cs プロジェクト: kbabiy/LogCast
 protected virtual void Send(Uri endpoint, string message, int timeout)
 {
     using (var client = new TimedWebClient(timeout))
         client.UploadData(endpoint, Encoding.UTF8.GetBytes(message));
 }
コード例 #21
0
ファイル: BaseScrawler.cs プロジェクト: DavidHuemer/PassLock
        protected static string DownloadString(string url, int timeout = TimedWebClient.DEFAULT_TIMEOUT)
        {
            var client = new TimedWebClient(timeout);

            return(client.DownloadString(url));
        }
コード例 #22
0
 public static byte[] ExecuteGetData(string url)
 {
     using (var wc = new TimedWebClient()) {
         return(wc.DownloadData(new Uri(url)));
     }
 }
コード例 #23
0
ファイル: Util.cs プロジェクト: RemaxThailand/POS
        public static string GetApiData(string method, string parameter)
        {

            using (WebClient wc = new TimedWebClient())
            {
                wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
                wc.Encoding = System.Text.Encoding.UTF8;
                return wc.UploadString(new Uri(Param.ApiUrl + method), parameter + "&apiKey=" + Param.ApiKey);
            }
        }
コード例 #24
0
 public static async Task <string> ExecuteGetAsString(string url)
 {
     using (var wc = new TimedWebClient()) {
         return(await wc.DownloadStringTaskAsync(new Uri(url)));
     }
 }