コード例 #1
0
        public virtual int IndexProductsWithCategories()
        {
            int numberOfProductsSentToSannsyn = 0;

            // Get all catalogs to index
            var catalogRoots = GetCatalogRoots();

            foreach (var catalogRoot in catalogRoots)
            {
                _logger.Debug("Indexing products in catalog: {0}", catalogRoot.ToString());

                IEnumerable <ContentReference> contentLinks = _contentLoader.GetDescendents(catalogRoot);

                var availableLocalizations = GetAvailableLocalizations();

                foreach (CultureInfo culture in availableLocalizations)
                {
                    int allContentsCount = contentLinks.Count();
                    for (var i = 0; i < allContentsCount; i += _bulkSize)
                    {
                        IEnumerable <EntryContentBase> products = GetEntriesToIndex(_bulkSize, contentLinks, culture, i);

                        // First get indexable content items
                        Dictionary <string, EntryContentBase> indexableContentItems = GetIndexableContentItems(products);

                        // Get models Sannsyn can index
                        List <SannsynUpdateEntityModel> sannsynObjects = GetUpdateModels(indexableContentItems);

                        numberOfProductsSentToSannsyn = numberOfProductsSentToSannsyn + sannsynObjects.Count;

                        _logger.Debug("Sending {0} entries to Sannsyn index", sannsynObjects.Count);

                        SannsynUpdateModel sannsynModel = new SannsynUpdateModel();
                        sannsynModel.Service = _configuration.Service;
                        sannsynModel.Updates = sannsynObjects;
                        _sannsynUpdateService.SendToSannsyn(sannsynModel);
                    }
                }

                _logger.Debug("Done sending {0} entries to Sannsyn index", numberOfProductsSentToSannsyn);
            }
            return(numberOfProductsSentToSannsyn);
        }
コード例 #2
0
        /// <summary>
        /// Sending data to Sannsyn
        /// </summary>
        /// <param name="sannsynModel">Model with entry codes</param>
        /// <returns>A HttpResponseMessage with result from the put request to Sannsyn</returns>
        public HttpResponseMessage SendToSannsyn(SannsynUpdateModel sannsynModel)
        {
            var jsonData = JsonConvert.SerializeObject(sannsynModel);
            // This method does not require the service name
            Uri        serviceUrl = _backendService.GetServiceMethodUri(Constants.ServiceMethod.Update, null, null);
            HttpClient client     = _backendService.GetConfiguredClient();

            HttpContent         content  = new StringContent(jsonData);
            HttpResponseMessage response = client.PutAsync(serviceUrl, content).Result;

            _log.Debug("Sent to Sannsyn. Result: {0}", response.StatusCode);
            if (response.IsSuccessStatusCode == false)
            {
                string resultContent = response.Content.ReadAsStringAsync().Result;
                _log.Warning("Send to Sannsyn failed: {0}", resultContent);
            }

            if (_logSendData)
            {
                _log.Debug("Data: {0}", jsonData);
            }

            return(response);
        }
        /// <summary>
        /// Creates a update model to Sannsyn, with a list of entry/variation codes, and service name
        /// </summary>
        /// <param name="orderGroup">Order to get lineitems from</param>
        public void AddLineItemsToSannsyn(OrderGroup orderGroup)
        {
            LineItemCollection lineItems = orderGroup.OrderForms.First().LineItems;

            List <SannsynUpdateEntityModel> sannsynObjects = new List <SannsynUpdateEntityModel>();

            foreach (LineItem lineItem in lineItems)
            {
                SannsynUpdateEntityModel model = CreateSannsynObject(lineItem, orderGroup.CustomerId);
                if (model != null)
                {
                    sannsynObjects.Add(model);
                }
            }

            // Make sure we have something to index
            if (sannsynObjects.Any())
            {
                SannsynUpdateModel sannsynModel = new SannsynUpdateModel();
                sannsynModel.Service = _configuration.Service;
                sannsynModel.Updates = sannsynObjects;
                _sannsynUpdateService.SendToSannsyn(sannsynModel);
            }
        }