/// <summary> /// Executes multyquery /// </summary> /// <param name="connectionGroup">Connection group</param> /// <param name="templateNodeQueryInfos">Template nodes</param> /// <param name="progress">Progress item</param> /// <param name="maxthreadCount">Maximum thread</param> /// <returns>Multyquery result</returns> public MultyQueryResultInfo ExecuteMultyQuery( ConnectionGroupInfo connectionGroup, List<TemplateNodeQueryInfo> templateNodeQueryInfos, ProgressItem progress, int maxthreadCount, bool checkHist = false ) { Settings.InstanceTemplate settings = null; //////////////////////////////////////////////////////////////////////////////////////// // string strLogMessage = "DEBUG:MSSQLServerAuditor.Model.ExecuteMultyQuery(1)"; // strLogMessage = strLogMessage + ";GD:" + connectionGroup.ToString(); // log.Debug(strLogMessage); //////////////////////////////////////////////////////////////////////////////////////// var result = new MultyQueryResultInfo(); if (templateNodeQueryInfos.Count > 0) { progress.SetPromisedChildCount(templateNodeQueryInfos.Count); foreach (var qi in templateNodeQueryInfos) { TemplateNodeQueryInfo queryInfo = qi; QueryResultInfo queryResult = null; try { var queries = this._model.GetQueryByTemplateNodeQueryInfo(queryInfo); if (this._skipMsSqlQueries) { queries.RemoveAll( x => ( x.Source == QuerySource.MSSQL || x.Source == QuerySource.TDSQL ) ); } if (checkHist) { queries.RemoveAll(x => (x.Source != QuerySource.SQLite)); } else { queries.RemoveAll(x => (x.Source == QuerySource.SQLite)); } if (queryInfo.ConnectionsSelectId == null) { if (!queries.Any( x => connectionGroup.Connections.Select(y => y.Type).Contains(x.Source) || x.Source == QuerySource.SQLite )) { continue; } } // var settings = Program.Model.TemplateSettings.UserSettings.FirstOrDefault(i => // i.TemplateName == connectionGroup.TemplateFileName // && i.Connection.ParentKey == queryInfo.TemplateNode.IdsHierarchy // ); if (Program.Model != null) { settings = Program.Model.TemplateSettings.UserSettings.FirstOrDefault(i => i.TemplateName == connectionGroup.TemplateFileName && i.Connection.ParentKey == queryInfo.TemplateNode.IdsHierarchy ); } else { settings = this._model.TemplateSettings.UserSettings.FirstOrDefault(i => i.TemplateName == connectionGroup.TemplateFileName && i.Connection.ParentKey == queryInfo.TemplateNode.IdsHierarchy ); } queryInfo.ReadParametersFrom(settings); string connectionsSelectId = queryInfo.ConnectionsSelectId; if (connectionsSelectId != null) { queryResult = ExecuteConnectionsSelectQuery( queryInfo, connectionGroup, queries, maxthreadCount ); } else { queryResult = ExecuteQuery( connectionGroup, queries, QueryExecutionParams.CreateFrom(queryInfo), maxthreadCount, progress.GetChild() ); } } catch (OperationCanceledException ex) { log.Error(queryInfo.ToString(), ex); throw; } catch (AggregateException ex) { if (ex.InnerExceptions.All(e => e is OperationCanceledException)) { throw; } queryResult = new QueryResultInfo( new ErrorInfo( ex.InnerExceptions.FirstOrDefault( e => !(e is OperationCanceledException) ) ) ); progress.GetChild().SetProgress(100); log.Error(queryInfo.ToString(), ex); } catch (Exception ex) { queryResult = new QueryResultInfo(new ErrorInfo(ex)); progress.GetChild().SetProgress(100); log.Error(queryInfo.ToString(), ex); } result.Add(new TemplateNodeResultItem(queryInfo, queryResult)); } } else { progress.SetProgress(100); } return result; }
private QueryDatabaseResultInfo ExecuteQueryItem( InstanceInfo connection, QueryItemInfo queryItem, string database, string databaseId, IEnumerable<QueryParameterInfo> parameters, IEnumerable<ParameterValue> parameterValues, ProgressItem progress = null ) { try { var table = ExecuteSql( connection, queryItem, database, parameters, parameterValues, progress ); return new QueryDatabaseResultInfo(table, queryItem, database, databaseId); } catch (OperationCanceledException ex) { return new QueryDatabaseResultInfo(new ErrorInfo(ex), queryItem, database, databaseId); } catch (Exception ex) { log.Error(ex); if (!ex.Data.Contains("IgnoreLog")) { log.Error(queryItem.ToString() + Environment.NewLine + "connection.Instance=" + connection.Instance + Environment.NewLine + " database=" + database + Environment.NewLine + " connection.Authentication.Username=" + connection.Authentication.Username, ex); } if (progress != null) { progress.SetProgress(100); } return new QueryDatabaseResultInfo(new ErrorInfo(ex), queryItem, database, databaseId); } }