示例#1
0
        public void Process()
        {
            var config = GetConfiguration();

            //Local directory files
            var LocalDir = config.AppSettings.Settings["LocalImportDir"].Value;

            if (!Directory.Exists(LocalDir))
            {
                Directory.CreateDirectory(LocalDir);
            }
#if DEBUG
            var activeTitlesFile       = Path.Combine(LocalDir, "ttlingv2.zip");
            var activeTitlesUpdateFile = Path.Combine(LocalDir, "ttladdch.zip");
            var annotationsFile        = Path.Combine(LocalDir, "antingrm-13.zip");
            var seriesFile             = Path.Combine(LocalDir, "SERIES.txt");
            var categoriesFile         = Path.Combine(LocalDir, "catg2.txt");
            var familiesFile           = Path.Combine(LocalDir, "family-13.zip");
            var stockFile = Path.Combine(LocalDir, "*****@*****.**");
#else
            var Username = config.AppSettings.Settings["FtpUsername"].Value;
            var Password = config.AppSettings.Settings["FtpPassword"].Value;
            var FtpUrl   = config.AppSettings.Settings["FtpUrl"].Value;


            FtpManager ftp = new FtpManager(FtpUrl, null, Username, Password, false, true, log);

            var categoriesFile         = ftp.DownloadToDisk(LocalDir, config.AppSettings.Settings["Categories"].Value);
            var annotationsFile        = ftp.DownloadToDisk(LocalDir, config.AppSettings.Settings["Annotations"].Value);
            var activeTitlesFile       = ftp.DownloadToDisk(LocalDir, config.AppSettings.Settings["Titles"].Value);
            var activeTitlesUpdateFile = ftp.DownloadToDisk(LocalDir, config.AppSettings.Settings["TitlesUpdate"].Value);
            var seriesFile             = ftp.DownloadToDisk(LocalDir, config.AppSettings.Settings["Series"].Value);
            var familiesFile           = ftp.DownloadToDisk(LocalDir, config.AppSettings.Settings["Familys"].Value);
            var stockFile = ftp.DownloadToDisk(LocalDir, config.AppSettings.Settings["Stock"].Value);
#endif
            var VendorID        = Int32.Parse(config.AppSettings.Settings["VendorID"].Value);
            var DefaultVendorID = Int32.Parse(config.AppSettings.Settings["VendorID"].Value);

            // var ftp.OpenFile(

            using (var unit = GetUnitOfWork())
            {
                #region Setup

                List <ProductAttributeMetaData> attributes;
                SetupAttributes(unit, AttributeMapping, out attributes, null);

                var productAttributes = unit.Scope.Repository <ProductAttributeMetaData>().GetAll(c => c.VendorID == DefaultVendorID).ToList();
                var attributeList     = productAttributes.ToDictionary(x => x.AttributeCode, y => y.AttributeID);

                #endregion

                try
                {
#if !DEBUG
                    FileStream activeFiles_Stream = File.Open(activeTitlesFile, FileMode.Open, FileAccess.Read, FileShare.None);
                    var        assortmentFile     = Unzip(activeFiles_Stream, LocalDir, "ttlingv2.txt");
                    FileStream annotations_Stream = File.Open(annotationsFile, FileMode.Open, FileAccess.Read, FileShare.None);
                    var        annotations        = Unzip(annotations_Stream, LocalDir, "ANTINGRM.TXT");
                    FileStream fam_Stream         = File.Open(familiesFile, FileMode.Open, FileAccess.Read, FileShare.None);
                    var        families           = Unzip(fam_Stream, LocalDir, "FAMILY-13.DAT");
                    FileStream stock_Stream       = File.Open(stockFile, FileMode.Open, FileAccess.Read, FileShare.None);
                    var        stocks             = Unzip(stock_Stream, LocalDir, "*****@*****.**");
#else
                    var assortmentFile = @"G:\Ingram\Import\ttlingv2.txt";
                    var annotations    = @"G:\Ingram\Import\ANTINGRM.TXT";
                    var families       = @"G:\Ingram\Import\FAMILY-13.DAT";
                    var stocks         = @"G:\Ingram\Import\[email protected]";
#endif

                    #region Assortment
                    var assortment = (from a in ReadFrom(assortmentFile)
                                      where a.Length > 400
                                      select new Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorAssortmentItem
                    {
                        #region BrandVendor
                        BrandVendors = new List <VendorAssortmentBulk.VendorImportBrand>()
                        {
                            new VendorAssortmentBulk.VendorImportBrand()
                            {
                                VendorID = DefaultVendorID,
                                VendorBrandCode = a.Substring(225, 40).Trim(), //UITGEVER_ID
                                ParentBrandCode = null,
                                Name = a.Substring(225, 40).Trim()             //row["Publisher Imprint"].ToString().Trim() //UITGEVER_NM
                            }
                        },
                        #endregion

                        #region GeneralProductInfo
                        VendorProduct = new VendorAssortmentBulk.VendorProduct
                        {
                            VendorItemNumber = a.Substring(442, 17).Trim(),     //EAN
                            CustomItemNumber = a.Substring(442, 17).Trim(),     //EAN
                            ShortDescription = a.Substring(161, 30).Trim(),     //ShortTitle
                            LongDescription = "",
                            LineType = null,
                            LedgerClass = null,
                            ProductDesk = null,
                            ExtendedCatalog = null,
                            VendorID = VendorID,
                            DefaultVendorID = DefaultVendorID,
                            VendorBrandCode = a.Substring(225, 40).Trim(),        //Contributor 1
                            Barcode = a.Substring(442, 17).Trim(),                //EAN
                            VendorProductGroupCode1 = a.Substring(212, 9).Trim(), //Series ID
                            VendorProductGroupCodeName1 = string.Empty,           //a.Substring(221, 4).Trim(),//series number
                            VendorProductGroupCode2 = a.Substring(459, 4).Trim(), // Ingram subject
                            VendorProductGroupCodeName2 = ""                      //GEEN NAAM
                        },
                        #endregion

                        #region RelatedProducts

                        RelatedProducts = new List <VendorAssortmentBulk.VendorImportRelatedProduct>(),     //getRelatedProducts(row, families, VendorID),

                        #endregion

                        #region Attributes
                        VendorImportAttributeValues = new List <VendorAssortmentBulk.VendorImportAttributeValue>(),
                        #endregion

                        #region Images
                        VendorImportImages = new List <VendorAssortmentBulk.VendorImportImage>(),
                        #endregion

                        #region Prices
                        VendorImportPrices = new List <Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorImportPrice>()
                        {
                            new Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorImportPrice()
                            {
                                VendorID = VendorID,
                                DefaultVendorID = DefaultVendorID,
                                CustomItemNumber = a.Substring(442, 17).Trim(), //EAN
                                Price = "0",                                    //row.Price.ToString().Trim(), //ADVIESPRIJS
                                CostPrice = "0",                                //row.Price.ToString().Trim(), //NETTOPRIJS
                                TaxRate = "19",                                 //TODO: Calculate this!
                                MinimumQuantity = 0,
                                CommercialStatus = ""                           //STADIUM_LEVENSCYCLUS_KD
                            }
                        },
                        #endregion

                        #region Stock
                        VendorImportStocks = new List <Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorImportStock>()
                        {
                            new Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorImportStock()
                            {
                                VendorID = VendorID,
                                DefaultVendorID = DefaultVendorID,
                                CustomItemNumber = a.Substring(442, 17).Trim(), //EAN
                                QuantityOnHand = 0,
                                StockType = "Assortment",
                                StockStatus = ""//GetProductStatusName(row.Price["Publisher Status Code"].ToString().Trim())//STADIUM_LEVENSCYCLUS_KD
                            }
                        },
                        #endregion
                    }).Take(100000);

                    using (VendorAssortmentBulk bulkExport = new VendorAssortmentBulk(assortment, VendorID, DefaultVendorID))
                    {
                        bulkExport.IncludeBrandMapping = true;
                        bulkExport.Init(unit.Context);
                        bulkExport.Sync(unit.Context);
                    }
                    #endregion

                    #region RawBulk

                    var Description = (from r in ReadFrom(annotations)
                                       select new tempDescriptionsModel
                    {
                        EAN = r.Substring(0, 12).Trim(),
                        Text = r.Substring(15).Trim()
                    });


                    var Category = (from r in ReadFrom(categoriesFile)
                                    select new tempCategoriesModel
                    {
                        IngramSubjectCode = r.Substring(1, 4).Trim(),
                        IngramSubjectDescription = r.Substring(8, 59).Trim()
                    });


                    var RelatedProduct = (from r in ReadFrom(families)
                                          select new tempRelatedProductsModel
                    {
                        EAN = r.Substring(0, 12).Trim(),
                        FamilyID = r.Substring(13, 7).Trim(),
                        ItemID = r.Substring(20, 3).Trim()
                    });

                    var Series = (from r in ReadFrom(seriesFile)
                                  select new tempSeriesModel
                    {
                        SeriesID = r.Substring(1, 9).Trim(),
                        Text = r.Substring(13).Replace('"', ' ')
                    });



                    var StockandPrice = (from r in ReadFrom(stocks)
                                         select new tempStockandPriceModel
                    {
                        EAN = r.Substring(1, 13),
                        Price = ((Int32.Parse(r.Substring(150, 7)) * 0.75) / 100).ToString("0.00", CultureInfo.InvariantCulture),
                        CostPrice = ((Int32.Parse(r.Substring(157, 7)) * 0.75) / 100).ToString("0.00", CultureInfo.InvariantCulture),
                        QuantityOnHand = (Int32.Parse(r.Substring(38, 7).Trim()) +
                                          Int32.Parse(r.Substring(45, 7).Trim()) +
                                          Int32.Parse(r.Substring(52, 7).Trim()) +
                                          Int32.Parse(r.Substring(59, 7).Trim())).ToString(),
                        CommercialStatus = GetProductStatusName(r.Substring(178, 2).ToString().Trim())
                    });


                    var rawDate = new RawBulkModel()
                    {
                        Categories      = Category,
                        Descriptions    = Description,
                        RelatedProducts = RelatedProduct,
                        Series          = Series,
                        StockandPrice   = StockandPrice
                    };

                    using (RawBulk rawbulk = new RawBulk(rawDate, VendorID))
                    {
                        rawbulk.Init(unit.Context);
                        rawbulk.Sync(unit.Context);
                    }

                    #endregion
                }
                catch (Exception ex)
                {
                }
            }
        }