protected override void OnReceive(object message) { if (message is PersistCompleted m) { if (this.lastUpdateStamp == null || this.lastUpdateStamp.Value.ToUnixDate().AddMinutes(MinutesPerAudit) <= m.Block.Timestamp.ToUnixDate()) { if (this.lastUpdateStamp == null) { this.lastUpdateStamp = m.Block.Timestamp; } var optionsBuilder = new DbContextOptionsBuilder <StateOfNeoContext>(); optionsBuilder.UseSqlServer(this.connectionString, opts => opts.CommandTimeout((int)TimeSpan.FromMinutes(10).TotalSeconds)); var db = new StateOfNeoContext(optionsBuilder.Options); var previousBlock = Blockchain.Singleton.GetBlock(m.Block.PrevHash); var previousBlockTime = previousBlock.Timestamp.ToUnixDate(); var nodes = db.Nodes .Include(x => x.NodeAddresses) .Include(x => x.Audits) .Where(x => x.Net == this.net) .ToList(); foreach (var node in nodes) { var successUrl = node.SuccessUrl; var audit = this.NodeAudit(node, m.Block); if (audit != null) { db.NodeAudits.Add(audit); node.LastAudit = m.Block.Timestamp; } if (string.IsNullOrEmpty(successUrl) || (!node.Longitude.HasValue && !node.Latitude.HasValue)) { foreach (var address in node.NodeAddresses) { var result = LocationCaller.UpdateNode(node, address.Ip).GetAwaiter().GetResult(); var peerById = db.Peers.FirstOrDefault(x => x.NodeId == node.Id); if (result && peerById == null) { var peer = db.Peers.FirstOrDefault(x => x.Ip == address.Ip); if (peer != null) { peer.NodeId = node.Id; } else { var newPeer = CreatePeerFromNode(node, address.Ip); db.Peers.Add(newPeer); } break; } else if (peerById != null) { if (!peerById.Longitude.HasValue && !peerById.Latitude.HasValue) { peerById.FlagUrl = node.FlagUrl; peerById.Locale = node.Locale; peerById.Latitude = node.Latitude; peerById.Longitude = node.Longitude; peerById.Location = node.Location; } } } } db.Nodes.Update(node); db.SaveChanges(); } this.lastUpdateStamp = m.Block.Timestamp; this.totalSecondsElapsed = null; } } }
public PeerService(StateOfNeoContext db) { this.db = db; }
public AddressService(StateOfNeoContext db) : base(db) { }
public NodeCache(StateOfNeoContext ctx) { _ctx = ctx; NodeList = new HashSet <NodeViewModel>(); }