Exemple #1
0
        public MainWindow()
        {
            try
            {
                InitializeComponent();

                using (webClient = new WebClient())
                {
                    webClient.Encoding = Encoding.UTF8;
                    var response   = webClient.DownloadString(@"https://kudago.com/public-api/v1.3/event-categories/");
                    var categories = JsonConvert.DeserializeObject <List <EventCategorie> >(response);
                    foreach (EventCategorie cat in categories)
                    {
                        lv_Categories.Items.Add(cat);
                    }
                }

                categorySuffics = "";

                labelStyle = new Style();
                labelStyle.Setters.Add(new Setter {
                    Property = Control.FontFamilyProperty, Value = new FontFamily("Verdana")
                });
                labelStyle.Setters.Add(new Setter {
                    Property = Control.ForegroundProperty, Value = new SolidColorBrush(Colors.White)
                });
                labelStyle.Setters.Add(new Setter {
                    Property = Control.BackgroundProperty, Value = new SolidColorBrush(Colors.Brown)
                });
                labelStyle.Setters.Add(new Setter {
                    Property = Control.HorizontalContentAlignmentProperty, Value = HorizontalAlignment.Left
                });
                labelStyle.Setters.Add(new Setter {
                    Property = Control.HorizontalAlignmentProperty, Value = HorizontalAlignment.Left
                });
                labelStyle.Setters.Add(new Setter {
                    Property = Control.VerticalAlignmentProperty, Value = VerticalAlignment.Top
                });

                string link   = @"https://kudago.com/public-api/v1.3/events/?fields=id,dates,short_title,categories,images,&expand=dates&page_size=10";
                var    events = DownloadEvents(link);
                FillEvents(events.results);

                nextPageEvents = DownloadEvents(events.next);

                time = DateTime.Now;

                downloader = new Thread(DownloaderEventsThread);
            }
            catch (Exception e)
            {
                MessageBox.Show("Произошла ошибка: " + e.Message, "KudaGoWinApp");
            }
        }
Exemple #2
0
 private void DownloaderEventsThread(object link)
 {
     lock (nextPageEvents)
     {
         if (link.GetType() == typeof(string))
         {
             nextPageEvents = DownloadEvents((string)link);
         }
         else
         {
             throw new ArgumentException("Неверный запрос");
         }
     }
 }