public void LoadDependencies(string pattern, string[] objectTypes, bool isTopDown, EMatchMethod matchMethod, bool forceReload, MySqlDatabase[] searchDatabases) { //_inMemoryDatabase.Load(checkedDatabases, forceReload);\\ _recommendedDatabases.Clear(); //---------------- int objectId = 0; IEnumerable <MySqlObject> rootObjects; // Parent objects rootObjects = from o in _mySqlServer.SqlObjects.AsEnumerable() where ( string.IsNullOrEmpty(pattern) || ( matchMethod == EMatchMethod.StartsWith && o.ObjectName.StartsWith(pattern, StringComparison.InvariantCultureIgnoreCase) || matchMethod == EMatchMethod.EndsWith && o.ObjectName.EndsWith(pattern, StringComparison.InvariantCultureIgnoreCase) || matchMethod == EMatchMethod.Equals && o.ObjectName.Equals(pattern, StringComparison.InvariantCultureIgnoreCase) || matchMethod == EMatchMethod.Contains && o.ObjectName.ToUpper().Contains(pattern.ToUpper()) ) ) && ( objectTypes == null || (objectTypes != null && objectTypes.Contains(o.ObjectTypeId)) ) && ( searchDatabases == null || (searchDatabases != null && searchDatabases.Select(sdb => "[" + sdb.ServerObjectName + "].[" + sdb.DatabaseName + "]").Contains("[" + o.ServerObjectName + "].[" + o.DatabaseName + "]")) ) select o; // -- nonExisting var nonExistingRootObjects = from d in _mySqlServer.SqlExpressionDependencies.Where(dl => dl.ChildObjectExists == false) where ( string.IsNullOrEmpty(pattern) || ( matchMethod == EMatchMethod.StartsWith && d.ChildObjectName.StartsWith(pattern, StringComparison.InvariantCultureIgnoreCase) || matchMethod == EMatchMethod.EndsWith && d.ChildObjectName.EndsWith(pattern, StringComparison.InvariantCultureIgnoreCase) || matchMethod == EMatchMethod.Equals && d.ChildObjectName.Equals(pattern, StringComparison.InvariantCultureIgnoreCase) || matchMethod == EMatchMethod.Contains && d.ChildObjectName.ToUpper().Contains(pattern.ToUpper()) ) ) && ( searchDatabases == null || (searchDatabases != null && searchDatabases.Select(sdb => "[" + sdb.ServerObjectName + "].[" + sdb.DatabaseName + "]").Contains("[" + d.ChildServerObjectName + "].[" + d.ChildDatabaseName + "]")) ) select new MySqlObject { ServerObjectName = d.ChildServerObjectName, DatabaseName = d.ChildDatabaseName, SchemaName = d.ChildSchemaName, ObjectName = d.ChildObjectName, ServerObjectId = -1, DatabaseId = -1, SchemaId = -1, ObjectId = -1, ObjectNameFull = string.Format("[{0}].[{1}].[{2}].[{3}]", d.ChildServerObjectName, d.ChildDatabaseName, d.ChildSchemaName, d.ChildObjectName), ObjectTypeId = "UNRESOLVED_ENTITY", ObjectType = "UNRESOLVED_ENTITY" }; MySqlObjectEqualityComparer moec = new MySqlObjectEqualityComparer(); rootObjects = rootObjects.Union(nonExistingRootObjects.Distinct(moec)); /* * * * * if(string.IsNullOrEmpty(pattern)) * rootObjects = from o in _inMemoryDatabase.SqlObjectList.AsEnumerable() * select o; * else if (matchMethod == EMatchMethod.StartsWith) * rootObjects = from o in _inMemoryDatabase.SqlObjectList.AsEnumerable() * where o.ObjectName.StartsWith(pattern, StringComparison.InvariantCultureIgnoreCase) * select o; * else if (matchMethod == EMatchMethod.EndsWith) * rootObjects = from o in _inMemoryDatabase.SqlObjectList.AsEnumerable() * where o.ObjectName.EndsWith(pattern, StringComparison.InvariantCultureIgnoreCase) * select o; * else if (matchMethod == EMatchMethod.Equals) * rootObjects = from o in _inMemoryDatabase.SqlObjectList.AsEnumerable() * where o.ObjectName.Equals(pattern, StringComparison.InvariantCultureIgnoreCase) * select o; * else * rootObjects = from o in _inMemoryDatabase.SqlObjectList.AsEnumerable() * where o.ObjectName.ToUpper().Contains(pattern.ToUpper()) * select o; * * // Filter by object types * if (objectTypes != null) * rootObjects = rootObjects.Where(ro => objectTypes.Contains(ro.ObjectTypeId)); */ // var allowedStatus = new[]{ "A", "B", "C" }; // var filteredOrders = orders.Order.Where(o => allowedStatus.Contains(o.StatusCode)); MyOutput.NewMessage(EOutputMessageType.INFORMATION, string.Format("{0:n0} matching search objects found. ", rootObjects.Count())); if (rootObjects.Count() <= 50 || rootObjects.Count() > 50 && MessageBox.Show(string.Format("Large number of matching objects was found - {0}!{1}Searching dependencies may take a while.{1}Are you sure you want to continue?", rootObjects.Count(), Environment.NewLine), "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) == DialogResult.Yes) { DateTime dt = DateTime.Now; MyOutput.NewMessage(EOutputMessageType.PROGRESS, string.Format("Finding dependent objects...")); _dependencyObjectList.Clear(); loadDependentObjects(null, rootObjects.ToArray(), isTopDown, ref objectId, 0); AreDependenciesInitialized = true; MyOutput.AppendToLastMessage(EOutputMessageType.INFORMATION, string.Format("Done. {0:n0} dependent objects found.", _dependencyObjectList.Count(d => d.HierarchyLevel > 0)), (DateTime.Now - dt).TotalSeconds); } else { AreDependenciesInitialized = false; MyOutput.AppendToLastMessage(EOutputMessageType.WARNING, string.Format("Finding dependent objects cancelled.")); } }
public void newDependencyCheck(object sender, EventArgs e) { bool useWizard = sender.ToString().Contains("Wizard"); if (mySqlServer1.ConnectionPool.GetConnection(0).State == ConnectionState.Open && mySqlServer1.SqlCheckedDatabases.Any()) { NewDependencyCheckForm ndcf = null; NewDependencyCheckWizard ndcw = null; if (sender.ToString().Contains("Wizard")) { ndcw = new NewDependencyCheckWizard(mySqlServer1.SqlCheckedDatabases); } else { ndcf = new NewDependencyCheckForm(); } if ((!useWizard && ndcf.ShowDialog() == DialogResult.OK) || (useWizard && ndcw.ShowDialog() == DialogResult.OK)) { if (!LongRunningOperationManager.IsBusy) { do { LongRunningOperationManager.NewOperationBatch(true, true, new[] { new LongRunningOperation("Initializing objects and dependencies", 0.45), new LongRunningOperation("Searching for dependencies", 0.45), new LongRunningOperation("Drawing objects", 0.10) }); string[] objTypes = (useWizard) ? ndcw.ObjectTypes : null; string objName = (useWizard) ? ndcw.ObjectName : ndcf.ObjectName; bool topDown = (useWizard) ? ndcw.IsTopDownDiscovery : ndcf.IsTopDownDiscovery; EMatchMethod mm = (useWizard) ? ndcw.MatchMethod : EMatchMethod.Contains; bool forceInternalDbReload = (useWizard) ? ndcw.IsForceReload : false; string title = (useWizard) ? ndcw.SearchObjectFullDescription : ndcf.SearchObjectFullDescription; MySqlDatabase[] searchDbs = (useWizard) ? ndcw.SearchDatabases : null; BwObject bwo = new BwObject { CheckedDatabases = mySqlServer1.SqlCheckedDatabases, ObjectTypes = objTypes, ObjectName = objName, IsTopDownDiscovery = topDown, MatchMethod = mm, IsForceReload = forceInternalDbReload, SearchDatabases = searchDbs, SearchObjectFullDescription = title }; LongRunningOperationManager.DoWork += lrom_DoWorkViewDependencies; LongRunningOperationManager.WorkCompleted += lrom_ViewDependenciesCompleted; LongRunningOperationManager.RunAsync(bwo); }while (LongRunningOperationManager.ProcessResult != null && ((DependencyBackgroundWorkerResult)LongRunningOperationManager.ProcessResult).ResultType == EResultType.RERUN); } else { MessageBox.Show("Please wait for background process to finish."); } } } else { if (mySqlServer1.ConnectionPool.GetConnection(0).State != ConnectionState.Open) { MessageBox.Show("Please connect to SQL Server and then select at least one database from the list to search for dependencies.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop); } if (mySqlServer1.ConnectionPool.GetConnection(0).State == ConnectionState.Open && !mySqlServer1.SqlCheckedDatabases.Any()) { MessageBox.Show("Please select at least one database from the list to search for dependencies.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop); } } }
private void Form1_Load(object sender, EventArgs e) { cueComboBoxObjectName.Items.AddRange(AppSettings.Default.LastSearches.Split(';')); if (cueComboBoxObjectName.Items.Count > 0) { cueComboBoxObjectName.Text = cueComboBoxObjectName.Items[0].ToString(); } EMatchMethod mm = (EMatchMethod)Enum.Parse(typeof(EMatchMethod), AppSettings.Default.ObjectMatchMethod); switch (mm) { case EMatchMethod.Contains: radioButtonObjectNameContains.Checked = true; break; case EMatchMethod.StartsWith: radioButtonObjectNameStartsWith.Checked = true; break; case EMatchMethod.EndsWith: radioButtonObjectNameEndsWith.Checked = true; break; case EMatchMethod.Equals: radioButtonObjectNameEquals.Checked = true; break; } radioButtonSearchDirectionTopDown.Checked = AppSettings.Default.DependencySearchDirectionTopDown; radioButtonSearchDirectionBottomUp.Checked = !AppSettings.Default.DependencySearchDirectionTopDown; /* * * cbxDbObjectsForceReload.Checked = AppSettings.Default.ForceObjectAndDependencyReload; */ checkedListBoxObjectTypes.Items.Clear(); checkedListBoxObjectTypes.Items.Add("Aggregate function (CLR) [AF]", CheckState.Checked); checkedListBoxObjectTypes.Items.Add("Assembly (CLR) DML trigger [TA]", CheckState.Checked); checkedListBoxObjectTypes.Items.Add("Assembly (CLR) scalar-function [FS]", CheckState.Checked); checkedListBoxObjectTypes.Items.Add("Assembly (CLR) stored-procedure [PC]", CheckState.Checked); checkedListBoxObjectTypes.Items.Add("Assembly (CLR) table-valued function [FT]", CheckState.Checked); checkedListBoxObjectTypes.Items.Add("CHECK constraint [C]", CheckState.Checked); checkedListBoxObjectTypes.Items.Add("DEFAULT (constraint or stand-alone) [D]", CheckState.Checked); checkedListBoxObjectTypes.Items.Add("Extended stored procedure [X]", CheckState.Checked); checkedListBoxObjectTypes.Items.Add("External Table [ET]", CheckState.Checked); checkedListBoxObjectTypes.Items.Add("FOREIGN KEY constraint [F]", CheckState.Checked); checkedListBoxObjectTypes.Items.Add("Internal table [IT]", CheckState.Checked); checkedListBoxObjectTypes.Items.Add("Plan guide [PG]", CheckState.Checked); checkedListBoxObjectTypes.Items.Add("PRIMARY KEY constraint [PK]", CheckState.Checked); checkedListBoxObjectTypes.Items.Add("Replication-filter-procedure [RF]", CheckState.Checked); checkedListBoxObjectTypes.Items.Add("Rule (old-style, stand-alone) [R]", CheckState.Checked); checkedListBoxObjectTypes.Items.Add("Sequence object [SO]", CheckState.Checked); checkedListBoxObjectTypes.Items.Add("Service queue [SQ]", CheckState.Checked); checkedListBoxObjectTypes.Items.Add("SQL DML trigger [TR]", CheckState.Checked); checkedListBoxObjectTypes.Items.Add("SQL inline table-valued function [IF]", CheckState.Checked); checkedListBoxObjectTypes.Items.Add("SQL scalar function [FN]", CheckState.Checked); checkedListBoxObjectTypes.Items.Add("SQL Stored Procedure [P]", CheckState.Checked); checkedListBoxObjectTypes.Items.Add("SQL table-valued-function [TF]", CheckState.Checked); checkedListBoxObjectTypes.Items.Add("Synonym [SN]", CheckState.Checked); checkedListBoxObjectTypes.Items.Add("System base table [S]", CheckState.Checked); checkedListBoxObjectTypes.Items.Add("Table (user-defined) [U]", CheckState.Checked); checkedListBoxObjectTypes.Items.Add("Table type [TT]", CheckState.Checked); checkedListBoxObjectTypes.Items.Add("UNIQUE constraint [UQ]", CheckState.Checked); checkedListBoxObjectTypes.Items.Add("View [V]", CheckState.Checked); if (!string.IsNullOrEmpty(AppSettings.Default.LastObjectTypes)) { string[] objectTypez = AppSettings.Default.LastObjectTypes.Split(',').ToArray(); for (int i = 0; i < checkedListBoxObjectTypes.Items.Count; i++) { checkedListBoxObjectTypes.SetItemChecked(i, false); foreach (string objectType in objectTypez) { if (checkedListBoxObjectTypes.Items[i].ToString().Contains("[" + objectType + "]")) { checkedListBoxObjectTypes.SetItemChecked(i, true); break; } } } } // checkedListBoxDatabasesToSearch.Items.Clear(); foreach (var db in this._checkedSqlDatabases) { checkedListBoxDatabasesToSearch.Items.Add(db, true); } }