/* * This reconciliation is done between different schema table */ public static ReconcileResult CustomReconcile(DataTable tbl1, DataTable tbl2, string table1_header, string table2_header, Dictionary <string, string> dictKey, Dictionary <string, string> dictCompareColumns, Dictionary <string, string> dictAmbigousSortKey, BaseReconcile reconcileMethod = null) { ReconcileResult result = new ReconcileResult(table1_header, table2_header); if (reconcileMethod == null) { reconcileMethod = new BaseReconcile(); } Dictionary <string, string> dictDuplicatesKey = new Dictionary <string, string>(Math.Max(tbl1.Rows.Count, tbl2.Rows.Count)); string strSortKeyTbl1 = GetSortString(dictKey.Keys.ToList()); List <string> lstKey2 = new List <string>(); foreach (string k in dictKey.Keys) { lstKey2.Add(dictKey[k]); } string strSortKeyTbl2 = GetSortString(lstKey2); tbl1.DefaultView.Sort = strSortKeyTbl1; tbl2.DefaultView.Sort = strSortKeyTbl2; foreach (DataRow r1 in tbl1.Rows) { string tbl1_key = GetFilterString(r1, dictKey.Keys.ToList()); if (dictDuplicatesKey.ContainsKey(tbl1_key)) { continue; } string tbl2_key = GetCounterpartFilterString(r1, dictKey, true); DataRow[] rows = tbl2.Select(tbl2_key); if (rows == null || rows.Length == 0) { result.Add(tbl1_key, null, r1, null, null); } else { if (rows.Length > 1) { lock (dictDuplicatesKey) { if (dictDuplicatesKey.ContainsKey(tbl1_key) == false) { dictDuplicatesKey.Add(tbl1_key, tbl2_key); } } } else { DataRow r2 = rows[0]; reconcileMethod.Reconcile(result, r1, r2, tbl1_key, table1_header, table2_header, dictKey, dictCompareColumns); } } } int i = 0; foreach (DataRow r2 in tbl2.Rows) { i++; string tbl1_key = GetCounterpartFilterString(r2, dictKey, false); if (dictDuplicatesKey.ContainsKey(tbl1_key)) { continue; } string tbl2_key = GetFilterString(r2, dictKey.Values.ToList()); DataRow[] rows = tbl1.Select(tbl1_key); if (rows == null || rows.Length == 0) { result.Add(tbl1_key, null, null, r2, null); } else if (rows.Length > 1) { lock (dictDuplicatesKey) { if (dictDuplicatesKey.ContainsKey(tbl1_key) == false) { dictDuplicatesKey.Add(tbl1_key, tbl2_key); } } } } foreach (string key in dictDuplicatesKey.Keys) { Console.WriteLine("Duplicate in " + key); reconcileCustomDuplicates(key, dictDuplicatesKey[key], result, dictCompareColumns, dictAmbigousSortKey, tbl1, tbl2, reconcileMethod); } return(result); }
private static void reconcileCustomDuplicates(string tbl1_key, string tbl2_key, ReconcileResult result, Dictionary <string, string> dictCompareColumns, Dictionary <string, string> dictAmbigousSortKey, DataTable tbl1, DataTable tbl2, BaseReconcile reconcileMethod) { StringBuilder strBufTbl1 = new StringBuilder(); StringBuilder strBufTbl2 = new StringBuilder(); foreach (string i in dictAmbigousSortKey.Keys) { if (strBufTbl1.Length > 0) { strBufTbl1.Append(" , "); strBufTbl2.Append(" , "); } strBufTbl1.Append(i); strBufTbl2.Append(dictAmbigousSortKey[i]); } DataView dv1 = new DataView(tbl1, tbl1_key, strBufTbl1.ToString(), DataViewRowState.CurrentRows); DataView dv2 = new DataView(tbl2, tbl2_key, strBufTbl2.ToString(), DataViewRowState.CurrentRows); if (dv1.Count != dv2.Count) { Console.WriteLine("Count mismatch in" + tbl1_key); Console.WriteLine("Table1:" + dv1.Count + "\tTable2:" + dv2.Count); result.AddCountMismatch(tbl1_key, new DataColumn("Different Count"), dv1.Count, dv2.Count); } else { for (int i = 0; i < dv1.Count; i++) { DataRow r1 = dv1[i].Row; DataRow r2 = dv2[i].Row; foreach (string tbl1_column_name in dictCompareColumns.Keys) { reconcileMethod.simpleMatching(result, r1, r2, tbl1_column_name, dictCompareColumns[tbl1_column_name], tbl1_key); } } } }
public static ReconcileResult CustomReconcileCSV(string csvFilename1, string csvFilename2, bool headerExist1, bool headerExist2, string table1_header, string table2_header, Dictionary <string, string> dictKey, Dictionary <string, string> dictCompareColumns, Dictionary <string, string> dictAmbigousSortKey, BaseReconcile reconcileMethod = null, string schema_ini_file = null) { DataTable tbl1 = null; DataTable tbl2 = null; Task t1 = Task.Factory.StartNew(() => { tbl1 = GetDataTableFromCSV(csvFilename1, headerExist1, schema_ini_file); }); Task t2 = Task.Factory.StartNew(() => { tbl2 = GetDataTableFromCSV(csvFilename2, headerExist2, schema_ini_file); }); Task.WaitAll(new Task[] { t1, t2 }); ReconcileResult result = CustomReconcile(tbl1, tbl2, table1_header, table2_header, dictKey, dictCompareColumns, dictAmbigousSortKey, reconcileMethod); tbl1.Clear(); tbl1 = null; tbl2.Clear(); tbl2 = null; return(result); }