Beispiel #1
0
        public override async Task HandleAsync(CallbackQueryUpdateMessage message)
        {
            var mainMetric = _metricRepository.GetMainByExternalId(message.ChatId);

            if (mainMetric == null)
            {
                await _botClient.SendTextMessageAsync(message, MessageCode.NoMainMetric);

                return;
            }

            var values = _valueRepository.GetByMetricId(mainMetric.Id, 1, int.MaxValue);

            if (values.Count() < 2)
            {
                await _botClient.SendTextMessageAsync(message, MessageCode.ToFewValues);

                return;
            }

            var          plotData    = new PlotDataFactory().ValuesTo(values, mainMetric.ToString());
            var          filename    = FileName.GetPlotFilename(message.UpdateId.ToString());
            IFileService fileService = new ScottPlotService(new PngFileName(filename), plotData);

            using (var plotService = new FileReaderService(fileService))
            {
                var stream = plotService.GetFileStream();
                await _botClient.SendFileAsync(message.ChatId, stream, filename);
            }
        }
Beispiel #2
0
        public override async Task HandleAsync(CallbackQueryUpdateMessage message)
        {
            if (!int.TryParse(Parameter, out int currentPageNumber))
            {
                currentPageNumber = 1;
            }

            var mainMetric = _metricRepository.GetMainByExternalId(message.ChatId);

            if (mainMetric == null)
            {
                await _botClient.SendTextMessageAsync(message, MessageCode.NoMainMetric);

                return;
            }

            var valueNames = _valueRepository.GetByMetricId(mainMetric.Id, currentPageNumber, PagingMenuData.DefaultPageSize)
                             .ToDictionary(m => FormatKey(m.Id), m => $"{m}");

            var count     = _valueRepository.CountByMetric(mainMetric.Id);
            var pageCount = (count / PagingMenuData.DefaultPageSize) + 1;

            var menuData = new PagingMenuData
            {
                ButtonTexts = valueNames,
                CurrentPage = currentPageNumber,
                PageCount   = pageCount,
                Previous    = ButtonCode.Menu,
            };

            message = message with {
                MenuMessageId = MenuMessageId
            };
            await _botClient.EditTextButtonsMenuWithPagingAsync(message, Button, menuData);
        }
    }