Пример #1
0
        /// <summary>
        /// Async method that returns Parsed list of CSPeople
        /// </summary>
        /// <returns></returns>
        async Task <List <CSPeople> > ParseHttpPeopleAsync()
        {
            HttpClient client = new HttpClient();
            var        doc    = new HtmlDocument();
            var        html   = await client.GetStringAsync("https://www.cs.uiowa.edu/people");

            doc.LoadHtml(html);

            List <CSPeople> p = await Task.Run(() => {
                List <CSPeople> people = new List <CSPeople>();
                var rows = doc.DocumentNode.SelectNodes("//table[contains(@class,'views-table')]//tr");

                foreach (var tr in rows)
                {
                    CSPeople person = new CSPeople();
                    foreach (var td in tr.ChildNodes)
                    {
                        if (td.GetAttributeValue("class", "Not found").Equals("views-field views-field-title"))
                        {
                            person.Name = td.InnerText;
                        }
                        else if (td.GetAttributeValue("class", "Not found").Equals("views-field views-field-field-office"))
                        {
                            person.Office = td.InnerText;
                        }
                        else if (td.GetAttributeValue("class", "Not found").Equals("views-field views-field-field-hours"))
                        {
                            person.Hours = td.InnerText;
                        }
                        else if (td.GetAttributeValue("class", "Not found").Equals("views-field views-field-field-email"))
                        {
                            person.Email = td.InnerText;
                        }
                    }
                    people.Add(person);
                }
                Regex r         = new Regex(@"\W*Name\W*");
                Regex blanksReg = new Regex(@"^\W*$");

                people.RemoveAll(person => r.IsMatch(person.Name));
                people.RemoveAll(person => blanksReg.IsMatch(person.Office));

                return(people);
            });

            return(p);
        }
Пример #2
0
        /// <summary>
        /// Click handler for rows in datagrid
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Row_Click(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            DataGridCellsPresenter dataRow = (DataGridCellsPresenter)e.Source;
            CSPeople person = (CSPeople)dataRow.DataContext;
            string   office = Regex.Replace(person.Office, @"\s+", "");
            string   floor  = SetFloor(office);

            if (floor != null)
            {
                MapsPage.initMap         = floor;
                navigationRegion.Content = Activator.CreateInstance(typeof(MapsPage));
            }
            else
            {
                MessageBox.Show("Office is not in Maclean Hall. Please tap 'OK' to remove");
            }
        }