예제 #1
0
 public void FireNodeUpdated()
 {
     if (NodeUpdated != null)
     {
         NodeUpdated.Invoke(this);
     }
 }
        /// <summary>
        /// Toggles the given nodes expanded state.
        /// </summary>
        /// <param name="node">The node to be expanded or collapsed.</param>
        public async Task ToggleNodeIsExpandedAsync(TreeNode <TItem> node)
        {
            var wasExpanded = node.IsExpanded;

            // if expanding and Nodes is null then request data
            if (!node.Isleaf && !wasExpanded && node.Nodes == null)
            {
                // fetch direct child items
                var key   = node.Data is null ? null : KeyField !(node.Data !).ToString();
                var items = await GetDataAsync(key).ConfigureAwait(true);

                // add new nodes to existing node
                node.Nodes = new List <TreeNode <TItem> >();              // indicates data fetched, even if no items returned
                UpdateModel(items);

                // notify any listeners that new data fetched
                await NodeUpdated.InvokeAsync(node).ConfigureAwait(true);
            }

            // expand / collapse and notify
            node.IsExpanded = !wasExpanded;
            if (wasExpanded)
            {
                await NodeCollapsed.InvokeAsync(node).ConfigureAwait(true);
            }
            else
            {
                await NodeExpanded.InvokeAsync(node).ConfigureAwait(true);
            }
        }
예제 #3
0
        private void UpdateNodes(IPAddress address, DateTime timestamp, Stream stream)
        {
            // Read the source's state and generation
            var sourceState      = stream.ReadState();
            var sourceGeneration = stream.ReadGeneration();

            // Read the source's version of our state and generation
            var localState      = stream.ReadState();
            var localGeneration = stream.ReadGeneration();

            // If the source has outdated information about the local node, or
            // the source thinks the local node is no longer alive, update the source
            if (localNode.IsLaterGeneration(localGeneration) ||
                (localState != NodeState.Alive && localGeneration == localNode.Generation))
            {
                // FIXME what is happening here?
                localNode.Generation = (byte)(localGeneration + 1);
            }

            // Handle the source node, then the rest of the nodes in the stream
            Node remoteNode = new Node {
                Address    = address,
                State      = sourceState,
                Generation = sourceGeneration
            };

            while (remoteNode != null)
            {
                lock (nodes) {
                    // Process this remote node if:
                    //   1. we are aware of it, and
                    //   2. the incoming information is newer than the information we have, or
                    //   3. we have the same information, but the state has changed
                    if (nodes.TryGetValue(remoteNode.Address, out var node) &&
                        (node.IsLaterGeneration(remoteNode.Generation) ||
                         (node.Generation == remoteNode.Generation && node.IsSupersededState(remoteNode.State))))
                    {
                        // Stop escalation
                        if (node.State == NodeState.Alive && remoteNode.IsLaterGeneration(node.Generation))
                        {
                            // Remove any pending ACK
                            acks.TryRemove(node.Address, out var _);
                        }

                        // Update and notify
                        node.State      = remoteNode.State;
                        node.Generation = remoteNode.Generation;
                        NodeUpdated?.Invoke(node);
                    }
                    else if (node == null)
                    {
                        node = remoteNode;
                        nodes.Add(node.Address, node);
                        NodeUpdated?.Invoke(node);
                    }

                    if (node.State != NodeState.Alive)
                    {
                        acks.TryAdd(node.Address, DateTime.UtcNow);
                    }
                }

                // Process next node in the stream
                remoteNode = Node.ReadFrom(stream);
            }
        }
예제 #4
0
 private void OnNodeUpdated(FileNode node)
 {
     NodeUpdated?.Invoke(node);
 }
예제 #5
0
 private void HandleDataChanged(object sender, DataTreeNode e)
 {
     NodeUpdated?.Invoke(this, new TreeViewEventArgs(e));
 }
예제 #6
0
 /// <summary>
 /// <inheritdoc />
 /// </summary>
 public void OnNodeUpdated(NodeSetup nodeSetup)
 {
     NodeUpdated?.Invoke(nodeSetup);
 }