public void Run() { _logger.Information("Running spv wallet"); var registry = new Registry(); registry.Schedule(() => { if (_lastHeight != CurrentHeight) { _logger.Information($"Connected nodes -> {ConnectedNodes.Count()}"); _logger.Information($"Height -> {CurrentHeight}"); _lastHeight = CurrentHeight; _logger.Information($"Wallet Balance -> {GetBalance()}"); SaveAsync(); _logger.Information("******************************************"); } }).ToRunNow().AndEvery(10).Seconds(); JobManager.Initialize(registry); JobManager.Start(); //Console.CancelKeyPress += (sender, eArgs) => { // _quitEvent.Set(); // eArgs.Cancel = true; //}; _wallet.Tracker.NewOperation += Tracker_NewOperation; // kick off asynchronous stuff _quitEvent.WaitOne(); }
// Description: Adds a link between every node in order that they were selected // PRE: N/A // POST: There exists a link between every node selected (n-1 links) public void Link() { // Spawn a new link where the origin is the first index, // and the secondary node is the second node if (selectedNodes.Count >= 2) { for (int i = 1; i < selectedNodes.Count; i++) { // Keys for our hash table, connectedNodes ConnectedNodes nodePair = new ConnectedNodes(selectedNodes[i - 1], selectedNodes[i]); ConnectedNodes reversedPair = new ConnectedNodes(selectedNodes[i], selectedNodes[i - 1]); if (!connectedNodes.Contains(nodePair)) { if (connectedNodes.Contains(reversedPair)) { Destroy((GameObject)connectedNodes[reversedPair]); connectedNodes.Remove(reversedPair); UpdateNumberOfNodeConnections(reversedPair, false); } GameObject newLink = CreateLink(nodePair); connectedNodes.Add(nodePair, newLink); UpdateNumberOfNodeConnections(nodePair, true); } } this.ClearSelection(); } UpdateLinkInspector(); }
// Description: Updates the number of connections in the BuildViewNode's information // PRE: The given nodepair has an origin and a destination nodes // POST: The number of connections for these nodes has been updated private void UpdateNumberOfNodeConnections(ConnectedNodes nodePair, bool isAddingOneConnection) { int i = isAddingOneConnection ? 1 : 0; nodePair.origin.NumberOfConnections += 2 * i - 1; nodePair.destination.NumberOfConnections += 2 * i - 1; }
protected override void OnDragFinish() { ExecuteNode hoveredNode = (SelectionManager.Instance.HoverNode as ExecuteNode); if (!hoveredNode) { Destroy(currentGameObject); currentDraggingLine = null; return; } if (hoveredNode != this) { if (hoveredNode.IsInputNode != IsInputNode) { NodeConnection <ExecuteNode> nodeConnection = new NodeConnectionBuilder <ExecuteNode>() .SetNodes(this, hoveredNode) .SetConnectionLine(currentDraggingLine) .Build(); ConnectedNodes.Add(nodeConnection.Cast <ConnectedNode>()); hoveredNode.ConnectedNodes.Add(nodeConnection.Cast <ConnectedNode>()); RegisterExecNodes(nodeConnection); nodeConnection.UpdateLine(); currentGameObject = null; return; } } Destroy(currentGameObject); currentDraggingLine = null; }
public void Connect(LocationNode n) { if (!ConnectedNodes.Contains(n)) { ConnectedNodes.Add(n); } }
/// <summary>Creates a deep copy of this device.</summary> /// <returns></returns> public virtual ICircuitDefinitionDevice Clone() { var circuitDefinitionDevice = (CircuitDefinitionDevice)MemberwiseClone(); circuitDefinitionDevice.ConnectedNodes = ConnectedNodes.Clone(); return(circuitDefinitionDevice); }
/// <summary> /// Remove this object from all connected anchors /// </summary> public void ClearNodes() { foreach (Node node in ConnectedNodes) { node.ConnectedElements.Remove(this); // Remove the anchor from the node } ConnectedNodes.Clear(); }
void node_StateChanged(Node node, NodeState oldState) { if (node.State == NodeState.Disconnecting || node.State == NodeState.Failed || node.State == NodeState.Offline) { ConnectedNodes.Remove(node); } }
// Description: Creates the Link object to be placed between two nodes // PRE: nodePair contains two nodes // POST: There exists a link between each of the nodes in nodePair private GameObject CreateLink(ConnectedNodes nodePair) { GameObject newLink = Instantiate(LinkPrefab); newLink.tag = "Link"; BuildViewLink linkScript = newLink.GetComponent <BuildViewLink>(); linkScript.origin = nodePair.origin; linkScript.destination = nodePair.destination; return(newLink); }
/// <summary> /// Asynchronously create a new set of nodes /// </summary> public void Purge(string reason) { Task.Factory.StartNew(() => { var initialNodes = ConnectedNodes.ToDictionary(n => n); while (!_disconnect.IsCancellationRequested && initialNodes.Count != 0) { var node = initialNodes.First(); node.Value.Disconnect(reason); initialNodes.Remove(node.Value); _disconnect.Token.WaitHandle.WaitOne(5000); } }); }
/// <summary> /// Splits this island across the /// specified field. This island will contain /// the field's parent node, while the returned island /// will contain the connected node. Note that this /// does not gurantee that the island will be split /// into two pieces (if the nodes are still connected). /// </summary> /// <returns>The newly created island</returns> public Island Split(Field field) { var parent = field.ParentNode; var connected = field.ConnectedNode; // Find all current connections with the parent node ConnectedNodes.Clear(); _connectedFields.Clear(); FindConnected(parent, ConnectedNodes, _connectedFields); // Find all current connections with the connected node var splitNodes = new HashSet <Node>(); var splitFields = new HashSet <Field>(); FindConnected(connected, splitNodes, splitFields); // Return the island containing the connected node return(new Island(splitNodes, splitFields)); }
/// <summary> /// /// </summary> /// <param name="dst_"></param> public bool ConnectTo(NodeSlot dst_) { if (dst_.Node == Node) { throw new InvalidOperationException("Try to connect itself"); } foreach (NodeSlot s in ConnectedNodes) { if (s.Node == dst_.Node) // already connected { return(true); //throw new InvalidOperationException(""); } } switch (ConnectionType) { case SlotType.NodeIn: case SlotType.NodeOut: if ((dst_.Node is VariableNode) == true) { return(false); } break; case SlotType.VarIn: case SlotType.VarOut: case SlotType.VarInOut: if ((dst_.Node is VariableNode) == false && (dst_ is NodeSlotVar) == false) { return(false); } break; } ConnectedNodes.Add(dst_); return(true); }
/// <summary> /// Connect all anchors to the nearest nodes /// </summary> private void ConnectToNodes() { ClearNodes(); // Clear previous connections foreach (Vector anchor in Anchors) { Node node = BoardGrid.Magnetize(ImagePosition + anchor); // The nearest node Vector nodeRelativePosition = node.Position - ImagePosition; // Node position relative to the image Directions direction = new Directions(); // Direction of the component relative to the node try { if (Math.Abs(ImageSize.X - nodeRelativePosition.X) < Properties.Settings.Default.GridThickness) // The grid thickness is used as an error threshold { direction = Directions.Left; } else if (Math.Abs(ImageSize.Y - nodeRelativePosition.Y) < Properties.Settings.Default.GridThickness) { direction = Directions.Up; } else if (Math.Abs(nodeRelativePosition.Y) < Properties.Settings.Default.GridThickness) { direction = Directions.Down; } else if (Math.Abs(nodeRelativePosition.X) < Properties.Settings.Default.GridThickness) { direction = Directions.Right; } else { throw new System.ApplicationException("Can't determine anchor position relatively to the node."); } } catch (System.ApplicationException e) { ((MainWindow)Application.Current.MainWindow).LogError(e); // Write error to log and close the processus } ConnectedNodes.Add(node); node.ConnectedElements.Add(this, direction); } }
public void Dispose() { if (DiscoveredNodeGroup != null) { DiscoveredNodeGroup.Dispose(); } if (ConnectNodeGroup != null) { ConnectNodeGroup.Dispose(); } if (AddNodeNodeGroup != null) { AddNodeNodeGroup.Dispose(); } foreach (var server in _Servers) { server.Dispose(); } foreach (var node in ConnectedNodes.Where(n => n.Behaviors.Find <ConnectionManagerBehavior>().OneTry)) { node.Disconnect(); } }
/// <summary> /// Calculates the degree of this node while only considering nodes that are in the subgraph. Ignores connections to all other nodes /// </summary> /// <param name="subGraph">The subgraph to calculate the remaining degree in</param> /// <returns>The remaining degree of this node in the subgraph</returns> public int RemainingDegree(HashSet <Node> subGraph) => ConnectedNodes.Count(n => subGraph.Contains(n));
// Description: Adds a link between every node in order that they were selected // PRE: N/A // POST: There exists a link between every node selected (n-1 links) public void Link() { // Spawn a new link where the origin is the first index, // and the secondary node is the second node if (selectedNodes.Count >= 2) { for (int i = 1; i < selectedNodes.Count; i++) { // Keys for our hash table, connectedNodes ConnectedNodes nodePair = new ConnectedNodes(selectedNodes[i - 1], selectedNodes[i]); ConnectedNodes reversedPair = new ConnectedNodes(selectedNodes[i], selectedNodes[i - 1]); if(!connectedNodes.Contains(nodePair)) { if (connectedNodes.Contains(reversedPair)) { Destroy((GameObject) connectedNodes[reversedPair]); connectedNodes.Remove(reversedPair); UpdateNumberOfNodeConnections(reversedPair, false); } GameObject newLink = CreateLink(nodePair); connectedNodes.Add(nodePair, newLink); UpdateNumberOfNodeConnections(nodePair, true); } } this.ClearSelection(); } UpdateLinkInspector(); }
public bool IsConnectedTo(Node node) => ConnectedNodes.Any(n => n == node);
// どこからも参照されていない /* * private void AddRange(IEnumerable<Point3Di> cluster) * { * voxels.AddRange(cluster); * } */ public void AddConnectedNode(DendriteNode node) { ConnectedNodes.Add(node); }
/// <summary> /// Adds node to list of connected nodes. /// </summary> /// <param name="node">The node that will be added to the list of connected nodes.</param> public void AddConnectedNode(NodeGene node) { ConnectedNodes.Add(node); }
/// <summary> /// Returns true if the node is contained inside this island /// </summary> public bool Contains(Node node) { return(ConnectedNodes.Contains(node)); }
public Node GetNextNode() { var nextNodeName = ConnectedNodes.randomItem(); return(NodeCollection.Nodes.FirstOrDefault(x => x.Id == nextNodeName)); }
public override string ToString() { var join = string.Join(",", ConnectedNodes.Select(node => node.ToString()).ToArray()); return($"[{join}]"); }
/// <summary> /// /// </summary> public void RemoveAllConnections() { ConnectedNodes.Clear(); }
// Description: Creates the Link object to be placed between two nodes // PRE: nodePair contains two nodes // POST: There exists a link between each of the nodes in nodePair private GameObject CreateLink(ConnectedNodes nodePair) { GameObject newLink = Instantiate(LinkPrefab); newLink.tag = "Link"; BuildViewLink linkScript = newLink.GetComponent<BuildViewLink>(); linkScript.origin = nodePair.origin; linkScript.destination = nodePair.destination; return newLink; }
private void ProcessMessageCore(IncomingMessage message) { if (message.Message.Payload is VersionPayload) { var version = message.AssertPayload <VersionPayload>(); var connectedToSelf = version.Nonce == Nonce; if (message.Node != null && connectedToSelf) { NodeServerTrace.ConnectionToSelfDetected(); message.Node.DisconnectAsync(); return; } if (message.Node == null) { var remoteEndpoint = version.AddressFrom; if (!remoteEndpoint.Address.IsRoutable(AllowLocalPeers)) { //Send his own endpoint remoteEndpoint = new IPEndPoint(((IPEndPoint)message.Socket.RemoteEndPoint).Address, Network.DefaultPort); } var peer = new NetworkAddress() { Endpoint = remoteEndpoint, Time = DateTimeOffset.UtcNow }; var node = new Node(peer, Network, CreateNodeConnectionParameters(), message.Socket, version); if (connectedToSelf) { node.SendMessage(CreateNodeConnectionParameters().CreateVersion(node.Peer.Endpoint, Network)); NodeServerTrace.ConnectionToSelfDetected(); node.Disconnect(); return; } CancellationTokenSource cancel = new CancellationTokenSource(); cancel.CancelAfter(TimeSpan.FromSeconds(10.0)); try { ConnectedNodes.Add(node); node.StateChanged += node_StateChanged; node.RespondToHandShake(cancel.Token); } catch (OperationCanceledException ex) { NodeServerTrace.Error("The remote node did not respond fast enough (10 seconds) to the handshake completion, dropping connection", ex); node.DisconnectAsync(); throw; } catch (Exception) { node.DisconnectAsync(); throw; } } } var messageReceived = MessageReceived; if (messageReceived != null) { messageReceived(this, message); } }
/// <summary> /// Drop connection to all connected nodes /// </summary> public void Disconnect() { _disconnect.Cancel(); ConnectedNodes.DisconnectAll(); }
internal void StartConnecting() { if (_disconnect.IsCancellationRequested) { return; } if (ConnectedNodes.Count >= MaximumNodeConnection) { return; } if (_connecting) { return; } Task.Factory.StartNew(() => { if (Monitor.TryEnter(_cs)) { _connecting = true; TraceCorrelationScope scope = null; try { while (!_disconnect.IsCancellationRequested && ConnectedNodes.Count < MaximumNodeConnection) { scope = scope ?? _trace.Open(); NodeServerTrace.Information("Connected nodes : " + ConnectedNodes.Count + "/" + MaximumNodeConnection); var parameters = NodeConnectionParameters.Clone(); parameters.TemplateBehaviors.Add(new NodesGroupBehavior(this)); parameters.ConnectCancellation = _disconnect.Token; var addrman = AddressManagerBehavior.GetAddrman(parameters); if (addrman == null) { addrman = _defaultAddressManager; AddressManagerBehavior.SetAddrman(parameters, addrman); } Node node = null; try { var groupSelector = CustomGroupSelector ?? (AllowSameGroup ? WellKnownGroupSelectors.ByRandom : null); node = Node.Connect(_network, parameters, ConnectedNodes.Select(n => n.RemoteSocketEndpoint).ToArray(), groupSelector); var timeout = CancellationTokenSource.CreateLinkedTokenSource(_disconnect.Token); timeout.CancelAfter(5000); node.VersionHandshake(Requirements, timeout.Token); NodeServerTrace.Information("Node successfully connected to and handshaked"); } catch (OperationCanceledException ex) { if (_disconnect.Token.IsCancellationRequested) { break; } NodeServerTrace.Error("Timeout for picked node", ex); if (node != null) { node.DisconnectAsync("Handshake timeout", ex); } } catch (Exception ex) { NodeServerTrace.Error("Error while connecting to node", ex); if (node != null) { node.DisconnectAsync("Error while connecting", ex); } } } } finally { Monitor.Exit(_cs); _connecting = false; if (scope != null) { scope.Dispose(); } } } }, TaskCreationOptions.LongRunning); }
/// <summary> /// /// </summary> /// <param name="slot_"></param> public bool DisconnectFrom(NodeSlot slot_) { ConnectedNodes.Remove(slot_); return(true); }
public bool IsTouchingEnemyCapRing(Node ignore_node) { var ignore_nodes = ignore_node.ConnectedNodes; return(ConnectedNodes.Any(x => x.IsCapRing && !ignore_nodes.Contains(x) && !x.ProvinceData.IsWater)); }