private static bool ValidateSource(Guid expectedValue, DataRowInfo row) { var source = Convert.ToString(row["source"]); try { return(expectedValue == new Guid(source)); } catch { return(false); } }
private bool Equals(DataRowInfo other) { if (this.Values.Length != other.Values.Length) { return(false); } for (int i = 0; i < this.Values.Length; i++) { if (AreObjectsEqual(this.Values[i], other.Values[i])) { return(false); } } return(true); }
private void WarnCantInsertRow(DataRowInfo row) { var sb = new StringBuilder("Can't create command to insert row with values [\"", 100); sb.Append(row.Values[0]); for (int i = 1; i < Math.Min(row.Values.Length, 4); i++) { sb.AppendFormat(", {0}", row.Values[i]); } if (row.Values.Length > 5) { sb.Append(", ..."); } sb.AppendFormat("\"] into table {0}", row.TableName); InvokeWarning(sb.ToString()); }
private static bool ResolveRelation(DataRowInfo row, params int[] matchingTypes) { var entityType = Convert.ToInt32(row["entity_type"]); return(matchingTypes.Contains(entityType)); }
protected override bool TryPrepareRow(bool dump, DbConnection connection, ColumnMapper columnMapper, TableInfo table, DataRowInfo row, out Dictionary <string, object> preparedRow) { if (table.Name == "mail_mailbox") { var boxType = row["is_server_mailbox"]; if (boxType != null && Convert.ToBoolean(int.Parse(boxType.ToString()))) { preparedRow = null; return(false); } } return(base.TryPrepareRow(dump, connection, columnMapper, table, row, out preparedRow)); }
protected virtual bool TryPrepareRow(bool dump, DbConnection connection, ColumnMapper columnMapper, TableInfo table, DataRowInfo row, out Dictionary <string, object> preparedRow) { preparedRow = new Dictionary <string, object>(); var parentRelations = TableRelations .Where(x => x.FitsForRow(row) && x.Importance != RelationImportance.Low) .GroupBy(x => x.ChildColumn) .ToDictionary(x => x.Key); foreach (var columnName in row.ColumnNames) { if (table.IdType == IdType.Autoincrement && columnName.Equals(table.IdColumn, StringComparison.OrdinalIgnoreCase)) { continue; } var val = row[columnName]; if (!parentRelations.ContainsKey(columnName)) { if (!TryPrepareValue(connection, columnMapper, table, columnName, ref val)) { return(false); } } else { if (!TryPrepareValue(dump, connection, columnMapper, table, columnName, parentRelations[columnName], ref val)) { return(false); } if (!table.HasIdColumn() && !table.HasTenantColumn() && val == row[columnName]) { return(false); } } preparedRow.Add(columnName, val); } return(true); }
public DbCommand CreateInsertCommand(bool dump, DbConnection connection, ColumnMapper columnMapper, TableInfo table, DataRowInfo row) { if (table.InsertMethod == InsertMethod.None) { return(null); } Dictionary <string, object> valuesForInsert; if (!TryPrepareRow(dump, connection, columnMapper, table, row, out valuesForInsert)) { return(null); } var columns = valuesForInsert.Keys.Intersect(table.Columns).ToArray(); var insertCommantText = string.Format("{0} into {1}({2}) values({3});", table.InsertMethod != InsertMethod.Ignore ? table.InsertMethod.ToString().ToLower() : "insert ignore", table.Name, string.Join(",", columns), string.Join(",", columns.Select(c => "@" + c))); var command = connection.CreateCommand(); command.CommandText = insertCommantText; foreach (var parameter in valuesForInsert) { AddParameter(command, parameter.Key, parameter.Value); } return(command); }
protected override bool TryPrepareRow(bool dump, DbConnection connection, ColumnMapper columnMapper, TableInfo table, DataRowInfo row, out Dictionary <string, object> preparedRow) { if (table.Name == "tenants_tenants" && string.IsNullOrEmpty(Convert.ToString(row["payment_id"]))) { var oldTenantID = Convert.ToInt32(row["id"]); columnMapper.SetMapping("tenants_tenants", "payment_id", row["payment_id"], Core.CoreContext.Configuration.GetKey(oldTenantID)); } return(base.TryPrepareRow(dump, connection, columnMapper, table, row, out preparedRow)); }
protected override bool TryPrepareRow(bool dump, DbConnection connection, ColumnMapper columnMapper, TableInfo table, DataRowInfo row, out Dictionary <string, object> preparedRow) { if (row.TableName == "files_thirdparty_id_mapping") { //todo: think... preparedRow = new Dictionary <string, object>(); object folderId = null; var sboxId = Regex.Replace(row[1].ToString(), @"(?<=(?:sbox-|box-|dropbox-|spoint-|drive-|onedrive-))\d+", match => { folderId = columnMapper.GetMapping("files_thirdparty_account", "id", match.Value); return(Convert.ToString(folderId)); }, RegexOptions.Compiled); if (folderId == null) { return(false); } var hashBytes = MD5.Create().ComputeHash(Encoding.UTF8.GetBytes(sboxId)); var hashedId = BitConverter.ToString(hashBytes).Replace("-", "").ToLower(); preparedRow.Add("hash_id", hashedId); preparedRow.Add("id", sboxId); preparedRow.Add("tenant_id", columnMapper.GetTenantMapping()); columnMapper.SetMapping("files_thirdparty_id_mapping", "hash_id", row["hash_id"], hashedId); return(true); } return(base.TryPrepareRow(dump, connection, columnMapper, table, row, out preparedRow)); }
protected override bool TryPrepareRow(bool dump, DbConnection connection, ColumnMapper columnMapper, TableInfo table, DataRowInfo row, out Dictionary <string, object> preparedRow) { if (table.Name == "core_acl") { if (int.Parse((string)row["tenant"]) == -1) { preparedRow = null; return(false); } } return(base.TryPrepareRow(dump, connection, columnMapper, table, row, out preparedRow)); }
private void WarnCantInsertRow(DataRowInfo row) { InvokeWarning(string.Format("Can't create command to insert row with values [{0}]", row)); }
public IDbCommand CreateInsertCommand(IDbConnection connection, ColumnMapper columnMapper, TableInfo table, DataRowInfo row) { if (table.InsertMethod == InsertMethod.None) { return(null); } Dictionary <string, object> valuesForInsert; if (!TryPrepareRow(connection, columnMapper, table, row, out valuesForInsert)) { return(null); } var insertCommantText = string.Format("{0} into {1}({2}) values({3});", table.InsertMethod != InsertMethod.Ignore ? table.InsertMethod.ToString().ToLower() : "insert ignore", table.Name, string.Join(",", valuesForInsert.Keys), string.Join(",", valuesForInsert.Keys.Select(x => "@" + x))); IDbCommand command = connection.CreateCommand(insertCommantText); foreach (var parameter in valuesForInsert) { command.AddParameter(parameter.Key, parameter.Value); } return(command); }