Ejemplo n.º 1
0
        private void ProcessFile(FtpManager.RemoteFile file, IUnitOfWork unit)
        {
            #region Fill DataSet
            //StreamReader reader = new StreamReader(file.Data);
            Dictionary <string, long> stockData = new Dictionary <string, long>();

            using (DataSet ds = new DataSet())
            {
                ds.ReadXml(file.Data);

                stockData = (from data in ds.Tables[0].Rows.Cast <DataRow>()
                             select new
                {
                    ProductCode = data.Field <string>("ProductCode"),
                    Quantity = data.Field <long>("QuantityAvailable")
                }).ToDictionary(x => x.ProductCode, x => x.Quantity);
            }

            #endregion

            #region Process

            var Vendor       = unit.Scope.Repository <Vendor>().GetSingle(v => v.VendorID == vendorID);
            var vendorstocks = (from s in unit.Scope.Repository <VendorStock>().GetAll()
                                let assortment = s.Vendor.VendorAssortments.FirstOrDefault(c => c.ProductID == s.ProductID)
                                                 where s.VendorID == vendorID && assortment.IsActive == true
                                                 select new
            {
                CustomerItemNumber = assortment.CustomItemNumber,
                Stock = s
            }).ToList();

            int totalProducts = stockData.Count;
            int couterProduct = 0;
            int logCount      = 0;
            log.DebugFormat("Start Stock processing for {0}, {1} Products", "VSN", totalProducts);

            foreach (var stock in stockData)
            {
                couterProduct++;
                logCount++;
                if (logCount == 1000)
                {
                    log.DebugFormat("Stock Processed : {0}/{1} for Vendor {2}", couterProduct, totalProducts, "VSN");
                    logCount = 0;
                }

                var vendorstock = vendorstocks.FirstOrDefault(x => x.CustomerItemNumber == stock.Key);

                if (vendorstock != null)
                {
                    vendorstock.Stock.QuantityOnHand = (int)stockData[stock.Key];
                    unit.Save();
                }
            }


            #endregion
        }
Ejemplo n.º 2
0
        private string Download(string LocalDir, FtpManager.RemoteFile remoteFile)
        {
            log.AuditInfo("Downloading file: " + remoteFile.FileName);

            var savePath = Path.Combine(LocalDir, remoteFile.FileName);

            try
            {
                FileStream file = File.Create(savePath);
                remoteFile.Data.CopyTo(file);
                file.Close();
                log.AuditInfo("Done downloading file: " + remoteFile.FileName);
            }
            catch (Exception e)
            {
                log.AuditError(e.Message, e);
            }
            return(savePath);
        }
Ejemplo n.º 3
0
        protected void ProcessImageFile(FtpManager.RemoteFile imageFile, IUnitOfWork unit)
        {
            var productID = Path.GetFileNameWithoutExtension(imageFile.FileName).Trim().Replace("_large", "").Trim();

            var product = unit.Scope.Repository <VendorAssortment>().GetSingle(va => va.CustomItemNumber == productID);

            if (product == null)
            {
                log.WarnFormat("Cannot process image for product with Lenmar number: {0} because it doesn't exist in Concentrator database", productID);
                return;
            }

            string destFileName    = String.Format("{0}_{1}_{2}{3}", product.ProductID, product.CustomItemNumber, product.VendorID, Path.GetExtension(imageFile.FileName));
            string destinationPath = Path.Combine(GetConfiguration().AppSettings.Settings["FTPImageDirectory"].Value, "Products");

            string finalDestination = Path.Combine(destinationPath, destFileName);
            var    mediaRepo        = unit.Scope.Repository <ProductMedia>();
            var    productImage     = mediaRepo.GetSingle(pi => pi.ProductID == product.ProductID && pi.VendorID == vendorID);

            if (productImage == null)
            {
                productImage = new ProductMedia
                {
                    ProductID = product.ProductID,
                    VendorID  = vendorID,
                    MediaUrl  = String.Empty,
                    TypeID    = 1
                };
                mediaRepo.Add(productImage);
            }

            if (File.Exists(finalDestination))
            {
                log.AuditWarning(string.Format("Skipping image for product with Lenmar number: {0} because it already exists", productID));
            }
            else
            {
                if (!Directory.Exists(destinationPath))
                {
                    Directory.CreateDirectory(destinationPath);
                }

                using (var file = new BinaryWriter(System.IO.File.Open(finalDestination, FileMode.Create)))
                {
                    using (Stream imageData = imageFile.Data)
                    {
                        using (var ms = new MemoryStream())
                        {
                            int count = 0;
                            do
                            {
                                byte[] buf = new byte[1024];
                                count = imageData.Read(buf, 0, 1024);
                                ms.Write(buf, 0, count);
                            } while (imageData.CanRead && count > 0);

                            byte[] data = ms.ToArray();
                            file.Write(data, 0, data.Length);
                        }
                    }
                }
            }
            productImage.MediaPath = Path.Combine("Products", destFileName);
        }