Ejemplo n.º 1
0
        private async Task <ShopModel> InitProductCostAsync(ShopModel shopModel)
        {
            log.Debug($"Ожидание инициализации {nameof(purchasingService)}");
            List <RealCurrencyCostModel> realCurrencyProducts = shopModel.GetRealCurrencyProducts();

            purchasingService.StartInitialization(realCurrencyProducts);
            await MyTaskExtensions.WaitUntil(purchasingService.IsStoreInitialized);

            log.Debug($"{nameof(purchasingService)} инициализирован");
            foreach (ProductModel productModel in shopModel.GetAllProducts())
            {
                if (productModel.CostModel.CostTypeEnum == CostTypeEnum.RealCurrency)
                {
                    var realCurrencyCostModel = ZeroFormatterSerializer
                                                .Deserialize <RealCurrencyCostModel>(productModel.CostModel.SerializedCostModel);
                    string productId = realCurrencyCostModel.GoogleProductId;
                    string cost      = null;
                    purchasingService.TryGetProductCostById(productId, ref cost);
                    if (cost == null)
                    {
                        throw new Exception("Не удалось достать цену товара из плагина магазина");
                    }


                    realCurrencyCostModel.CostString           = cost;
                    productModel.CostModel.SerializedCostModel =
                        ZeroFormatterSerializer.Serialize(realCurrencyCostModel);
                }
            }

            return(shopModel);
        }