/// <summary> /// Upload a file to the specfied Ftp server /// </summary> /// <param name="Path"></param> /// <returns></returns> public bool UploadFile(string PathToFile, string PathOnFtp) { try { string Filename = Path.GetFileName(PathToFile); // Get the object used to communicate with the server. FtpWebRequest request = (FtpWebRequest)WebRequest.Create(new Uri(new Uri(new Uri(_Url), PathOnFtp), Filename)); request.Method = WebRequestMethods.Ftp.UploadFile; if (_isPassive.HasValue) { request.UsePassive = _isPassive.Value; } request.Credentials = new NetworkCredential(_Username, _Password); // Copy the contents of the file to the request stream. byte[] fileContents = File.ReadAllBytes(PathToFile); request.ContentLength = fileContents.Length; using (Stream requestStream = request.GetRequestStream()) { requestStream.Write(fileContents, 0, fileContents.Length); requestStream.Close(); } using (FtpWebResponse response = (FtpWebResponse)request.GetResponse()) { _log.InfoFormat("Upload File Complete, status {0}", response.StatusDescription); response.Close(); } return(true); } catch (Exception ex) { _log.AuditFatal("Upload File Failed, status {0}", ex.Message); return(false); } }
public void ProcessData(AuditLog4Net.Adapter.IAuditLogAdapter log, Dictionary <ShopProduct, ShopLanguage> prods) { using (var unit = GetUnitOfWork()) { var itemProducts = (from a in prods.Keys select new AtomBlockProduct { ProductName = a.Title, AllowedForSale = a.AllowedForSale, Currency = a.Pricing.Currency, Price = a.Pricing.Advise, CostPrice = a.Pricing.Purchase, IsActive = a.IsActive, VendorItemNumber = a.ArticleNumber, ProductID = a.Identifier, ProductGroupcode1 = a.Genre, ProductGroupCodes = a.Pegi, Barcode = a.EAN, Language = prods[a].Name, BrandName = a.Publisher, Description = a.Description ?? string.Empty, Docs = a.Documents, ReleaseDate = a.ReleaseDate, Attributes = new AtomBlockProductAttribute { DownloadSize = a.DownloadSize, ReleaseDate = a.ReleaseDate, Genre = a.Genre.Name, Pegi = a.Pegi, SystemRequirements = a.SystemRequirements, DrmType = a.DrmType.Name }, ShortDescription = a.Punchline }).ToList(); SetupAttributes(unit, AttributeMapping.ToArray(), out attributes, VendorID); //Used for VendorImportAttributeValues var productAttributes = unit.Scope.Repository <ProductAttributeMetaData>().GetAll(c => c.VendorID == VendorID).ToList(); attributeList = productAttributes.ToDictionary(x => x.AttributeCode, y => y.AttributeID); List <Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorAssortmentItem> assortmentList = new List <Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorAssortmentItem>(); int counter = 0; int total = itemProducts.Count(); int totalNumberOfProductsToProcess = total; log.InfoFormat("Start processing {0} products", total); foreach (var product in itemProducts) { var languageID = 0; switch (product.Language) { case "nl-NL": languageID = 2; break; case "en-GB": languageID = 1; break; default: continue; } if (counter == 50) { counter = 0; log.InfoFormat("Still need to process {0} of {1}; {2} done;", totalNumberOfProductsToProcess, total, total - totalNumberOfProductsToProcess); } totalNumberOfProductsToProcess--; counter++; var assortment = new Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorAssortmentItem { #region BrandVendor BrandVendors = new List <VendorAssortmentBulk.VendorImportBrand>() { new VendorAssortmentBulk.VendorImportBrand() { VendorID = VendorID, VendorBrandCode = product.BrandName.Trim(), ParentBrandCode = null, Name = product.BrandName.Trim() } }, #endregion #region GeneralProductInfo VendorProduct = new VendorAssortmentBulk.VendorProduct { VendorItemNumber = product.ProductID.Trim(), //EAN CustomItemNumber = product.ProductID.Trim(), //EAN ShortDescription = product.Description != null ? product.Description.Length > 150 ? product.Description.Substring(0, 150) : product.Description : string.Empty, LongDescription = product.Description != null ? product.Description.Length > 1000 ? product.Description.Substring(0, 1000) : product.Description : string.Empty, LineType = null, LedgerClass = null, ProductDesk = null, ExtendedCatalog = null, VendorID = VendorID, DefaultVendorID = DefaultVendorID, VendorBrandCode = product.BrandName.Trim(), //UITGEVER_ID Barcode = product.Try(x => x.Barcode, string.Empty), //EAN VendorProductGroupCode1 = product.Try(x => x.ProductGroupcode1.Name, string.Empty), VendorProductGroupCodeName1 = product.Try(x => x.ProductGroupcode1.Name, string.Empty), }, #endregion #region RelatedProducts RelatedProducts = new List <VendorAssortmentBulk.VendorImportRelatedProduct>() { //new Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorImportRelatedProduct //{ // VendorID = VendorID, // DefaultVendorID = DefaultVendorID, // CustomItemNumber = product.ProductID.Trim(), //EAN // RelatedProductType = string.Empty, // RelatedCustomItemNumber = string.Empty //} }, #endregion #region Attributes VendorImportAttributeValues = GetProductAttributeValues(product, languageID, VendorID, unit), #endregion #region Prices VendorImportPrices = new List <Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorImportPrice>() { new Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorImportPrice() { VendorID = VendorID, DefaultVendorID = DefaultVendorID, CustomItemNumber = product.ProductID.Trim(), //EAN Price = ((Decimal)product.Price / 100).ToString("0.00", CultureInfo.InvariantCulture), CostPrice = decimal.Round((product.CostPrice / 100), 4).ToString("0.00", CultureInfo.InvariantCulture), //NETTOPRIJS TaxRate = "19", //TODO: Calculate this! MinimumQuantity = 0, CommercialStatus = product.AllowedForSale ? "AllowedForSale" : "NotAllowedForSale" } }, #endregion #region Stock VendorImportStocks = new List <Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorImportStock>() { new Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorImportStock() { VendorID = VendorID, DefaultVendorID = DefaultVendorID, CustomItemNumber = product.ProductID.Trim(), //EAN QuantityOnHand = 1, StockType = "Assortment", StockStatus = product.ReleaseDate.HasValue ? product.ReleaseDate > DateTime.Now ? "Pre Release" : product.AllowedForSale ? "InStock" : "OutOfStock" : product.AllowedForSale ? "InStock" : "OutOfStock" } }, #endregion #region Descriptions VendorProductDescriptions = new List <VendorAssortmentBulk.VendorProductDescription>() { new VendorAssortmentBulk.VendorProductDescription() { VendorID = VendorID, LanguageID = languageID, DefaultVendorID = VendorID, CustomItemNumber = product.ProductID.Trim(), //EAN LongContentDescription = product.Description, ShortContentDescription = product.Description != string.Empty ? product.Description.Length > 1000 ? product.Description.Substring(0, 1000) : product.Description : product.ShortDescription, ProductName = product.ProductName } } #endregion }; // assortment will be added to the list defined outside of this loop assortmentList.Add(assortment); } // Creates a new instance of VendorAssortmentBulk(Passes in the AssortmentList defined above, vendorID and DefaultVendorID) using (var vendorAssortmentBulk = new VendorAssortmentBulk(assortmentList, VendorID, DefaultVendorID)) { vendorAssortmentBulk.Init(unit.Context); vendorAssortmentBulk.Sync(unit.Context); } } }