Exemple #1
0
        private string GetProductJsonDownloadUrl(string customerCode, string slug, NameValueCollection parameters, bool allFields, SiteMode siteMode, string[] fields)
        {
            var customerCodePart = GetCustomerCodeUrlPart(customerCode);
            var url = $"{_settings.BaseUrl}/{customerCodePart}invariant/{siteMode.ToString().ToLower()}/products/{slug}";

            if (parameters.HasKeys())
            {
                var queryParams = string.Join("&", parameters.AllKeys.Select(key => $"{key}={parameters[key]}"));
                url += $"?{queryParams}";
            }

            if (allFields)
            {
                fields = new[] { "*" }
            }
            ;

            if (fields != null && fields.Any())
            {
                url += parameters.HasKeys() ? "&" : "?";
                url += $"fields={string.Join(",", fields)}";
            }

            return(url);
        }
Exemple #2
0
        private string GetProductsJsonDownloadUrl(string customerCode, string productType, int[] ids, SiteMode siteMode)
        {
            var customerCodePart = GetCustomerCodeUrlPart(customerCode);

            //вариант для получения одним запросом(когда починят).
            return($"{_settings.BaseUrl}/{customerCodePart}invariant/{siteMode.ToString().ToLower()}/products/{productType}?Id={string.Join("{or}", ids)}");
        }
Exemple #3
0
        public async Task <string> MapProductJson(string customerCode, int productId, string category, int?mapperId, int?templateId, bool forceDownload, SiteMode siteMode)
        {
            if (!mapperId.HasValue)
            {
                PdfTemplate pdfTemplate;
                if (templateId.HasValue)
                {
                    pdfTemplate = await _dpcApiClient.GetProduct <PdfTemplate>(customerCode, templateId.Value, siteMode);
                }
                else
                {
                    pdfTemplate = await _pdfTemplateSelector.GetPdfTemplateForProduct(customerCode, productId, category, siteMode);
                }
                mapperId = pdfTemplate.PdfScriptMapper.Id;
            }

            var mapper = await _dpcApiClient.GetProduct <PdfScriptMapper>(customerCode, mapperId.Value, true, siteMode);

//            var mapper = await _dpcApiDbApiClient.GetPdfScriptMapper(mapperId.Value);


            var productBase = await _dpcApiClient.GetProduct <DpcProductBase>(customerCode, productId, false, siteMode, new[] { "Id", "UpdateDate" });

            if (productBase == null)
            {
                throw new GetProductJsonException();
            }
            var productDownloadUrl = _dpcApiClient.GetProductJsonDownloadUrl(customerCode, productId, true, siteMode);

            var request = new PreviewJsonRequest
            {
                TariffData = new GenerateHtmlFileInfo
                {
                    Id            = productId,
                    Timestamp     = ConvertToTimestamp(productBase.UpdateDate),
                    ForceDownload = forceDownload,
                    DownloadUrl   = productDownloadUrl,
                    SiteMode      = siteMode.ToString()
                },

                MapperData = new GenerateHtmlFileInfo
                {
                    Id            = mapperId.Value,
                    Timestamp     = ConvertToTimestamp(mapper.Timestamp),
                    ForceDownload = forceDownload,
                    DownloadUrl   = $"{_settings.DpcStaticFilesScheme}:{mapper.PdfScriptMapperFile.AbsoluteUrl}",
                    SiteMode      = "db"
                },
            };

            var response = await MakeRequest(request);

            if (response.Success)
            {
                return(response.Json);
            }

            throw new ProductMappingException(response.Error?.Message ?? "Unknown error while mapping product");
        }
