public void SimpleValueTests() { Set<int> empty = new Set<int>(); Set<int> a = new Set<int>(1, 2, 3); Set<int> b = new Set<int>(3, 4, 5); Set<int> a_and_b = a + b; Assert.AreEqual("{}", empty.ToString()); Assert.AreEqual("{ 1, 2, 3 }", a.ToString()); Assert.AreEqual("{ 3, 4, 5 }", b.ToString()); Assert.AreEqual("{ 1, 2, 3, 4, 5 }", a_and_b.ToString()); Assert.AreEqual("{}", (empty * a).ToString()); Assert.AreEqual("{}", (a * empty).ToString()); Assert.IsTrue(a_and_b * a == a); Assert.IsTrue((a_and_b * a).Equals(a)); Assert.IsTrue(a_and_b - a == new Set<int>(4, 5)); Assert.IsTrue(a - a == new Set<int>()); Assert.IsTrue(a * a == a); Assert.IsTrue(a.IsSubsetOf(a_and_b)); Assert.IsTrue(b.IsSubsetOf(a_and_b)); Assert.IsTrue(a_and_b.IsSubsetOf(a_and_b)); Assert.IsTrue(a.IsSubsetOf(a)); Assert.IsTrue(b.IsSubsetOf(b)); Assert.IsFalse(a.IsSubsetOf(b)); Assert.IsFalse(b.IsSubsetOf(a)); Assert.IsFalse(a_and_b.IsSubsetOf(a)); Assert.IsFalse(a_and_b.IsSubsetOf(b)); Set<int> a_copy = a.Copy(); Set<int> b_copy = b.Copy(); a.UnionUpdate(b); Assert.AreEqual(a, a_and_b); a.DifferenceUpdate(b); Assert.AreEqual(a, a_and_b - b); a.UnionUpdate(9); Assert.AreEqual(a, (a_and_b - b) + new Set<int>(9)); a.DifferenceUpdate(1); Assert.AreEqual(a, (a_and_b - b) + new Set<int>(9) - new Set<int>(1)); a_copy.IntersectionUpdate(b_copy); Assert.AreEqual(new Set<int>(3), a_copy); }
ForeignKeyConstraint FindConstraint(string tableName, params string[] columnNames) { Table table = _database.TablesByShortName[tableName]; Set<Column> columns = new Set<Column>(); foreach (string columnName in columnNames) { columns.UnionUpdate(table.Columns[columnName]); } foreach (ForeignKeyConstraint constraint in table.ForeignKeyConstraints) { if (new Set<Column>(constraint.KeyColumns).Equals(columns)) return constraint; } throw new KeyNotFoundException(string.Format( "The table \"{0}\" does not have a constraint with the specified key columns ({1}).", tableName, NaturalStrings.FormatList(columnNames))); }
internal static void CompareInCurrentDirectory() { List<Database> databases = LoadDatabasesInCurrentDirectory(); // Find which tables are common to all databases: Set<ObjectName> allTables = new Set<ObjectName>(); Set<ObjectName> commonTables = new Set<ObjectName>(); if (databases.Count > 0) commonTables.UnionUpdate(databases[0].TablesByName.Keys); foreach (Database database in databases) { Set<ObjectName> tablesInThisDatabase = new Set<ObjectName>(database.TablesByName.Keys); allTables.UnionUpdate(tablesInThisDatabase); commonTables.IntersectionUpdate(tablesInThisDatabase); } Set<ObjectName> nonCommonTables = Set<ObjectName>.Difference(allTables, commonTables); Console.WriteLine(nonCommonTables); // Find which columns are common to all databases: foreach (ObjectName commonTableName in commonTables) { Set<string> allColumns = new Set<string>(); Set<string> commonColumns = new Set<string>(); if (databases.Count > 0) { Set<string> columns = new Set<string>(databases[0].TablesByName[commonTableName].Columns.Keys); commonColumns.UnionUpdate(columns.Map<string>(NormaliseColumnName)); } foreach (Database database in databases) { Set<string> columnsInThisTable = new Set<string>(database.TablesByName[commonTableName].Columns.Keys).Map<string>(NormaliseColumnName); commonColumns.IntersectionUpdate(columnsInThisTable); allColumns.UnionUpdate(columnsInThisTable); } Set<string> nonCommonColumns = Set<string>.Difference(allColumns, commonColumns); if (nonCommonColumns.Count > 0) { Console.WriteLine(commonTableName.Name); Console.WriteLine(nonCommonColumns); } } }
public static void CreateFilteredDependenciesGraph(Database database, Table startTable, Plan plan) { Set<Table> visited = new Set<Table>(); Stack<Table> seen = new Stack<Table>(); seen.Push(startTable); // The relations that, as a precondition of the delete, must not exist: while (seen.Count > 0) { Table table = seen.Pop(); visited.UnionUpdate(table); foreach (ForeignKeyConstraint constraint in table.ForeignKeyDependencies) { if (plan.IsConstraintExcludedFromDependencyDiagram(constraint)) continue; if (!visited.Contains(constraint.Table)) { seen.Push(constraint.Table); } } } CreateDependenciesGraph(database, visited); }
void PopulateNoTagsSet() { _noEndTags = new Set<string>(); _noEndTags.UnionUpdate("img"); _noEndTags.UnionUpdate("br"); }
void CheckNames(Protocol protocol) { Set<string> usedDeclarationNames = new Set<string>(); foreach (Declaration declaration in protocol.Declarations) { if (usedDeclarationNames.Contains(declaration.Identifier)) { throw new SemanticException(string.Format("The name \"{0}\" is used in more than one declaration.", declaration.Identifier)); } usedDeclarationNames.UnionUpdate(declaration.Identifier); Set<string> usedMemberNames = new Set<string>(); foreach (DeclarationMember member in declaration.MemberBases) { if (usedMemberNames.Contains(member.Identifier)) { throw new SemanticException(string.Format( "The name \"{0}\" in the declaration \"{1}\" is used in more " + " than once within the declaration.", member.Identifier, declaration.Identifier)); } } } }
static void CodePatchMain(string[] args) { DatabaseConnectionString connectionString = new DatabaseConnectionString(); connectionString.ServerName = "SERVER14"; connectionString.DatabaseName = "RMTSv2"; connectionString.UseIntegratedAuthentication = false; connectionString.Username = "******"; connectionString.Password = "******"; Database database; using (SqlConnection connection = new SqlConnection(connectionString.ToString())) { connection.Open(); database = Database.FromConnection(connection); } Dictionary<string, string> fieldMappings = GetColumnTypeMappings(database); Dictionary<string, string> functionMap = new Dictionary<string,string>(); functionMap["char"] = "FieldCasts.FromChar"; functionMap["nvarchar"] = "FieldCasts.FromNVarChar"; functionMap["nchar"] = "FieldCasts.FromNChar"; functionMap["float"] = "FieldCasts.FromFloat"; functionMap["real"] = "FieldCasts.FromReal"; functionMap["datetime"] = "FieldCasts.FromDateTime"; functionMap["bit"] = "FieldCasts.FromBit"; functionMap["varchar"] = "FieldCasts.FromVarChar"; functionMap["text"] = "FieldCasts.FromText"; functionMap["ntext"] = "FieldCasts.FromNText"; functionMap["numeric"] = "FieldCasts.FromNumeric"; functionMap["int"] = "FieldCasts.FromInt"; functionMap["image"] = "FieldCasts.FromImage"; functionMap["varbinary"] = "FieldCasts.FromVarBinary"; functionMap["smallint"] = "FieldCasts.FromSmallInt"; functionMap["tinyint"] = "FieldCasts.FromTinyInt"; DirectoryInfo info = new DirectoryInfo(@"C:\Versioning\Haulage"); FileInfo[] files = info.GetFiles("*.vb", SearchOption.AllDirectories); Set<string> unknownFields = new Set<string>(); foreach (FileInfo file in files) { using (StreamReader reader = new StreamReader(file.FullName)) { string entireFile = reader.ReadToEnd(); _fields.Replace(entireFile, (MatchEvaluator)delegate(Match match) { Console.WriteLine(match.Value); string characterBeforeIdentifier = match.Groups[1].Value; string recordSetIdentifier = match.Groups[2].Value; string fieldName = match.Groups[3].Value; string converterName = "FieldCasts.Identity"; if (fieldMappings.ContainsKey(fieldName.ToLower())) { string fieldType = fieldMappings[fieldName.ToLower()]; converterName = functionMap[fieldType]; } else { unknownFields.UnionUpdate(fieldName.ToLower()); } string replacementText = string.Format("{0}{1}({2}.Fields(\"{3}\").Value)", characterBeforeIdentifier, converterName, recordSetIdentifier, fieldName); Console.WriteLine(" " + replacementText); return replacementText; }); } } }
static Dictionary<string, string> GetColumnTypeMappings(Database database) { Dictionary<string, string> fieldMappings = new Dictionary<string, string>(); Set<string> ambiguousMappings = new Set<string>(); foreach (Table table in database.Tables) { foreach (KeyValuePair<string, Column> pair in table.Columns) { string fieldNameLower = pair.Key.ToLower(); if (fieldMappings.ContainsKey(fieldNameLower)) { if (fieldMappings[fieldNameLower] != pair.Value.DataType) { ambiguousMappings.UnionUpdate(fieldNameLower); } } else { fieldMappings[fieldNameLower] = pair.Value.DataType; } } } foreach (string ambiguousMapping in ambiguousMappings) { fieldMappings.Remove(ambiguousMapping); } return fieldMappings; }