private static bool Exists(TableName tname) { if (!tname.Exists()) { cout.WriteLine("table not found : {0}", tname); return(false); } return(true); }
public static string TableSchemaDifference(CompareSideType sideType, TableName tableName1, TableName tableName2) { string sql; if (tableName2.Exists()) { TableSchemaCompare compare = new TableSchemaCompare(tableName1, tableName2) { SideType = sideType }; sql = compare.Compare(); } else { sql = tableName1.GenerateCreateTableClause(appendGO: true); } return(sql); }
public static string DatabaseDifference(CompareSideType sideType, DatabaseName dname1, DatabaseName dname2, string[] excludedTables) { TableName[] names = dname1.GetDependencyTableNames(); excludedTables = excludedTables.Select(row => row.ToUpper()).ToArray(); StringBuilder builder = new StringBuilder(); foreach (TableName tableName in names) { TableName tname1 = tableName; TableName tname2 = new TableName(dname2, tableName.SchemaName, tableName.Name); TableSchema schema1 = new TableSchema(tname1); TableSchema schema2 = new TableSchema(tname2); cout.WriteLine(tname1.ShortName); if (excludedTables.Contains(tableName.ShortName.ToUpper())) { cout.WriteLine("skip to compare data on excluded table {0}", tableName.ShortName); continue; } if (schema1.PrimaryKeys.Length == 0) { cout.WriteLine("undefined primary key"); continue; } if (tname2.Exists()) { builder.Append(TableDifference(sideType, schema1, schema2, schema1.PrimaryKeys.Keys, new string[] { })); } else { builder.Append(Compare.GenerateRows(schema1, new TableReader(tname1))); } builder.AppendLine(); } return(builder.ToString()); }
public static string DatabaseDifference(CompareSideType sideType, DatabaseName dname1, DatabaseName dname2, string[] excludedTables) { TableName[] names = dname1.GetDependencyTableNames(); excludedTables = excludedTables.Select(row => row.ToUpper()).ToArray(); StringBuilder builder = new StringBuilder(); foreach (TableName tableName in names) { TableName tname1 = tableName; TableName tname2 = new TableName(dname2, tableName.SchemaName, tableName.Name); TableSchema schema1 = new TableSchema(tname1); TableSchema schema2 = new TableSchema(tname2); Console.WriteLine(tname1.ShortName); if (excludedTables.Contains(tableName.ShortName.ToUpper())) { Console.WriteLine("skip to compare data on excluded table {0}", tableName.ShortName); continue; } if (schema1.PrimaryKeys.Length == 0) { Console.WriteLine("undefined primary key"); continue; } if (tname2.Exists()) { builder.Append(TableDifference(sideType, schema1, schema2, schema1.PrimaryKeys.Keys, new string[] { })); } else { builder.Append(Compare.GenerateRows(schema1, new TableReader(tname1))); } builder.AppendLine(); } return builder.ToString(); }
private void ExtractStringList() { const string _File = "file"; const string _Line = "line"; const string _Col = "col"; const string _Type = "type"; const string _String = "string"; Dictionary <string, string> defaultColumns = new Dictionary <string, string> { [_File] = "File", [_Line] = "Line", [_Col] = "Col", [_Type] = "Type", [_String] = "String", }; string schema_name = cmd.GetValue("schema-name") ?? SchemaName.dbo; string table_name = cmd.GetValue("table-name"); bool allDirectories = cmd.Has("subdirectory"); string[] file_names = cmd.InputFiles(allDirectories); string[] excludes = cmd.Excludes; IDictionary <string, string> column_names = cmd.GetDictionary("column-names", defaultColumns); if (file_names == null) { cerr.WriteLine($"file name or directory is not defined, use option /in:file_name"); return; } if (file_names.Length == 0) { cerr.WriteLine($"file doesn't exist: \"{file_names}\""); return; } if (tname == null) { if (table_name == null) { cerr.WriteLine($"/table-name is not defined"); return; } if (dname == null) { cerr.WriteLine($"required to select a database"); return; } tname = new TableName(dname, schema_name, table_name); if (!tname.Exists()) { cerr.WriteLine($"table-name doesn't exist: {tname}"); return; } } DataTable dt = new TableReader(tname) { CaseSensitive = true, }.Table; StringDumper dumper = new StringDumper(tname) { Line = column_names[_Line], Column = column_names[_Col], Type = column_names[_Type], FileName = column_names[_File], Value = column_names[_String], }; dumper.Initialize(); StringExtractor extractor = new StringExtractor(dumper); if (!ValidateColumn <int>(dt, dumper.Line, "column-name", required: true)) { return; } if (!ValidateColumn <int>(dt, dumper.Column, "column-name", required: true)) { return; } if (!ValidateColumn <string>(dt, dumper.FileName, "column-name", required: false)) { return; } if (!ValidateColumn <string>(dt, dumper.Type, "column-name", required: false)) { return; } if (!ValidateColumn <string>(dt, dumper.Value, "column-name", required: false)) { return; } foreach (string file in file_names) { if (file.IsMatch(excludes)) { Console.WriteLine($"skip: {file}"); continue; } if (file.EndsWith("AssemblyInfo.cs")) { continue; } int count = extractor.Extract(file); if (count > 0) { cout.WriteLine($"{count} of strings were extracted in file: \"{file}\""); } else { cout.WriteLine($"no string found in file: \"{file}\""); } } bool commit = cmd.Has("submit-changes"); if (!commit) { return; } cout.WriteLine($"starting to save changes into table \"{tname}\""); try { TableWriter tableWriter = new TableWriter(tname); tableWriter.Save(dumper.Table); cout.WriteLine($"completed to save on table \"{tname}\" from \"{cmd.InputPath()}\""); } catch (Exception ex) { cerr.WriteLine($"failed to save in \"{tname}\" , {ex.AllMessages()}"); } }
private void ImportResourceData() { string file_name = cmd.InputPath(); ResourceFormat format = cmd.GetEnum("format", ResourceFormat.resx); string schema_name = cmd.GetValue("schema-name") ?? SchemaName.dbo; string table_name = cmd.GetValue("table-name"); string name_column = cmd.GetValue("name-column") ?? "name"; string value_column = cmd.GetValue("value-column") ?? name_column; string order_column = cmd.GetValue("order-column"); bool trim_name = cmd.Has("trim-name"); bool trim_value = cmd.Has("trim-value"); bool deleteRowNotInResource = cmd.Has("delete-rows-not-in-resource-file"); if (file_name == null) { cerr.WriteLine($"file name is not defined, use option /in:file_name"); return; } if (!File.Exists(file_name)) { cerr.WriteLine($"file doesn't exist: \"{file_name}\""); return; } if (tname == null) { if (table_name == null) { cerr.WriteLine($"/table-name is not defined"); return; } if (dname == null) { cerr.WriteLine($"required to select a database"); return; } tname = new TableName(dname, schema_name, table_name); if (!tname.Exists()) { cerr.WriteLine($"table-name doesn't exist: {tname}"); return; } } DataTable dt = new TableReader(tname) { CaseSensitive = true, }.Table; if (!ValidateColumn <string>(dt, name_column, "name-column", required: true)) { return; } if (!ValidateColumn <string>(dt, value_column, "value-column", required: true)) { return; } if (!ValidateColumn <int>(dt, order_column, "order-column", required: false)) { return; } cout.WriteLine($"{dt.Rows.Count} of entries on \"{file_name}\""); ResourceTableWriter writer = new ResourceTableWriter(file_name, tname, name_column, value_column, order_column); List <ResourceEntry> entries = writer.Differ(format, dt, trim_name, trim_value); foreach (var entry in entries) { switch (entry.Action) { case DataRowAction.Add: cout.WriteLine($"new entry: \"{entry.Name}\", \"{entry.NewValue}\""); break; case DataRowAction.Change: cout.WriteLine($"update entry: \"{entry.Name}\", \"{entry.OldValue}\" -> \"{entry.NewValue}\""); break; case DataRowAction.Delete: cout.WriteLine($"delete entry: \"{entry.Name}\""); break; } } if (entries.Count > 0) { cout.WriteLine($"{entries.Count} of entries were changed"); } else { cout.WriteLine($"no entry is changed"); } if (entries.Count == 0) { return; } bool commit = cmd.Has("submit-changes"); if (!commit) { return; } cout.WriteLine($"starting to save changes into table \"{tname}\""); try { writer.SubmitChanges(entries, deleteRowNotInResource); cout.WriteLine($"completed to save on table \"{tname}\" from \"{file_name}\""); } catch (Exception ex) { cerr.WriteLine($"failed to save in \"{tname}\" , {ex.AllMessages()}"); } }
private static bool Exists(TableName tname) { if (!tname.Exists()) { stdio.WriteLine("table not found : {0}", tname); return false; } return true; }
public static string TableSchemaDifference(CompareSideType sideType, TableName tableName1, TableName tableName2) { string sql; if (tableName2.Exists()) { TableSchemaCompare compare = new TableSchemaCompare(tableName1, tableName2) { SideType = sideType }; sql = compare.Compare(); } else { sql = tableName1.GenerateCluase(); } return sql; }