Exemplo n.º 1
0
        private async void _getCategoriesCallback(IAsyncResult asynchronousResult)
        {
            HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState;

            try
            {
                HttpWebResponse response      = (HttpWebResponse)request.EndGetResponse(asynchronousResult);
                string          resultContent = string.Empty;
                using (var reader = new StreamReader(response.GetResponseStream()))
                {
                    resultContent = reader.ReadToEnd();
                };
                if (!string.IsNullOrEmpty(resultContent))
                {
                    await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                                                                                  () =>
                    {
                        StaticResources.ListCategories = Newtonsoft.Json.JsonConvert.DeserializeObject <ObservableCollection <Categories> >(resultContent);
                        this.ListCategories            = StaticResources.ListCategories;
                        if (StaticResources.ShopeePreConfig != null)
                        {
                            this.TbHeight             = StaticResources.ShopeePreConfig.height;
                            this.TbLength             = StaticResources.ShopeePreConfig.length;
                            this.TbWeight             = StaticResources.ShopeePreConfig.weight;
                            this.TbWidth              = StaticResources.ShopeePreConfig.width;
                            this.isPreorder           = StaticResources.ShopeePreConfig.isPreOrder;
                            this.TbShippingFee        = StaticResources.ShopeePreConfig.shippingfee;
                            this.isCoverShippingFee   = StaticResources.ShopeePreConfig.isCoverFee;
                            this.TbEstimatedDate      = StaticResources.ShopeePreConfig.estDate.ToString();
                            this.SelectedMainCategory = ListCategories.Single(p => p.main.catid == StaticResources.ShopeePreConfig.parCatID);
                            this.SelectedSubCategory  = ListSubCategories.Single(p => p.catid == StaticResources.ShopeePreConfig.subCatID);
                            if (StaticResources.LogisticsChannel != null)
                            {
                                this.ListLogisticsChannelClone = StaticResources.LogisticsChannel;
                                Utility.getLogisticChannel(StaticResources.SelectedShopLogin, new AsyncCallback(_getLogisticChannelCallback));
                            }
                            else
                            {
                                Utility.getLogisticChannel(StaticResources.SelectedShopLogin, new AsyncCallback(_getLogisticChannelCallback));
                            }
                        }
                        else
                        {
                            Utility.getLogisticChannel(StaticResources.SelectedShopLogin, new AsyncCallback(_getLogisticChannelCallback));
                        }
                    });
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }