public ProfileItemViewModel(Profile profile) { _profile = profile; }
/// <summary> /// Compares the schema (currently, by using field names only) of the left and right profiles, /// and /// </summary> /// <param name="leftProfile"></param> /// <param name="rightProfile"></param> /// <param name="tableFoundDelegate">A delegate that is invoked whenever a table comparison has completed. Useful for tracking progress.</param> /// <returns>TableComparison objects that explain the differences found between both profiles.</returns> public static List<TableComparison> CompareSchema(Profile leftProfile, Profile rightProfile, Action<double, TableComparison> tableFoundDelegate) { List<TableComparison> tables = new List<TableComparison>(); DbConnection leftConnection = new DbConnection(leftProfile.Host, leftProfile.Port, leftProfile.UserName, leftProfile.Password, leftProfile.Schema); DbConnection rightConnection = new DbConnection(rightProfile.Host, rightProfile.Port, rightProfile.UserName, rightProfile.Password, rightProfile.Schema); if (leftConnection.Open()) { if (rightConnection.Open()) { List<string> leftTables = DbTableDescriptions.GetTables(leftConnection); List<string> rightTables = DbTableDescriptions.GetTables(rightConnection); int leftTableCount = leftTables.Count; int currentTableCount = 0; foreach (string leftTable in leftTables) { currentTableCount++; double progress = ((double)currentTableCount / (double)leftTableCount) * 100; // Look for this table in the collection of right tables if (!rightTables.Contains(leftTable)) { Table missingTable = new Table(leftTable); // Get the properties of this table List<TableProperty> missingProperties = DbTableDescriptions.GetFieldsForTable(leftTable, leftConnection); missingTable.Properties = missingProperties; missingTable.CreateStatement = DbTableDescriptions.GetCreateTableStatement(leftTable, leftConnection); TableComparison tableComp = new TableComparison(missingTable, null); // Use the supplied delegate to inform the consumer that we've found another table tableFoundDelegate(progress, tableComp); tables.Add(tableComp); } else { // Compare the properties of this table with those of the right table List<TableProperty> leftProperties = DbTableDescriptions.GetFieldsForTable(leftTable, leftConnection); List<TableProperty> rightProperties = DbTableDescriptions.GetFieldsForTable(leftTable, rightConnection); // Note: Not a typo. Using "leftTable" as a convenience, since they should be identical. List<TableProperty> leftMissingProperties = new List<TableProperty>(); List<TableProperty> rightMissingProperties = new List<TableProperty>(); // Search for properties in the left table that are missing from the right foreach (TableProperty prop in leftProperties) { bool propFound = false; foreach (TableProperty rightProp in rightProperties) { if (rightProp.Name == prop.Name) { propFound = true; } } if (!propFound) { leftMissingProperties.Add(prop); } } // Search for properties in the right table that are missing from the left foreach (TableProperty prop in rightProperties) { bool propFound = false; foreach (TableProperty leftProp in leftProperties) { if (leftProp.Name == prop.Name) { propFound = true; } } if (!propFound) { rightMissingProperties.Add(prop); } } if (leftMissingProperties.Count > 0 || rightMissingProperties.Count > 0) { TableComparison tableComp = new TableComparison(); if (leftMissingProperties.Count > 0) { Table tableWithMissingProps = new Table(leftTable); tableWithMissingProps.Properties = leftMissingProperties; tableComp.LeftTable = tableWithMissingProps; } if (rightMissingProperties.Count > 0) { Table tableWithMissingProps = new Table(leftTable); tableWithMissingProps.Properties = rightMissingProperties; tableComp.RightTable = tableWithMissingProps; } tables.Add(tableComp); tableFoundDelegate(progress, tableComp); } else { tableFoundDelegate(progress, null); } } } rightConnection.Close(); } else { throw new Exception("Right connection error."); } leftConnection.Close(); } else { throw new Exception("Left connection error."); } return tables; }
public ProfileItemViewModel() { _profile = new Profile("New profile", "", 3306, "", "", ""); }
public static List<Profile> getProfiles() { List<Profile> profiles = new List<Profile>(); // Parse the XML settings file to get the stored MySQL connection profiles // System.IO.Stream settingsFile = getSettingsFile(); string settingsFile = getSettingsFilePath(); XmlReader settingsReader = XmlReader.Create(settingsFile); settingsReader.MoveToContent(); while (settingsReader.Read()) { if (settingsReader.NodeType == XmlNodeType.Element) { if (String.Compare(settingsReader.Name, "Profile", true) == 0) { string Name = ""; string Host = ""; string Port = ""; string Username = ""; string Password = ""; string Schema = ""; // Get all the attributes for this profile while (settingsReader.MoveToNextAttribute()) { if (String.Compare(settingsReader.Name, "Name", true) == 0) { Name = settingsReader.Value; } else if (String.Compare(settingsReader.Name, "Host", true) == 0) { Host = settingsReader.Value; } else if (String.Compare(settingsReader.Name, "Port", true) == 0) { Port = settingsReader.Value; } else if (String.Compare(settingsReader.Name, "Username", true) == 0) { Username = settingsReader.Value; } else if (String.Compare(settingsReader.Name, "Password", true) == 0) { Password = settingsReader.Value; } else if (String.Compare(settingsReader.Name, "Schema", true) == 0) { Schema = settingsReader.Value; } } // All attributes are required, so only create the Profile object if we have all attributes if (Name != "" && Host != "" && Port != "" && Username != "" && Password != "" && Schema != "") { // TODO: Catch invalid int exception (FormatException?) int portNum = Int32.Parse(Port); Profile newProfile = new Profile(Name, Host, portNum, Username, Password, Schema); profiles.Add(newProfile); } } } } return profiles; }