private void ExtractPeople(HotTag tags, MergeBlock block, string holderOrSubtantialOwner, List <XElement> ahPerson) { string orgOrIndividual = string.Empty; string personId = string.Empty; string birthDate = string.Empty; string scv = string.Empty; string fullName = string.Empty; string firstName, middleName, lastName = string.Empty; XElement xmlPerson = new XElement("dummy", "dummy"); foreach (var item in ahPerson) { if (item.HasElements) { orgOrIndividual = item.Element(ns + tags.tagOrganisation) != null ? tags.tagOrganisation : tags.tagIndividual; foreach (XElement p in item.Descendants(ns + orgOrIndividual)) { personId = p.Element(sfa + tags.tagIndID) != null?p.Element(sfa + tags.tagIndID).Value.ToString() : ""; var bd = p.Descendants(sfa + "BirthInfo").Descendants(sfa + "BirthDate").Select(s => s.Value).FirstOrDefault(); birthDate = bd != null?bd.ToString() : ""; var nm = p.Descendants(sfa + "Name").FirstOrDefault(); if (orgOrIndividual == tags.tagOrganisation) { fullName = p.Element(sfa + "Name") != null?p.Element(sfa + "Name").Value.ToString().Trim() : ""; } else { firstName = nm.Element(sfa + "FirstName") != null?nm.Element(sfa + "FirstName").Value.ToString() : ""; middleName = nm.Element(sfa + "MiddleName") != null?nm.Element(sfa + "MiddleName").Value.ToString() : ""; lastName = nm.Element(sfa + "LastName") != null?nm.Element(sfa + "LastName").Value.ToString() : ""; fullName = (lastName + "," + firstName + " " + middleName).Trim(); } xmlPerson = p; break; } //personId = person.Element(sfa + tags.tagIndID)[0] != null ? person.Element(sfa + tags.tagIndID)[0].Value.ToString() : ""; if (personId != "") { AddPerson(block, holderOrSubtantialOwner, orgOrIndividual, personId, birthDate, scv, fullName, xmlPerson); } } } }
private void ExtractMoreDetails(HotTag tags, IEnumerable <MergeBlock> Blocks, List <MergeBlock> blockList) { // // Extract Individuals within each block // // SWIUS Can have individuals at the tags : // AccountHolder.Organisation // AccountHolder.Individual // SubstantialOwner.Individual foreach (var block in Blocks) { string holderOrSubtantialOwner = string.Empty; // Look for people under "Account Holder" holderOrSubtantialOwner = "AccountHolder"; List <XElement> ahPerson = block.XmlChunk.Descendants(ns + tags.tagIndBlockowner).ToList(); ExtractPeople(tags, block, holderOrSubtantialOwner, ahPerson); // Look for people under "Substantial Owner" holderOrSubtantialOwner = "SubstantialOwner"; List <XElement> soPerson = block.XmlChunk.Descendants(ns + tags.tagIndBlocksubowner).ToList(); ExtractPeople(tags, block, holderOrSubtantialOwner, soPerson); List <XElement> payments = block.XmlChunk.Descendants(ns + tags.tagPayment).ToList(); ExtractPayments(tags, block, payments); if (mergeType == "Secondary") { if (!secClientIsInPri[block.ClientId]) // Client is only in secondary { var actionReq = "AddToEndofTrain"; var primaryChunkId = string.Empty; var primaryTag = string.Empty; var secondaryTag = block.ClientId; AddToDo(block, actionReq, primaryChunkId, primaryTag, secondaryTag); } } block.BlockId = MergeBlock.nextBlockId; blockList.Add(block); MergeBlock.nextBlockId++; } }
private void SetEndOfTrain(HotTag tags) { endOfTrain.xml = new XDocument(xSecondary); // Remove any AccountReports that are matched in the primary endOfTrain.xml.Descendants(ftc + tags.tagAccBlock) .Where(e => secClientIsInPri[e.Element(ftc + tags.tagAccID).Value] == true) .Remove(); // Remove any remaining empty ReportingGroups endOfTrain.xml.Descendants(ftc + tags.tagReportingGroup) .Where(e => e.Element(ftc + tags.tagAccBlock) == null) .Remove(); // Add a comment "Added from secondary file" for each AccountReport foreach (XElement eleDocCli in endOfTrain.xml.Descendants(ftc + tags.tagReportingGroup).Elements(ftc + tags.tagAccBlock)) { eleDocCli.AddBeforeSelf(new XComment("** Added from secondary file **")); } }
private void MarkMatchedSecondaryPeople(HotTag tags, List <MergeBlock> priBlockList, List <MergeBlock> secBlockList) { foreach (MergeBlock pb in priBlockList) { string secAcc; if (!mapPriToSec.TryGetValue(pb.ClientId, out secAcc)) { continue; } else { MergeBlock sb = GetMergeBlock(secBlockList, secAcc); foreach (Person pbp in pb.Persons) { if (sb != null) { MarkTheMatches(tags, pb, pbp, sb); } } } } }
private static void MarkTheMatches(HotTag tags, MergeBlock pb, Person pbp, MergeBlock sb) { foreach (Person sbp in sb.Persons) { // skip to next iteration if already matched if ((sbp.ExistsInPrimaryBlockId > 0) || (sbp.OrgOrIndividual == tags.tagOrganisation)) { continue; } else { // check for a match if (sbp.PersonId == pbp.PersonId && sbp.FullName == pbp.FullName) { sbp.ExistsInPrimaryBlockId = pb.BlockId; } if (sbp.FullName == pbp.FullName) { sbp.ExistsInPrimaryBlockId = pb.BlockId; } } } }
private void PrepUnmatchedSecondaryPeople(HotTag tags, List <MergeBlock> priBlockList, List <MergeBlock> secBlockList) { foreach (MergeBlock sb in secBlockList) { string priAcc; if (!mapSecToPri.TryGetValue(sb.ClientId, out priAcc)) { continue; } else { MergeBlock pb = GetMergeBlock(priBlockList, priAcc); int personIdx = 0; foreach (Person sbp in sb.Persons) { if (sbp.ExistsInPrimaryBlockId == 0) { // Add ToDo to the secondary person : Action append Person to Primary Client int np = sb.Persons[personIdx].ToDos != null ? sb.Persons[personIdx].ToDos.Count() : 0; if (np == 0) { ToDo td = new ToDo(); td.ActionReq = "AddPerson"; td.PrimaryChunkId = pb.ClientId; td.PrimaryTag = tags.tagIndividual; td.SecondaryTag = string.Empty; td.Log = string.Empty; td.doneRef = 0; MergeBlock.AddPersonToDo(sb, personIdx, td); } } personIdx++; } //AddToDoForThoseWeNeedToAdd(tags, pb, sb); } } }
public void MakeChunks(HotTag tags) { var priBlocks = (from c in xPrimary.Descendants(ns + tags.tagAccBlock) select new MergeBlock { //BlockId = MergeBlock.nextBlockId ClientId = (string)c.Element(ns + tags.tagAccID) , XmlChunk = c }); mergeType = "Primary"; ExtractMoreDetails(tags, priBlocks, primaryBlocks); // Create Secondary Client Blocks var secBlocks = (from c in xSecondary.Descendants(ns + tags.tagAccBlock) select new MergeBlock { //BlockId = MergeBlock.nextBlockId ClientId = (string)c.Element(ns + tags.tagAccID) , XmlChunk = c }); mergeType = "Secondary"; ExtractMoreDetails(tags, secBlocks, secondaryBlocks); // Collect Clients that only appear on the Secondary File SetEndOfTrain(tags); MarkMatchedSecondaryPeople(tags, primaryBlocks, secondaryBlocks); PrepUnmatchedSecondaryPeople(tags, primaryBlocks, secondaryBlocks); }
public void ReadIdentifiers(HotTag tags) { ns = xPrimary.Root.GetDefaultNamespace(); //if (fileType == "SWIUS") //{ // var accs = from cust in xPrimary.Descendants(ftc + tags.tagAccBlock) select cust; //} //if (fileType == "SWICRS") //{ // var accs = from cust in xPrimary.Descendants(crs + tags.tagAccBlock) select cust; //} //if (fileType == "SWIS") //{ // var accs = from cust in xPrimary.Descendants(tags.tagAccBlock) select cust; //} // Primary file - find all Identifiers priClientIds = PopulateStringListFromXdoc(xPrimary, ns, tags.tagAccBlock, ns, tags.tagAccID); priPersonIds = PopulateStringListFromXdoc(xPrimary, ns, tags.tagAccBlock, sfa, tags.tagIndID); // Secondary file - find all Identifiers secClientIds = PopulateStringListFromXdoc(xSecondary, ns, tags.tagAccBlock, ns, tags.tagAccID); secPersonIds = PopulateStringListFromXdoc(xSecondary, ns, tags.tagAccBlock, sfa, tags.tagIndID); }
private static void ShowMatches(XDocument xdoc, HotTag tags, Dictionary <string, string> mapHPToAvq) { // Console.WriteLine(xdoc); Console.WriteLine("\nShow Matches:\n"); foreach (var hpToAvq in mapHPToAvq) { Console.WriteLine("HPRef={0} AvqRef={1}", hpToAvq.Key.PadLeft(10), hpToAvq.Value.PadLeft(10)); } //mapHPToAvq = CSVToDictionary(mapPath, 1, 0); IEnumerable <string> accID = from customers in xdoc.Descendants(tags.tagAccBlock) // where (double)customers.Descendants("Payment") > 400.00 select customers.Element(tags.tagAccID).Value; foreach (string strName in accID) { if (mapHPToAvq.ContainsKey(strName)) { Console.WriteLine(strName + " Account will be merged"); } else { Console.WriteLine(strName + " Account only in Legacy file"); //var names2 = from customers2 in // xdoc.Element(tags.tagReportingGroup).Elements(tags.tagAccBlock) // where (bool)customers2.Descendants(tags.tagAccID).Select(v => v.Value == strName) // select customers2; } } // Create a KeyedArray for ints (now generic). KeyedArray <int> ka = new KeyedArray <int>(); // Save the ages of the Simpsons' kids. ka["Bart"] = 8; ka["Lisa"] = 10; ka["Maggie"] = 2; // Look up the age of Lisa. Console.WriteLine("Let's find Lisa's age"); int age = ka["Lisa"]; Console.WriteLine("Lisa is {0}", age); // Replace Bart's age with a new value (Bart already in list). ka["Bart"] = 108; Console.WriteLine(ka["Bart"]); // KeyedArray <string> la = new KeyedArray <string>(); // Save the likes of the Simpsons' kids. string bartlike = "shorts"; la["Bart"] = bartlike; la["Lisa"] = "sax"; la["Maggie"] = "dummy"; // Look up the age of Lisa. Console.WriteLine("Let's find Bart's like"); string like = la["Bart"]; Console.WriteLine("Bart likes {0}", like); // Replace Bart's age with a new value (Bart already in list). var who = "Lisa"; la[who] = "Democracy"; Console.WriteLine("{0} also likes {1}", who, la[who]); // Account Numbers var avAccTag = "Account"; var avIndTag = "Person"; Console.WriteLine("\nhit Spacebar for menu"); }
// HotTags to navigate each type of xml static void Main(string[] args) { // Set up new merge profile MergeProfile mp = new MergeProfile(); mp.SetState("new"); // Load the Primary xml (master) and the Secondary xml and csv with the to/from identifiers var directory = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); mp.filePrimary = Path.Combine(directory, "xmlValidate", @"SWI_US_AV.xml"); mp.fileSecondary = Path.Combine(directory, "xmlValidate", @"SWI_US_HP.xml"); mp.fileMapping = Path.Combine(directory, "xmlValidate", @"SWI_US_MapAvqFirst.csv"); mp.fileMerged = Path.Combine(directory, "xmlValidate", @"SWI_US_AV_Merged.xml"); mp.xPrimary = XDocument.Load(mp.filePrimary); mp.xSecondary = XDocument.Load(mp.fileSecondary); mp.mapPriToSec = new Dictionary <string, string>(); mp.mapSecToPri = new Dictionary <string, string>(); mp.fileType = "SWIUS"; //try //{ // dsMerge myds = new dsMerge(); // myds.Test(mp.filePrimary.ToString(), mp.fileSecondary.ToString()); //} //catch (Exception) //{ // throw; //} try { mp.ReadMappings(); } catch (Exception) { throw; } XDocument xmlLegacyOnlyAccs = new XDocument(); //xmlAvaloq.Save(mp.filePrimary); //xmlLegacy.Save(mp.fileSecondary); // Set up xml naigation name HotTag htSWIUS = new HotTag(); htSWIUS.tagReportingGroup = "ReportingGroup"; htSWIUS.tagAccBlock = "AccountReport"; htSWIUS.tagAccID = "AccountNumber"; htSWIUS.tagIndBlockowner = "AccountHolder"; htSWIUS.tagIndBlocksubowner = "SubstantialOwner"; htSWIUS.tagIndID = "TIN"; htSWIUS.tagAccBalance = "AccountBalance"; htSWIUS.tagAccBalCurrAtt = "currCode"; htSWIUS.tagOrganisation = "Organisation"; htSWIUS.tagIndividual = "Individual"; htSWIUS.tagPayment = "Payment"; htSWIUS.tagPayType = "Type"; htSWIUS.tagPayAmount = "PaymentAmnt"; htSWIUS.tagPayCurrAttr = "currCode"; // Read all the identifiers in both xmls try { mp.ReadIdentifiers(htSWIUS); } catch (Exception) { throw; } // Create a list of Secondary clients that exist in the Primary try { mp.AssessSecondaryClients(); } catch (Exception) { throw; } // Create Primary Client Blocks try { mp.MakeChunks(htSWIUS); } catch (Exception) { throw; } // Merge secondary chunks into Primary try { mp.MergeIntoPrimary(htSWIUS); } catch (Exception) { throw; } // Merge secondary chunks into Primary try { mp.SavedMergedFile(htSWIUS); Console.WriteLine("\n Merged Results Saved to {0}", mp.fileMerged); } catch (Exception) { throw; } // Create Secondary Client Blocks // Present Menu ShowMenu(); ConsoleKeyInfo cki; do { cki = Console.ReadKey(); string option = cki.Key.ToString().Tail(1); switch (option) { case "r": //SpaceBa[r] ShowMenu(); break; case "1": //Viewxml(xmlAvaloq, htSWIUS); Console.WriteLine(mp.xPrimary); Console.WriteLine("\nList of Accounts:\n"); foreach (string client in mp.priClientIds) { Console.WriteLine(client); } Console.WriteLine(" "); foreach (string person in mp.priPersonIds) { Console.WriteLine(person); } Console.WriteLine("\nhit Spacebar for menu"); break; case "2": //Viewxml(xmlLegacy,htSWIUS); Console.WriteLine(mp.xSecondary); Console.WriteLine("\nList of Accounts:\n"); foreach (string client in mp.secClientIds) { Console.WriteLine(client); } Console.WriteLine(" "); foreach (string person in mp.secPersonIds) { Console.WriteLine(person); } Console.WriteLine("\nhit Spacebar for menu"); break; case "3": ViewMapping(mp); break; case "4": ShowMatches(mp.xSecondary, htSWIUS, mp.mapSecToPri); break; default: break; } } while (cki.Key != ConsoleKey.Escape); }