Esempio n. 1
0
        /// <summary>
        /// Gets the loadout by type ID.
        /// </summary>
        /// <param name="id">The id.</param>
        public override async Task GetLoadoutByIDAsync(long id)
        {
            // Quit if query is pending
            if (s_queryPending)
            {
                return;
            }

            Uri url = new Uri(NetworkConstants.OsmiumBaseUrl + string.Format(
                                  CultureConstants.InvariantCulture, NetworkConstants.OsmiumLoadoutDetails, id));

            s_queryPending = true;

            OnLoadoutDownloaded(await HttpWebClientService.DownloadStringAsync(url));
        }
        /// <summary>
        /// Asynchronously gets the external parser.
        /// </summary>
        private static void GetExternalParserAsync()
        {
            if (s_queryPending)
            {
                return;
            }

            Uri url = new Uri(NetworkConstants.BitBucketWikiBase + NetworkConstants.
                              ExternalEveNotificationTextParser);

            s_queryPending = true;
            HttpWebClientService.DownloadStringAsync(url).ContinueWith(task =>
            {
                OnDownloaded(task.Result);
            });
        }
Esempio n. 3
0
        /// <summary>
        /// Retrieves a token from the server with the specified authentication data.
        /// </summary>
        /// <param name="data">The POST data, either an auth code or a refresh token.</param>
        /// <param name="callback">A callback to receive the new token.</param>
        /// <param name="isJWT">true if a JWT response is expected, or false if a straight JSON response is expected.</param>
        private void FetchToken(string data, Action <AccessResponse> callback, bool isJWT)
        {
            var obtained = DateTime.UtcNow;
            var url      = new Uri(NetworkConstants.SSOBaseV2 + NetworkConstants.SSOToken);
            var rp       = new RequestParams()
            {
                Content = data,
                Method  = HttpMethod.Post
            };

            if (!string.IsNullOrEmpty(m_secret))
            {
                // Non-PKCE
                rp.Authentication = GetBasicAuthHeader();
            }
            HttpWebClientService.DownloadStringAsync(url, rp).ContinueWith((result) =>
            {
                AccessResponse response = null;
                DownloadResult <string> taskResult;
                string encodedToken;
                // It must be completed or failed if ContinueWith is reached
                if (result.IsFaulted)
                {
                    ExceptionHandler.LogException(result.Exception, true);
                }
                else if ((taskResult = result.Result) != null)
                {
                    // Log HTTP error if it occurred
                    if (taskResult.Error != null)
                    {
                        ExceptionHandler.LogException(taskResult.Error, true);
                    }
                    else if (!string.IsNullOrEmpty(encodedToken = taskResult.Result))
                    {
                        // For some reason the JWT token is not returned according to the ESI
                        // spec
                        response = TokenFromString(encodedToken, false, obtained);
                    }
                }
                Dispatcher.Invoke(() => callback?.Invoke(response));
            });
        }
Esempio n. 4
0
        /// <summary>
        /// Asynchronously download an object from a JSON stream.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="url">The URL.</param>
        /// <param name="acceptEncoded">if set to <c>true</c> [accept encoded].</param>
        /// <param name="postData">The post data.</param>
        /// <returns></returns>
        public static async Task <DownloadResult <T> > DownloadJsonAsync <T>(Uri url, bool acceptEncoded = false,
                                                                             string postData             = null)
            where T : class
        {
            DownloadResult <String> asyncResult =
                await HttpWebClientService.DownloadStringAsync(url, HttpMethod.Post, acceptEncoded, postData);

            T result = null;
            HttpWebClientServiceException error = null;

            // Was there an HTTP error ??
            if (asyncResult.Error != null)
            {
                error = asyncResult.Error;
            }
            else
            {
                // No http error, let's try to deserialize
                try
                {
                    // Deserialize
                    result = new JavaScriptSerializer().Deserialize <T>(asyncResult.Result);
                }
                catch (ArgumentException exc)
                {
                    // An error occurred during the deserialization
                    ExceptionHandler.LogException(exc, true);
                    error = new HttpWebClientServiceException(exc.InnerException?.Message ?? exc.Message);
                }
                catch (InvalidOperationException exc)
                {
                    // An error occurred during the deserialization
                    ExceptionHandler.LogException(exc, true);
                    error = new HttpWebClientServiceException(exc.InnerException?.Message ?? exc.Message);
                }
            }

            return(new DownloadResult <T>(result, error));
        }