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() { 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 }
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 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 } }