Exemplo n.º 1
0
        public static IPAddress getExternalIPAddressFromWebsite()
        {
            String    external_ip_str;
            IPAddress external_ip;

            try
            {
                external_ip_str = new System.Net.WebClient().DownloadString(xbs_upnp.EXTERNAL_IP_WEB_SERVICE);
            }
            catch (WebException)
            {
                xbs_messages.addInfoMessage("!! Could not resolve external IP Address.", xbs_message_sender.UPNP, xbs_message_type.ERROR);
                return(null);
            }
            bool ret = IPAddress.TryParse(external_ip_str.Trim(), out external_ip);

            if (ret)
            {
                xbs_messages.addInfoMessage(" @ discovered external public IP " + external_ip, xbs_message_sender.UPNP);
            }
            return(ret ? external_ip : null);
        }
Exemplo n.º 2
0
 public static IPAddress getExternalIPAddressFromWebsite()
 {
     String external_ip_str;
     IPAddress external_ip;
     try
     {
         external_ip_str = new System.Net.WebClient().DownloadString(xbs_upnp.EXTERNAL_IP_WEB_SERVICE);
     }
     catch (WebException)
     {
         xbs_messages.addInfoMessage("!! Could not resolve external IP Address.", xbs_message_sender.UPNP, xbs_message_type.ERROR);
         return null;
     }
     bool ret = IPAddress.TryParse(external_ip_str.Trim(), out external_ip);
     if ( ret )
         xbs_messages.addInfoMessage(" @ discovered external public IP " + external_ip, xbs_message_sender.UPNP);
     return ( ret ? external_ip : null);
 }
Exemplo n.º 3
0
Arquivo: Uo.cs Projeto: jonbonne/OCTGN
 public void ProcessMessage(IrcMessageEventArgs args, string @from, string message)
 {
     var ret = new WebClient().DownloadString("http://www.octgn.net/api/stats/usersonlinenow.php");
     Channel.Message("There are " + ret.Trim() + " users online right now.",true);
 }
Exemplo n.º 4
0
        static void stockLookup(string msg)
        {
            // setup vars
            //	string stock = new string(msg.Substring(5).Where(c => Char.IsLetter(c)).ToArray());
            string stock = msg.Substring(5);

            if (stock == "help") {
                botSay("[stock/exchange]name Last Trade (change/change%) Average Daily Volume " +
                    "Market Cap [(high/low)52 week h/l range in %, Short Ratio, 50 day moving average " +
                    "200 day moving average] -");
                botSay("Ratios: Price/Earnings, Earnings/Share, Price/Sales, Price/Earnings Growth, " +
                    "- Other fundamentals: Book Value, EBITDA");
            }

            string url = "http://finance.yahoo.com/d/quotes.csv?s=" + stock +
                "&f=a2b4cej1j4j6k5l1m3m4np5p6rr5ss7xlc6t7";

            // csvSplit() the csv
            string scRes = "";

            try {
                scRes = new WebClient().DownloadString(url);
            } catch (WebException ex) {
                Console.WriteLine("Error ({0}):\n {1}", ex.Source, ex.Message);
                botSay("I threw an ex... I don't feel so well");
                return;
            }

            string[] result;

            if (scRes.Trim('\n','\r') == "Missing Symbols List.") {
                botSay("MSL... whatever");
                return;
            }

            result = csvSplit(",", "\"", scRes);

            // filter out bad results
            if (result[18] == "\"N/A\"") {
                botSay("Lookup of " + stock.ToUpper() + " failed");
            //	botSay(result[result.Length-1]);
                return;
            }

            string sColor = "{dred}";
            if (result[20].Contains("+")) sColor = "{green}";

            // 0	a2
            string sADV = String.Format("{0:n0}", Convert.ToInt32(result[0].Trim(' ', '"')));

            // 1	b4
            string sBV = result[1].Trim('"', ' ');

            // 2	c
            string[] cMod = result[2].Trim('"', ' ').Split(' ');
            string cChangeP = cMod[2];

            // 3	e
            string sES = result[3].Trim('"', ' ');

            // 4	j1
            string sMC = result[4].Trim('"', ' ');

            // 5	j4
            string sEBITDA = result[4].Trim('"', ' ');

            // 6    j6
            string s52WL = result[6].Trim('"', ' ');

            // 7	k5
            string s52WH = result[7].Trim('"', ' ');

            // 8	l1
            // 9	m3
            string s50MA = result[9].Trim('"', ' ');

            // 10	m4
            string s200MA = result[10].Trim('"', ' ');

            // 11	n
            string sName = result[11];

            // 12	p5
            string sPS = result[12].Trim('"', ' ');

            // 13	p6
            // 14	r
            string sPE = result[14].Trim('"', ' ');

            // 15	r5
            string sPEG = result[15].Trim('"', ' ');

            // 16   s
            string sSymbol = result[16].Trim('"', ' ');
            // 17   s7
            string sSR = result[17].Trim('"', ' ');
            // 18	x
            string sExchange = result[18].Trim('"');

            // 19   k1 -> l
            string[] cParts2 = result[19].Trim('"').Split('-');
            decimal sLastTrade = Convert.ToDecimal(cParts2[1].Trim('<', 'b', '/', '>', '"', ' '));

            // 20	c6
            decimal sChange = Convert.ToDecimal(result[20].Trim('+', '"', ' '));

            // 21	t7 (ticker trend)

            // parse the stock
            StringBuilder say = new StringBuilder(
                "[{cyan}" + sSymbol + "{reset}/{cyan}" + sExchange + "{reset}] " +
                sName + " " + sColor + sLastTrade + "{reset} (" + sColor + sChange +
                "{reset}/" + sColor + cChangeP + "{reset}) "
            //		result[20]
            );

            // Begin parsing through these, if data is available, show it!
            if (sADV != "0") {
                say.Append("ADV:{orange}" + sADV + "{reset} MC:{orange}" +
                    sMC + "{reset} [({dred}" + s52WH + "{reset}/{green}" +
                    s52WL + "{reset})52WH/L SR:{lblue}" +
                    sSR + "{reset} 50MA:{lblue}" + s50MA + "{reset} 200MA:{lblue}" +
                    s200MA + "{reset}] "
                    );
            }
            // Short Ratio, 50/200 Day Moving Average
            say.Append("- P/E:{lgreen}" + sPE + "{reset} E/S:{lgreen}" +
                sES + "{reset} P/S:{lgreen}" + sPS + "{reset} PEG:{lgreen}" + sPEG + "{reset} ");
            say.Append("- BV:{lgreen}" + sBV + "{reset} EBITDA:{lgreen}" + sEBITDA + "{reset} ");

            // output to channel
            botSay(say.ToString());
        }
