-
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
8 changed files
with
188 additions
and
1 deletion.
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
2 changes: 1 addition & 1 deletion
2
samples/Modules.AssemblyResolution.Actions/Modules.AssemblyResolution.Actions.csproj
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// -------------------------------------------------------------- | ||
// Copyright (c) Jesus Fernandez. All Rights Reserved. | ||
// -------------------------------------------------------------- | ||
|
||
namespace PowerAutomate.Desktop.Modules.Tasks.Actions; | ||
|
||
internal static class ErrorCodes | ||
{ | ||
public const string Unknown = "UnknownError"; | ||
} |
16 changes: 16 additions & 0 deletions
16
samples/Modules.Tasks.Actions/Modules.Tasks.Actions.csproj
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,16 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<AssemblyTitle>Tasks</AssemblyTitle> | ||
<TargetFramework>net472</TargetFramework> | ||
<LangVersion>latest</LangVersion> | ||
<Nullable>enable</Nullable> | ||
<PackCustomModule Condition=" '$(Configuration)' == 'Debug' ">true</PackCustomModule> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.PowerPlatform.PowerAutomate.Desktop.Actions.SDK" /> | ||
<PackageReference Include="Newtonsoft.Json" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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,36 @@ | ||
// -------------------------------------------------------------- | ||
// Copyright (c) Jesus Fernandez. All Rights Reserved. | ||
// -------------------------------------------------------------- | ||
|
||
using System; | ||
using Microsoft.PowerPlatform.PowerAutomate.Desktop.Actions.SDK; | ||
using Microsoft.PowerPlatform.PowerAutomate.Desktop.Actions.SDK.Attributes; | ||
|
||
namespace PowerAutomate.Desktop.Modules.Tasks.Actions; | ||
|
||
[Action(Id = "Delay")] | ||
[Throws(ErrorCodes.Unknown)] | ||
public class TaskDelayAction : ActionBase | ||
{ | ||
[InputArgument(Order = 2)] | ||
public int DelayInMilliseconds { get; set; } | ||
|
||
[InputArgument(Order = 1)] | ||
public string Name { get; set; } = null!; | ||
|
||
[OutputArgument(Order = 0)] | ||
public TaskObject Task { get; set; } = null!; | ||
|
||
public override void Execute(ActionContext context) | ||
{ | ||
try | ||
{ | ||
var task = System.Threading.Tasks.Task.Delay(DelayInMilliseconds); | ||
Task = new TaskObject(Name, task); | ||
} | ||
catch (Exception ex) | ||
{ | ||
throw new ActionException(ErrorCodes.Unknown, ex.Message, ex); | ||
} | ||
} | ||
} |
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,49 @@ | ||
// -------------------------------------------------------------- | ||
// Copyright (c) Jesus Fernandez. All Rights Reserved. | ||
// -------------------------------------------------------------- | ||
|
||
using System; | ||
using System.Threading.Tasks; | ||
using Microsoft.PowerPlatform.PowerAutomate.Desktop.Actions.SDK.Attributes; | ||
using Microsoft.PowerPlatform.PowerAutomate.Desktop.Actions.SDK.Enums; | ||
using Newtonsoft.Json; | ||
|
||
namespace PowerAutomate.Desktop.Modules.Tasks.Actions; | ||
|
||
[JsonObject(MemberSerialization.OptOut)] | ||
[Type(DefaultPropertyVisibility = Visibility.Visible)] | ||
public class TaskObject : IComparable<TaskObject>, IComparable | ||
{ | ||
public string Name { get; private set; } = null!; | ||
internal Task Task { get; private set; } = null!; | ||
|
||
[JsonConstructor] | ||
public TaskObject() | ||
{ | ||
} | ||
|
||
internal TaskObject(string name, Task task) | ||
{ | ||
Name = name ?? throw new ArgumentNullException(nameof(name)); | ||
Task = task ?? throw new ArgumentNullException(nameof(task)); | ||
} | ||
|
||
public int CompareTo(object? obj) | ||
{ | ||
if (ReferenceEquals(null, obj)) return 1; | ||
if (ReferenceEquals(this, obj)) return 0; | ||
return obj is TaskObject other ? CompareTo(other) : throw new ArgumentException($"Object must be of type {nameof(TaskObject)}"); | ||
} | ||
|
||
public int CompareTo(TaskObject? other) | ||
{ | ||
if (ReferenceEquals(this, other)) return 0; | ||
if (ReferenceEquals(null, other)) return 1; | ||
return string.Compare(Name, other.Name, StringComparison.InvariantCultureIgnoreCase); | ||
} | ||
|
||
public override string ToString() | ||
{ | ||
return Name; | ||
} | ||
} |
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,33 @@ | ||
// -------------------------------------------------------------- | ||
// Copyright (c) Jesus Fernandez. All Rights Reserved. | ||
// -------------------------------------------------------------- | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.PowerPlatform.PowerAutomate.Desktop.Actions.SDK; | ||
using Microsoft.PowerPlatform.PowerAutomate.Desktop.Actions.SDK.Attributes; | ||
|
||
namespace PowerAutomate.Desktop.Modules.Tasks.Actions; | ||
|
||
[Action(Id = "WhenAll")] | ||
[Throws(ErrorCodes.Unknown)] | ||
public class TasksWhenAllAction : ActionBase | ||
{ | ||
[InputArgument] | ||
public List<TaskObject> Tasks { get; set; } = null!; | ||
|
||
public override void Execute(ActionContext context) | ||
{ | ||
try | ||
{ | ||
var tasks = Tasks.Select(task => task.Task).ToList(); | ||
Task.WhenAll(tasks).GetAwaiter().GetResult(); | ||
} | ||
catch (Exception ex) | ||
{ | ||
throw new ActionException(ErrorCodes.Unknown, ex.Message, ex); | ||
} | ||
} | ||
} |
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,33 @@ | ||
// -------------------------------------------------------------- | ||
// Copyright (c) Jesus Fernandez. All Rights Reserved. | ||
// -------------------------------------------------------------- | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.PowerPlatform.PowerAutomate.Desktop.Actions.SDK; | ||
using Microsoft.PowerPlatform.PowerAutomate.Desktop.Actions.SDK.Attributes; | ||
|
||
namespace PowerAutomate.Desktop.Modules.Tasks.Actions; | ||
|
||
[Action(Id = "WhenAny")] | ||
[Throws(ErrorCodes.Unknown)] | ||
public class TasksWhenAnyAction : ActionBase | ||
{ | ||
[InputArgument] | ||
public List<TaskObject> Tasks { get; set; } = null!; | ||
|
||
public override void Execute(ActionContext context) | ||
{ | ||
try | ||
{ | ||
var tasks = Tasks.Select(task => task.Task).ToList(); | ||
Task.WhenAny(tasks).GetAwaiter().GetResult(); | ||
} | ||
catch (Exception ex) | ||
{ | ||
throw new ActionException(ErrorCodes.Unknown, ex.Message, ex); | ||
} | ||
} | ||
} |