Exemplo n.º 1
0
        /// <summary>
        /// Проверить список презентаций клуба
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public async Task <IList <NnmclubListItem> > CheckList(NnmclubCheckListInput param)
        {
            IList <NnmclubListItem> items = await GetList(param);

            if (items != null)
            {
                if (_context.NnmclubListItems.Count() == 0)
                {
                    _context.NnmclubListItems.AddRange(items);
                    _context.SaveChanges();
                    return(items);
                }
                IList <NnmclubListItem> oldItems =
                    _context
                    .NnmclubListItems
                    .OrderByDescending(d => d.Created)
                    .Take(200)
                    .ToList();
                IList <NnmclubListItem> onlyNew =
                    items.Except(oldItems, new NnmclubListItemComparer())
                    .ToList();

                _context.NnmclubListItems.AddRange(onlyNew);
                _context.SaveChanges();
                return(onlyNew);
            }
            _logger.LogError("При получении последних презентаций вернулось null");
            return(null);
        }
        public async Task <ActionResult <IList <NnmclubListItem> > > CheckList([FromBody] NnmclubCheckListInput input)
        {
            IList <NnmclubListItem> result = await _nnmclubService.CheckList(input);

            if (result != null)
            {
                return(Ok(result));
            }
            return(BadRequest("При проверке списка раздач произошла ошибка"));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Получает последние презентации клуба
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        async Task <IList <NnmclubListItem> > GetList(NnmclubCheckListInput param)
        {
            var result = new List <NnmclubListItem>();

            for (int i = param.UriListCount; i >= 0; i--)
            {
                string page = await GetPage(
                    param.UriList + (i *param.UriListIncrement),
                    param.ProxySocks5Addr,
                    param.ProxySocks5Port,
                    param.ProxyActive,
                    new Uri(param.AuthPage),
                    param.AuthParam);

                if (page != null)
                {
                    var htmlDocument = new HtmlDocument();
                    htmlDocument.LoadHtml(page);
                    HtmlNodeCollection nodesDate = htmlDocument.DocumentNode.SelectNodes(param.XPathDate);
                    HtmlNodeCollection nodesName = htmlDocument.DocumentNode.SelectNodes(param.XPathName);

                    if (nodesDate != null &&
                        nodesName != null)
                    {
                        var ruCultutre = new CultureInfo("RU-ru");
                        var postQuery  =
                            from date in nodesDate
                            join name in nodesName on date.Line equals name.Line + 6
                            select new NnmclubListItem
                        {
                            Created = DateTime.Now,
                            Added   = DateTime.ParseExact(
                                HttpUtility.HtmlDecode(
                                    date.InnerText.Remove(0, date.InnerText.Length - param.DateTimeFormat.Length)),
                                param.DateTimeFormat,
                                ruCultutre,
                                DateTimeStyles.AllowInnerWhite),
                            Name = HttpUtility.HtmlDecode(
                                name.GetAttributeValue("title", null)),
                            Href = name.GetAttributeValue("href", null)
                        };
                        result.AddRange(postQuery.ToList());
                        continue;
                    }
                    _logger.LogError("XPath выражение вернуло null");
                    return(null);
                }
                return(null);
            }
            return(result);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Запуск пакетного парсинаг Nnmclub
        /// </summary>
        /// <returns></returns>
        async Task <bool> ManagerNnmclub(int dayFromError)
        {
            IList <NnmclubListItem> errorList =
                _context
                .NnmclubListItems
                .FromSqlInterpolated($"NnmclubListItemsError {DateTime.Now.AddDays(-dayFromError)}")
                .ToList();

            if (errorList.Count > 0)
            {
                bool resTails = await FlowNnmclub(errorList);

                if (!resTails)
                {
                    _logger.LogError("Ошибка пакетной публикации хвостов");
                    return(false);
                }
            }

            NnmclubCheckListInput inp =
                _context
                .NnmclubCheckListInputs
                .Single(el => el.Active);
            IList <NnmclubListItem> list = await _nnmclubService.CheckList(inp);

            if (list == null)
            {
                _logger.LogError("Ошибка проверки новых презентаций. NnmclubCheckListInput.Id = " + inp.Id);
                return(false);
            }
            bool res = await FlowNnmclub(list);

            if (!res)
            {
                _logger.LogError("Ошибка пакетной публикации рогов");
                return(false);
            }
            return(true);
        }