Exemplo n.º 5
0
 public void AddEventWithPhoto()
 {
     bool s = false;
     dynamic ev;
     var Wc = new WebClient();
     Wc.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
     var firstdata = "grant_type=password&username="******"TestUserName" + "&password="******"TestPassword361";
     var result1 = Wc.UploadString(SiteUrl + TokenUrl, firstdata);
     JObject o1 = JObject.Parse(result1);
     var token = o1["access_token"].Value<string>();
     Wc = new WebClient();
     Wc.Encoding = Encoding.UTF8;
     Wc.Headers.Add("Content-Type", "application/json");
     Wc.Headers.Add("Authorization", "Bearer " + token);
     string sdata;
     var photoIds = new string[0];
     var url = new WebClient().DownloadString(new Uri(SiteUrl + "api/Endpoints/GetUploadUrl/AddEvent"));
     url = url.Trim(new char[] { '\"' });
     url = url.TrimStart(new char[] { '/' });
     using (var client = new HttpClient())
     {
         MultipartFormDataContent form = new MultipartFormDataContent();
         client.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", "Bearer " + token);
         var fs = new FileStream("C:\\Users\\Александр\\Desktop\\kompot.jpg", FileMode.Open);
         form.Add(new StreamContent(fs), "file", "file.jpg");
         fs = new FileStream("C:\\Users\\Александр\\Desktop\\qRISsLk7j3E.jpg", FileMode.Open);
         form.Add(new StreamContent(fs), "file", "file.jpg");
         var response = client.PostAsync(SiteUrl + url, form).Result;
         sdata = response.Content.ReadAsStringAsync().Result;
     }
     using (var client = new HttpClient())
     {
         client.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", "Bearer " + token);
         var content = new StringContent(sdata, Encoding.UTF8, "application/json");
         var response = client.PostAsync(SiteUrl
                                 + "api/Endpoints/SaveUploadedFile/AddEvent", content).Result;
         sdata = response.Content.ReadAsStringAsync().Result;
         photoIds = JArray.Parse(sdata).Select(tok => (tok as JObject)["Id"].Value<string>()).ToArray();
     }
     try
     {
         var time = System.DateTime.Now.ToString("u");
         var data = JsonConvert.SerializeObject(new
         {
             Latitude = 76,
             Longitude = 92,
             Description = "TestEvent",
             EventDate = time,
             PhotoIds = photoIds
         });
         var result = Wc.UploadString(SiteUrl + AddEventUrl, data);
     }
     catch(WebException we)
     {
         Assert.Fail(we.Message);
     }
 }