private void GetItemsPollEvent(object src, ElapsedEventArgs e)
        {
            try
            {
                HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create("http://localhost:3000");
                httpWebRequest.Method = WebRequestMethods.Http.Get;
                httpWebRequest.Accept = "application/json";
                var response = (HttpWebResponse)httpWebRequest.GetResponse();

                using (var sr = new StreamReader(response.GetResponseStream()))
                {
                    List <SmartCartItem> items = JsonConvert.DeserializeObject <List <SmartCartItem> >(sr.ReadToEnd());

                    foreach (var item in items)
                    {
                        if (!SmartCartItems.Contains(item))
                        {
                            MainUserControlViewModel.AddSmartCartItem(item);
                        }
                    }
                    Total = smartCartItems.Select(x => (x.Price * x.Count)).Sum();
                }
            }
            catch (Exception ex)
            {
                AddLog(ex.Message, LogMessageType.ERROR);
            }
        }
Exemplo n.º 2
0
        private async void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            MainUserControlViewModel vm = this.DataContext as MainUserControlViewModel;

            if (vm != null)
            {
                await vm.StartGetItemsLoop();
            }
        }