Ejemplo n.º 1
0
        /// <summary>
        /// Asynchronously download an XML and deserializes it into the specified type.
        /// </summary>
        /// <typeparam name="T">The inner type to deserialize</typeparam>
        /// <param name="url">The url to query</param>
        /// <param name="param">The request parameters. If null, defaults will be used.</param>
        /// <param name="transform">The XSL transform to apply, may be null.</param>
        internal static async Task <CCPAPIResult <T> > DownloadAPIResultAsync <T>(Uri url,
                                                                                  RequestParams param = null, XslCompiledTransform transform = null)
        {
            var asyncResult = await HttpWebClientService.DownloadXmlAsync(url, param);

            CCPAPIResult <T> result;

            try
            {
                // Was there an HTTP error ?
                result = (asyncResult.Error != null) ? new CCPAPIResult <T>(asyncResult.Error) :
                         DeserializeAPIResultCore <T>(asyncResult.Result, transform);
                // We got the result
                return(result);
            }
            catch (Exception e)
            {
                result = new CCPAPIResult <T>(HttpWebClientServiceException.Exception(url, e));

                ExceptionHandler.LogException(e, false);
                EveMonClient.Trace($"Method: DownloadAPIResultAsync, url: {url.AbsoluteUri}, postdata: {param?.Content}, type: {typeof(T).Name}",
                                   false);
            }

            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Asynchronously download an XML and deserializes it into the specified type.
        /// </summary>
        /// <typeparam name="T">The inner type to deserialize</typeparam>
        /// <param name="url">The url to query</param>
        /// <param name="acceptEncoded">if set to <c>true</c> accept encoded response.</param>
        /// <param name="postData">The post data.</param>
        /// <param name="transform">The XSL transform to apply, may be null.</param>
        internal static async Task <CCPAPIResult <T> > DownloadAPIResultAsync <T>(Uri url, bool acceptEncoded    = false,
                                                                                  string postData                = null,
                                                                                  XslCompiledTransform transform = null)
        {
            DownloadResult <IXPathNavigable> asyncResult =
                await HttpWebClientService.DownloadXmlAsync(url, HttpMethod.Post, acceptEncoded, postData);

            CCPAPIResult <T> result;

            try
            {
                // Was there an HTTP error ?
                result = asyncResult.Error != null
                    ? new CCPAPIResult <T>(asyncResult.Error)
                    : DeserializeAPIResultCore <T>(asyncResult.Result, transform);

                // We got the result
                return(result);
            }
            catch (Exception e)
            {
                result = new CCPAPIResult <T>(HttpWebClientServiceException.Exception(url, e));

                ExceptionHandler.LogException(e, false);
                EveMonClient.Trace(
                    $"Method: DownloadAPIResultAsync, url: {url.AbsoluteUri}, postdata: {postData}, type: {typeof(T).Name}",
                    false);
            }

            return(result);
        }
Ejemplo n.º 3
0
            /// <summary>
            /// Begins the download.
            /// </summary>
            private void BeginDownload()
            {
                Uri    url = new Uri($"{m_datafile.Address}/{m_datafile.Name}");
                string urlValidationError;

                if (!HttpWebClientService.IsValidURL(url, out urlValidationError))
                {
                    return;
                }

                if (File.Exists(m_tempFilename))
                {
                    FileHelper.DeleteFile(m_tempFilename);
                }

                try
                {
                    using (WebClient)
                    {
                        WebClient.DownloadFileCompleted   += DownloadCompleted;
                        WebClient.DownloadProgressChanged += ProgressChanged;

                        try
                        {
                            WebClient.DownloadFileAsync(url, m_tempFilename);
                        }
                        catch (WebException ex)
                        {
                            throw HttpWebClientServiceException.HttpWebClientException(url, ex);
                        }
                        catch (Exception ex)
                        {
                            throw HttpWebClientServiceException.Exception(url, ex);
                        }
                    }
                }
                catch (Exception ex)
                {
                    ExceptionHandler.LogRethrowException(ex);
                    throw;
                }
            }
Ejemplo n.º 4
0
        /// <summary>
        /// Handles the Shown event of the UpdateDownloadForm control.
        /// </summary>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected override void OnShown(EventArgs e)
        {
            base.OnShown(e);

            string urlValidationError;

            if (!HttpWebClientService.IsValidURL(m_url, out urlValidationError))
            {
                throw new ArgumentException(urlValidationError);
            }

            try
            {
                using (m_client = HttpWebClientService.GetWebClient())
                {
                    m_client.DownloadFileCompleted   += DownloadCompleted;
                    m_client.DownloadProgressChanged += ProgressChanged;

                    try
                    {
                        m_client.DownloadFileAsync(m_url, m_fileName);
                    }
                    catch (WebException ex)
                    {
                        throw HttpWebClientServiceException.HttpWebClientException(m_url, ex);
                    }
                    catch (Exception ex)
                    {
                        throw HttpWebClientServiceException.Exception(m_url, ex);
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionHandler.LogRethrowException(ex);
                throw;
            }
        }