Example #1
0
        public async Task RemoveItemAsync(Message itemMessage)
        {
            var itemText  = itemMessage.Text;
            var firstLine = itemText.Substring(0, itemText.IndexOf(Environment.NewLine));

            if (string.IsNullOrEmpty(firstLine))
            {
                throw new Exception(Exceptions.PARSE_NAME_EXCEPTION);
            }

            _timerService.RemoveFromQueue(firstLine);

            await _trackingRepository.RemoveItemAsync(firstLine);
        }
Example #2
0
        private async void OnTimedEvent(Object source, ElapsedEventArgs e)
        {
            if (!itemsQueue.Any())
            {
                return;
            }

            var item = itemsQueue.Dequeue();

            try
            {
                var newInfo = item.Source switch
                {
                    PullAndBear.SHOP_NAME => await _pullAndBearClient.GetItemInfoAsync(item.Url),
                    Bershka.SHOP_NAME => await _bershkaClient.GetItemInfoAsync(item.Url),
                    _ => throw new Exception(Exceptions.UNKNOWN_SHOP_EXCEPTION),
                };
                if (item.Status != newInfo.Status || item.Price != newInfo.Price)
                {
                    await _botService.SendMessageMarkdownV2Async(
                        item.ChatId,
                        _textConverter.ToString(item, newInfo));
                }
                _updateInfoHelper.GetUpdatedItem(ref item, newInfo);
                await _trackingRepository.UpdateInfoOfItemAsync(item);
            }
            catch (Exception ex)
            {
                // it's ok; lets update item information next time;
            }
            if ((DateTime.Now - item.LastUpdateDate).TotalHours > maxTimeWithoutUpdateIntervalHours)
            {
                await _trackingRepository.RemoveItemAsync(item.Url);

                await _botService.SendMessageAsync(
                    item.ChatId,
                    WANNA_REMOVE_ITEM_EXCEPTION);
            }
            else
            {
                itemsQueue.Enqueue(item);
                if ((DateTime.Now - item.LastUpdateDate).TotalHours > maxUpdateTimeIntervalHours)
                {
                    await _botService.SendMessageAsync(
                        item.ChatId,
                        CANT_UPDATE_EXCEPTION);
                }
            }
        }