protected virtual void OnFieldDeleted(EventArgs e) { WriteLine(5, "Field Deleted"); FieldDeleted?.Invoke(this, e); }
public void DeleteIndexes() { var deleteIndexes = new List <IIndexInfo>(); foreach (var node in Indexes.Values) { bool used = false; foreach (var reverseEdge in node.ReverseEdges) { var sourceNode = reverseEdge.Source; foreach (var forwardEdge in sourceNode.Edges) { if (forwardEdge.Target == node && forwardEdge.Traversed) { used = true; break; } } if (used) { break; } } if (!used) { deleteIndexes.Add(node.Index); } } var deleteFields = new List <IFieldInfo>(); foreach (var node in Fields.Values) { bool used = false; foreach (var reverseEdge in node.ReverseEdges) { var sourceNode = reverseEdge.Source; foreach (var forwardEdge in sourceNode.Edges) { if (forwardEdge.Target == node && forwardEdge.Traversed) { used = true; break; } } if (used) { break; } } if (!used && node.Field.Tag != "%0") { deleteFields.Add(node.Field); } } var updateDatabases = new List <IAdlibDatabaseInfo>(); foreach (var indexInfo in deleteIndexes) { var databaseInfo = indexInfo.DatabaseInfo; using (DatabaseEngine databaseEngine = (DatabaseEngine)OpenDatabase(databaseInfo.PhysicalPath)) { databaseInfo.IndexList.Remove(indexInfo); databaseEngine.DeleteIndexTable(indexInfo); if (!updateDatabases.Contains(databaseInfo)) { updateDatabases.Add(databaseInfo); } IndexDeleted?.Invoke(this, new IndexDeletedEventArgs(indexInfo.TableName)); } } foreach (var fieldInfo in deleteFields) { var databaseInfo = (DatabaseInfo)fieldInfo.DatabaseInfo; databaseInfo.Delete(fieldInfo); if (!updateDatabases.Contains(databaseInfo)) { updateDatabases.Add(databaseInfo); } FieldDeleted?.Invoke(this, new FieldDeletedEventArgs(fieldInfo.Name)); } foreach (var databaseInfo in updateDatabases) { databaseInfo.Save(); } }