Beispiel #1
0
 private void CloneLogisticChannel(LogisticsChannel channel, LogisticsChannelClone cloneChannel, List <LogisticsSize> sizes)
 {
     cloneChannel.size = channel.size;
     cloneChannel.is_shipping_fee_promotion_rule = channel.is_shipping_fee_promotion_rule;
     cloneChannel.sizeid          = channel.sizeid;
     cloneChannel.enable_massship = channel.enable_massship;
     cloneChannel.discount_json   = channel.discount_json;
     cloneChannel.id                    = channel.id;
     cloneChannel.item_flag             = channel.item_flag;
     cloneChannel.category              = channel.category;
     cloneChannel.mass_apply_prices     = channel.mass_apply_prices;
     cloneChannel.display_name          = channel.display_name;
     cloneChannel.cod_whitelist_enabled = channel.cod_whitelist_enabled;
     cloneChannel.priority              = channel.priority;
     cloneChannel.icon                  = channel.icon;
     cloneChannel.desc_key              = channel.desc_key;
     cloneChannel.price                 = channel.price;
     cloneChannel.preferred             = channel.preferred;
     cloneChannel.discount              = channel.discount;
     cloneChannel.flag                  = channel.flag;
     cloneChannel.name_key              = channel.name_key;
     cloneChannel.level                 = channel.level;
     cloneChannel.cod_enabled           = channel.cod_enabled;
     cloneChannel.extra_data            = channel.extra_data;
     cloneChannel.name                  = channel.name;
     cloneChannel.limits                = channel.limits;
     if (channel.sizes.Count() > 0)
     {
         var sizeID = channel.sizes[0];
         if (sizes.Count() > 0)
         {
             cloneChannel.sizes = new List <LogisticsSize>()
             {
                 sizes[sizeID.GetValueOrDefault() - 1]
             };
         }
     }
     else
     {
         cloneChannel.sizes = new List <LogisticsSize>();
     }
     cloneChannel._default           = channel._default;
     cloneChannel.country            = channel.country;
     cloneChannel.channelid          = channel.channelid;
     cloneChannel.enabled            = channel.enabled;
     cloneChannel.cover_shipping_fee = channel.cover_shipping_fee;
     cloneChannel.command            = channel.command;
     cloneChannel.save_into_item     = channel.save_into_item;
     cloneChannel.supported          = channel.supported;
 }
Beispiel #2
0
        private async void _getLogisticChannelCallback(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,
                                                                                  async() =>
                    {
                        try
                        {
                            var dumpJson = Newtonsoft.Json.JsonConvert.DeserializeObject <ErrorMessage>(resultContent);
                            if (dumpJson.error != null && dumpJson.err_message != null)
                            {
                                if (!string.IsNullOrEmpty(dumpJson.error))
                                {
                                    await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                                                                                                  async() =>
                                    {
                                        await new MessageDialog(StaticResources.choosingLanguage.GlobalWarningSession).ShowAsync();
                                        StaticResources.NavigationFrame.Navigate(typeof(ShopeeLoginPage), null, new DrillInNavigationTransitionInfo());
                                        StaticResources.isLoginPage = true;
                                    });
                                }
                                return;
                            }
                            var dumpJson2 = Newtonsoft.Json.JsonConvert.DeserializeObject <ErrorMessage2>(resultContent);
                            if (dumpJson2.errcode != null && dumpJson2.message != null)
                            {
                                if (!string.IsNullOrEmpty(dumpJson2.errcode))
                                {
                                    await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                                                                                                  async() =>
                                    {
                                        await new MessageDialog(StaticResources.choosingLanguage.GlobalWarningSession).ShowAsync();
                                        StaticResources.NavigationFrame.Navigate(typeof(ShopeeLoginPage), null, new DrillInNavigationTransitionInfo());
                                        StaticResources.isLoginPage = true;
                                    });
                                }
                                return;
                            }
                        }
                        catch
                        {
                        }
                        var dumpjson          = Newtonsoft.Json.JsonConvert.DeserializeObject <LogisticsChannels>(resultContent);
                        this.ListLogisticSize = dumpjson.logistics_sizes;
                        var listChannel       = new ObservableCollection <LogisticsChannel>(dumpjson.logistics_channels.Where(p => p.enabled == 1).ToList());
                        if (listChannel.Count() != this.ListLogisticsChannelClone.Count())
                        {
                            foreach (var channel in listChannel)
                            {
                                LogisticsChannelClone channelClone = new LogisticsChannelClone();
                                if (double.Parse(channel.price) > 0)
                                {
                                    channel.supported = true;
                                }
                                this.CloneLogisticChannel(channel, channelClone, this.ListLogisticSize);
                                this.ListLogisticsChannelClone.Add(channelClone);
                            }
                        }
                    });
                }
            }
            catch (WebException ex)
            {
                try
                {
                    using (var streamReader = new StreamReader(ex.Response.GetResponseStream()))
                    {
                        var resp     = streamReader.ReadToEnd();
                        var dumpJson = Newtonsoft.Json.JsonConvert.DeserializeObject <ErrorMessage>(resp);
                        if (dumpJson.error != null && dumpJson.err_message != null)
                        {
                            if (!string.IsNullOrEmpty(dumpJson.error))
                            {
                                await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                                                                                              async() =>
                                {
                                    StaticResources.SelectedShopLogin.ShopStatus = "Out of date";
                                    await new MessageDialog(StaticResources.choosingLanguage.GlobalWarningSession).ShowAsync();
                                    StaticResources.NavigationFrame.Navigate(typeof(ShopeeLoginPage), null, new DrillInNavigationTransitionInfo());
                                    StaticResources.isLoginPage = true;
                                });
                            }
                            return;
                        }
                        var dumpJson2 = Newtonsoft.Json.JsonConvert.DeserializeObject <ErrorMessage2>(resp);
                        if (dumpJson2.errcode != null && dumpJson2.message != null)
                        {
                            if (!string.IsNullOrEmpty(dumpJson2.errcode))
                            {
                                await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                                                                                              async() =>
                                {
                                    StaticResources.SelectedShopLogin.ShopStatus = "Out of date";
                                    await new MessageDialog(StaticResources.choosingLanguage.GlobalWarningSession).ShowAsync();
                                    StaticResources.NavigationFrame.Navigate(typeof(ShopeeLoginPage), null, new DrillInNavigationTransitionInfo());
                                    StaticResources.isLoginPage = true;
                                });
                            }
                            return;
                        }
                    }
                }
                catch (Exception)
                {
                }
            }
        }