Beispiel #1
0
        public void ZipTest()
        {
            string str1 = "12312312312312";
            string str2 = "<\nconghoaxahoichunghiavietnam";

            Assert.AreEqual(str1, UtilZipFile.UnzipWithEndcode(UtilZipFile.ZipWithEndcode(str1)));
            Assert.AreEqual(str2, UtilZipFile.UnzipWithEndcode(UtilZipFile.ZipWithEndcode(str2)));
        }
Beispiel #2
0
        private void RootProductAnalyzed(byte[] rootProductByte)
        {
            var jsonListProduct = UtilZipFile.Unzip(rootProductByte);
            var result          = JsonConvert.DeserializeObject <List <RootProductAnalyzedObject> >(jsonListProduct);
            var dataNameCode    = new Dictionary <long, List <RootProductAnalyzedObject> >();

            foreach (var rootItem in result)
            {
                if (dataNameCode.ContainsKey(rootItem.RootProductId))
                {
                    dataNameCode[rootItem.RootProductId].Add(rootItem);
                }
                else
                {
                    dataNameCode.Add(rootItem.RootProductId, new List <RootProductAnalyzedObject>()
                    {
                        rootItem
                    });
                }
            }
            var rootAdapter = new RootProductsTableAdapter();

            rootAdapter.Connection.ConnectionString = _connectionStringIndi;

            var solrRootProductClient =
                SolrRootProductClient.GetClient(SolrClientManager.GetSolrClient("solrRootProducts"));

            DBProductTableAdapters.ProductTableAdapter productAdapter = new ProductTableAdapter();
            productAdapter.Connection.ConnectionString = _connectionProduct;
            foreach (var rootItem in dataNameCode)
            {
                try
                {
                    var rootProductSql = new RootProductSql()
                    {
                        RootId      = rootItem.Key,
                        Name        = rootItem.Value[0].Name,
                        WebsiteId   = rootItem.Value[0].WebsiteId,
                        NumMerchant = rootItem.Value.Count,
                        CategoryId  = rootItem.Value[0].CategoryId
                    };
                    rootProductSql.LocalPath =
                        Websosanh.Core.Common.BAL.UrlUtilities.GetRootProductLocalPath(rootProductSql.RootId,
                                                                                       rootProductSql.Name);
                    long minprice = 0;
                    rootProductSql.ProductIdList = new List <long>();
                    var imagePath = "";
                    foreach (var item in rootItem.Value)
                    {
                        rootProductSql.ProductIdList.Add(item.Id);
                        if (!(minprice > 0 && minprice < item.Price))
                        {
                            minprice = item.Price;
                        }
                        if (string.IsNullOrEmpty(imagePath))
                        {
                            imagePath = GetImagePath(item.Id, productAdapter);
                        }
                    }
                    rootProductSql.MinPrice = minprice;
                    rootProductSql.Image    = imagePath;

                    rootProductSql.ProductIdListString = rootProductSql.GetProductIdListString();
                    if (InsertSQlRootProduct(ref rootProductSql, rootAdapter))
                    {
                        InsertSolrRootProduct(rootProductSql, solrRootProductClient);
                    }
                }
                catch (Exception exception)
                {
                    Log.Error(exception);
                }
            }
        }