示例#1
0
        private void downloadButton_Click(object sender, EventArgs e)
        {
            // 1) Get uri
            var uri = GetStringFromUI(uriTextBox);

            if (string.IsNullOrEmpty(uri))
            {
                _outputManager.DisplayMessage("Uri is not set");
                return;
            }

            // 2) Get filePath
            var fileName = GetStringFromUI(filePathTextBox);

            if (string.IsNullOrEmpty(fileName))
            {
                _outputManager.DisplayMessage("File name is not set");
                return;
            }

            try
            {
                var downloadItem = new DownloadItem
                {
                    SourseId   = fileName,
                    Uri        = uri,
                    OutputPath = FileSystemHelper.FormOutputDownloadPath(fileName)
                };

                itemsSource.Add(downloadItem);

                _safeExecuteManager.ExecuteWithExceptionHandling(() =>
                {
                    _downloadManager.StartDownloadingAsync(downloadItem)
                    .ContinueWith(prev => FormListBoxDownloadCompletedString(downloadItem),
                                  new CancellationTokenSource().Token,
                                  TaskContinuationOptions.NotOnCanceled | TaskContinuationOptions.NotOnFaulted,
                                  TaskScheduler.FromCurrentSynchronizationContext());
                });
            }
            catch (Exception exception)
            {
                _outputManager.DisplayMessage(exception.Message);
            }
        }
示例#2
0
        private void removeFromOrderButton_Click(object sender, EventArgs e)
        {
            var item = (Product)productsListBox.SelectedItem;

            if (item == null)
            {
                _outputManager.DisplayMessage("Some invalid selected product.");
            }

            _order.Products.Remove(item);

            _safeExecuteManager.ExecuteWithExceptionHandling(() =>
            {
                _orderService.UpdateOrderAsync(_order)
                .ContinueWith(prev => RefreshOrderData(),
                              new CancellationTokenSource().Token,
                              TaskContinuationOptions.NotOnCanceled | TaskContinuationOptions.NotOnFaulted,
                              TaskScheduler.FromCurrentSynchronizationContext());
            });
        }