Beispiel #1
0
        /// <summary>
        /// Sends http GET request to api.steampowered.com
        /// for steam application news.
        /// </summary>
        /// <returns>AppNewsCollection object</returns>
        public async Task <AppNewsResponse> GetAppNewsAsync(uint appId, uint count = 20,
                                                            long endDateTimestamp  = -1, CToken cToken = default, params string[] tags)
        {
            UrlBuilder.Host = HOST;
            UrlBuilder.AppendPath(ISTEAM_NEWS, "GetNewsForApp", "v2");
            UrlBuilder.AppendQuery("appid", appId.ToString())
            .AppendQuery("count", count.ToString())
            .AppendQuery("enddate", ValidateTimestamp(endDateTimestamp).ToString())
            .AppendQuery("tags", string.Join(",", tags));

            string          url       = UrlBuilder.PopEncodedUrl(false);
            AppNewsResponse result    = null;
            Exception       exception = null;

            try
            {
                var response = await GetModelAsync <AppNewsResponseParent>(url, cToken)
                               .ConfigureAwait(false);

                result = new AppNewsResponse()
                {
                    Contents = response.AppNews
                };
            }
            catch (Exception ex)
            {
                // API creators did really excellet job, invalid id results to Forbidden HTTP status code
                if (ex is ApiException apiEx && apiEx.HttpStatusCode == 403)
                {
                    exception = new ApiEmptyResultException($"App id is propably invalid: {appId}", apiEx);
                }
Beispiel #2
0
 /// <summary>
 /// Creates URL for GetSteamProducts-method.
 /// </summary>
 /// <returns>UrlBuilder object</returns>
 private void CreateProductUrl(IncludeProducts products, string count)
 {
     UrlBuilder.Host = HOST;
     UrlBuilder.AppendPath(ISTORE_SERVICE, "GetAppList", "v1");
     UrlBuilder.AppendQuery("key", ApiKey)
     .AppendQuery("max_results", count)
     .AppendQuery("include_games", products.HasFlag(IncludeProducts.Games) ? "1" : "0")
     .AppendQuery("include_dlc", products.HasFlag(IncludeProducts.DLC) ? "1" : "0")
     .AppendQuery("include_software", products.HasFlag(IncludeProducts.Software) ? "1" : "0")
     .AppendQuery("include_hardware", products.HasFlag(IncludeProducts.Harware) ? "1" : "0")
     .AppendQuery("include_videos", products.HasFlag(IncludeProducts.Videos) ? "1" : "0");
 }
        public void AppendQuery(string url, string key, string value, string expected)
        {
            var builder = new UrlBuilder(url);

            builder.Should().NotBeNull();

            builder.AppendQuery(key, value);
            builder.Query.Should().NotBeEmpty();
            builder.Query.Should().ContainKey(key);
            builder.Query[key].Should().Contain(value);

            builder.ToString().Should().Be(expected);
        }
Beispiel #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="result"></param>
        /// <param name="thrown"></param>
        /// <param name="cToken"></param>
        /// <returns></returns>
        private async Task <(SteamProductsResponse, Exception)> GetAllProducts(
            SteamProductsResponse result, Exception thrown, CToken cToken)
        {
            try
            {
                SteamProductsResponseParent chunk       = null;
                SteamProductsResponseParent allProducts =
                    await GetModelAsync <SteamProductsResponseParent>(UrlBuilder.GetEncodedUrl(), cToken : cToken)
                    .ConfigureAwait(false);

                while (allProducts.Content.MoreResults)
                {
                    UrlBuilder.AppendQuery("last_appid", allProducts.Content.LastId.ToString());
                    chunk = await GetModelAsync <SteamProductsResponseParent>(UrlBuilder.GetEncodedUrl(), cToken : cToken)
                            .ConfigureAwait(false);

                    allProducts.Content.LastId = chunk.Content.LastId;
                    allProducts.Content.ProductList.AddRange(chunk.Content.ProductList);
                    allProducts.Content.MoreResults = chunk.Content.MoreResults;
                }
                result = new SteamProductsResponse()
                {
                    Contents    = allProducts.Content.ProductList,
                    LastAppId   = chunk.Content.LastId,
                    MoreResults = chunk.Content.MoreResults
                };
            }
            catch (Exception ex)
            {
                thrown = ex;
            }
            finally
            {
                UrlBuilder.PopEncodedUrl(false);
            }
            return(result, thrown);
        }
Beispiel #5
0
        /// <summary>
        /// Sends http GET request to api.steampowered.com for
        /// CSGO server status info. Request can be cancelled by
        /// providing cancellation token.
        /// </summary>
        /// <param name="version">API method version</param>
        /// <param name="cToken">Cancellation token</param>
        /// <returns>CSGO server status model</returns>
        public async Task <CsGoServerStatusResponse> GetCsGoServerStatusAsync(string version = "v1",
                                                                              Ctoken cToken  = default)
        {
            UrlBuilder.Host = HOST;
            UrlBuilder.AppendPath("ICSGOServers_730", "GetGameServersStatus", version);
            UrlBuilder.AppendQuery("key", ApiKey);

            string url = UrlBuilder.PopEncodedUrl(false);
            CsGoServerStatusResponse result = null;
            Exception exception             = null;

            try
            {
                var response = await GetModelAsync <CsGoServerStatusResponse>(url, cToken)
                               .ConfigureAwait(false);

                result = response;
            }
            catch (Exception ex)
            {
                exception = ex;
            }
            return(WrapResponse(result, url, exception));
        }
        public ActionResult Log(LogViewModel formModel)
        {
            if (!string.IsNullOrEmpty(formModel.Message))
            {
                Trace.TraceInformation("MasterAdminController.Log(formModel): " + formModel.Message);
            }

            var levels = formModel.GetLevels();
            IEnumerable <WindowsAzureLogHelper.TraceLogsEntity> logsSource = WindowsAzureLogHelper.GetLogEvents(
                formModel.Page ?? 1, levels.ToArray(), formModel.FilterRoleInstance, formModel.FilterPath);

            var logs = logsSource
                       .Select(
                item => new LogViewModel.TraceLogItem(item.Message)
            {
                Timestamp    = DateTime.Parse(item.Timestamp),
                Level        = item.Level,
                RoleInstance = item.RoleInstance,
                Role         = item.Role,
            });

            if (formModel.HasPathFilter())
            {
                logs = logs.Where(l => l.Path.StartsWith(formModel.FilterPath));
            }

            if (formModel.HasSourceFilter())
            {
                logs = logs.Where(l => l.Source.Equals(formModel.FilterSource, StringComparison.InvariantCultureIgnoreCase));
            }

            if (formModel.HasTextFilter())
            {
                logs = logs.Where(l => l.Text.IndexOf(formModel.FilterText, StringComparison.InvariantCultureIgnoreCase) > 0);
            }

            if (formModel.HasRoleInstanceFilter())
            {
                logs = logs.Where(l => formModel.FilterRoleInstance == l.RoleInstance);
            }

            if (formModel.HasLevelFilter())
            {
                logs = logs.Where(l => levels.Contains(l.Level));
            }

            if (formModel.HasSpecialFilter())
            {
                logs = logs.Where(l => l.SpecialStrings.Any(s => formModel.FilterSpecial.Contains(s)));
            }

            if (formModel.HasRoleFilter())
            {
                logs = logs.Where(l => formModel.FilterRole == l.Role);
            }

            if (formModel.HasTimestampFilter())
            {
                if (formModel.FilterTimestamp == "now")
                {
                    var vm = formModel.Clone();
                    vm.FilterLevel = null;
                    var q = UrlBuilder.GetListQueryParams("FilterSpecial", vm.FilterSpecial);
                    vm.FilterTimestamp = this.GetUtcNow().ToString("yyyy'-'MM'-'dd'-'HH'-'mm");

                    return(this.Redirect(UrlBuilder.AppendQuery(this.Url.Action("Log", vm), q)));
                }

                var date =
                    DateTime.Parse(
                        Regex.Replace(
                            formModel.FilterTimestamp,
                            @"(\d{4})\-(\d{2})\-(\d{2})\-(\d{2})\-(\d{2})",
                            @"$1-$2-$3T$4:$5:00"));

                logs = logs.Where(l => l.Timestamp > date);
            }

            formModel.Logs = logs.ToList();

            return(this.View(formModel));
        }