Exemplo n.º 1
0
        async Task RefreshData()
        {
            IsBusy = true;
            try
            {
                Items.Clear();
                ItemsGrouped.Clear();
                var employee = await Repo.GetEmployeeAsync(App.DefaultEmployeeAlias);

                //TODO: Temp Hack. Fix this when login page is ready
                App.EmployeeId = employee.Id;
                DependencyService.Get <CurrentIdentityService>().SetNewIdentity(employee.Alias, employee.Id, employee.Manager, employee.Name, false);

                var items = await Repo.GetOutstandingChargesForEmployeeAsync(employee.Id);

                Items.ReplaceRange(items);

                var sorted = from item in Items
                             orderby item.ExpenseDate descending
                             group item by item.ExpenseDate.ToString("MMMM") into itemGroup
                             select new Grouping <string, Charge>(itemGroup.Key, itemGroup);

                ItemsGrouped.ReplaceRange(sorted);


                OnPropertyChanged("TotalAmount");
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
                MessagingCenter.Send(new MessagingCenterAlert
                {
                    Title   = "Error",
                    Message = "Unable to load items.",
                    Cancel  = "OK"
                }, "message");
            }
            finally
            {
                IsBusy = false;
            }
        }
Exemplo n.º 2
0
        public async Task getCategoryData()
        {
            if (CategoryPosts.Count != 0)
            {
                return;
            }

            string htmlPage = "";

            try
            {
                using (var client = new HttpClient())
                {
                    htmlPage = await client.GetStringAsync("http://id.wikihow.com/Istimewa:Categorylisting").ConfigureAwait(false);
                }


                htmlDocument.LoadHtml(htmlPage);
                var innerText = htmlDocument.DocumentNode
                                .Descendants("div")
                                .Where(o => o.GetAttributeValue("class", "") == "section_text").FirstOrDefault();

                htmlDocument.LoadHtml(innerText.OuterHtml);
                var divs = htmlDocument.DocumentNode
                           .Descendants("div")
                           .Where(o => o.GetAttributeValue("class", "") == "thumbnail").ToList();

                foreach (var div in divs)
                {
                    Post   newPosts = new Post();
                    string imageUrl = "";
                    string title    = "";
                    string url      = "";


                    imageUrl = Regex.Match(div.OuterHtml, "<img.+?src=[\"'](.+?)[\"'].*?>", RegexOptions.IgnoreCase).Groups[1].Value;
                    url      = Regex.Match(div.OuterHtml, "<a.+?href=[\"'](.+?)[\"'].*?>", RegexOptions.IgnoreCase).Groups[1].Value;

                    var match = Regex.Match(div.OuterHtml, @"(<p.*?>.*?</p>)", RegexOptions.Singleline);
                    title = Regex.Replace(match.Groups[1].Value, @"\s*<.*?>\s*", "");

                    title = WebUtility.HtmlDecode(title);

                    newPosts.Title    = title;
                    newPosts.ImageUrl = imageUrl;
                    newPosts.PostUrl  = "http://id.wikihow.com" + url;

                    CategoryPosts.Add(newPosts);
                }


                var sorted = from item in CategoryPosts
                             orderby item.Title
                             group item by item.Title[0].ToString() into itemGroup
                             select new Grouping <string, Post>(itemGroup.Key, itemGroup);

                var itemsGrouped = new ObservableRangeCollection <Grouping <string, Post> >(sorted);

                ItemsGrouped.ReplaceRange(itemsGrouped);
            }
            catch (Exception)
            {
            }
        }