public void SetObject(MySqlObject mo, IEnumerable <MySqlObject> childrenObjects) { this.Enabled = mo != null; if (mo != null) { richTextBox1.Rtf = mo.Rtf; MySqlObjectEqualityComparer moec = new MySqlObjectEqualityComparer(); var resultAll = from o in childrenObjects group o.SystemId by o.ObjectType into g orderby g.Key ascending select new { ObjectType = g.Key, ObjectCount = g.Count() }; var resultUnique = from o in childrenObjects.Distinct(moec) group o.SystemId by o.ObjectType into g orderby g.Key ascending select new { ObjectType = g.Key, UniqueObjectCount = g.Count() }; var result = from r1 in resultAll join r2 in resultUnique on r1.ObjectType equals r2.ObjectType select new { r1.ObjectType, r1.ObjectCount, r2.UniqueObjectCount }; var totals = from r in result select new { ObjectType = totalString, ObjectCount = result.Sum(r1 => r1.ObjectCount), UniqueObjectCount = result.Sum(r2 => r2.UniqueObjectCount) }; objectListView1.SetObjects(result.Union(totals)); tsslObjectCount.Text = string.Format("{0} objects, {1} unique", result.Sum(r1 => r1.ObjectCount), result.Sum(r2 => r2.UniqueObjectCount)); } else { this.richTextBox1.Text = AppSettings.Default.NoObjectSelectedDefaultText; objectListView1.ClearObjects(); } }
public void SetObject(object obj, IEnumerable <MySqlObject> childrenObjects, string titlePropertyName, bool allowEdit = false) { this._object = obj; this._allowEdit = allowEdit; this.Enabled = obj != null; //string title = obj.GetType().GetProperty(titlePropertyName).GetValue(obj, null).ToString(); if (obj != null) { string title; if (obj.GetType().GetProperty("Rtf") != null) { title = obj.GetType().GetProperty("Rtf").GetValue(obj, null).ToString(); richTextBox1.Rtf = string.Format("{0}", title); } else { try { var t = obj.GetType(); var p = t.GetProperty(titlePropertyName); var v = p.GetValue(obj, null); var s = v.ToString(); title = s; richTextBox1.Text = string.Format("{0}", title); } catch { richTextBox1.Text = titlePropertyName; } } } else { this.richTextBox1.Text = AppSettings.Default.NoObjectSelectedDefaultText; } // Set TotalTableRowCount if (obj != null) { PropertyInfo propertyInfo = obj.GetType().GetProperty("UnderlyingTableCount"); if (propertyInfo != null && childrenObjects != null) { try { MySqlObjectEqualityComparer moec = new MySqlObjectEqualityComparer(); Int64 val = childrenObjects.Where(co => co.ObjectType.Equals("USER_TABLE")).Distinct(moec).Count(); propertyInfo.SetValue(obj, val, null); } catch (Exception ex) { propertyInfo.SetValue(obj, Convert.ChangeType(ex.Message, propertyInfo.PropertyType), null); } } propertyInfo = obj.GetType().GetProperty("UnderlyingTableRowCount"); if (propertyInfo != null && childrenObjects != null) { try { MySqlObjectEqualityComparer moec = new MySqlObjectEqualityComparer(); var uniqueUserTables = childrenObjects.Where(co => co.ObjectType.Equals("USER_TABLE")).Distinct(moec); var totalTableRowCount = uniqueUserTables.Select(co => co.RowCount).Sum(); //var val = string.Format("{0:n0} ({1:n0} tables)", totalTableRowCount, uniqueUserTables.Count()); propertyInfo.SetValue(obj, totalTableRowCount, null); } catch (Exception ex) { propertyInfo.SetValue(obj, Convert.ChangeType(ex.Message, propertyInfo.PropertyType), null); } } } propertyGrid1.SelectedObject = obj; }
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.")); } }