private void CanonicalizeItem(RawDataItem item) { /* for conanoicalization we really only care about the ordering of related rows remains consistent */ foreach (var relatedTable in item.RelatedTables) { relatedTable.Rows = relatedTable.Rows.OrderBy(i => i.GetHashCode()).ToList(); } }
public RawDataItem DataItemFromReader(DataTable dataTable, OracleDataReader reader) { RawDataItem item = new RawDataItem(); object[] vals = new object[dataTable.Rows.Count]; int foo = reader.GetValues(vals); for (var x = 0; x < dataTable.Rows.Count; x++) { var columnName = dataTable.Rows[x].ItemArray[0]; item.Fields.Add(columnName.ToString(), vals[x]); } return(item); }
private ChangedItem SaveRawDataItem(string path, string pattern, RawDataItem item) { /* build out file name */ Regex placeHolder = new Regex("{([^}]+)}"); var filePath = path + Path.DirectorySeparatorChar + pattern; var matches = placeHolder.Matches(filePath); string invalid = new string(Path.GetInvalidFileNameChars()); foreach (Match m in matches) { var col = m.Groups[1].Value; var colValue = item.Fields[col].ToString(); foreach (char c in invalid) { colValue = colValue.Replace(c.ToString(), "_"); } filePath = filePath.Replace("{" + col + "}", colValue); } string oprID; if (item.Fields.ContainsKey("LASTUPDOPRID")) { oprID = item.Fields["LASTUPDOPRID"].ToString(); } else { oprID = "RAWDATA"; } Directory.CreateDirectory(Path.GetDirectoryName(filePath)); CanonicalizeItem(item); File.WriteAllText(filePath, JsonConvert.SerializeObject(item, Formatting.Indented)); return(new ChangedItem(filePath, oprID)); }
public void LoadRelatedTables(List <string> relatedKeys, List <string> relatedTables, RawDataItem topLevelItem) { /* build the where clause for the selects */ StringBuilder sb = new StringBuilder(); sb.Append("WHERE "); for (var x = 1; x <= relatedKeys.Count; x++) { sb.Append(relatedKeys[x - 1]).Append(" = :").Append(x); if (x < relatedKeys.Count) { sb.Append(" AND "); } } var whereClause = sb.ToString(); sb.Clear(); foreach (string relatedTable in relatedTables) { using (var secondaryLevel = new OracleCommand($"SELECT * FROM {relatedTable} {whereClause}", _conn)) { RawDataRelatedTable relatedTableData = new RawDataRelatedTable(); relatedTableData.TableName = relatedTable; /* setup the parameters */ foreach (string relatedKey in relatedKeys) { secondaryLevel.Parameters.Add(new OracleParameter() { Value = topLevelItem.Fields[relatedKey] }); } using (var reader = secondaryLevel.ExecuteReader()) { var dataTable = reader.GetSchemaTable(); while (reader.Read()) { var rawItem = DataItemFromReader(dataTable, reader); relatedTableData.Rows.Add(rawItem); } } if (relatedTableData.Rows.Count > 0) { topLevelItem.RelatedTables.Add(relatedTableData); } } } }