Esempio n. 1
0
        /// <summary>
        /// Führt eine POST-Anfrage auf dem Server aus.
        /// </summary>
        /// <returns></returns>
        public async Task <object> PostAsync(Type type)
        {
            HttpClient client = await GetHttpClientAsync();

            Uri apiEndpoint = ServerAddress;

            try
            {
                HttpResponseMessage response = await client.PostAsync(apiEndpoint, Body);

                await response.GetContentAsync(type);
            }
            catch (Exception ex)
            {
                var context = new EndpointFailedContext(apiEndpoint, ex);
                await RunEndpointEventsAsync(context);

                if (!context.IsHandled)
                {
                    throw context.Error;
                }
            }

            return(null);
        }
Esempio n. 2
0
        /// <summary>
        /// Wenn <see cref="EndpointFailedContext"/> angegeben sind, dann ausführen.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        private async Task RunEndpointEventsAsync(EndpointFailedContext context)
        {
            if (_client.Options.EndpointEvents?.OnRequestFailed != null)
            {
                await _client.Options.EndpointEvents.OnRequestFailed(context);
            }

            if (!context.IsHandled)
            {
                throw context.Error;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Führt eine DELETE-Anfrage auf dem Server aus.
        /// </summary>
        /// <returns></returns>
        public async Task DeleteAsync()
        {
            HttpClient client = await GetHttpClientAsync();

            Uri apiEndpoint = ServerAddress;

            try
            {
                HttpResponseMessage response = await client.DeleteAsync(apiEndpoint);

                await response.GetContentAsync();
            }
            catch (Exception ex)
            {
                var context = new EndpointFailedContext(apiEndpoint, ex);
                await RunEndpointEventsAsync(context);

                if (!context.IsHandled)
                {
                    throw context.Error;
                }
            }
        }
Esempio n. 4
0
 /// <summary>
 /// Wird ausgeführt, wenn ein Anfrage an den Server fehlschlägt.
 /// </summary>
 /// <param name="context">Ein <see cref="EndpointFailedContext"/> mit weiteren Informationen.</param>
 /// <returns></returns>
 private Task OnRequestFailed(EndpointFailedContext context)
 {
     MessageBox.Show(context.Error.Message, "Request Error", MessageBoxButton.OK, MessageBoxImage.Error);
     context.Handled();
     return(Task.CompletedTask);
 }