コード例 #1
0
        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);
                }
            }
        }