private int?LoadNodeCounterValue(TreeNode treeNode) { if (treeNode == null) { return(null); } ConcreteTemplateNodeDefinition nodeDefinition = treeNode.Tag as ConcreteTemplateNodeDefinition; if (nodeDefinition == null) { return(null); } long handle = nodeDefinition.ComputeHandle(); lock (this._lockObj) { if (this._nodeCountMap.ContainsKey(handle)) { return(this._nodeCountMap[handle]); } } TemplateNodeInfo templateNode = nodeDefinition.TemplateNode; CurrentStorage storage = GetStorage(templateNode.ConnectionGroup); int? count = storage.GetTreeNodeCounterValue(templateNode); lock (this._lockObj) { if (this._nodeCountMap.ContainsKey(handle)) { this._nodeCountMap[handle] = count; } else { this._nodeCountMap.Add(handle, count); } } return(count); }
public TreeTask BeginRefreshTask( TreeNode treeNode, bool hierarchically, NodeUpdatingSource mode, Action continueWith = null ) { if (treeNode == null) { return(null); } ConcreteTemplateNodeDefinition templateDef = treeNode.Tag as ConcreteTemplateNodeDefinition; if (templateDef == null) { log.Debug("MSSQLServerAuditor.TreeTaskManager:BeginRefreshTask templateDef is not defined."); return(null); } long nodeHandle = templateDef.ComputeHandle(); if (this.RunningTasks.ContainsKey(nodeHandle)) { return(null); } ConnectionData connectionData = GetConnectionData(treeNode); TreeTaskInfo taskInfo = new TreeTaskInfo { Connection = connectionData, Mode = mode, Hierarchically = hierarchically, Note = string.Format("{0}", DateTime.Now.ToString("mm:ss")), Handle = nodeHandle }; TreeTask treeTask = TreeTask.Create(taskInfo); if (this._treeControl != null) { treeTask.Progress.ProgressChanged += (sender, args) => this._treeControl.SetProgressValue((int)args.NewValue); } treeTask.Completed += (sender, args) => { Task.Factory.StartNew(() => RemoveClosedTask(treeTask)); if (continueWith != null) { continueWith(); } }; lock (this._runningTasksLock) { this.RunningTasks.TryAdd(taskInfo.Handle, treeTask); } // don't change order of Add and Subscribe! treeTask.JobChanged += OnTaskJobChanged; if (this._treeControl != null) { this._treeControl.SetInProgress(taskInfo, true, true); } ProgressItem progress = new ProgressItem(); RefreshNode(treeTask, null, treeNode, progress); return(treeTask); }
private int?UpdateNodeCounterValue(TreeNode treeNode) { int?count = null; if (treeNode == null) { return(null); } ConcreteTemplateNodeDefinition nodeDefinition = treeNode.Tag as ConcreteTemplateNodeDefinition; if (nodeDefinition == null) { return(null); } if (treeNode.Nodes.Count == 0) { count = this._model.VisualizeProcessor.GetDataRowCount(nodeDefinition, nodeDefinition.Connection); if (nodeDefinition.IsDataseDetail && count == 0 && nodeDefinition.TemplateNode.HideEmptyResultDatabases) { count = null; } else { count = nodeDefinition.TemplateNode.Childs.Any() && count == 0 ? null : count; } } else { count = treeNode.Nodes .Cast <TreeNode>() .Select(LoadNodeCounterValue) .Where(add => add.HasValue && add != 0) .Aggregate <int?, int?>(0, (current, add) => current + add); if (count == 0) { count = null; } } long handle = nodeDefinition.ComputeHandle(); lock (this._lockObj) { if (this._nodeCountMap.ContainsKey(handle)) { int?currentCount = this._nodeCountMap[handle]; if (Nullable.Equals(currentCount, count) || count == null) { return(currentCount); } this._nodeCountMap[handle] = count; } else { this._nodeCountMap.Add(handle, count); } } CurrentStorage storage = GetStorage(nodeDefinition.TemplateNode.ConnectionGroup); storage.UpdateTreeNodeCounterValue(nodeDefinition.TemplateNode, count); return(count); }