-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
51 changed files
with
7,339 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
modules/Modules.Windows.TaskScheduler.Actions/Actions/CreateTaskAction.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// -------------------------------------------------------------- | ||
// Copyright (c) Jesus Fernandez. All Rights Reserved. | ||
// -------------------------------------------------------------- | ||
|
||
using System; | ||
using System.Diagnostics.CodeAnalysis; | ||
using Microsoft.PowerPlatform.PowerAutomate.Desktop.Actions.SDK; | ||
using Microsoft.PowerPlatform.PowerAutomate.Desktop.Actions.SDK.Attributes; | ||
using Microsoft.Win32.TaskScheduler; | ||
using PowerAutomate.Desktop.Modules.Actions.Shared; | ||
|
||
namespace PowerAutomate.Desktop.Modules.Windows.TaskScheduler.Actions.Actions; | ||
|
||
[Action(Id = "CreateTask")] | ||
[Group(Name = Groups.General, Order = 1)] | ||
[Group(Name = Groups.Advanced, Order = 2, IsDefault = true)] | ||
[Throws(ErrorCodes.Unknown)] | ||
[SuppressMessage("ReSharper", "AutoPropertyCanBeMadeGetOnly.Global", Justification = "PowerAutomate.Desktop.Module.Action")] | ||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global", Justification = "PowerAutomate.Desktop.Module.Action")] | ||
[SuppressMessage("ReSharper", "UnusedAutoPropertyAccessor.Global", Justification = "PowerAutomate.Desktop.Module.Action")] | ||
[SuppressMessage("ReSharper", "ClassNeverInstantiated.Global", Justification = "PowerAutomate.Desktop.Module.Action")] | ||
[SuppressMessage("ReSharper", "UnusedType.Global", Justification = "PowerAutomate.Desktop.Module.Action")] | ||
public class CreateTaskAction : ActionBase | ||
{ | ||
[InputArgument(Order = 4, Required = false)] | ||
public string AccountDomain { get; set; } = null!; | ||
|
||
[InputArgument(Order = 5, Required = false)] | ||
public string Password { get; set; } = null!; | ||
|
||
[InputArgument(Order = 2, Required = false)] | ||
public string TargetServer { get; set; } = null!; | ||
|
||
[InputArgument(Order = 1, Group = Groups.General)] | ||
public string TaskName { get; set; } = null!; | ||
|
||
[InputArgument(Order = 3, Required = false)] | ||
public string UserName { get; set; } = null!; | ||
|
||
public override void Execute(ActionContext context) | ||
{ | ||
Debugger.Launch(); | ||
|
||
try | ||
{ | ||
using var taskService = new TaskService(TargetServer, UserName, AccountDomain, Password); | ||
using var task = taskService.NewTask(); | ||
|
||
taskService.RootFolder | ||
.RegisterTaskDefinition(TaskName, task) | ||
.Dispose(); | ||
} | ||
catch (Exception ex) | ||
{ | ||
throw new ActionException(ErrorCodes.Unknown, ex.Message, ex); | ||
} | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
modules/Modules.Windows.TaskScheduler.Actions/Actions/CreateTaskActionAction.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// -------------------------------------------------------------- | ||
// Copyright (c) Jesus Fernandez. All Rights Reserved. | ||
// -------------------------------------------------------------- | ||
|
||
using System; | ||
using System.Diagnostics.CodeAnalysis; | ||
using Microsoft.PowerPlatform.PowerAutomate.Desktop.Actions.SDK; | ||
using Microsoft.PowerPlatform.PowerAutomate.Desktop.Actions.SDK.Attributes; | ||
using Microsoft.Win32.TaskScheduler; | ||
using PowerAutomate.Desktop.Modules.Actions.Shared; | ||
using PowerAutomate.Desktop.Modules.Windows.TaskScheduler.Actions.Exceptions; | ||
|
||
namespace PowerAutomate.Desktop.Modules.Windows.TaskScheduler.Actions.Actions; | ||
|
||
[Action(Id = "CreateTaskAction")] | ||
[Group(Name = Groups.General, Order = 1)] | ||
[Group(Name = Groups.Advanced, Order = 2, IsDefault = true)] | ||
[Throws(ErrorCodes.TaskNotFound)] | ||
[Throws(ErrorCodes.Unknown)] | ||
[SuppressMessage("ReSharper", "AutoPropertyCanBeMadeGetOnly.Global", Justification = "PowerAutomate.Desktop.Module.Action")] | ||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global", Justification = "PowerAutomate.Desktop.Module.Action")] | ||
[SuppressMessage("ReSharper", "UnusedAutoPropertyAccessor.Global", Justification = "PowerAutomate.Desktop.Module.Action")] | ||
[SuppressMessage("ReSharper", "ClassNeverInstantiated.Global", Justification = "PowerAutomate.Desktop.Module.Action")] | ||
[SuppressMessage("ReSharper", "UnusedType.Global", Justification = "PowerAutomate.Desktop.Module.Action")] | ||
public class CreateTaskActionAction : ActionBase | ||
{ | ||
[InputArgument(Order = 7, Required = false)] | ||
public string AccountDomain { get; set; } = null!; | ||
|
||
[InputArgument(Order = 3, Group = Groups.General, Required = false)] | ||
public string Arguments { get; set; } = null!; | ||
|
||
[InputArgument(Order = 8, Required = false)] | ||
public string Password { get; set; } = null!; | ||
|
||
[InputArgument(Order = 2, Group = Groups.General)] | ||
public string Path { get; set; } = null!; | ||
|
||
[InputArgument(Order = 5, Required = false)] | ||
public string TargetServer { get; set; } = null!; | ||
|
||
[InputArgument(Order = 1, Group = Groups.General)] | ||
public string TaskName { get; set; } = null!; | ||
|
||
[InputArgument(Order = 6, Required = false)] | ||
public string UserName { get; set; } = null!; | ||
|
||
[InputArgument(Order = 4, Group = Groups.General, Required = false)] | ||
public string WorkingDirectory { get; set; } = null!; | ||
|
||
public override void Execute(ActionContext context) | ||
{ | ||
Debugger.Launch(); | ||
|
||
try | ||
{ | ||
using var taskService = new TaskService(TargetServer, UserName, AccountDomain, Password); | ||
|
||
using var task = taskService.FindTask(TaskName); | ||
if (task is null) | ||
{ | ||
throw new TaskNotFoundException(TaskName); | ||
} | ||
|
||
using var execAction = new ExecAction(Path, Arguments, WorkingDirectory); | ||
task.Definition.Actions.Add(execAction); | ||
} | ||
catch (TaskNotFoundException ex) | ||
{ | ||
throw new ActionException(ErrorCodes.TaskNotFound, ex.Message, ex); | ||
} | ||
catch (Exception ex) | ||
{ | ||
throw new ActionException(ErrorCodes.Unknown, ex.Message, ex); | ||
} | ||
} | ||
} |
Oops, something went wrong.