예제 #1
0
 //called after a path update, if there was a meaningful change to the node then NodeStateChanged is invoked
 public void FinalizeState()
 {
     if (changed || mPathId != finalId)
     {
         finalId = mPathId;
         changed = false;
         NodeStateChanged?.Invoke(mPathId);
     }
 }
예제 #2
0
        public void AssignNodeState(string endpoint, NodeState nodeState)
        {
            lock (lockObject)
            {
                var n = nodeInformationDictionary[endpoint];
                var p = n.NodeStateProperty;

                var originState = p.StateProperty;
                p.StateProperty = nodeState;
                p.Version       = n.LastKnownPropertyVersion + 1;

                if (p.StateProperty != originState)
                {
                    NodeStateChanged?.Invoke(this, new NodeStateChangedEventArgs
                    {
                        EndPoint          = endpoint,
                        PreviousNodeState = originState,
                        CurrentNodeState  = p.StateProperty
                    });
                }
            }
        }
예제 #3
0
 internal void MergeUpdateNodes(IEnumerable <NodeInformation> updateNodes)
 {
     foreach (var n in updateNodes)
     {
         if (nodeInformationDictionary.ContainsKey(n.Endpoint))
         {
             var myNode          = nodeInformationDictionary[n.Endpoint];
             var originNodeState = myNode.NodeState;
             if (myNode.NodeVersion < n.NodeVersion)
             {
                 myNode = n;
                 nodeInformationDictionary[n.Endpoint] = n;
             }
             else if (myNode.NodeVersion > n.NodeVersion)
             {
                 logger.LogDebug(
                     "Node {0} received node version ({1}) is lower than current known node version ({2})",
                     n.Endpoint,
                     n.NodeVersion,
                     myNode.NodeVersion);
             }
             else
             {
                 foreach (var p in n.Properties)
                 {
                     if (myNode.Properties.ContainsKey(p.Key))
                     {
                         if (myNode.Properties[p.Key].Version < p.Value.Version)
                         {
                             myNode.Properties[p.Key] = p.Value;
                         }
                         else
                         {
                             logger.LogDebug(
                                 "Node {0} property {1} received version ({2}) is lower or equal to current known version ({3})",
                                 myNode.Endpoint,
                                 p.Key,
                                 p.Value.Version,
                                 myNode.Properties[p.Key].Version);
                         }
                     }
                     else
                     {
                         myNode.Properties.Add(p.Key, p.Value);
                     }
                 }
             }
             if (myNode.NodeState != originNodeState)
             {
                 NodeStateChanged?.Invoke(this, new NodeStateChangedEventArgs
                 {
                     EndPoint          = myNode.Endpoint,
                     PreviousNodeState = originNodeState,
                     CurrentNodeState  = myNode.NodeState
                 });
             }
         }
         else
         {
             nodeInformationDictionary.Add(n.Endpoint, n);
             NodeStateChanged?.Invoke(this, new NodeStateChangedEventArgs
             {
                 EndPoint          = n.Endpoint,
                 PreviousNodeState = NodeState.Unknown,
                 CurrentNodeState  = n.NodeState
             });
         }
     }
 }
예제 #4
0
 /// <summary>
 /// <inheritdoc />
 /// </summary>
 public void OnNodeStateChanged(Guid nodeId, NodeState state)
 {
     NodeStateChanged?.Invoke(nodeId, state);
 }