private void TestConnectionAsync(bool notify) { var taskBuilder = new TaskBuilder() .OnCurrentThread() .DoWork(TestConnection) .Fail(Fail) .Succeed(Succeed); if (notify) { taskBuilder.Finally(NotifyObservers); } taskBuilder.Build().Start(); }
//implementation of the button that adds tasks public void AddTaskButton_Click(object sender, RoutedEventArgs e) { //binding gui fields to values string title, description; title = AddTitle.Text; description = AddDescription.Text; DateTime dueDate; // Check if correct dueDate was passed: try { dueDate = (DateTime)DueDateCalendar.SelectedDate; } catch (InvalidOperationException err) { MessageBox.Show("Check the due date!"); return; } //creating a task if fields are filled bool isTaskValid = ValidateTask(title, description, dueDate); if (isTaskValid) { //Buid a new Task TaskBuilder builder = new TaskBuilder(); builder.SetTaskTitle(title) .SetTaskDesc(description) .SetCreationDate() .SetDueDate(dueDate) .SetUserId(currentUser.Id) .SetStatus(TaskStatus.New.ToString()); Task newTask = builder.Build(); // Add it to the repo: taskRepo.Add(newTask); taskRepo.Save(); MessageBox.Show("Task created successfully!"); ReloadTaskList(); } }
private void ProcessInternal() { DeploymentTask temp = null; try { foreach (DeploymentTaskRequest request in _taskQueue.GetConsumingEnumerable(_cancellationSource.Token)) { temp = _builder.Build(request); temp.Process(); } } catch (OperationCanceledException) { //Operation canceled by cancellation source } catch (Exception ex) { Logger.Error(ex, "Error processing task '{0}'", temp.Name); } }
private void Button_Click(object sender, RoutedEventArgs e) { var btn = sender as Button; if (btn.Equals(btnRefresh)) { Refresh(); } else if (btn.Equals(btnStart)) { var buttons = this.FindChildren <Button>(); foreach (var button in buttons) { if (button.Equals(btnStart) || button.Equals(btnStop)) { continue; } button.IsEnabled = false; } btnStop.Visibility = Visibility.Visible; btnStart.Visibility = Visibility.Collapsed; tab_content.IsEnabled = false; if (tokenSource == null) { TaskBuilder.Build(ProcessStartAsync, out CancellationTokenSource cancellationTokenSource); tokenSource = cancellationTokenSource; } } else if (btn.Equals(btnStop)) { this.ProgressbarShow(() => { if (tokenSource != null) { tokenSource.Cancel(); tokenSource = null; } _taskQueue.Clear(); tab_content.IsEnabled = true; return(Task.CompletedTask); }).ContinueWith(task => { Dispatcher.Invoke(() => { var buttons = this.FindChildren <Button>(); foreach (var button in buttons) { if (button.Equals(btnStart) || button.Equals(btnStop)) { continue; } button.IsEnabled = true; } btnStart.Visibility = Visibility.Visible; btnStop.Visibility = Visibility.Collapsed; }); }); } else if (btn.Equals(btnSetting)) { settingFlyout.IsOpen = !settingFlyout.IsOpen; } else if (btn.Equals(btnGithub)) { Process.Start(ConstHelper.HelpUrl); } }