Closed josephlugo closed 2 years ago
What information do you want and in what kind of format?
public class Task : IDisposable, IComparable, IComparable<Task>, INotifyPropertyChanged
|
/// <summary>
/// Retrieves a list of params used to execute the task.
/// </summary>
- > public List<string> Params
Thank you. Will you also provide a general idea about what the output would contain?
Assuming the following task:
// Retrieve the task
Microsoft.Win32.TaskScheduler.Task t = TaskService.Instance.GetTask(taskName);
List<string> taskArguments = t.Actions[0].Params;
taskArguments object will return values: {arg1} and {arg2}
I believe you want to list the parameters specified for actions that run programs. If that is correct, the following code should do it:
var t = TaslService.Instace.GetTask(taskName);
foreach (var action in t.Actions)
{
if (action is ExecAction exe && exe.Params != null)
Console.WriteLine(exe.Params);
}
Part of the challenge here is that a task can have multiple actions of different types. Using Linq, you could also do the following in one line to get the first action with params (or null otherwise):
return TaslService.Instace.GetTask(taskName)?.Actions.OfType<ExecAction>().FirstOrDefault()?.Params;
Exactly,
I was able to do so, although had to update a little your suggested code to:
string taskParamsValue = TaskService.Instance.GetTask(taskName)?.Definition.Actions.OfType<ExecAction>().FirstOrDefault()?.Arguments;
Thanks again!
Is there a way to add a new property to Microsoft.Win32.TaskScheduler.Task object, where one can list all the params that were added to execute the Task?
Only way I can think off right now is by manipulating the string "ParamsValue" as shown below:
Microsoft.Win32.TaskScheduler.Task t = TaskService.Instance.GetTask("TaskName"); string ParamsValue = t.Definition.Actions.ToString();
Is there a better way to do this?
Thanks.