public Task <T> regTask <T>(Task <T> task, CancellationToken?cancelToken = null) { TaskRegistration <T> reg = new TaskRegistration <T>(task, cancelToken); _taskRegDict.Add(task, reg); return(reg.task); }
// React to a change in configuration parameters: // Save new values to local settings // Set link-loss alert level on the device if appropriate // Register or unregister background task if necessary private async void SaveSettings() { // Save this device's settings into nonvolatile storage localSettings.Values[addressString] = string.Join(",", alertOnPhone, alertOnDevice, alertLevel); // If the device is connected and wants to hear about the alert level on link loss, tell it if (alertOnDevice && device.ConnectionStatus == BluetoothConnectionStatus.Connected) { await SetAlertLevelCharacteristic(); } // If we need a background task and one isn't already registered, create one if (TaskRegistration == null && (alertOnPhone || alertOnDevice)) { DeviceConnectionChangeTrigger trigger = await DeviceConnectionChangeTrigger.FromIdAsync(device.DeviceId); trigger.MaintainConnection = true; BackgroundTaskBuilder builder = new BackgroundTaskBuilder(); builder.Name = TaskName; builder.TaskEntryPoint = "KeepTheKeysBackground.KeyFobTask"; builder.SetTrigger(trigger); TaskRegistration = builder.Register(); } // If we don't need a background task but have one, unregister it if (TaskRegistration != null && !alertOnPhone && !alertOnDevice) { TaskRegistration.Unregister(false); TaskRegistration = null; } }
private void UnregisterTask() { TaskRegistration.Completed -= OnCompleted; TaskRegistration.Progress -= OnProgress; TaskRegistration.Unregister(false); TaskRegistration = null; }
public object[] GetRowObjects(TaskRegistration taskReg) { return(new object[] { taskReg.ProcessName, taskReg.TaskName, this.GetFormattedDuration(taskReg.Duration) }); }
public void CreateStuff() { var typeFactory = new InternalContainerTypeFactory(new ServiceContainer()); TaskRegistration = new TaskRegistration(Fake<IDefaultFilterRegistration>()); KnownCmdArguments = A.Fake<IKnownCmdArguments>(); BuildState = new BuildStateService(); TaskDirector = new TaskDirector(TaskRegistration, new TaskGraphResolver(TaskRegistration), KnownCmdArguments, typeFactory, A.Fake<IOutput>(), BuildState); TaskManagementTestHelper.Clear(); SetTargetTask(null); }
private void AddTaskRegistration(TaskRegistration newTask, DateTime endTime) { // calculate duration of previous task and register it. if (this.currentlyActiveTask != null && !string.IsNullOrEmpty(this.currentlyActiveTask.TaskName)) { this.currentlyActiveTask.TimeStamp = taskStart; this.currentlyActiveTask.Duration = endTime - taskStart; this.PomodoroRegistrations.Add(currentlyActiveTask); } // now we have a new task running. this.taskStart = this.Now; this.currentlyActiveTask = newTask; }
public void Registering_task_without_implementation_should_use_the_given_name_as_task_name() { var taskRegistration = new TaskRegistration(A.Fake<IDefaultFilterRegistration>()); taskRegistration.RegisterTask("TestTask"); Assert.AreEqual("TestTask", Enumerable.Single<RegisteredTask>(taskRegistration.Tasks).Name); }
public void Registering_task_by_instance_should_use_the_type_name_as_task_name() { var taskRegistration = new TaskRegistration(A.Fake<IDefaultFilterRegistration>()); taskRegistration.RegisterTask(new ExampleTask0()); Assert.AreEqual(nameof(ExampleTask0), Enumerable.Single<RegisteredTask>(taskRegistration.Tasks).Name); }
public void Registering_task_with_name_should_not_use_the_class_name2() { var taskRegistration = new TaskRegistration(A.Fake<IDefaultFilterRegistration>()); taskRegistration.RegisterTask("TestTask", new ExampleTask0()); Assert.AreEqual("TestTask", Enumerable.Single<RegisteredTask>(taskRegistration.Tasks).Name); }
public void Registering_task_which_implement_ITask_should_not_throw_a_exception() { var taskRegistration = new TaskRegistration(A.Fake<IDefaultFilterRegistration>()); taskRegistration.RegisterTask(typeof (ExampleTask0)); }
public void Registering_task_which_not_implement_ITask_should_throw_a_exception() { var taskRegistration = new TaskRegistration(A.Fake<IDefaultFilterRegistration>()); Assert.Catch<ArgumentException>(() => taskRegistration.RegisterTask(typeof (string))); }