private Dictionary <TemplateNodeQueryInfo, DataTable> ReadHistTable( ConnectionGroupInfo connectionGroup, ConcreteTemplateNodeDefinition concreteTemplateNode ) { Dictionary <TemplateNodeQueryInfo, DataTable> histTable = new Dictionary <TemplateNodeQueryInfo, DataTable>(); TemplateNodeInfo templateNodeInfo = concreteTemplateNode.TemplateNode; ProgressItem progress = new ProgressItem(); using (SqlProcessor sqlProcessor = MsSqlAuditor.GetNewSqlProcessor(new CancellationToken())) { progress.SetPromisedChildCount(1); MultyQueryResultInfo resultQuery = sqlProcessor.ExecuteMultyQuery( connectionGroup, templateNodeInfo.Queries, progress.GetChild(), Program.Model.Settings.SystemSettings.MaximumDBRequestsThreadCount, true ); if (resultQuery != null) { if (resultQuery.List != null) { if (resultQuery.List.Count != 0) { long requestId = this.Storage.MetaResultTable.GetMaxRequestId() + 1L; DateTime timestamp = DateTime.Now; histTable = PrepareHistoryData(resultQuery); this.Storage.SaveMeta( templateNodeInfo, resultQuery, requestId, timestamp ); } } } } return(histTable); }
/// <summary> /// Run queries for the node /// </summary> /// <param name="nodeInfo">TemplateNodeInfo</param> /// <param name="connData">Connection data</param> /// <param name="templateRowId">Template Id</param> private void RunQueries(TemplateNodeInfo nodeInfo, ConnectionData connData, long templateRowId, long scheduleId, string runningKey) { MultyQueryResultInfo result; ProgressItem item = new ProgressItem(); CancellationToken token = new CancellationToken(); log.DebugFormat( @"Started: Connection:'{0}';templateRowId:'{1}';Query:'{2}'", connData.Title, templateRowId, nodeInfo.Name ); lock (_runningTasksLock) { _runningTasks.TryAdd(runningKey, nodeInfo.Name); } using (SqlProcessor sqlProcessor = _model.GetNewSqlProcessor(token)) { nodeInfo.SetConnectionData(null); TemplateNodeInfo node = nodeInfo.Instantiate(connData, null, null); node.AssignTemplateId(templateRowId); node.LoadUserParameters(_storage); Stopwatch durationWatch = new Stopwatch(); DateTime startTime = DateTime.Now; durationWatch.Start(); result = sqlProcessor.ExecuteMultyQuery( connData.ConnectionGroup, node.Queries, item, _model.Settings.SystemSettings.MaximumDBRequestsThreadCount ); IStorageManager istorage = _model.GetVaultProcessor(connData.ConnectionGroup); istorage.SaveRequestedData(node, result); durationWatch.Stop(); DateTime duration = new DateTime(durationWatch.Elapsed.Ticks); istorage.CurrentStorage.UpdateTreeNodeTimings( node, startTime, duration ); //_serviceSchedules.FirstOrDefault(sch => sch.TemplateNodeId == nodeInstanceRowId).LastRan = startTime; _serviceSchedules[scheduleId].LastRan = startTime; } nodeInfo.SetConnectionData(connData); lock (_runningTasksLock) { string outTask; _runningTasks.TryRemove(runningKey, out outTask); } }
private void RefreshQueries( TreeTask treeTask, ConcreteTemplateNodeDefinition nodeDefinition, ProgressItem progress ) { log.DebugFormat("taskInfo.Connection:'{0}';nodeDefinition:'{1}'", treeTask.Info.Connection.ConnectionGroup.ToString() ?? "?", nodeDefinition.TemplateNode.Name ?? "?" ); ErrorLog errorLog = new ErrorLog(); MsSqlAuditorModel model = this._treeControl._model; DateTime startTime = DateTime.Now; Stopwatch durationWatch = new Stopwatch(); durationWatch.Start(); using (SqlProcessor sqlProcessor = model.GetNewSqlProcessor(treeTask.CancellationSource.Token)) { if (!treeTask.Info.Connection.IsLiveConnection) { sqlProcessor.SetSkipMSSQLQueries(); } progress.SetPromisedChildCount(1); TemplateNodeInfo templateNode = nodeDefinition.TemplateNode; ConnectionGroupInfo group = nodeDefinition.Connection; MultyQueryResultInfo result; if (nodeDefinition.Group.Instance != null) { result = sqlProcessor.ExecuteMultyQuery( nodeDefinition.Group, templateNode.Queries, progress.GetChild() ); } else { result = sqlProcessor.ExecuteMultyQuery( group, templateNode.Queries, progress.GetChild(), model.Settings.SystemSettings.MaximumDBRequestsThreadCount ); } if (group != null && group.Connections != null) { group.Connections.ForEach( x => x.ConnectionGroup = x.ConnectionGroup ?? group ); } errorLog.AppendErrorLog(result); IStorageManager storage = model.GetVaultProcessor(group); storage.SaveRequestedData(templateNode, result); durationWatch.Stop(); DateTime duration = new DateTime(durationWatch.Elapsed.Ticks); storage.CurrentStorage.UpdateTreeNodeTimings( templateNode, startTime, duration ); foreach (GroupDefinition database in result.ExtractDatabases()) { ConcreteTemplateNodeDefinition nodeDef = new ConcreteTemplateNodeDefinition( templateNode, database, group ); this._treeControl.VisualizeData(nodeDef); } } }