public override void Process()
        {
            foreach (Resource resource in ResourceListMessage.Resources)
            {
                if (resource.Length == 0)
                {
                    continue;
                }
                if (resource.ResourceName == ResourceType.NodeCommanderLog)
                {
                    string lines = Encoding.Default.GetString(resource.Data);
                    foreach (string line in lines.Split(new string[] { "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries))
                    {
                        string[] fields = line.Split(new string[] { "||" }, StringSplitOptions.None);

                        NodeLogMessage logMessage = new NodeLogMessage()
                        {
                            FullNodeName = resource.FullNodeName,
                            Timestamp    = DateTime.ParseExact(fields[0], "yyyy-MM-dd HH:mm:ss.ffff", null),
                            Thread       = int.Parse(fields[1]),
                            Level        = fields[2],
                            CallSite     = fields[3],
                            Message      = fields[4],
                            Exception    = fields[5],
                            Stacktrace   = fields[6]
                        };
                        Agent.Session.Database.Persist(logMessage);

                        if (fields.Length == 5 && fields[3] == "Stratis.Bitcoin.Features.Miner.PowMining.GenerateBlocks")
                        {
                            Regex miningRegex = new Regex("([0-9]+)-([0-9a-f]+)");
                            Match match       = miningRegex.Match(fields[4]);

                            BlockchainMining miningEntry = new BlockchainMining();
                            miningEntry.Timestamp    = logMessage.Timestamp;
                            miningEntry.FullNodeName = resource.FullNodeName;
                            miningEntry.BlockNumber  = int.Parse(match.Groups[1].Value);
                            miningEntry.BlockHash    = match.Groups[2].Value;

                            Agent.Session.Database.Persist(miningEntry);
                        }
                        else if (fields.Length == 5 && fields[3] == "Stratis.Bitcoin.Features.Consensus.ConsensusLoop.RewindCoinViewLockedAsync")
                        {
                            Regex reorgRegex = new Regex("([0-9]+)-([0-9a-f]+)' to '([0-9]+)-([0-9a-f]+)");
                            Match match      = reorgRegex.Match(fields[4]);

                            BlockchainReorg reorgEntry = new BlockchainReorg();
                            reorgEntry.Timestamp       = logMessage.Timestamp;
                            reorgEntry.FullNodeName    = resource.FullNodeName;
                            reorgEntry.FromBlockNumber = int.Parse(match.Groups[1].Value);
                            reorgEntry.FromBlockHash   = match.Groups[2].Value;
                            reorgEntry.ToBlockNumber   = int.Parse(match.Groups[3].Value);
                            reorgEntry.ToBlockHash     = match.Groups[4].Value;

                            Agent.Session.Database.Persist(reorgEntry);
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public void Persist(BlockchainReorg reorgEntry)
        {
            try
            {
                using (var t = Engine.GetTransaction())
                {
                    t.SynchronizeTables("Reorg");

                    bool newEntity = reorgEntry.Id == 0;
                    if (newEntity)
                    {
                        reorgEntry.Id = t.ObjectGetNewIdentity <long>("Reorg");
                    }

                    t.ObjectInsert("Reorg", new DBreezeObject <BlockchainReorg>
                    {
                        NewEntity = newEntity,
                        Entity    = reorgEntry,
                        Indexes   = new List <DBreezeIndex>
                        {
                            new DBreezeIndex(1, reorgEntry.Id)
                            {
                                PrimaryIndex = true
                            },
                            new DBreezeIndex(2, reorgEntry.Timestamp),
                            new DBreezeIndex(3, reorgEntry.FullNodeName),
                        }
                    }, false);

                    t.TextInsert("TS_Reorg", reorgEntry.Id.ToBytes(), reorgEntry.FullNodeName);

                    t.Commit();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }