protected override string GetReplacements() { string result = "\n" + ReplacementFilename + ": "; ProgressText += result; string tempDisplay = ProgressText; ProgressText += "Exporting..."; if (m_replacementList == null) m_replacementList = new List<ReplacementRecord>(); // check for any replacement rules if (m_replacements != null) { if (m_replacements[0].Type != ReplacementCondition.RepType.Catalog) //individual item replacement { foreach (ReplacementCondition rc in m_replacements) { if (rc.Type != ReplacementCondition.RepType.Item) { m_log.WriteEntry("Invalid replacement condition: " + rc.ToString(), EventLogEntryType.Warning, m_alias); continue; //ignore any invalid entries } var r = new ReplacementRecord(); r.OldId = rc.OldName; r.NewId = rc.NewName; m_replacementList.Add(r); } } else //full catalog replacement { //Query the catalog for the data string oldfield = m_replacements[0].OldName; string newfield = m_replacements[0].NewName; if ((m_catalogXml != null) && (m_catalogXml.Count() > 0)) { foreach (XElement item in m_catalogXml) { var r = new ReplacementRecord(); r.OldId = Client.GetValue(item, oldfield); r.NewId = Client.GetValue(item, newfield); m_replacementList.Add(r); } } } } if (m_replacementList.Count < 1) { m_replacementsEnabled = false; return result + "(no data)"; //no data matches rules } m_replacementsEnabled = true; //upload to 4-Tell ProgressText = tempDisplay + result + "Uploading..."; result += m_boostService.WriteTable(m_alias, ReplacementFilename, m_replacementList); ProgressText = tempDisplay + result; return result; }
protected override string GetReplacements() { if (!m_replacementsEnabled) return Environment.NewLine + "Replacements disabled"; m_replacementsEnabled = false; if (m_replacements == null || m_replacements.Count == 0) return Environment.NewLine + "No replacements"; var result = string.Format("{0}{1}: ", Environment.NewLine, ReplacementFilename); ProgressText += result; string tempDisplay = ProgressText; ProgressText += "Exporting..."; var replacements = new List<ReplacementRecord>(); if (!m_replacements[0].Type.Equals(ReplacementCondition.RepType.Catalog)) { foreach (var rc in m_replacements) { if (!rc.Type.Equals(ReplacementCondition.RepType.Item)) { m_log.WriteEntry(string.Format("Invalid replacement condition: {0}", rc), EventLogEntryType.Warning, m_alias); continue; } replacements.Add(new ReplacementRecord { OldId = rc.OldName, NewId = rc.NewName }); } } else { var products = LoadTabDelimitedFile(m_catalogFilePath).Select(x => new ProductRecord { ProductId = x["PRODUCT_CODE"], Name = x["PRODUCT_NAME"] }); if (products.Count() == 0) return result + " ( no data)"; foreach(var p in products) { var rr = new ReplacementRecord { OldId = products.Where(x => x.Name.Equals(m_replacements[0].OldName)).Select(y => y.ProductId).DefaultIfEmpty("").Single(), NewId = products.Where(x => x.Name.Equals(m_replacements[0].NewName)).Select(y => y.ProductId).DefaultIfEmpty("").Single() }; replacements.Add(rr); } } if (replacements.Count < 1) return result + "(no data)"; m_replacementsEnabled = true; var countDisplay = string.Format("({0} items) ", replacements.Count); ProgressText = tempDisplay + countDisplay + "Uploading..."; result += countDisplay + m_boostService.WriteTable(m_alias, ReplacementFilename, replacements); return result; }