public virtual void TestChildThrowsIndexOutOfBoundsOnMissing()
        {
            Document doc = Jsoup.Parse("<div><p>One</p><p>Two</p></div>");
            Element  div = doc.Select("div").First();

            Assert.AreEqual(2, div.Children().Count);
            Assert.AreEqual("One", div.Child(0).Text());

            Assert.Throws(typeof(ArgumentOutOfRangeException), () => div.Child(3));
        }
示例#2
0
        /// <summary>
        /// Fetches the Result from SJCE website
        /// </summary>
        /// <param name="usn">USN of the Student</param>
        /// <returns> A Student Object containg the Details </returns>
        /// <exception cref="StudentException">If USN is incorrect</exception>
        /// <exception cref="HttpRequestException">If an Connectictivity Error is occured</exception>
        /// <example><code lang="cs">
        ///		var result = Student.FetchResult("4jC15CS000");
        ///		try {
        ///			result.Wait();
        ///			Console.WriteLine(result.Result);
        ///		}
        ///		catch (Exception e) {
        ///			if (e.InnerException is HttpRequestException)
        ///				Console.WriteLine(e.InnerException.Message + " Net sari mada manga!");
        ///			else if (e.InnerException is StudentException)
        ///				Console.WriteLine(e.InnerException.Message + " Nee JC Student Pakka na??");
        ///			else
        ///				Console.WriteLine("Fatal Error" + e);
        ///			Thread.CurrentThread.Abort(-1);
        ///		}
        ///	</code></example>
        public static async Task <Student> FetchResult(string usn)
        {
            using (var client = new HttpClient()) {
                var values = new Dictionary <string, string> {
                    ["USN"]           = usn,
                    ["submit_result"] = "Fetch Result"
                };
                try {
                    Student s        = new Student(usn);
                    var     content  = new FormUrlEncodedContent(values);
                    var     response = await client.PostAsync("http://sjce.ac.in/view-results", content);

                    if (response.StatusCode != HttpStatusCode.OK)
                    {
                        throw new HttpRequestException("Website unable to Handle Request...Might be busy");
                    }
                    var responseString = await response.Content.ReadAsStringAsync();

                    //Jsoup.jar was used
                    //Coverted using IVMC ! :)
                    //Inlcude IKVM.OpenJDK.Core.dll as Reference
                    Document doc        = Jsoup.parse(responseString);
                    Elements nameAndUsn = doc.getElementsByTag("center");
                    string   name       = nameAndUsn.select("h1").first().text().Substring(7);
                    s.name = name;
                    Element marks = doc.getElementsByTag("table").first();
                    foreach (Element row in marks.select("tr"))
                    {
                        Elements td    = row.select("td");
                        string   value = td.text();
                        if (!string.IsNullOrEmpty(value))
                        {
                            s.AddSubject(value.Split()[0], value.Substring(value.LastIndexOf(" ")));
                        }
                    }
                    return(s);
                }
                catch (Exception e) {
                    if (e is NullReferenceException)
                    {
                        throw new StudentException("Might be a bad USN", e);
                    }
                    else if (e is HttpRequestException)
                    {
                        throw new HttpRequestException("Net sari illa marre", e);
                    }
                    else
                    {
                        throw;
                    }
                }
            }
        }
示例#3
0
    protected override Java.Lang.Object DoInBackground(params Java.Lang.Object[] @params)
    {
        var val1 = Jsoup.Connect("https://play.google.com/store/apps/details?id=" + "com.app.in.app" + "&hl=en")
                   .Timeout(30000).UserAgent("Mozilla/5.0 (Windows; U; WindowsNT 5.1; en-US; rv1.8.1.6) Gecko/20070725 Firefox/2.0.0.6").Referrer("http://www.google.com")
                   .Get();
        var val2 = val1.Select(".htlgb");
        var val3 = val2.Get(7).ToString();
        //here mobile app version is of 3 values like 2.1, 4.2 etc
        var version = val3.Substring(val3.IndexOf(">") + 1, 3);         //fetching only 3 values ex 1.1

        CosntValues.PlayStoreValues = version;
        return(version);
    }
