protected override void Process() { foreach (Connector connector in Connectors.Where(x => ((ConnectorType)x.ConnectorType).Has(ConnectorType.WebAssortment) && x.Selectors)) { #if DEBUG if (connector.ConnectorID != 1) { continue; } #endif using ( WebsiteDataContext context = new WebsiteDataContext( ConfigurationManager.ConnectionStrings[connector.Connection].ConnectionString)) { log.DebugFormat("Start Selector Product import for {0}", connector.Name); try { DateTime start = DateTime.Now; log.DebugFormat("Start Selector Product:{0}", start); AssortmentServiceSoapClient soap = new AssortmentServiceSoapClient(); XDocument products; var selectorIDs = (from s in context.Selectors select s.SelectorID).ToList(); foreach (int selectorID in selectorIDs) { products = new XDocument(soap.GetSelectorProducts(connector.ConnectorID, selectorID)); Processor processor = new Processor(products, log, connector); log.Debug("Start import brands"); processor.ImportBrands(); log.Debug("Finished import brands"); log.Debug("Start import productgroups"); processor.ImportProductGroups(false); log.Debug("Finished import productgroups"); log.Debug("Start import Products"); processor.ImportSelectorProducts(); log.Debug("Finished import Products"); //log.Debug("Start import Attributes"); //processor.ProcessAttributes(soap, connector, false, null, false); //log.Debug("Finished import Attributes"); //processor.CleanUpProducts(); //processor.CleanUpProductGroupMapping(); } } catch (Exception ex) { log.Error("Error import Selector Products", ex); } log.DebugFormat("Finish Process Selector Product for {0}", connector.Name); } } }
protected override void Process() { log.DebugFormat("Start Retail Stock Export processing Connectors"); try { foreach (Connector connector in Connectors.Where(x => ((ConnectorType)x.ConnectorType).Has(ConnectorType.RetailStock))) { log.InfoFormat("Start Retail Stock Export for {0}", connector.Name); DateTime start = DateTime.Now; log.InfoFormat("Start process stock:{0}", start); AssortmentServiceSoapClient soap = new AssortmentServiceSoapClient(); XDocument products = new XDocument(soap.GetStockAssortment(connector.ConnectorID, null)); Processor process = new Processor(products, log, connector); process.ImportRetailStock(); log.InfoFormat("Finish Retail Stock Export: {0} duration {1} minutes", DateTime.Now, TimeSpan.FromMilliseconds(DateTime.Compare(DateTime.Now, start)).TotalMinutes); } } catch (Exception ex) { log.Error("Error import retail stock", ex); } }
protected override void Process() { try { foreach (Connector connector in base.Connectors.Where(c => ((ConnectorType)c.ConnectorType).Has(ConnectorType.Images))) { log.DebugFormat("Start Process Image import for {0}", connector.Name); DateTime start = DateTime.Now; AssortmentServiceSoapClient soap = new AssortmentServiceSoapClient(); images = new XDocument(soap.GetAssortmentImages(connector.ConnectorID)); connectionStringName = connector.Connection; log.Info("Start Brand images"); ProcessBrandImages(connector); log.Info("Finished Brand images"); log.Info("Start Productgroup images"); ProcessProductGroupImages(connector); log.Info("Finished Productgroup images"); log.Info("Start Product Images"); ProcessProductImages(connector); log.Info("Finished Product Images"); //log.Info("Start Product O Images"); //ProcessOProductImages(connector.ConnectorID, soap); //log.Info("Finished Product O Images"); log.DebugFormat("Finished Process Image import for {0}", connector.Name); } } catch (Exception ex) { log.Fatal(ex); } }
protected override void Process() { try { foreach (Connector connector in base.Connectors.Where(x => x.ObsoleteProducts)) { if (connector.ObsoleteProducts) { log.DebugFormat("Start Process O items import for {0}", connector.Name); DateTime start = DateTime.Now; log.InfoFormat("Start process stock:{0}", start); AssortmentServiceSoapClient soap = new AssortmentServiceSoapClient(); XDocument products = new XDocument(soap.GetOAssortment(connector.ConnectorID, false, "227782")); Processor process = new Processor(products, log, connector); process.ImportOItems(products, null); process.ImportStock();; } } } catch (Exception ex) { log.Error("Error import obsolete items", ex); } }
protected override void Process() { foreach (Connector connector in Connectors.Where(x => ((ConnectorType)x.ConnectorType).Has(ConnectorType.WebAssortment))) { #if DEBUG if (connector.ConnectorID != 1) { continue; } #endif log.DebugFormat("Start Process web productgroup import for {0}", connector.Name); DateTime start = DateTime.Now; try { AssortmentServiceSoapClient soap = new AssortmentServiceSoapClient(); XDocument products; products = new XDocument(soap.GetAssortment(connector.ConnectorID, null, true).Value); Processor processor = new Processor(products, log, connector); log.Debug("Start import productgroups"); processor.ImportProductGroups(true); log.Debug("Finished import productgroups"); } catch (Exception ex) { log.Error("Error import ProcessProducts", ex); } log.DebugFormat("Finish Process web productgroup import for {0}", connector.Name); } }
protected override void Process() { foreach (Connector connector in Connectors.Where(x => ((ConnectorType)x.ConnectorType).Has(ConnectorType.WebAssortment))) { log.DebugFormat("Start Process price import for {0}", connector.Name); try { DateTime start = DateTime.Now; log.DebugFormat("Start process products:{0}", start); AssortmentServiceSoapClient soap = new AssortmentServiceSoapClient(); XDocument products; products = new XDocument(soap.GetPriceAssortment(connector.ConnectorID, null, null)); Processor processor = new Processor(products, log, connector); log.Debug("Start import ProductPrice"); bool errorImportProduct = processor.ImportPrice(); log.Debug("Finished import ProductPrice"); if (!errorImportProduct) { processor.CleanUpProducts(); } } catch (Exception ex) { log.Error("Error import ProcessProducts", ex); } log.DebugFormat("Finish Process price import for {0}", connector.Name); } }
protected override void Process() { log.Info("Starting import of AlaTest product reviews"); AssortmentServiceSoapClient client = new AssortmentServiceSoapClient(); try { var reviews = client.GetProductReviews(); foreach (Connector connector in base.Connectors.Where(c => c.ConnectorType.Has(ConnectorType.WebAssortment))) { using (WebsiteDataContext context = new WebsiteDataContext(ConfigurationManager.ConnectionStrings[connector.Connection].ConnectionString)) { XDocument reviewsDoc = XDocument.Parse(reviews.OuterXml); foreach (var productReviewElement in reviewsDoc.Element("ProductReviews").Elements("Product")) { #region Product reviews var product = (from p in context.Products where p.ManufacturerID == productReviewElement.Attribute("vendorItemNumber").Value select p).FirstOrDefault(); if (product != null) { var ProductReview = (from pr in context.AlatestReviews where pr.ProductID == product.ProductID select pr).FirstOrDefault(); if (ProductReview == null) { ProductReview = new AlatestReview { Product = product }; context.AlatestReviews.InsertOnSubmit(ProductReview); } ProductReview.Review = productReviewElement.Try(c => c.Element("Review").Value, string.Empty); ProductReview.ReviewSnippet = productReviewElement.Try(c => c.Element("ReviewSnippet").Value, string.Empty); } #endregion } try { using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Suppress, TimeSpan.FromMinutes(3))) { context.SubmitChanges(); ts.Complete(); } } catch (Exception e) { log.Error("Saving product reviews to the database failed for connector" + connector.Name, e); } } } } catch (Exception e) { log.Fatal("Downloading product reviews failed", e); } }
public void ProcessStock(Connector connector, log4net.ILog log, XDocument products) { DateTime start = DateTime.Now; log.InfoFormat("Start process stock:{0}", start); AssortmentServiceSoapClient soap = new AssortmentServiceSoapClient(); if (products == null) { products = new XDocument(soap.GetAssortment(connector.ConnectorID, null, false)); } log.Info(products.Root.Elements("Product").Count()); ImportStock(connector, products, log); // DC10 Stock naar winkels ImportRetailStock(connector, products, log); // Overige winkels naar winkel }
protected override void Process() { foreach (Connector connector in base.Connectors.Where(x => ((ConnectorType)x.ConnectorType).Has(ConnectorType.FileExport))) { #region Assortiment if (((ConnectorType)connector.ConnectorType).Has(ConnectorType.ShopAssortment) || ((ConnectorType)connector.ConnectorType).Has(ConnectorType.WebAssortment)) { foreach (var language in connector.ConnectorLanguages) { log.DebugFormat("Start Process Full XML export for {0} language {1}", connector.Name, language.Language.Name); string path = connector.ConnectorSettings.GetValueByKey("XmlExportPath", string.Empty); if (!string.IsNullOrEmpty(path)) { AssortmentServiceSoapClient soap = new AssortmentServiceSoapClient(); XDocument products; products = XDocument.Parse(soap.GetFullInformation(connector.ConnectorID, true, false, null, null, true, language.LanguageID)); string file = Path.Combine(path, string.Format("products_{0}_{1}.xml", connector.ConnectorID, language.LanguageID)); if (File.Exists(file)) { File.Delete(file); } products.Save(file, SaveOptions.DisableFormatting); } else { log.AuditCritical(string.Format("Export XML failed for {0}, XmlExportPath not set", connector.Name)); } log.DebugFormat("Finish Process Full XML import for {0}", connector.Name); } } #endregion } }
protected override void Process() { foreach (Connector connector in base.Connectors.Where(c => ((ConnectorType)c.ConnectorType).Has(ConnectorType.ShopAssortment) && c.ObsoleteProducts)) { log.DebugFormat("Start Process shop O import for {0}", connector.Name); DateTime start = DateTime.Now; try { using (AssortmentServiceSoapClient soap = new AssortmentServiceSoapClient()) { var input = soap.GetOAssortment(connector.ConnectorID, true, null); if (input != null) { XDocument o_Products = XDocument.Parse(input); if (o_Products != null) { ImportOItems(o_Products, connector); //ImportOBarcodes(o_Products); } else { log.Info("Get O Assortment failed"); } } else { log.Info("Empty O product Feed"); } } } catch (Exception ex) { log.Fatal(ex); } log.DebugFormat("Finish Process shop O import for {0}", connector.Name); } }
protected override void Process() { foreach (Connector connector in base.Connectors.Where(x => ((ConnectorType)x.ConnectorType).Has(ConnectorType.FileExport))) { #region Stock if (((ConnectorType)connector.ConnectorType).Has(ConnectorType.ShopAssortment) || ((ConnectorType)connector.ConnectorType).Has(ConnectorType.WebAssortment)) { log.DebugFormat("Start Process Dmis stock export for {0}", connector.Name); AssortmentServiceSoapClient soap = new AssortmentServiceSoapClient(); try { XDocument products = null; products = XDocument.Parse(soap.GetStockAssortment(connector.ConnectorID, null)); string fileName = string.Format("WEBVRRD_{0}_{1}", connector.ConnectorID, DateTime.Now.ToString("yyyyMMddHHmmss")); using (var stream = new MemoryStream()) { using (StreamWriter sw = new StreamWriter(stream)) { sw.WriteLine("INIT;" + DateTime.Now.ToString("YYMMddHHmm")); var csv = (from p in products.Root.Elements("Product") select new { ProductID = DmisUtilty.GetCustomItemNumber(p.Attribute("CustomProductID").Value, p.Attribute("ProductID").Value), Stock = p.Element("Stock").Attribute("InStock").Value }).ToList(); csv.ForEach(x => { sw.WriteLine(string.Format("{0};{1}", x.ProductID, x.Stock)); }); sw.WriteLine("ENDOFFILE"); } DmisUtilty.UploadFiles(connector, stream, fileName, log); } } catch (Exception ex) { log.Error("FTP upload Dmis stockfile failed for connector" + connector.ConnectorID, ex); } } else { log.AuditCritical(string.Format("Export stock Dmis failed for {0}, XmlExportPath not set", connector.Name)); } log.DebugFormat("Finish Process Dmis stock import for {0}", connector.Name); #endregion #region RetailStock if (((ConnectorType)connector.ConnectorType).Has(ConnectorType.ShopAssortment) || ((ConnectorType)connector.ConnectorType).Has(ConnectorType.WebAssortment)) { log.DebugFormat("Start Process Dmis retail stock export for {0}", connector.Name); AssortmentServiceSoapClient soap = new AssortmentServiceSoapClient(); try { XDocument products = null; products = XDocument.Parse(soap.GetStockAssortment(connector.ConnectorID, null)); var retailProducts = (from p in products.Root.Elements("Product") from g in p.Element("Stock").Element("Retail").Elements("RetailStock") select new { ProductID = DmisUtilty.GetCustomItemNumber(p.Attribute("CustomProductID").Value, p.Attribute("ProductID").Value), VendorCode = g.Attribute("VendorCode").Value, Stock = g.Attribute("InStock").Value }).Distinct().ToList(); var vendors = retailProducts.Select(x => x.VendorCode).Distinct().ToList(); vendors.ForEach(x => { var vendorStock = retailProducts.Where(v => v.VendorCode == x); string fileName = string.Format("WEBFILVRRD{0}_{1}_{2}", connector.ConnectorID, x, DateTime.Now.ToString("yyyyMMddHHmmss")); using (var stream = new MemoryStream()) { using (StreamWriter sw = new StreamWriter(stream)) { sw.WriteLine("INIT;" + DateTime.Now.ToString("YYMMddHHmm")); var csv = (from p in vendorStock select new { ProductID = p.ProductID, Stock = p.Stock }).ToList(); csv.ForEach(z => { sw.WriteLine(string.Format("{0};{1}", z.ProductID, z.Stock)); }); sw.WriteLine("ENDOFFILE"); } DmisUtilty.UploadFiles(connector, stream, fileName, log); } }); } catch (Exception ex) { log.Error("FTP upload Dmis stockfile failed for connector" + connector.ConnectorID, ex); } } else { log.AuditCritical(string.Format("Export stock Dmis failed for {0}, XmlExportPath not set", connector.Name)); } log.DebugFormat("Finish Process Dmis stock import for {0}", connector.Name); } #endregion }
//public static Workbook GenerateExcel(List<ExcelColumn> columns, DataSet data, bool generateHeader) //{ // Workbook book = new Workbook(); // Worksheet sheet = book.Worksheets.Add("Assortment"); // WorksheetRow row; // GenerateStyles(book.Styles); // foreach (var name in columns) // { // WorksheetColumn column = new WorksheetColumn(); // column.AutoFitWidth = true; // sheet.Table.Columns.Add(column); // } // int rowIndex = GenerateHeaders(sheet, generateHeader, columns); // Dictionary<int, Dictionary<string, string>> excelRows = new Dictionary<int, Dictionary<string, string>>(); // foreach (var productRow in data.Tables[0].AsEnumerable()) // { // rowIndex++; // var product = productRow; // Dictionary<string, string> excelvalues = new Dictionary<string, string>(); // foreach (var att in data.Tables[0].AsEnumerable()) // { // if (excelvalues.ContainsKey(att.Field<string>)) // excelvalues[att.Name.LocalName] = att.Value; // else // excelvalues.Add(att.Name.LocalName, att.Value); // } // foreach (XElement el in product.Elements()) // { // if (columns.Any(x => x.ValueFieldName == el.Name.LocalName)) // { // if (excelvalues.ContainsKey(el.Name.LocalName)) // excelvalues[el.Name.LocalName] = el.Value; // else // excelvalues.Add(el.Name.LocalName, el.Value); // } // foreach (XAttribute att in el.Attributes()) // { // if (columns.Any(x => x.ValueFieldName == att.Name.LocalName)) // { // if (excelvalues.ContainsKey(att.Name.LocalName)) // excelvalues[att.Name.LocalName] = att.Value; // else // excelvalues.Add(att.Name.LocalName, att.Value); // } // } // } // excelRows.Add(rowIndex, excelvalues); // } // foreach (var val in excelRows.Keys) // { // row = sheet.Table.Rows.Add(); // foreach (var key in columns) // { // row.Cells.Add(excelRows[val][key.ColumnName]); // } // } // return book; //} public static Workbook GenerateExcel(int connectorID, List <ExcelColumn> columns, bool generateHeader) { AssortmentServiceSoapClient client = new AssortmentServiceSoapClient(); var assortmentSource = new XDocument(client.GetAssortment(1, null, true)); Workbook book = new Workbook(); Worksheet sheet = book.Worksheets.Add("Assortment"); WorksheetRow row; GenerateStyles(book.Styles); foreach (var name in columns) { WorksheetColumn column = new WorksheetColumn(); column.AutoFitWidth = true; sheet.Table.Columns.Add(column); } int rowIndex = GenerateHeaders(sheet, generateHeader, columns); Dictionary <int, Dictionary <string, string> > excelRows = new Dictionary <int, Dictionary <string, string> >(); foreach (var productRow in assortmentSource.Root.Elements("Product")) { rowIndex++; var product = productRow; Dictionary <string, string> excelvalues = new Dictionary <string, string>(); foreach (XAttribute att in product.Attributes()) { if (columns.Any(x => x.ValueFieldName == att.Name.LocalName)) { if (excelvalues.ContainsKey(att.Name.LocalName)) { excelvalues[att.Name.LocalName] = att.Value; } else { excelvalues.Add(att.Name.LocalName, att.Value); } } } foreach (XElement el in product.Elements()) { if (columns.Any(x => x.ValueFieldName == el.Name.LocalName)) { if (excelvalues.ContainsKey(el.Name.LocalName)) { excelvalues[el.Name.LocalName] = el.Value; } else { excelvalues.Add(el.Name.LocalName, el.Value); } } foreach (XAttribute att in el.Attributes()) { if (columns.Any(x => x.ValueFieldName == att.Name.LocalName)) { if (excelvalues.ContainsKey(att.Name.LocalName)) { excelvalues[att.Name.LocalName] = att.Value; } else { excelvalues.Add(att.Name.LocalName, att.Value); } } } } excelRows.Add(rowIndex, excelvalues); } foreach (var val in excelRows.Keys) { row = sheet.Table.Rows.Add(); foreach (var key in columns) { row.Cells.Add(excelRows[val][key.ColumnName]); } } return(book); }
protected override void Process() { foreach (Connector connector in base.Connectors.Where(x => ((ConnectorType)x.ConnectorType).Has(ConnectorType.FileExport))) { if (connector.ConnectorID != 666) { continue; } //#region Assortiment string path = "F:/tmp/BEX"; //if (!string.IsNullOrEmpty(path)) //{ // #region ProductGroups // using (var unit = GetUnitOfWork()) // { // var repoContentProductGroup = unit.Scope.Repository<ContentProductGroup>().Include(c => c.ProductGroupMapping); // var repoProductGroupMapping = unit.Scope.Repository<ProductGroupMapping>().Include(c => c.ProductGroup); // var pra = repoContentProductGroup.GetAll(x => x.ConnectorID == 666).ToList(); // List<ProductGroupMapping> mappingslist = repoProductGroupMapping.GetAll(x => x.ConnectorID == 666).ToList(); // List<int> pgList = new List<int>(); // //foreach(var a in assortment){ // // var el = GetProductGroupHierarchy(a, 2, unit.Scope.Repository<ProductGroupLanguage>(), mappingslist); // //} // XElement element = new XElement("ProductGroupHierarchy"); // foreach (var mapping in pra) // { // if (!pgList.Contains(mapping.ProductGroupMappingID)) // { // var map = mappingslist.Where(x => x.ProductGroupMappingID == mapping.ProductGroupMappingID && mapping.ConnectorID == 666).FirstOrDefault(); // if (map == null) // continue; // GetProductGroupHierarchy(map, element, 2, unit.Scope.Repository<ProductGroupLanguage>(), mappingslist); // pgList.Add(mapping.ProductGroupMappingID); // } // } // var elements = (from e in element.Elements("ProductGroup") // select e).Distinct(); // XElement element2 = new XElement("ProductGroupHierarchy"); // element2.Add(elements); // XDocument productGroupsDoc = new XDocument(); // productGroupsDoc.Add(element2); // string fileName2 = string.Format("ProductGroups_{0}_{1}.xml", connector.ConnectorID, DateTime.Now.ToString("yyyyMMddHHmmss")); // productGroupsDoc.Save(Path.Combine(path, fileName2)); // using (var stream = new MemoryStream()) // { // productGroupsDoc.Save(stream, SaveOptions.DisableFormatting); // //DmisUtilty.UploadFiles(connector, stream, fileName2, log); // } // } // #endregion // AssortmentServiceSoapClient soap = new AssortmentServiceSoapClient(); // XDocument products; // products = XDocument.Parse(soap.GetAdvancedPricingAssortment(connector.ConnectorID, false, false, null, null, true, 2)); // #region Products // string fileName = string.Format("Assortment_{0}_{1}.xml", connector.ConnectorID, DateTime.Now.ToString("yyyyMMddHHmmss")); // products.Save(Path.Combine(path, fileName)); // using (var stream = new MemoryStream()) // { // products.Save(stream, SaveOptions.DisableFormatting); // DmisUtilty.UploadFiles(connector, stream, fileName, log); // } // #endregion //} //else //{ // log.AuditCritical(string.Format("Export XML failed for {0}, XmlExportPath not set", connector.Name)); //} //log.DebugFormat("Finish Process XML Assortment import for {0}", connector.Name); //#endregion #region Images log.DebugFormat("Start Process XML Image export for {0}", connector.Name); if (!string.IsNullOrEmpty(path)) { AssortmentServiceSoapClient soap = new AssortmentServiceSoapClient(); XDocument products; products = XDocument.Parse(soap.GetFTPAssortmentImages(connector.ConnectorID)); string file = Path.Combine(path, string.Format("Images_{0}.xml", connector.ConnectorID)); if (File.Exists(file)) { File.Delete(file); } products.Save(file, SaveOptions.DisableFormatting); } else { log.AuditCritical(string.Format("Export XML failed for {0}, XmlExportPath not set", connector.Name)); } log.DebugFormat("Finish Process XML Image import for {0}", connector.Name); #endregion log.DebugFormat("Start Process XML Content export for {0} language {1}", connector.Name, 2); if (!string.IsNullOrEmpty(path)) { AssortmentServiceSoapClient soap = new AssortmentServiceSoapClient(); XDocument content = XDocument.Parse(soap.GetAssortmentContentDescriptionsByLanguage(connector.ConnectorID, null, 2)); string contentFile = Path.Combine(path, string.Format("Content_{0}_{1}.xml", connector.ConnectorID, 2)); if (File.Exists(contentFile)) { File.Delete(contentFile); } content.Save(contentFile, SaveOptions.DisableFormatting); XDocument attributes = XDocument.Parse(soap.GetAttributesAssortmentByLanguage(connector.ConnectorID, null, null, 2)); string attributeFile = Path.Combine(path, string.Format("Attribute_{0}_{1}.xml", connector.ConnectorID, 2)); if (File.Exists(attributeFile)) { File.Delete(attributeFile); } attributes.Save(attributeFile, SaveOptions.DisableFormatting); } else { log.AuditCritical(string.Format("Export XML failed for {0}, XmlExportPath not set", connector.Name)); } log.DebugFormat("Finish Process XML Content import for {0} language {1}", connector.Name, 2); } }
protected override void Process() { foreach (Connector connector in Connectors.Where(x => ((ConnectorType)x.ConnectorType).Has(ConnectorType.WebAssortment))) { log.DebugFormat("Start Process web import for {0}", connector.Name); try { DateTime start = DateTime.Now; log.DebugFormat("Start process products:{0}", start); AssortmentServiceSoapClient soap = new AssortmentServiceSoapClient(); //#if DEBUG // if (File.Exists(@"C:\products.xml")) // products = XDocument.Load(@"C:\products.xml"); // else // { //#endif XDocument products = new XDocument(soap.GetAssortment(connector.ConnectorID, null, true)); //#if DEBUG // products.Save(@"C:\products.xml"); // } //#endif Processor processor = new Processor(products, log, connector); log.Debug("Start import brands"); processor.ImportBrands(); log.Debug("Finished import brands"); log.Debug("Start import productgroups"); processor.ImportProductGroups(true); log.Debug("Finished import productgroups"); log.Debug("Start import Products"); bool errorImportProduct = processor.ImportProducts(); log.Debug("Finished import Products"); if (connector.ImportCommercialText) { log.Debug("Start import Product descriptions"); processor.ProcessContentDescriptions(soap, connector); log.Debug("Finished import descriptions"); } if (!errorImportProduct) { processor.CleanUpProducts(); processor.CleanUpProductGroupMapping(); } log.Debug("Start import Attributes"); processor.ProcessAttributes(soap, connector, false, null, false); log.Debug("Finished import Attributes"); } catch (Exception ex) { log.Error("Error import ProcessProducts", ex); } log.DebugFormat("Finish Process web import for {0}", connector.Name); } }
protected override void Process() { var path = Path.Combine(GetConfiguration().AppSettings.Settings["ExportPath"].Value); bool networkDrive = false; bool.TryParse(GetConfiguration().AppSettings.Settings["IsNetworkDrive"].Value, out networkDrive); if (networkDrive) { string userName = GetConfiguration().AppSettings.Try(x => x.Settings["NetworkUserName"].Value, string.Empty); string passWord = GetConfiguration().AppSettings.Try(x => x.Settings["NetworkPassword"].Value, string.Empty); NetworkDrive oNetDrive = new NetworkDrive(); try { oNetDrive.LocalDrive = "H:"; oNetDrive.ShareName = path; //oNetDrive.MapDrive("diract", "D1r@ct379"); if (!string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty(passWord)) { oNetDrive.MapDrive(userName, passWord); } else { oNetDrive.MapDrive(); } path = "H:"; } catch (Exception err) { log.Error("Invalid network drive", err); } oNetDrive = null; } var baseConnector = base.Connectors.Where(x => ((ConnectorType)x.ConnectorType).Has(ConnectorType.ShopAssortment)).FirstOrDefault(); List <string> added = new List <string>(); var stockPath = Path.Combine(path, "SAPStock2CF/GDATEN"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } string DC = baseConnector.ConnectorSettings.GetValueByKey("DC", string.Empty); if (string.IsNullOrEmpty(DC)) { throw new Exception(string.Format("No DC set for connector {0} in settings", baseConnector.Name)); } string fileName = string.Format("{0}.sapvrd", DC); string filePath = Path.Combine(stockPath, fileName); using (StreamWriter sw = new StreamWriter(filePath)) { foreach (Connector connector in base.Connectors.Where(x => ((ConnectorType)x.ConnectorType).Has(ConnectorType.ShopAssortment))) { #region Stock log.DebugFormat("Start Process ConnectFlow stock export for {0}", connector.Name); AssortmentServiceSoapClient soap = new AssortmentServiceSoapClient(); try { XDocument products = new XDocument(soap.GetStockAssortment(connector.ConnectorID, null)); Dictionary <string, string> productTranslation = ConnectFlowUtility.GetCrossProducts(products); var csv = (from p in products.Root.Elements("Product") select new { ProductID = ConnectFlowUtility.GetAtricleNumber(p.Attribute("ProductID").Value, productTranslation, true), Stock = p.Element("Stock").Attribute("InStock").Value }).ToList(); csv.ForEach(x => { if (!added.Contains(x.ProductID)) { var sapArtNr = ConnectFlowUtility.GetAtricleNumber(x.ProductID, productTranslation, true).Trim(); int artNr = 0; sw.WriteLine(string.Format("{0},{1},{2},{3},{4}", DC, DateTime.Now.ToString("yyyyMMdd"), DateTime.Now.ToString("HHmmss"), (int.TryParse(sapArtNr, out artNr) ? artNr.ToString().PadLeft(18, '0') : sapArtNr.PadRight(18)), x.Stock.ToString().PadLeft(13, '0'))); //1001,20110701,020005,000000000000081846,0000000000000 added.Add(x.ProductID); } }); //var retailProducts = (from r in products.Root.Elements("Product") // select new // { // sapArtNr = ConnectFlowUtility.GetAtricleNumber(r.Attribute("ProductID").Value, productTranslation, true).Trim(), // RetailStock = r.Element("Stock").Element("Retail").Elements("RetailStock") // }).Distinct().ToList(); //Dictionary<string, List<CFstock>> Shops = new Dictionary<string, List<CFstock>>(); //Dictionary<string, IEnumerable<XElement>> records = new Dictionary<string, IEnumerable<XElement>>(); //using (var unit = GetUnitOfWork()) //{ // var shopNumbers = (from v in unit.Scope.Repository<Vendor>().GetAll() // join vs in unit.Scope.Repository<VendorSetting>().GetAll() on v.VendorID equals vs.VendorID // where vs.SettingKey == "ShopNumber" // select new // { // VendorCode = v.BackendVendorCode, // ShopNumber = vs.Value // }).ToDictionary(x => x.VendorCode, x => x.ShopNumber); // foreach (var retail in retailProducts) // { // if (!records.ContainsKey(retail.sapArtNr)) // records.Add(retail.sapArtNr, retail.RetailStock.ToList()); // } // int totalProducts = records.Keys.Count; // int couterProduct = 0; // int logCount = 0; // foreach (var art in records.Keys) // { // couterProduct++; // logCount++; // if (logCount == 100) // { // log.DebugFormat("'Magento retailstock products Processed : {0}/{1} for connector {2}", couterProduct, totalProducts, connector.Name); // logCount = 0; // } // foreach (var p in records[art]) // { // if (shopNumbers.ContainsKey(p.Attribute("VendorCode").Value)) // { // CFstock s = new CFstock() // { // ShopNumber = shopNumbers[p.Attribute("VendorCode").Value], // SapNr = art, // Stock = int.Parse(p.Attribute("InStock").Value) // }; // if (Shops.ContainsKey(s.ShopNumber)) // Shops[s.ShopNumber].Add(s); // else // Shops.Add(s.ShopNumber, new List<CFstock>() { s }); // } // } // } //} //foreach (var shop in Shops.Keys) //{ // var rec = Shops[shop]; // var shopNr = rec.FirstOrDefault().ShopNumber; // fileName = string.Format("{0}.sapvrd", shopNr); // filePath = Path.Combine(stockPath, fileName); // using (StreamWriter sw = new StreamWriter(filePath)) // { // rec.ForEach(x => // { // var sapArtNr = x.SapNr; // int artNr = 0; // sw.WriteLine(string.Format("{0},{1},{2},{3},{4}", shopNr, DateTime.Now.ToString("yyyyMMdd"), DateTime.Now.ToString("HHmmss"), (int.TryParse(sapArtNr, out artNr) ? artNr.ToString().PadLeft(18, '0') : sapArtNr.PadRight(18)), x.Stock.ToString().PadLeft(13, '0'))); //1001,20110701,020005,000000000000081846,0000000000000 // }); // } //} } catch (Exception ex) { log.Error("FTP upload ConnectFlow stockfile failed for connector" + connector.ConnectorID, ex); } log.DebugFormat("Finish Process ConnectFlow stock import for {0}", connector.Name); #endregion } } string readyFile = Path.Combine(path, "SAPStock2CF/Aggretor.Ready"); using (StreamWriter sw = new StreamWriter(readyFile)) { sw.Write("Trigger"); } }
protected override void Process() { foreach (Connector connector in Connectors.Where(x => ((ConnectorType)x.ConnectorType).Has(ConnectorType.WebAssortment))) { log.DebugFormat("Start process push product for {0}", connector.Name); using (var unit = GetUnitOfWork()) { try { var _pushRepo = unit.Scope.Repository <Concentrator.Objects.Models.Products.PushProduct>(); DateTime start = DateTime.Now; log.DebugFormat("Start process products:{0}", start); AssortmentServiceSoapClient soap = new AssortmentServiceSoapClient(); XDocument products = null; var pushProducts = _pushRepo.GetAll(x => !x.Processed && x.ConnectorID == connector.ConnectorID).ToList(); foreach (var product in pushProducts) { if (product.ProductID.HasValue) { products = new XDocument(soap.GetAssortment(connector.ConnectorID, product.ProductID.Value.ToString(), false)); } else { products = new XDocument(soap.GetOAssortment(connector.ConnectorID, false, product.CustomItemNumber)); } Processor process = new Processor(products, log, connector); process.ImportOItems(products, product.CustomItemNumber); product.Processed = true; unit.Save(); } } catch (Exception ex) { log.Error("Error push product", ex); } } log.DebugFormat("Finish push product import for {0}", connector.Name); } foreach (Connector connector in Connectors.Where(x => ((ConnectorType)x.ConnectorType).Has(ConnectorType.ShopAssortment))) { log.DebugFormat("Start process push product for {0}", connector.Name); using (var unit = GetUnitOfWork()) { try { var _pushRepo = unit.Scope.Repository <Concentrator.Objects.Models.Products.PushProduct>(); DateTime start = DateTime.Now; log.DebugFormat("Start process products:{0}", start); AssortmentServiceSoapClient soap = new AssortmentServiceSoapClient(); XDocument products = null; var pushProducts = _pushRepo.GetAll(x => !x.Processed && x.ConnectorID == connector.ConnectorID).ToList(); foreach (var product in pushProducts) { // if (product.ProductID.HasValue) // products = new XDocument(soap.GetAssortment(connector.ConnectorID, product.ProductID.Value.ToString(), false)); //else // products = new XDocument(soap.GetOAssortment(connector.ConnectorID, false, product.CustomItemNumber)); ShopImportOProduct processor = new ShopImportOProduct(); processor.ImportOItems(products, connector); //Processor process = new Processor(products, log, connector); //process.ImportOItems(products, product.CustomItemNumber); product.Processed = true; unit.Save(); } } catch (Exception ex) { log.Error("Error push product", ex); } } log.DebugFormat("Finish push product import for {0}", connector.Name); } }
protected override void Process() { foreach (Connector connector in base.Connectors.Where(x => ((ConnectorType)x.ConnectorType).Has(ConnectorType.FileExport))) { #if DEBUG if (connector.ConnectorID != 10) { continue; } #endif #region Assortiment if (((ConnectorType)connector.ConnectorType).Has(ConnectorType.ShopAssortment) || ((ConnectorType)connector.ConnectorType).Has(ConnectorType.WebAssortment)) { foreach (var language in connector.ConnectorLanguages) { log.DebugFormat("Start Process XML stock export for {0}", connector.Name); string drive = connector.ConnectorSettings.GetValueByKey("XmlExportPath", string.Empty); bool networkDrive = false; //string drive = @"\\SOL\Company_Shares\Database Backup"; bool.TryParse(connector.ConnectorSettings.GetValueByKey("IsNetorkDrive", "false"), out networkDrive); NetworkExportUtility util = new NetworkExportUtility(); if (networkDrive) { drive = util.ConnectorNetworkPath(drive, "I:"); } string path = drive; if (!string.IsNullOrEmpty(path)) { AssortmentServiceSoapClient soap = new AssortmentServiceSoapClient(); XDocument products = new XDocument(soap.GetStockAssortment(connector.ConnectorID, null)); string file = Path.Combine(path, string.Format("stock_{0}.xml", connector.ConnectorID)); if (File.Exists(file)) { File.Delete(file); } products.Save(file, SaveOptions.DisableFormatting); } else { log.AuditCritical(string.Format("Export stock XML failed for {0}, XmlExportPath not set", connector.Name)); } if (networkDrive) { util.DisconnectNetworkPath(drive); } log.DebugFormat("Finish Process XML stock import for {0}", connector.Name); } } #endregion } }
protected override void Process() { foreach (Connector connector in base.Connectors) //already filtered { log.DebugFormat("Start Process auction export for {0}", connector.Name); DateTime start = DateTime.Now; try { log.Debug("Start import auction items"); AssortmentServiceSoapClient soap = new AssortmentServiceSoapClient(); XDocument products = new XDocument(soap.GetAssortment(connector.ConnectorID, null, true)); Processor processor = new Processor(products, log, connector); DateTime? lastUpdate = null; using (WebsiteDataContext ctx = new WebsiteDataContext(connector.ConnectionString)) { var auctionProductList = (from p in ctx.AuctionProducts select new { AuctionProduct = p, BrandCode = p.Product.Brand.BrandCode, Product = p.Product }).ToList(); if (auctionProductList.Count > 0) { lastUpdate = (from lu in auctionProductList let update = (lu.AuctionProduct.LastModificationTime.HasValue ? lu.AuctionProduct.LastModificationTime.Value : lu.AuctionProduct.CreationTime) select update).Max(); } Dictionary <int, Product> existingProducts = new Dictionary <int, Product>(); log.DebugFormat("Xml contains {0} products", products.Root.Elements("Product").Count()); log.Info("Start import brands"); processor.ImportBrands(); log.Info("Finish import brands"); log.Info("Start import productgroups"); processor.ImportProductGroups(false); log.Info("Finish import productgroups"); var allProductGroups = (from p in ctx.ProductGroups select p).ToList(); var productGroupMappings = (from p in ctx.ProductGroupMappings group p by p.ProductGroupID into grouped select grouped).ToDictionary(x => x.Key, y => y.ToList()); foreach (var r in products.Root.Elements("Product")) { #region Get Concentrator Product ID int concentratorProductID = Utility.GetConcentratorProductID(connector, r, log); if (concentratorProductID == 0) { continue; } AuctionProduct auctionProduct = null; Product product = null; if (connector.UseConcentratorProductID) { auctionProduct = (from a in auctionProductList where a.Product.ConcentratorProductID.HasValue && a.Product.ConcentratorProductID.Value == concentratorProductID select a.AuctionProduct).FirstOrDefault(); product = (from a in ctx.Products where a.ConcentratorProductID.HasValue && a.ConcentratorProductID.Value == concentratorProductID select a).FirstOrDefault(); } else { auctionProduct = (from a in auctionProductList where a.Product.ProductID == concentratorProductID select a.AuctionProduct).FirstOrDefault(); product = (from a in ctx.Products where a.ProductID == concentratorProductID select a).FirstOrDefault(); } #endregion try { List <ProductGroup> productgroups = new List <ProductGroup>(); foreach (var productGroupNode in r.Element("ProductGroupHierarchy").Elements("ProductGroup")) { var productGroups = (from pg in allProductGroups where pg.BackendProductGroupCode == productGroupNode.Attribute("ID").Value select pg).ToList(); List <string> parentNodes = new List <string>() { productGroupNode.Attribute("ID").Value }; var parent = productGroupNode.Element("ProductGroup"); while (parent != null) { parentNodes.Add(parent.Attribute("ID").Value); parent = parent.Element("ProductGroup"); } string path = String.Join("/", parentNodes.ToArray()); ProductGroup group = null; foreach (var g in productGroups) { string groupPath = g.GetProductGroupCodeTree(); if (groupPath == path) { group = g; break; } } if (group != null) { productgroups.Add(group); } } if (r.Element("Price") != null) { decimal unitprice = decimal.Parse(r.Element("Price").Element("UnitPrice").Value, CultureInfo.InvariantCulture); decimal costprice = decimal.Parse(r.Element("Price").Element("CostPrice").Value, CultureInfo.InvariantCulture); string shortDescription = r.Element("Content").Attribute("ShortDescription").Value; string longDescription = r.Element("Content").Attribute("LongDescription").Value; string backendDescription = string.Empty; if (connector.ImportCommercialText) { backendDescription = longDescription; //shortDescription = r.Element("Content").Attribute("ShortContentDescription").Value; //if (!string.IsNullOrEmpty(r.Element("Content").Attribute("LongContentDescription").Value)) //longDescription = r.Element("Content").Attribute("LongContentDescription").Value; } int?taxRateID = (from t in ctx.TaxRates where t.TaxRate1.HasValue && (t.TaxRate1.Value * 100) == decimal.Parse(r.Element("Price").Attribute("TaxRate").Value, CultureInfo.InvariantCulture) select t.TaxRateID).FirstOrDefault(); if (!taxRateID.HasValue) { taxRateID = 1; } if (auctionProduct == null) { #region Create New (Auction) Product Brand brand = (from b in ctx.Brands where b.BrandCode == r.Element("Brands").Element("Brand").Attribute("BrandID").Value.Trim() select b).FirstOrDefault(); if (brand != null) { //DateTime temppdDate = DateTime.MinValue; //DateTime? pdDate = null; //if (DateTime.TryParse(r.Element("Stock").Attribute("PromisedDeliveryDate").Value, out temppdDate)) //{ // if (temppdDate == DateTime.MinValue && temppdDate == DateTime.MaxValue) // pdDate = null; // else // pdDate = temppdDate; //} if (product == null) { if (!connector.UseConcentratorProductID) { //create stub product with identity_insert on string cmd = String.Format( @" INSERT INTO Products (ProductID, ShortDescription,LongDescription,brandid,taxrateid,iscustom,isvisible,extendedcatalog , canmodifyprice,creationtime,lastmodificationtime ) VALUES( {0}, '{1}','{2}', {3},{4},0,0,1,0,getdate(), getdate()) ", concentratorProductID, shortDescription, longDescription, brand.BrandID, taxRateID.Value); ctx.ExecuteCommand(cmd); product = ctx.Products.Single(x => x.ProductID == concentratorProductID); product.IsVisible = false; ctx.SubmitChanges(); } else { product = new Product { //ProductID = int.Parse(r.Attribute("CustomProductID").Value), //ProductGroupID = subprodid, IsVisible = false, CreationTime = DateTime.Now, LastModificationTime = DateTime.Now }; ctx.Products.InsertOnSubmit(product); } if (!string.IsNullOrEmpty(backendDescription)) { product.BackEndDescription = backendDescription; } DateTime pdDate; if (DateTime.TryParse(r.Element("Stock").Attribute("PromisedDeliveryDate").Value, out pdDate)) { if (pdDate != DateTime.MinValue && pdDate != DateTime.MaxValue) { product.PromisedDeliveryDate = pdDate; } } } if (!product.IsVisible) { product.UnitPrice = unitprice; product.ShortDescription = shortDescription; product.LongDescription = longDescription; product.ManufacturerID = r.Attribute("ManufacturerID").Value; product.BrandID = brand.BrandID; product.TaxRateID = taxRateID.Value; product.UnitCost = 0; product.IsCustom = false; product.LineType = string.IsNullOrEmpty(r.Attribute("LineType").Value) ? "S" : r.Attribute("LineType").Value.Trim(); product.ProductStatus = r.Element("Price").Attribute("CommercialStatus").Value; } product.CustomProductID = r.Attribute("CustomProductID").Value; product.ConcentratorProductID = int.Parse(r.Attribute("ProductID").Value); ctx.SubmitChanges(); } else { log.DebugFormat("Product {0} does not have a price in xml", r.Attribute("ProductID").Value); } if (product != null) { auctionProduct = new AuctionProduct() { AuctionProductID = product.ProductID, CreationTime = DateTime.Now }; ctx.AuctionProducts.InsertOnSubmit(auctionProduct); auctionProductList.Add(new { AuctionProduct = auctionProduct, BrandCode = product.Brand.BrandCode, Product = product }); } else { log.WarnFormat("Cannot create new product info for product ID : {0}", concentratorProductID); continue; } #endregion } } else { log.DebugFormat("Brand {0} does not exists for {1}", r.Elements("Brands").Elements("Brand").FirstOrDefault().Attribute("BrandID").Value.Trim(), r.Attribute("ProductID").Value); continue; } if (auctionProduct == null) { log.WarnFormat("Cannot create new auction product info for product ID : {0}", concentratorProductID); continue; } #region Parse Stock Data var bsc = (from b in r.Element("Stock").Element("Retail").Elements("RetailStock") where b.Attribute("Name").Value == "BSC" select b.Attribute("InStock").Value).FirstOrDefault(); int bscStock = 0; int.TryParse(bsc, out bscStock); var bscOEM = (from b in r.Element("Stock").Element("Retail").Elements("RetailStock") where b.Attribute("Name").Value == "BSCOEM" select b.Attribute("InStock").Value).FirstOrDefault(); int bscOEMStock = 0; int.TryParse(bscOEM, out bscOEMStock); //DEMO var bscDemo = (from b in r.Element("Stock").Element("Retail").Elements("RetailStock") where b.Attribute("Name").Value == "BSCDEMO" select b.Attribute("InStock").Value).FirstOrDefault(); int bscDemoStock = 0; int.TryParse(bscDemo, out bscDemoStock); //DMGBOX var bscDMGBOX = (from b in r.Element("Stock").Element("Retail").Elements("RetailStock") where b.Attribute("Name").Value == "BSCDMGBOX" select b.Attribute("InStock").Value).FirstOrDefault(); int bscDMGBOXStock = 0; int.TryParse(bscDMGBOX, out bscDMGBOXStock); //DMGITEM var bscDMGITEM = (from b in r.Element("Stock").Element("Retail").Elements("RetailStock") where b.Attribute("Name").Value == "BSCDMGITEM" select b.Attribute("InStock").Value).FirstOrDefault(); int bscDMGITEMStock = 0; int.TryParse(bscDMGITEM, out bscDMGITEMStock); //INCOMPL var bscINCOMPL = (from b in r.Element("Stock").Element("Retail").Elements("RetailStock") where b.Attribute("Name").Value == "BSCINCOMPL" select b.Attribute("InStock").Value).FirstOrDefault(); int bscINCOMPLStock = 0; int.TryParse(bscINCOMPL, out bscINCOMPLStock); //RETURN var bscRETURN = (from b in r.Element("Stock").Element("Retail").Elements("RetailStock") where b.Attribute("Name").Value == "BSCRETURN" select b.Attribute("InStock").Value).FirstOrDefault(); int bscRETURNStock = 0; int.TryParse(bscRETURN, out bscRETURNStock); //USED var bscUSED = (from b in r.Element("Stock").Element("Retail").Elements("RetailStock") where b.Attribute("Name").Value == "BSCUSED" select b.Attribute("InStock").Value).FirstOrDefault(); int bscUSEDStock = 0; int.TryParse(bscUSED, out bscUSEDStock); //COSTPRice var totalBscStock = bscDemoStock + bscDMGBOXStock + bscDMGITEMStock + bscINCOMPLStock + bscRETURNStock + bscUSEDStock + bscStock; var bscCostPrices = (from b in r.Element("Stock").Element("Retail").Elements("RetailStock") where b.Attribute("Name").Value == "BSC" select b.Attribute("CostPrice").Value).FirstOrDefault(); decimal BSCCostPrice = 0; if (bscCostPrices != null) { BSCCostPrice = decimal.Parse(bscCostPrices, CultureInfo.InvariantCulture); } decimal DC10CostPrice = decimal.Parse(r.Element("Price").Element("CostPrice").Value, CultureInfo.InvariantCulture); #endregion if (auctionProduct.AuctionBSCStock != totalBscStock || auctionProduct.AuctionDC10Stock != int.Parse(r.Element("Stock").Attribute("InStock").Value) || auctionProduct.AuctionOEMStock != bscOEMStock || auctionProduct.BSCCostPrice != BSCCostPrice || auctionProduct.DC10CostPrice != DC10CostPrice || auctionProduct.AuctionDEMOStock != bscDemoStock || auctionProduct.AuctionDMGBOXStock != bscDMGBOXStock || auctionProduct.AuctionDMGITEMStock != bscDMGITEMStock || auctionProduct.AuctionINCOMPLStock != bscINCOMPLStock || auctionProduct.AuctionRETURNStock != bscRETURNStock || auctionProduct.AuctionUSEDStock != bscUSEDStock || auctionProduct.AuctionMYVEILStock != bscStock || auctionProduct.QuantityToReceive != int.Parse(r.Element("Stock").Attribute("QuantityToReceive").Value) || auctionProduct.StockStatus != r.Element("Stock").Attribute("StockStatus").Value) { auctionProduct.LastModificationTime = DateTime.Now; } auctionProduct.AuctionBSCStock = totalBscStock; auctionProduct.AuctionDC10Stock = int.Parse(r.Element("Stock").Attribute("InStock").Value); auctionProduct.AuctionOEMStock = bscOEMStock; auctionProduct.BSCCostPrice = BSCCostPrice; auctionProduct.AuctionDEMOStock = bscDemoStock; auctionProduct.AuctionDMGBOXStock = bscDMGBOXStock; auctionProduct.AuctionDMGITEMStock = bscDMGITEMStock; auctionProduct.AuctionINCOMPLStock = bscINCOMPLStock; auctionProduct.AuctionRETURNStock = bscRETURNStock; auctionProduct.AuctionUSEDStock = bscUSEDStock; auctionProduct.AuctionMYVEILStock = bscStock; auctionProduct.DC10CostPrice = DC10CostPrice; auctionProduct.QuantityToReceive = int.Parse(r.Element("Stock").Attribute("QuantityToReceive").Value);; auctionProduct.StockStatus = r.Element("Stock").Attribute("StockStatus").Value; ctx.SubmitChanges(); processor.ImportProductGroupMapping(ctx, productgroups, productGroupMappings, auctionProduct.AuctionProductID, concentratorProductID); ctx.SubmitChanges(); if (!product.ConcentratorProductID.HasValue) { product.ConcentratorProductID = int.Parse(r.Attribute("ProductID").Value); ctx.SubmitChanges(); } } catch (Exception ex) { log.Error("error insert product", ex); } } //log.Info("Start import productgroupmapppings"); //processor.ImportProductGroupMapping(ctx, connector); //log.Info("Finish import productgroupmapppings"); log.Debug("Start cleanup auctionproducts"); var cItemNumbers = (from r in products.Root.Elements("Product") select new { concentratorProductID = r.Attribute("ProductID").Value, customProductID = r.Attribute("CustomProductID").Value }).ToList(); List <string> xmlProducts = new List <string>(); if (connector.UseConcentratorProductID) { xmlProducts = (from c in cItemNumbers where c.concentratorProductID != String.Empty select c.concentratorProductID).ToList(); } else { foreach (var c in cItemNumbers.Select(x => x.customProductID)) { int tmp = 0; if (Int32.TryParse(c, out tmp)) { xmlProducts.Add(tmp.ToString()); } } } List <AuctionProduct> siteProducts = new List <AuctionProduct>(); if (connector.UseConcentratorProductID) { var tempSiteProducts = (from c in ctx.AuctionProducts where c.Product.ConcentratorProductID.HasValue select new { concentratorProductID = c.Product.ConcentratorProductID.Value.ToString(), auctionItem = c }).ToList(); foreach (var p in cItemNumbers) { tempSiteProducts.RemoveAll(c => c.concentratorProductID == p.concentratorProductID.ToString()); } siteProducts = tempSiteProducts.Select(x => x.auctionItem).ToList(); if (siteProducts != null && siteProducts.Count > 0) { ctx.AuctionProducts.DeleteAllOnSubmit(siteProducts); } ctx.SubmitChanges(); var delProds = (from c in ctx.AuctionProducts where !c.Product.ConcentratorProductID.HasValue select c).ToList(); log.DebugFormat("Delete {0} items without concentrator productid", delProds.Count); ctx.AuctionProducts.DeleteAllOnSubmit(delProds); ctx.SubmitChanges(); } else { siteProducts = (from c in ctx.AuctionProducts select c).ToList(); foreach (var p in cItemNumbers) { siteProducts.RemoveAll(c => c.AuctionProductID.ToString() == p.customProductID); } if (siteProducts != null && siteProducts.Count > 0) { ctx.AuctionProducts.DeleteAllOnSubmit(siteProducts); } ctx.SubmitChanges(); } } log.Debug("Finish cleanup assormtent"); // processor.CleanUpProductGroupMapping(); log.Debug("Start import productattributes"); processor.ProcessAttributes(soap, connector, true, lastUpdate, false); log.Debug("Finish import productattributes"); log.DebugFormat("Auction Product import Completed On: {0}", DateTime.Now); } catch (Exception ex) { log.Error("Error import products", ex); } log.DebugFormat("Finish Process auction import for {0}", connector.Name); } }
protected override void Process() { using (var unit = GetUnitOfWork()) { var repoOrderResponses = unit.Scope.Repository <OrderResponseLine>(); var orderLedgerRepo = unit.Scope.Repository <OrderLedger>(); foreach (Connector connector in base.Connectors.Where(c => ((ConnectorType)c.ConnectorType).Has(ConnectorType.ShopAssortment))) { log.DebugFormat("Start Process shop Third Party import for {0}", connector.Name); DateTime start = DateTime.Now; try { using (AssortmentServiceSoapClient soap = new AssortmentServiceSoapClient()) { var products = repoOrderResponses.GetAll(o => o.OrderLineID.HasValue && o.OrderLine.OrderLedgers.Max(x => x.Status) == (int)OrderLineStatus.PushProduct).Distinct().ToList(); foreach (var product in products) { try { if (product.OrderLine.DispatchedToVendorID.HasValue) { var vendorAss = product.OrderLine.Product.VendorAssortments.Where(x => x.VendorID == product.OrderLine.DispatchedToVendorID.Value || (x.Vendor.ParentVendorID.HasValue && x.Vendor.ParentVendorID.Value == product.OrderLine.DispatchedToVendorID.Value)).FirstOrDefault(); decimal unitcost = 0; if (vendorAss.VendorPrices.FirstOrDefault().CostPrice.HasValue) { unitcost = vendorAss.VendorPrices.FirstOrDefault().CostPrice.Value; } else if (vendorAss.VendorPrices.FirstOrDefault().Price.HasValue) { unitcost = vendorAss.VendorPrices.FirstOrDefault().Price.Value; } var input = soap.GetOAssortment(connector.ConnectorID, false, product.VendorItemNumber.Trim()); if (input != null) { XDocument o_Products = XDocument.Parse(input); if (o_Products != null && o_Products.Root.Elements("Product").Count() > 0) { ImportOItems(o_Products, connector, (decimal)(product.OrderLine.Price.HasValue ? (decimal)product.OrderLine.Price.Value : product.Price), unitcost); product.OrderLine.SetStatus(OrderLineStatus.ReadyToOrder, orderLedgerRepo); unit.Save(); } else { log.Info("Get Third Party product failed"); } } else { log.Info("Empty Third Party product Feed"); } } } catch (Exception ex) { log.Error(string.Format("Failed to insert product {0} to shop", product.VendorItemNumber.Trim()), ex); } } } } catch (Exception ex) { log.Fatal(ex); } log.DebugFormat("Finish Process shop Third Party product import for {0}", connector.Name); } } }
protected override void Process() { using(var unit = GetUnitOfWork()){ foreach (ConnectorRelation connectorRelation in unit.Scope.Repository<ConnectorRelation>().GetAll(x => x.IsActive && ) { string drive = connector.ConnectorSettings.GetValueByKey("XmlExportPath", string.Empty); bool networkDrive = false; //string drive = @"\\SOL\Company_Shares\Database Backup"; bool.TryParse(connector.ConnectorSettings.GetValueByKey("IsNetorkDrive", "false"), out networkDrive); NetworkExportUtility util = new NetworkExportUtility(); if (networkDrive) { drive = util.ConnectorNetworkPath(drive); } string path = drive; #region Assortiment if (((ConnectorType)connector.ConnectorType).Has(ConnectorType.ShopAssortment) || ((ConnectorType)connector.ConnectorType).Has(ConnectorType.WebAssortment)) { foreach (var language in connector.ConnectorLanguages) { log.DebugFormat("Start Process XML Assortment export for {0} language {1}", connector.Name, language.Language.Name); if (!string.IsNullOrEmpty(path)) { AssortmentServiceSoapClient soap = new AssortmentServiceSoapClient(); XDocument products; products = XDocument.Parse(soap.GetAdvancedPricingAssortment(connector.ConnectorID, false, false, null, null, true, language.LanguageID)); string file = Path.Combine(path, string.Format("products_{0}_{1}.xml", connector.ConnectorID, language.LanguageID)); if (File.Exists(file)) File.Delete(file); products.Save(file, SaveOptions.DisableFormatting); } else { log.AuditCritical(string.Format("Export XML failed for {0}, XmlExportPath not set", connector.Name)); } log.DebugFormat("Finish Process XML Assortment import for {0}", connector.Name); } } #endregion #region Images if (((ConnectorType)connector.ConnectorType).Has(ConnectorType.Images)) { log.DebugFormat("Start Process XML Image export for {0}", connector.Name); if (!string.IsNullOrEmpty(path)) { AssortmentServiceSoapClient soap = new AssortmentServiceSoapClient(); XDocument products; products = XDocument.Parse(soap.GetFTPAssortmentImages(connector.ConnectorID)); string file = Path.Combine(path, string.Format("Images_{0}.xml", connector.ConnectorID)); if (File.Exists(file)) File.Delete(file); products.Save(file, SaveOptions.DisableFormatting); } else { log.AuditCritical(string.Format("Export XML failed for {0}, XmlExportPath not set", connector.Name)); } log.DebugFormat("Finish Process XML Image import for {0}", connector.Name); } #endregion #region content if (((ConnectorType)connector.ConnectorType).Has(ConnectorType.Content)) { foreach (var language in connector.ConnectorLanguages) { log.DebugFormat("Start Process XML Content export for {0} language {1}", connector.Name, language.Language.Name); if (!string.IsNullOrEmpty(path)) { AssortmentServiceSoapClient soap = new AssortmentServiceSoapClient(); XDocument content = XDocument.Parse(soap.GetAssortmentContentDescriptionsByLanguage(connector.ConnectorID, null, language.LanguageID)); string contentFile = Path.Combine(path, string.Format("Content_{0}_{1}.xml", connector.ConnectorID, language.LanguageID)); if (File.Exists(contentFile)) File.Delete(contentFile); content.Save(contentFile, SaveOptions.DisableFormatting); XDocument attributes = XDocument.Parse(soap.GetAttributesAssortmentByLanguage(connector.ConnectorID, null, null, language.LanguageID)); string attributeFile = Path.Combine(path, string.Format("Attribute_{0}_{1}.xml", connector.ConnectorID, language.LanguageID)); if (File.Exists(attributeFile)) File.Delete(attributeFile); attributes.Save(attributeFile, SaveOptions.DisableFormatting); } else { log.AuditCritical(string.Format("Export XML failed for {0}, XmlExportPath not set", connector.Name)); } log.DebugFormat("Finish Process XML Content import for {0} language {1}", connector.Name, language.Language.Name); } } #endregion if (networkDrive) { util.DisconnectNetworkPath(drive); } } } }
private void ProcessXML() { log.Info("Start import of expert product reviews"); AssortmentServiceSoapClient client = new AssortmentServiceSoapClient(); var message = client.GetExpertProductReviews(); XDocument reviews = XDocument.Parse(message); var productReviews = (from p in reviews.Element("ExpertReviews").Element("Products").Elements("Product") select new { ConcentratorID = int.Parse(p.Attribute("ID").Value), Reviews = from r in p.Element("Reviews").Elements("Review") let sourceID = int.Parse(r.Attribute("SourceID").Value) select new { CustomID = r.Attribute("ConcentratorID").Value, SourceID = sourceID, isSummary = bool.Parse(r.Attribute("isSummary").Value), Author = r.Element("Author").Value, Date = r.Element("Date").Value, Title = r.Element("Title").Value, Summary = r.Element("Summary").Value, Verdict = r.Element("Verdict").Value, ReviewURL = r.Element("ReviewURL").Value, RatingImageURL = r.Element("RatingImageURL").Value, Rating = r.Element("Rating").Try <XElement, int?>(c => int.Parse(c.Value), null), Source = (from s in reviews.Element("ExpertReviews").Element("Sources").Elements("Source") where int.Parse(s.Attribute("ID").Value) == sourceID select new { Name = s.Element("Name").Value, LanguageCode = s.Element("LanguageCode").Value, CountryCode = s.Element("CountryCode").Value, SourceURL = s.Element("SourceURL").Value, SourceLogoURL = s.Element("SourceLogoURL").Value, SourceRank = s.Element("SourceRank").Try <XElement, int?>(c => int.Parse(c.Value), null) }).FirstOrDefault() } } ); foreach (Connector connector in base.Connectors.Where(x => ((ConnectorType)x.ConnectorType).Has(ConnectorType.Reviews))) { log.InfoFormat("Start expert product review import for connector {0}", connector.Name); DateTime start = DateTime.Now; using (WebsiteDataContext context = new WebsiteDataContext(ConfigurationManager.ConnectionStrings[connector.Connection].ConnectionString)) { var productIDs = (from p in context.Products select p.ConcentratorProductID).ToList(); var sources = (from s in context.ReviewSources select s).ToList(); productIDs.Sort(); foreach (var product in productReviews) { if (!productIDs.Contains(product.ConcentratorID)) { continue; } var productItem = (from p in context.Products where p.ConcentratorProductID == product.ConcentratorID select p).FirstOrDefault(); foreach (var review in product.Reviews) { #region Source var src = sources.FirstOrDefault(c => c.CustomSourceID == review.SourceID); if (src == null) { src = new ReviewSource { CustomSourceID = review.SourceID }; context.ReviewSources.InsertOnSubmit(src); sources.Add(src); } src.CountryCode = review.Source.CountryCode; src.LanguageCode = review.Source.LanguageCode; src.Name = review.Source.Name; src.SourceLogoUrl = review.Source.SourceLogoURL; src.SourceRank = review.Source.SourceRank; src.SourceUrl = review.Source.SourceURL; #endregion var reviewItem = (from s in context.AlatestExpertReviews where s.CustomID == review.CustomID select s).FirstOrDefault(); if (reviewItem == null) { reviewItem = new AlatestExpertReview() { Product = productItem, ReviewSource = src, CustomID = review.CustomID }; context.AlatestExpertReviews.InsertOnSubmit(reviewItem); } reviewItem.Author = review.Author; DateTime date; DateTime.TryParse(review.Date, out date); reviewItem.Date = review.Date.Try <string, DateTime?>(c => DateTime.Parse(c), null); reviewItem.isSummary = review.isSummary; reviewItem.Rating = review.Rating; reviewItem.RatingImageURL = review.RatingImageURL; reviewItem.ReviewURL = review.ReviewURL; reviewItem.Summary = review.Summary; reviewItem.Title = review.Title; reviewItem.Verdict = review.Verdict; } } try { using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Suppress, TimeSpan.FromMinutes(5))) { context.SubmitChanges(); } } catch (Exception e) { log.AuditError("Import of alatest expert reviews failed for connector: " + connector.Name, e, "Import Expert Reviews"); } } } }
protected override void Process() { log.Info("Selector import cycle started..."); try { foreach (Connector connector in base.Connectors.Where(c => ((ConnectorType)c.ConnectorType).Has(ConnectorType.WebAssortment) && c.Selectors)) { DateTime start = DateTime.Now; AssortmentServiceSoapClient contentClient = new AssortmentServiceSoapClient(); SelectorServiceSoapClient serviceClient = new SelectorServiceSoapClient(); using ( WebsiteDataContext context = new WebsiteDataContext( ConfigurationManager.ConnectionStrings[connector.Connection].ConnectionString)) { log.InfoFormat("Start selector import for connector {0}", connector.Name); var selectorIDs = (from s in context.Selectors select s.SelectorID).ToList(); foreach (int selectorID in selectorIDs) { var products = XDocument.Parse(contentClient.GetSelectorProducts(connector.ConnectorID, selectorID)); Processor processor = new Processor(products, log, connector); log.Debug("Start import brands"); processor.ImportBrands(); log.Debug("Finished import brands"); log.Debug("Start import productgroups"); processor.ImportProductGroups(false); log.Debug("Finished import productgroups"); log.Debug("Start import Products"); processor.ImportSelectorProducts(); log.Debug("Finished import Products"); log.Debug("Start import Attributes"); processor.processSelectorAttributes(connector); log.Debug("Finished import Attributes"); log.Debug("Start import images"); ProcessProductImages(connector, products); log.Debug("Finish import images"); //processor.CleanUpProducts(); // } try { log.InfoFormat("Starting import of related products"); ImportRelatedProducts(context, serviceClient, contentClient, connector); log.InfoFormat("Finished import of related products"); } catch (Exception e) { log.Error("Importing of related products for connector " + connector.Name + "failed ", e); } try { using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Suppress, TimeSpan.FromMinutes(5))) { context.SubmitChanges(); scope.Complete(); } log.AuditSuccess("Finished selector export for connector " + connector.Name, "Selector export"); } catch (Exception e) { log.AuditFatal("There was an error inserting the selectors", e); } } } } catch (Exception e) { log.Fatal("Selector import cycle failed", e); } }