예제 #1
0
        /// <inheritdoc />
        public void OnNext(ActionFileAttachment value)
        {
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            CurrentItem.Add(value);
        }
        public async void getinfo()
        {
            Item.Clear();
            if (NetworkInterface.GetIsNetworkAvailable())
            {
                ProgressVisibility = Visibility.Visible;
                string uristring = "https://www.hackerrank.com/calendar/feed.json";
                result = null;

                var httpClient = new HttpClient();
                var uri        = new Uri(uristring);

                try
                {
                    HttpResponseMessage responseMessage = await httpClient.GetAsync(uri);

                    responseMessage.EnsureSuccessStatusCode();
                    result = await responseMessage.Content.ReadAsStringAsync();
                }
                catch (Exception ex) { }


                httpClient.Dispose();
            }
            else
            {
                var mssg = new MessageDialog("No Internet");
                await mssg.ShowAsync();
            }
            if (result != null && result != string.Empty)
            {
                string          title       = null;
                string          description = null;
                string          start       = null;
                string          end         = null;
                string          link        = null;
                Uri             logo        = null;
                SolidColorBrush brush       = null;



                JsonObject CodeFeed      = JsonObject.Parse(result);
                JsonArray  CodeFeedArray = CodeFeed.GetNamedArray("models");

                int len = CodeFeedArray.Count;
                for (uint i = 0; i < len; i++)
                {
                    if (CodeFeedArray.GetObjectAt(i).ContainsKey("title"))
                    {
                        title = CodeFeedArray.GetObjectAt(i).GetNamedString("title");
                    }
                    else
                    {
                        title = null;
                    }

                    if (CodeFeedArray.GetObjectAt(i).ContainsKey("description"))
                    {
                        description = CodeFeedArray.GetObjectAt(i).GetNamedString("description");
                    }
                    else
                    {
                        description = null;
                    }

                    if (CodeFeedArray.GetObjectAt(i).ContainsKey("start"))
                    {
                        start = CodeFeedArray.GetObjectAt(i).GetNamedString("start");
                    }
                    else
                    {
                        start = null;
                    }

                    if (CodeFeedArray.GetObjectAt(i).ContainsKey("end"))
                    {
                        end = CodeFeedArray.GetObjectAt(i).GetNamedString("end");
                    }
                    else
                    {
                        end = null;
                    }

                    if (CodeFeedArray.GetObjectAt(i).ContainsKey("url"))
                    {
                        link = CodeFeedArray.GetObjectAt(i).GetNamedString("url");
                    }
                    else
                    {
                        link = null;
                    }
                    DateTime dtstart = Convert.ToDateTime(start);
                    DateTime dtend   = Convert.ToDateTime(end);
                    DateTime now     = DateTime.Now;
                    if (link.Contains("topcoder"))
                    {
                        logo  = new Uri("ms-appx:///Assets/CodeRadarLogo/topcoder_logo.png");
                        brush = Application.Current.Resources["topcoder"] as SolidColorBrush;
                    }
                    else if (link.Contains("hackerrank"))
                    {
                        logo  = new Uri("ms-appx:///Assets/CodeRadarLogo/hackerearth_logo.png");
                        brush = Application.Current.Resources["hackerrank"] as SolidColorBrush;
                    }
                    else if (link.Contains("codechef"))
                    {
                        logo  = new Uri("ms-appx:///Assets/CodeRadarLogo/codechef_logo.png");
                        brush = Application.Current.Resources["codechef"] as SolidColorBrush;
                    }
                    else if (link.Contains("codeforces"))
                    {
                        logo  = new Uri("ms-appx:///Assets/CodeRadarLogo/codeforces_logo.png");
                        brush = Application.Current.Resources["codeforces"] as SolidColorBrush;
                    }
                    else if (link.Contains("urionlinejudge"))
                    {
                        logo  = new Uri("ms-appx:///Assets/CodeRadarLogo/uri_logo.png");
                        brush = Application.Current.Resources["urioj"] as SolidColorBrush;
                    }
                    else if (link.Contains("hackerearth"))
                    {
                        logo  = new Uri("ms-appx:///Assets/CodeRadarLogo/hackerearth_logo.png");
                        brush = Application.Current.Resources["hackerearth"] as SolidColorBrush;
                    }
                    else
                    {
                        logo  = new Uri("ms-appx:///Assets/CodeRadarLogo/unknown_logo.png");
                        brush = new SolidColorBrush(Colors.BlanchedAlmond);
                    }
                    if (now <= dtend && now >= dtstart)
                    {
                        Item.Add(new CodeRadarItem()
                        {
                            Days = "right now", Start = dtstart.ToString("d MMM , yyy"), End = dtend.ToString("d MMM , yyy"), Description = description, Title = title, Link = link, Logo = logo, Color = brush
                        });
                    }
                    else
                    {
                        CurrentItem.Add(new CodeRadarItem()
                        {
                            Days = (int)(dtstart - now).TotalDays + " days", Start = dtstart.ToString("d MMM , yyy"), End = dtend.ToString("d MMM , yyy"), Description = description, Title = title, Link = link, Logo = logo, Color = brush
                        });
                    }
                }
            }
            for (int i = 0; i < CurrentItem.Count; i++)
            {
                CurrentItem.Move(CurrentItem.Count - 1, i);
            }
            ProgressVisibility = Visibility.Collapsed;
        }