示例#4
0
 protected override Java.Lang.Object DoInBackground(params Java.Lang.Object[] @params)
 {
     try
     {
         string MarketVersion = Jsoup.Connect("https://play.google.com/store/apps/details?id=" + PackageName)
                                .Timeout(60000)
                                .IgnoreHttpErrors(true)
                                .Referrer("http://www.google.com").Get()
                                .Select("div[itemprop=" + ItemType + "]").First() // .recent-change
                                .OwnText();
         return(MarketVersion);
     }
     catch (Exception e)
     {
     }
     return(MarketVersion);
 }
示例#5
0
        //####################################################################

        private string GetPlainOfHtml(string html)
        {
            string plain = "";

            Document doc = Jsoup.ParseBodyFragment(html); var it = doc.Select("*");

            for (int i = 0; i < it.Size(); i++)
            {
                Element e = ((Element)it.Get(i));

                string node = e.NodeName();

                //Neue Zeile
                if (node == "p" ||
                    node == "br")
                {
                    plain += System.Environment.NewLine;
                }

                //Links
                if (node == "a")
                {
                    bool href = e.HasAttr("href");
                    if (href)
                    {
                        string link = e.Attr("href");
                        link = link.Replace("/:b:/s", "https://maltesercloud.sharepoint.com/:b:/s");

                        plain += System.Environment.NewLine + System.Environment.NewLine +
                                 GetPlainOfHtml(e.Html()) + System.Environment.NewLine +
                                 link +
                                 System.Environment.NewLine + System.Environment.NewLine;
                    }
                    break;
                }

                plain += e.OwnText();
            }

            return(plain);
        }
示例#6
0
        public async Task <ActionResult> IndexAsync()
        {
            List <EmailContent> mails = new List <EmailContent>();

            if (await checkCredential())
            {
                ViewBag.Success = 1;

                // mới

                var request = service.Users.Messages.List("me");

                request.LabelIds         = "INBOX";
                request.IncludeSpamTrash = false;
                // request.Q = "is:unread"; // This was added because I only wanted unread emails...

                //    Get our emails
                var emailListResponse = request.Execute();

                if (emailListResponse != null && emailListResponse.Messages != null)
                {
                    // Loop through each email and get what fields you want...
                    foreach (var email in emailListResponse.Messages)
                    {
                        EmailContent mail = new EmailContent();

                        var emailInfoRequest = service.Users.Messages.Get("me", email.Id);
                        // Make another request for that email id...
                        var emailInfoResponse = emailInfoRequest.Execute();

                        if (emailInfoResponse != null)
                        {
                            // Loop through the headers and get the fields we need...
                            foreach (var mParts in emailInfoResponse.Payload.Headers)
                            {
                                if (mParts.Name == "Date")
                                {
                                    mail.date = mParts.Value;
                                }
                                else if (mParts.Name == "Delivered-To")
                                {
                                    emailAddress = mParts.Value;
                                }
                                else if (mParts.Name == "From")
                                {
                                    mail.from = mParts.Value;
                                }
                                else if (mParts.Name == "Subject")
                                {
                                    mail.subject = mParts.Value;
                                }


                                if (mail.date != "" && mail.from != "")
                                {
                                    if (emailInfoResponse.Payload.Parts == null)
                                    {
                                        byte[] data          = FromBase64ForUrlString(emailInfoResponse.Payload.Body.Data);
                                        string decodedString = Encoding.UTF8.GetString(data);
                                        mail.body = Jsoup.Parse(decodedString).Text();

                                        continue;
                                    }

                                    foreach (MessagePart p in emailInfoResponse.Payload.Parts)
                                    {
                                        if (p.MimeType == "text/html")
                                        {
                                            byte[] data          = FromBase64ForUrlString(p.Body.Data);
                                            string decodedString = Encoding.UTF8.GetString(data);
                                            mail.body = Jsoup.Parse(decodedString).Text();
                                        }
                                    }
                                }
                            }
                        }
                        mails.Add(mail);
                    }
                }

                return(View(mails));
            }
            else
            {
                ViewBag.Success = 0;

                return(View("/Home/IndexAsync"));
                //return View(mails);
            }
        }
示例#7
0
 public String html2text(String html)
 {
     return(Jsoup.Parse(html).Text());
 }