Exemple #4
0
        public string GetProductJsonDownloadUrl(string customerCode, int id, bool allFields, SiteMode siteMode, string[] fields = null)
        {
            var customerCodePart = GetCustomerCodeUrlPart(customerCode);

            var url = $"{_settings.BaseUrl}/{customerCodePart}invariant/{siteMode.ToString().ToLower()}/products/{id}";

            if (allFields)
            {
                fields = new[] { "*" }
            }
            ;

            if (fields != null && fields.Any())
            {
                url += $"?fields={string.Join(",", fields)}";
            }
            return(url);
        }
Exemple #5
0
        private string GetRegionTagsUrl(string customerCode, int productId, SiteMode siteMode)
        {
            var customerCodePart = GetCustomerCodeUrlPart(customerCode);

            return($"{_settings.BaseUrl}/{customerCodePart}invariant/{siteMode.ToString().ToLower()}/products/RegionTags?ProductId={productId}");
        }
 private void SetCookieWithMode( SiteMode mode )
 {
   var newCookie = new HttpCookie( LONG_TERM_VIEW_SELECTION_COOKIE_NAME, mode.ToString() )
                     {Expires = DateTime.Now.AddDays( 5 )};
   HttpContext.Current.Response.Cookies.Add( newCookie );
 }
        public async Task <string> GenerateHtml(string customerCode, int productId, string category, int?templateId,
                                                int?regionId, SiteMode siteMode, bool forceDownload)
        {
            PdfTemplate pdfTemplate;

            if (templateId.HasValue)
            {
                pdfTemplate = await _client.GetProduct <PdfTemplate>(customerCode, templateId.Value, siteMode);
            }
            else
            {
                pdfTemplate =
                    await _pdfTemplateSelector.GetPdfTemplateForProduct(customerCode, productId, category, siteMode);
            }

            if (pdfTemplate == null)
            {
                throw new TemplateNotFoundException();
            }

            var productBase = await _client.GetProduct <DpcProductBase>(customerCode, productId, false, siteMode,
                                                                        new[] { "Id", "UpdateDate" });

            if (productBase == null)
            {
                throw new GetProductJsonException();
            }
            var productDownloadUrl = _client.GetProductJsonDownloadUrl(customerCode, productId, true, siteMode);
            var request            = new GenerateHtmlRequest
            {
                TariffData = new GenerateHtmlFileInfo
                {
                    Id            = productId,
                    Timestamp     = ConvertToTimestamp(productBase.UpdateDate),
                    DownloadUrl   = productDownloadUrl,
                    ForceDownload = forceDownload,
                    SiteMode      = siteMode.ToString()
                },
                MapperData = new GenerateHtmlFileInfo
                {
                    Id          = pdfTemplate.PdfScriptMapper.Id,
                    Timestamp   = ConvertToTimestamp(pdfTemplate.PdfScriptMapper.Timestamp),
                    DownloadUrl =
                        $"{_settings.DpcStaticFilesScheme}:{pdfTemplate.PdfScriptMapper.PdfScriptMapperFile.AbsoluteUrl}",
                    ForceDownload = forceDownload,
                    SiteMode      = siteMode.ToString()
                },
                TemplateData = new GenerateHtmlFileInfo
                {
                    Id            = pdfTemplate.Id,
                    Timestamp     = ConvertToTimestamp(pdfTemplate.UpdateDate),
                    DownloadUrl   = $"{_settings.DpcStaticFilesScheme}:{pdfTemplate.PdfTemplateFile.AbsoluteUrl}",
                    ForceDownload = forceDownload,
                    SiteMode      = siteMode.ToString()
                },
                TemplateEngine = pdfTemplate.PdfTemplateEngine
            };
            var response = await MakeGenerateRequest(request);

            if (response.Success && !string.IsNullOrWhiteSpace(response.RelativePath))
            {
                var generatedHtml = await GetHtml(response.RelativePath);

                var replacedHtml =
                    await _regionTagsReplacer.ReplaceTags(customerCode, generatedHtml, productId, siteMode, regionId);

                return(replacedHtml);
            }

            throw new HtmlGenerationException(response.Error?.Message ?? "Unknown error while generating html");
        }