public static ITransformPlug CreateTransformPlugFromBTM(XElement btmRoot, IDocumentPlug sourcePlug, IDocumentPlug targetPlug) { string srcName, trgName; srcName = trgName = null; XElement e = GetFirstElement(btmRoot, "SrcTree"); srcName = GetAttributeValue(e, "RootNode_Name"); XElement reference = GetFirstElement(e, "Reference"); string sourceLocation = null; if (reference != null) { sourceLocation = GetAttributeValue(reference, "Location"); } e = GetFirstElement(btmRoot, "TrgTree"); trgName = GetAttributeValue(e, "RootNode_Name"); reference = GetFirstElement(e, "Reference"); string targetLocation = null; if (reference != null) { targetLocation = GetAttributeValue(reference, "Location"); } ITransformPlug plug = new TransformPlug(sourcePlug, targetPlug, null, sourceLocation, targetLocation); IEnumerable <XElement> pageList = btmRoot.Elements(XName.Get("Pages")); IEnumerable <XElement> pages = null; foreach (XElement p in pageList) { pages = p.Elements(XName.Get("Page")); break; } foreach (XElement page in pages) { ITransformGroup group = ParsePage(page); MarkForIgnore(group); plug.Facets.Add(group); } //PrintTransformPlug(plug); return(plug); }
static void ParseListOfLink(XElement page, ITransformGroup group) { IEnumerable <XElement> links = page.Elements(XName.Get("Links")); IEnumerable <XElement> linkList = null; foreach (XElement l in links) { linkList = l.Elements(XName.Get("Link")); break; } foreach (XElement link in linkList) { ITransformLink docLink = ParseLink(link); group.Links.Add(docLink); } }
static void ParseListOfFunctoid(XElement page, ITransformGroup group) { IEnumerable <XElement> functoids = page.Elements(XName.Get("Functoids")); IEnumerable <XElement> functoidList = null; foreach (XElement f in functoids) { functoidList = f.Elements(XName.Get("Functoid")); break; } foreach (XElement functoid in functoidList) { IFormula formula = ParseFunctoid(functoid); group.Formulas.Add(formula); } }
static bool GetReferencedLinksAndFormula(ITransformGroup group, out Dictionary <string, ITransformLink> referencedLinkMap, out Dictionary <string, IFormula> formulaMap) { referencedLinkMap = new Dictionary <string, ITransformLink>(); foreach (ITransformLink link in group.Links) { if (link.Source.ReferenceType == ReferenceType.Formula || link.Target.ReferenceType == ReferenceType.Formula) { referencedLinkMap[link.Name] = link; } } formulaMap = new Dictionary <string, IFormula>(); foreach (IFormula formula in group.Formulas) { formulaMap[formula.Name] = formula; } return(true); }
static void MarkForIgnore(ITransformGroup group) { Dictionary <string, ITransformLink> linkMap = new Dictionary <string, ITransformLink>(); foreach (ITransformLink link in group.Links) { if (link.Source.ReferenceType == ReferenceType.Formula || link.Target.ReferenceType == ReferenceType.Formula) { linkMap[link.Name] = link; } } Dictionary <string, IFormula> ignoredFormulaMap = new Dictionary <string, IFormula>(); ITransformLink referencedLink; foreach (IFormula formula in group.Formulas) { if (formula.FormulaType == FormulaType.Copy) { formula.Ignore = true; ignoredFormulaMap[formula.Name] = formula; foreach (IParameter param in formula.Parameters) { if (param.Reference.ReferenceType == ReferenceType.Document) { linkMap.TryGetValue(param.Reference.Name, out referencedLink); if (referencedLink != null) { referencedLink.Ignore = true; } } } } } IFormula referencedFormula; //2nd pass over links to see which ones refer to ignored formula foreach (ITransformLink link in group.Links) { if (link.Ignore) { continue; } if (link.Source.ReferenceType == ReferenceType.Formula) { ignoredFormulaMap.TryGetValue(link.Source.Name, out referencedFormula); if (referencedFormula != null && referencedFormula.Ignore) { link.Ignore = true; } } if (!link.Ignore && link.Target.ReferenceType == ReferenceType.Formula) { ignoredFormulaMap.TryGetValue(link.Target.Name, out referencedFormula); if (referencedFormula != null && referencedFormula.Ignore) { link.Ignore = true; } } } }
private static void CreateTransformLinks(ExcelWorksheet current, ref int row, ref ITransformGroup group) { int index = 0; while (true) { if (current.Cells[row, TargetFieldIndex].Value == null) { break; } ITransformLink link = new TransformLink(group.Name + index); index++; link.Address = row.ToString(); link.Target.Name = BuildLinkName(current.Cells[row, TargetFieldIndex].Value.ToString(), current.Cells[row, TargetRecordIndex].Value.ToString()); if (current.Cells[row, TypeIndex].Value.ToString().Equals("Data Copy")) { link.Source.Name = BuildLinkName(current.Cells[row, SourceFieldIndex].Value.ToString(), current.Cells[row, SourceRecordIndex].Value.ToString()); } //code to handle missing fields if (current.Cells[row, TypeIndex].Value.ToString().Equals("Missing Value")) { link.Source.Name = "Missing Name"; link.Source.ReferenceType = ReferenceType.Document; link.Target.ReferenceType = ReferenceType.Document; group.Links.Add(link); row++; continue; } //code to auto generate some fields if (current.Cells[row, TypeIndex].Value.ToString().Equals("AutoField")) { string value = current.Cells[row, SourceRecordIndex].Value.ToString(); switch (value) { case "MAARG.GetInvoiceDate(PartnerID, Invoice#)": Random random = new Random(); link.Source.Name = "INV" + random.Next(); break; case "MAARG.GetInvoiceNumber(PartnerID)": link.Source.Name = System.Convert.ToDateTime(DateTime.Today).ToString("yyyyMMdd"); break; } link.Source.ReferenceType = ReferenceType.Literal; link.Target.ReferenceType = ReferenceType.Document; group.Links.Add(link); row++; continue; } //finish auto if (current.Cells[row, TargetFieldIndex].Formula == null || current.Cells[row, TargetFieldIndex].Formula == "") { link.Target.ReferenceType = ReferenceType.Document; } else { link.Target.ReferenceType = ReferenceType.Formula; } if (current.Cells[row, SourceFieldIndex].Formula == null || current.Cells[row, SourceFieldIndex].Formula == "") { link.Source.ReferenceType = ReferenceType.Document; } else { link.Source.ReferenceType = ReferenceType.Formula; } group.Links.Add(link); row++; } }