Exemplo n.º 1
0
 private void UpdateTreeCounts(
     TreeNode parentNode,
     NodeUpdatingSource mode
     )
 {
     StartUpdateNodeCounterTask(parentNode, mode).Wait();
 }
Exemplo n.º 2
0
        public void UpdateChildren(NodeUpdatingSource mode, CancellationTokenSource cancellationSource)
        {
            if (IsDisabled)
            {
                mode = NodeUpdatingSource.LocallyOnly;
            }

            Debug.Assert(this.IsInstance);

            IStorageManager vault   = this._model.GetVaultProcessor(Connection.ConnectionGroup);
            bool            updated = false;

            if (mode == NodeUpdatingSource.FromServerIfNotSavedLocally || mode == NodeUpdatingSource.LocallyOnly)
            {
                updated = vault.CurrentStorage.NodeInstances.TryLoadChildren(this);
            }

            if (updated || mode == NodeUpdatingSource.LocallyOnly)
            {
                return;
            }

            Childs.Clear();
            Childs.AddRange(InstantiateStaticNodes(this.Template.Childs, Connection, this));

            vault.CurrentStorage.NodeInstances.SaveChildren(this);

            if (MayHaveDynamicChildren && Connection.IsLiveConnection)
            {
                UpdateDynamicChildren(cancellationSource.Token);
            }
        }
Exemplo n.º 3
0
		public Task<int?> StartUpdateTask(TreeNode treeNode, NodeUpdatingSource mode)
		{
			switch (mode)
			{
				case NodeUpdatingSource.ForcedFromServer:
					return Task.Factory.StartNew(
						t => UpdateNodeCounterValue((TreeNode)t),
						treeNode
					);

				default:
					return Task.Factory.StartNew(
						t => LoadNodeCounterValue((TreeNode)t),
						treeNode
					);
			}
		}
Exemplo n.º 4
0
        public Task <int?> StartUpdateTask(TreeNode treeNode, NodeUpdatingSource mode)
        {
            switch (mode)
            {
            case NodeUpdatingSource.ForcedFromServer:
                return(Task.Factory.StartNew(
                           t => UpdateNodeCounterValue((TreeNode)t),
                           treeNode
                           ));

            default:
                return(Task.Factory.StartNew(
                           t => LoadNodeCounterValue((TreeNode)t),
                           treeNode
                           ));
            }
        }
Exemplo n.º 5
0
        private Task StartUpdateNodeCounterTask(
            TreeNode treeNode,
            NodeUpdatingSource mode,
            Action onFinished = null
            )
        {
            Task updateNodeTask = this._nodeCounter.StartUpdateTask(treeNode, mode)
                                  .ContinueWith(t =>
            {
                if (t.IsFaulted)
                {
                    HandleTaskFailure(t);
                }
                else
                {
                    if (t.IsCompleted)
                    {
                        try
                        {
                            int?count = t.Result;

                            UpdateNodeTitle(treeNode, count);
                        }
                        catch (Exception exc)
                        {
                            log.Error("Failed to update node title with count.", exc);
                        }
                    }
                }

                if (onFinished != null)
                {
                    onFinished();
                }
            });

            return(updateNodeTask);
        }
Exemplo n.º 6
0
		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;
		}
Exemplo n.º 7
0
		private Task StartUpdateNodeCounterTask(
			TreeNode           treeNode,
			NodeUpdatingSource mode,
			Action             onFinished = null
		)
		{
			Task updateNodeTask = this._nodeCounter.StartUpdateTask(treeNode, mode)
				.ContinueWith(t =>
				{
					if (t.IsFaulted)
					{
						HandleTaskFailure(t);
					}
					else
					{
						if (t.IsCompleted)
						{
							try
							{
								int? count = t.Result;

								UpdateNodeTitle(treeNode, count);
							}
							catch (Exception exc)
							{
								log.Error("Failed to update node title with count.", exc);
							}
						}
					}

					if (onFinished != null)
					{
						onFinished();
					}
				});

			return updateNodeTask;
		}
Exemplo n.º 8
0
		private void UpdateTreeCounts(
			TreeNode           parentNode,
			NodeUpdatingSource mode
		)
		{
			StartUpdateNodeCounterTask(parentNode, mode).Wait();
		}
Exemplo n.º 9
0
        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);
        }
Exemplo n.º 10
0
		public void UpdateChildren(NodeUpdatingSource mode, CancellationTokenSource cancellationSource)
		{
			if (IsDisabled)
			{
				mode = NodeUpdatingSource.LocallyOnly;
			}

			Debug.Assert(this.IsInstance);

			IStorageManager vault   = this._model.GetVaultProcessor(Connection.ConnectionGroup);
			bool            updated = false;

			if (mode == NodeUpdatingSource.FromServerIfNotSavedLocally || mode == NodeUpdatingSource.LocallyOnly)
			{
				updated = vault.CurrentStorage.NodeInstances.TryLoadChildren(this);
			}

			if (updated || mode == NodeUpdatingSource.LocallyOnly)
			{
				return;
			}

			Childs.Clear();
			Childs.AddRange(InstantiateStaticNodes(this.Template.Childs, Connection, this));

			vault.CurrentStorage.NodeInstances.SaveChildren(this);

			if (MayHaveDynamicChildren && Connection.IsLiveConnection)
			{
				UpdateDynamicChildren(cancellationSource.Token);
			}
		}