Beispiel #1
0
        public async Task <ActionResult> AppIndexLinked(VMSteamApp filterModel, SxOrderItem order, int page = 1, int pageSize = 10, int?gameId = null)
        {
            var gid = string.IsNullOrEmpty(Request.Form.Get("gameId"))?null: Request.Form.Get("gameId");

            ViewBag.GameId = gid ?? gameId.ToString();

            var filter = new SxFilter(page, pageSize)
            {
                Order = order != null && order.Direction != SortDirection.Unknown ? order : null, WhereExpressionObject = filterModel, AddintionalInfo = new object[] { null, ViewBag.GameId }
            };

            var viewModel = await Repo.ReadAsync(filter);

            if (page > filter.PagerInfo.TotalPages)
            {
                page = 1;
            }
            if (page > 1 && !viewModel.Any())
            {
                return(new HttpNotFoundResult());
            }

            ViewBag.Filter = filter;
            return(PartialView("_GridViewAppLinked", viewModel));
        }
Beispiel #2
0
        public async Task <ActionResult> AppIndexFree(VMSteamApp filterModel, SxOrderItem order, int page = 1, int pageSize = 10)
        {
            var filter = new SxFilter(page, pageSize)
            {
                Order = order != null && order.Direction != SortDirection.Unknown ? order : null, WhereExpressionObject = filterModel, AddintionalInfo = new object[] { true, null }
            };

            var viewModel = await Repo.ReadAsync(filter);

            if (page > filter.PagerInfo.TotalPages)
            {
                page = 1;
            }
            if (page > 1 && !viewModel.Any())
            {
                return(new HttpNotFoundResult());
            }

            ViewBag.Filter = filter;
            return(PartialView("_GridViewAppFree", viewModel));
        }
        public async Task GetNewsForApp(int gameId)
        {
            var apiKey = (await _repoApiParameter.GetApiParameterAsync("Steam", "steam-api-key"))?.Value;

            if (string.IsNullOrEmpty(apiKey))
            {
                Clients.All.insertModalAppNewsHtml($"<strong class=\"text-danger\">Необходимо задать натройку steam-api-key для API Steam</strong>");
                return;
            }

            var game = await _repoGame.GetByKeyAsync(gameId);

            if (game == null)
            {
                Clients.All.insertModalAppNewsHtml($"<strong class=\"text-danger\">Отсутсвует запрашиваемая игра</strong>");
                return;
            }

            Clients.All.insertModalAppNewsHtml($"<strong>{game.Title}</strong>");

            var gameSteamApps = await _repoSteamApp.ReadAsync(new SxFilter(1, int.MaxValue) { AddintionalInfo = new object[] { null, gameId } });

            if (!gameSteamApps.Any())
            {
                Clients.All.insertModalAppNewsHtml($"<strong class=\"text-danger\">У данной игры нет привязанных приложений Steam</strong>");
                return;
            }

            // формирование списка приложений Steam
            var sb = new System.Text.StringBuilder();

            sb.Append("<table class=\"table table-striped table-condensed game-modal-steam-apps-table\">");
            VMSteamApp item = null;

            for (int i = 0; i < gameSteamApps.Length; i++)
            {
                item = gameSteamApps[i];
                sb.Append("<tr>");
                sb.AppendFormat("<td><input type=\"checkbox\" name=\"steamAppArray[]\" checked=\"checked\" value=\"{0}\"/></td>", item.Id);
                sb.AppendFormat("<td style=\"width:50%;\">{0}</td>", item.Name);
                sb.Append("<td style=\"width:50%;\"><div class=\"text-right\"><div class=\"game-modal-steam-apps-table__progress\"></div></td>");
                sb.Append("</tr>");
            }
            sb.Append("</table>");
            Clients.All.insertModalAppNewsHtml(sb.ToString());

            // запрос новостей по каждому steam приложению
            _gamesNews.Clear();
            SteamNews[] news;
            for (int i = 0; i < gameSteamApps.Length; i++)
            {
                item = gameSteamApps[i];
                var appId = item.Id;
                using (var httpClient = new HttpClient())
                {
                    try
                    {
                        var url  = $"{_getAppNewsUrl}?appid={appId}&key={apiKey}";
                        var json = await httpClient.GetStringAsync(url);

                        news = ((JArray)JsonConvert.DeserializeObject <dynamic>(json).appnews.newsitems).Select(x => new SteamNews()
                        {
                            Author        = (string)x["author"],
                            Contents      = (string)x["contents"],
                            Date          = (int)x["date"],
                            FeedLabel     = (string)x["feedlabel"],
                            FeedName      = (string)x["feedname"],
                            Gid           = (string)x["gid"],
                            IsExternalUrl = Convert.ToBoolean(x["is_external_url"]),
                            Title         = (string)x["title"],
                            Url           = (string)x["url"],
                            SteamAppId    = appId
                        }).ToArray();
                    }
                    catch (Exception ex)
                    {
                        Clients.All.addModalAppNewsProcessedCount(appId, new { Status = "error", Count = 0, Message = ex.Message });
                        continue;
                    }
                }

                if (news.Any())
                {
                    var existNews = await _repoSteamNews.GetSteamAppNewsAsync(appId, news.Select(x => x.Gid).ToArray());

                    var comparer = new SteamNewsComparer();
                    var data     = news.Except(existNews, comparer).ToArray();

                    if (data.Any())
                    {
                        for (int y = 0; y < data.Length; y++)
                        {
                            _gamesNews.Add(data[y]);
                        }
                    }
                    Clients.All.addModalAppNewsProcessedCount(appId, new { Status = "ok", Count = data.Length });
                }
                else
                {
                    Clients.All.addModalAppNewsProcessedCount(appId, new { Status = "ok", Count = 0 });
                }
            }

            Clients.All.showAddNewsButton(gameId);
        }