public OneServerMarketViewModel()
        {
            WorkersPercentLimit = 60;

            Messenger.Default.Register <CheckAutoStartMessage>(this, m =>
            {
                if (m.Checked)
                {
                    CalcLevelForJump();
                    CalcServersPowers();
                }

                CatchUp = m.Checked;

                MarketLogger.Information($"!!! AutoStart message {m.Checked}!!!");
            });

            _timer = new Timer(state =>
            {
                CalcLevelForJump();
            }, null, 0, 300);
        }
示例#2
0
        private void ParseOnPageAndFindBlocks(HtmlWeb web, int stepsCounter)
        {
            HtmlDocument document = null;

            try
            {
                document = web.Load(stepsCounter == 0 || !Blocks.Any()
                    ? _blocksRequest
                    : $"{_blocksRequest}&height={Blocks.OrderBy(b => b.Id).First()?.Id}");
            }
            catch (Exception ex)
            {
                MarketLogger.Error(ex, $"GetStatisticOfBlocks {ex.Message} {_blocksRequest}");
            }

            if (document == null)
            {
                return;
            }

            var rowsOfBlock = document.DocumentNode.Descendants("table")
                              .Where(y => y.Attributes.Contains("class") &&
                                     y.Attributes["class"].Value.Contains("table") &&
                                     y.Attributes["class"].Value.Contains("table-striped") &&
                                     y.Attributes["class"].Value.Contains("table-bordered") &&
                                     y.Attributes["class"].Value.Contains("table-hover")

                                     && y.Descendants("tr").Count() > 10
                                     )
                              .SelectMany(y => y.Descendants("tr"))
                              .Where(y => !y.Descendants("td").Any(yy => yy.Attributes.Contains("colspan")))
                              .ToList();

            rowsOfBlock.ForEach(r =>
            {
                var id = r.Descendants("td").FirstOrDefault()?.InnerText;

                if (id == null)
                {
                    return;
                }

                //var descendants = r.Descendants("td").ToList();

                var percent  = r.Descendants("td").LastOrDefault()?.Descendants("font").Single().InnerText;
                var dateTime = r.Descendants("td").Skip(3).FirstOrDefault()?.InnerText;
                var diff     = r.Descendants("td").Skip(4).FirstOrDefault()?.InnerText;
                double.TryParse(diff, NumberStyles.AllowDecimalPoint | NumberStyles.AllowThousands, CultureInfo.InvariantCulture, out var diffDouble);
                var block = new BlockInfo(id, percent, diffDouble, DateTime.ParseExact(dateTime, "MM/dd/yyyy HH:mm:ss", CultureInfo.InvariantCulture).AddHours(_currentTimeZoneHoursOffset));

                OnRowOfBlockParsed(block);

                var existBlock = Blocks.FirstOrDefault(b => b.Id == block.Id);

                if (existBlock == null)
                {
                    Blocks.Enqueue(block);

                    OnNewBlockFounded(block);
                    OnDifficultyChanged(new DashboardPoolResult {
                        Difficulty = block.Difficulty, QueryDateTime = block.Created
                    });
                }
                else if (Math.Abs(existBlock.Percent - block.Percent) > 0.001 && existBlock.Percent < block.Percent)
                {
                    existBlock.Percent = block.Percent;
                    OnBlockUpdated(existBlock);
                }
            });
        }