dahall / TaskScheduler

Provides a .NET wrapper for the Windows Task Scheduler. It aggregates the multiple versions, provides an editor and allows for localization.
MIT License
1.21k stars 191 forks source link

Request for a new GetTask() method #805

Closed InteXX closed 5 years ago

InteXX commented 5 years ago

Is your feature request related to a problem? Please describe. It's not related to a problem. It's a request for a convenience feature.

Describe the solution you'd like Could you add a GetTask(Name As String) method to the TaskFolder class. While it's true that we currently have this as a method on the TaskService class, that method requires the full path to the task. TaskFolder.GetTask(Name As String) could be used in cases where we don't necessarily have the full path but we do have a TaskFolder object.

Describe alternatives you've considered If this isn't feasible, we can always use an extension method.

Additional context None.

dahall commented 5 years ago

Can you use myFolder.Tasks["TaskName"]?

InteXX commented 5 years ago

Hm, I guess I missed that one.

OK, never mind :-)

InteXX commented 5 years ago

Oops, it throws an exception if the task doesn't exist.

InteXX commented 5 years ago

Here's my extension method:

Friend Module Extensions
  <Extension>
  Public Function GetTask(Folder As TaskFolder, Name As String) As Task
    Return TaskService.Instance.GetTask($"{Folder.Name}\{Name}")
  End Function
End Module
dahall commented 5 years ago

If you want to make it folder-centric, you could also do

Return Folder.GetTasks(Name).FirstOrDefault()
InteXX commented 5 years ago

Yes, I did consider the FirstOrDefault / SingleOrDefault approach, but I didn't want to drag out RegEx for that. (RegEx is far from comfortable for me, I must admit.)

Perhaps an overload accepting a String for the task name would accomplish the same thing.

dahall commented 5 years ago

Given that there are multiple ways to accomplish this same task, I'm reticent to add yet another. Of the two approaches above, the second (which I proposed) is likely faster. Using a full string with RegEx effectively just does a string compare. By querying from the folder, you reduce the number of tasks that have to be searched.

InteXX commented 5 years ago

OK, no problem.