/// <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);
            }
        }
Example #2
0
        private void RefreshNode(
            TreeTask treeTask,
            TreeJob parentJob,
            TreeNode treeNode,
            ProgressItem progress
            )
        {
            ConcreteTemplateNodeDefinition nodeDefinition = treeNode.Tag as ConcreteTemplateNodeDefinition;

            if (treeTask.CancellationSource.IsCancellationRequested)
            {
                return;
            }

            if (nodeDefinition == null)
            {
                return;
            }

            TreeJob treeJob = new TreeJob(nodeDefinition);

            if (parentJob != null)
            {
                parentJob.AddChildJob(treeJob);
                treeJob.Parent = parentJob;
            }

            WeakReference treeNodeRef = new WeakReference(treeNode);

            treeTask.JobCompleted += (sender, args) =>
            {
                TreeTask task = sender as TreeTask;

                if (task != null && treeNodeRef.IsAlive)
                {
                    if (!task.CancellationSource.IsCancellationRequested)
                    {
                        TreeNode targetNode = (TreeNode)treeNodeRef.Target;
                        UpdateTreeCounts(targetNode, task.Info.Mode);
                    }
                }
            };

            bool refreshChildren = treeTask.Info.Hierarchically;

            Action refreshNodeAction = () =>
            {
                try
                {
                    TemplateNodeInfo templateNode = nodeDefinition.TemplateNode;

                    if (templateNode == null || !nodeDefinition.NodeAvailable)
                    {
                        return;
                    }

                    templateNode.LastUpdateNode = DateTime.Now;

                    CurrentStorage storage = GetStorage(templateNode.ConnectionGroup);

                    templateNode.LoadUserParameters(storage);

                    if (nodeDefinition.NodeActivated)
                    {
                        RefreshQueries(treeTask, nodeDefinition, progress);
                    }

                    if (templateNode.IsLeaf())
                    {
                        return;
                    }

                    AddLoadingNode(treeNode);

                    templateNode.UpdateChildren(treeTask.Info.Mode, treeTask.CancellationSource);
                    FillTreeNodes(templateNode, treeNode.Nodes);

                    if (refreshChildren)
                    {
                        treeJob.PromisedChildCount = treeNode.Nodes.Count;

                        foreach (TreeNode node in treeNode.Nodes)
                        {
                            if (node != null)
                            {
                                RefreshNode(treeTask, treeJob, node, progress);
                            }
                        }
                    }
                }
                catch (Exception exc)
                {
                    log.Error("MSSQLServerAuditor.Managers:RefreshNode:subTask (Exception)", exc);
                }
            };

            treeJob.Action = refreshNodeAction;

            lock (this._schedulingLock)
            {
                treeTask.Schedule(treeJob);
            }
        }