コード例 #1
0
        public static router CreateProductServiceProxy()
        {
            //var ps = new ProductSearchWebServiceGateway();
            //var wsConfig = new OPVWebServiceConfiguration();
            //var username = wsConfig.Username;
            //var password = wsConfig.Password;

            var header = new gepirRequestHeader { requesterGln = "7350050279998", cascade = 9, cascadeSpecified = true};
            var gepirRouter = new router
                                  {
                                      UseDefaultCredentials = true,
                                      gepirRequestHeaderValue = header,
                                      Timeout = 60000
                                  };
            return gepirRouter;
        }
コード例 #2
0
        private void UpdateDomain(router router, string gtin, itemDataLineType gepirProduct)
        {
            if (string.IsNullOrEmpty(gepirProduct.brandName))
            {
                return;
            }
            using (var brandRepository = _repositoryFactory.Build<IBrandRepository, Brand>())
            {
                Brand brand = null;
                var matchingBrands = brandRepository.Find(x => x.BrandName == gepirProduct.brandName);

                // If a brand with the given name doesn't exist yet, we create it.
                if (!matchingBrands.Any())
                {
                    brand = new Brand{BrandName = gepirProduct.brandName, LastUpdated = DateTime.Now};
                    brandRepository.Add(brand);
                }
                // Else if there exists exactly one brand with the given name we use that brand
                else if (matchingBrands.Count() == 1)
                {
                    brand = matchingBrands.First();

                    // If the brand we retrieved doesn't have an owner we can add it as well
                    if (brand.Owner == null)
                    {
                        var manufacturerGln = gepirProduct.manufacturerGln ?? gepirProduct.informationProviderGln;
                        var getPartyByGln = new GetPartyByGLN { requestedGln = new[] { manufacturerGln }, versionSpecified = false };
                        var partyByGln = router.GetPartyByGLN(getPartyByGln);
                        if (partyByGln != null && partyByGln.partyDataLine != null && partyByGln.partyDataLine.Length > 0)
                        {
                            using (var companyRepository = _repositoryFactory.Build<IRepository<Company>, Company>())
                            {

                                var manufacturer = partyByGln.partyDataLine[0];
                                Company company = null;
                                var matchingCompanies =
                                    companyRepository.Find(x => x.CompanyName == manufacturer.partyName);
                                if (!matchingCompanies.Any())
                                {
                                    company = _gepirCompanyMapper.Map(manufacturer);
                                    companyRepository.Add(company);
                                    companyRepository.Persist();
                                }
                                else if(matchingCompanies.Count() == 1)
                                {
                                    company = matchingCompanies.First();
                                }

                                // If we added or found the correct company
                                if (company != null)
                                {
                                    //Todo: This should actually be done within the repository
                                    var brandOwner = brandRepository.FindDomainObject(company);
                                    brand.Owner = brandOwner;
                                }

                                brandRepository.Persist();

                                using (var productRepository = _repositoryFactory.Build<IProductRepository, Product>())
                                {
                                    // If product doesn't exist in database yet - add it.
                                    if (!productRepository.Find(x => x.GlobalTradeItemNumber == gtin).Any())
                                    {
                                        gepirProduct.gtin = gtin;
                                        var newProduct = _gepirProductMapper.Map(gepirProduct);
                                        productRepository.Add(newProduct);
                                        productRepository.Persist();
                                    }
                                }
                            }
                        }
                    }
                }

                if (brand != null && brand.Owner == null)
                {
                    
                }
            }
        }