예제 #1
0
        public static void getDataFromPostgres(Database pg, Database sql)
        {
            var data     = pg.Query <DbModels.Data>().ToList();
            var products = sql.Query <DbModels.Product>().ToList();

            Parallel.ForEach(data, x =>
            {
                var productType  = products.Where(p => p.Id == x.ProductId).FirstOrDefault();
                var productModel = JsonConvert.DeserializeObject <Models.Product>(x.ProductModel);

                var newData = new DbModels.Data()
                {
                    ProductId    = x.ProductId,
                    ProductModel = x.ProductModel,
                    RawData      = x.RawData,
                    When         = x.When
                };

                LockInsert(sql, newData);


                var price = new DbModels.Price
                {
                    DataId         = newData.Id,
                    ProductId      = productType.Id,
                    OriginalPrice  = productModel.Price,
                    OnSalePrice    = productModel.SpecialPrice,
                    Company        = productModel.Company,
                    Description    = productModel.Description.Trim(),
                    AdditionalData = new Dictionary <string, object>()
                    {
                        {
                            "$/L", productModel.DollarPerLitre
                        },
                        {
                            "imgUrl",
                            productModel.ImgUrl
                        },
                    },
                    When = newData.When
                };
                LockInsert(sql, price);
            });
        }
예제 #2
0
        public static void tryMigrate(Database sql)
        {
            var items    = sql.Query <OldPrice>().ToList();
            var products = sql.Query <DbModels.Product>().ToList();

            Parallel.ForEach(items, x =>
            {
                try
                {
                    Models.Product product = null;
                    var data = new DbModels.Data();

                    data.When = x.When.AddHours(-11);

                    if (ApiConstants.Coles.Is(x.Company))
                    {
                        data.RawData = x.OriginalData;

                        product = ApiConstants.Coles.GetProductFromJson(data.RawData);
                    }
                    else if (ApiConstants.Woolworths.Is(x.Company))
                    {
                        data.RawData = x.OriginalData;

                        product = ApiConstants.Woolworths.GetProductFromJson(data.RawData);
                    }
                    data.ProductModel = JsonConvert.SerializeObject(product);
                    var productType   = products.Where(p => p.Code == product.Id).FirstOrDefault();
                    data.ProductId    = productType.Id;
                    LockInsert(sql, data);
                    LockUpdate(sql, data);


                    var price = new DbModels.Price
                    {
                        DataId         = data.Id,
                        ProductId      = productType.Id,
                        OriginalPrice  = product.Price,
                        OnSalePrice    = product.SpecialPrice,
                        Company        = product.Company,
                        Description    = product.Description.Trim(),
                        AdditionalData = new Dictionary <string, object>()
                        {
                            {
                                "$/L", product.DollarPerLitre
                            },
                            {
                                "imgUrl",
                                product.ImgUrl
                            },
                        },
                        When = data.When
                    };

                    LockInsert(sql, price);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(x.Id);
                }
            });
        }