public override void Process() { foreach (BlockchainNodeState state in BlockchainNodeStateMessage.NodesStatistics) { BlockchainHeight blockchainHeight = new BlockchainHeight(); blockchainHeight.FullNodeName = state.NodeEndpoint.FullNodeName; blockchainHeight.Timestamp = DateTime.Now; blockchainHeight.HeadersHeight = state.NodeLogState.HeadersHeight; blockchainHeight.ConsensusHeight = state.NodeLogState.ConsensusHeight; blockchainHeight.BlockStoreHeight = state.NodeLogState.BlockStoreHeight; //blockchainHeight.WalletsHeight = node.NodeLogState.WalletHeight; Agent.Session.Database.Persist(blockchainHeight); } if (BlockchainNodeStateMessage == null || BlockchainNodeStateMessage.NodesStatistics.Length == 0) { return; } foreach (BlockchainNodeState nodeState in BlockchainNodeStateMessage.NodesStatistics) { if (Agent.Session.ManagedNodes.Nodes.ContainsKey(nodeState.NodeEndpoint.FullNodeName)) { Agent.Session.ManagedNodes.Nodes[nodeState.NodeEndpoint.FullNodeName].NodeState = nodeState; } else { logger.Error($"Cannot update state of node {nodeState.NodeEndpoint.FullNodeName} because it is not managed by the agent."); } } Agent.Session.OnNodesUpdated(Agent, Agent.Session.ManagedNodes); }
public void Persist(BlockchainHeight blockchainHeight) { try { using (var t = Engine.GetTransaction()) { t.SynchronizeTables("BlockchainHeight"); bool newEntity = blockchainHeight.Id == 0; if (newEntity) { blockchainHeight.Id = t.ObjectGetNewIdentity <long>("BlockchainHeight"); } t.ObjectInsert("BlockchainHeight", new DBreezeObject <BlockchainHeight> { NewEntity = newEntity, Entity = blockchainHeight, Indexes = new List <DBreezeIndex> { new DBreezeIndex(1, blockchainHeight.Id) { PrimaryIndex = true }, new DBreezeIndex(2, blockchainHeight.Timestamp), new DBreezeIndex(3, blockchainHeight.FullNodeName), } }, false); t.TextInsert("TS_BlockchainHeight", blockchainHeight.Id.ToBytes(), blockchainHeight.FullNodeName); t.Commit(); } } catch (Exception ex) { throw ex; } }