Queue.Administrator.EditMediaConfigFileForm.uploadButton_Click C# (CSharp) Méthode

uploadButton_Click() private méthode

private uploadButton_Click ( object sender, EventArgs eventArgs ) : void
sender object
eventArgs EventArgs
Résultat void
        private async void uploadButton_Click(object sender, EventArgs eventArgs)
        {
            if (selectMediaFileDialog.ShowDialog() == DialogResult.OK)
            {
                string fileName = selectMediaFileDialog.FileName;

                using (var channel = ChannelManager.CreateChannel())
                {
                    try
                    {
                        if (MediaConfigFile.Id == Guid.Empty)
                        {
                            MediaConfigFile = await taskPool.AddTask(channel.Service.EditMediaConfigFile(MediaConfigFile));
                        }

                        CancellationTokenSource uploadOperation = new CancellationTokenSource();

                        var progress = new ProgressMessageHandler();
                        progress.HttpSendProgress += new EventHandler<HttpProgressEventArgs>((s, e) =>
                        {
                            try
                            {
                                Invoke(new MethodInvoker(() =>
                                {
                                    uploadMediaFileProgressBar.Value = e.ProgressPercentage;
                                }));
                            }
                            catch (ObjectDisposedException)
                            {
                                uploadOperation.Cancel();
                            }
                        });

                        Uri uri = new Uri(string.Format("{0}/media-config/files/{1}/upload", mediaConfig.ServiceUrl, mediaConfigFile.Id));

                        var message = new HttpRequestMessage()
                        {
                            Method = HttpMethod.Post,
                            Content = new StreamContent(File.OpenRead(selectMediaFileDialog.FileName)),
                            RequestUri = uri
                        };

                        var client = HttpClientFactory.Create(progress);

                        await taskPool.AddTask(client.SendAsync(message, uploadOperation.Token));
                    }
                    catch (OperationCanceledException) { }
                    catch (CommunicationObjectAbortedException) { }
                    catch (ObjectDisposedException) { }
                    catch (InvalidOperationException) { }
                    catch (FaultException exception)
                    {
                        UIHelper.Warning(exception.Reason.ToString());
                    }
                    catch (Exception exception)
                    {
                        UIHelper.Warning(exception.Message);
                    }
                }
            }
        }
    }