From d02f2fecae269106f3ea9ac1b8681c27140b331c Mon Sep 17 00:00:00 2001 From: Jesus Fernandez Date: Sun, 4 Aug 2024 08:04:43 +0300 Subject: [PATCH] Initial implementation --- Directory.Packages.props | 1 + PowerAutomate.Desktop.sln | 7 + modules/Modules.PowerFx.Actions/ErrorCodes.cs | 10 ++ .../ExecutePowerFxExpression.cs | 48 ++++++ .../Modules.PowerFx.Actions.csproj | 32 ++++ .../Properties/Resources.Designer.cs | 95 ++++++++++++ .../Properties/Resources.resx | 137 ++++++++++++++++++ 7 files changed, 330 insertions(+) create mode 100644 modules/Modules.PowerFx.Actions/ErrorCodes.cs create mode 100644 modules/Modules.PowerFx.Actions/ExecutePowerFxExpression.cs create mode 100644 modules/Modules.PowerFx.Actions/Modules.PowerFx.Actions.csproj create mode 100644 modules/Modules.PowerFx.Actions/Properties/Resources.Designer.cs create mode 100644 modules/Modules.PowerFx.Actions/Properties/Resources.resx diff --git a/Directory.Packages.props b/Directory.Packages.props index 058c9ef..c5d5fea 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -10,6 +10,7 @@ + diff --git a/PowerAutomate.Desktop.sln b/PowerAutomate.Desktop.sln index 7172277..a79b854 100644 --- a/PowerAutomate.Desktop.sln +++ b/PowerAutomate.Desktop.sln @@ -69,6 +69,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "5.Conditionals", "5.Conditi EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Modules.Conditionals.Actions", "samples\Modules.Conditionals.Actions\Modules.Conditionals.Actions.csproj", "{791698E0-931E-4F35-97A4-B050FD0B4F82}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Modules.PowerFx.Actions", "modules\Modules.PowerFx.Actions\Modules.PowerFx.Actions.csproj", "{86C08ED2-7025-4898-BE9B-BCD10A0C5774}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -147,6 +149,10 @@ Global {791698E0-931E-4F35-97A4-B050FD0B4F82}.Debug|Any CPU.Build.0 = Debug|Any CPU {791698E0-931E-4F35-97A4-B050FD0B4F82}.Release|Any CPU.ActiveCfg = Release|Any CPU {791698E0-931E-4F35-97A4-B050FD0B4F82}.Release|Any CPU.Build.0 = Release|Any CPU + {86C08ED2-7025-4898-BE9B-BCD10A0C5774}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {86C08ED2-7025-4898-BE9B-BCD10A0C5774}.Debug|Any CPU.Build.0 = Debug|Any CPU + {86C08ED2-7025-4898-BE9B-BCD10A0C5774}.Release|Any CPU.ActiveCfg = Release|Any CPU + {86C08ED2-7025-4898-BE9B-BCD10A0C5774}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -182,6 +188,7 @@ Global {10147DFD-8CFC-41CD-A3EC-A8B8AA110DF1} = {58A11983-1ED4-4D38-998C-C1B033A58842} {22D1EE4E-815F-48F2-AB46-754518B1F914} = {FEFFE5BC-DCBD-466C-87DE-5B9D8A553256} {791698E0-931E-4F35-97A4-B050FD0B4F82} = {22D1EE4E-815F-48F2-AB46-754518B1F914} + {86C08ED2-7025-4898-BE9B-BCD10A0C5774} = {3B78C634-DFD6-43DA-A30E-33AC42224BD4} EndGlobalSection GlobalSection(SharedMSBuildProjectFiles) = preSolution Modules.Actions.Shared\Modules.Actions.Shared.projitems*{7e19e2f1-6de7-4a0e-aed8-7cea38b166af}*SharedItemsImports = 13 diff --git a/modules/Modules.PowerFx.Actions/ErrorCodes.cs b/modules/Modules.PowerFx.Actions/ErrorCodes.cs new file mode 100644 index 0000000..b16f6cc --- /dev/null +++ b/modules/Modules.PowerFx.Actions/ErrorCodes.cs @@ -0,0 +1,10 @@ +// --------------------------------------------------- +// Copyright (c) Jesus Fernandez. All Rights Reserved. +// --------------------------------------------------- + +namespace PowerAutomate.Desktop.Modules.PowerFx.Actions; + +internal static class ErrorCodes +{ + public const string Unknown = "UnknownError"; +} \ No newline at end of file diff --git a/modules/Modules.PowerFx.Actions/ExecutePowerFxExpression.cs b/modules/Modules.PowerFx.Actions/ExecutePowerFxExpression.cs new file mode 100644 index 0000000..fa14f1e --- /dev/null +++ b/modules/Modules.PowerFx.Actions/ExecutePowerFxExpression.cs @@ -0,0 +1,48 @@ +// --------------------------------------------------- +// Copyright (c) Jesus Fernandez. All Rights Reserved. +// --------------------------------------------------- + +using System; +using System.Diagnostics.CodeAnalysis; +using System.Linq; +using Microsoft.PowerFx; +using Microsoft.PowerPlatform.PowerAutomate.Desktop.Actions.SDK; +using Microsoft.PowerPlatform.PowerAutomate.Desktop.Actions.SDK.Attributes; + +namespace PowerAutomate.Desktop.Modules.PowerFx.Actions; + +[Action(Id = "ExecutePowerFxExpression")] +[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 ExecutePowerFxExpression : ActionBase +{ + [InputArgument] + public string Expression { get; set; } = null!; + + [OutputArgument] + public string Result { get; set; } = null!; + + public override void Execute(ActionContext context) + { + try + { + var engine = new Engine(); + var result = engine.Parse(Expression); + + if (!result.IsSuccess) + { + throw new AggregateException(result.Errors.Select(error => new Exception(error.Message))); + } + + Result = result.Text; + } + catch (Exception ex) + { + throw new ActionException(ErrorCodes.Unknown, ex.Message, ex); + } + } +} \ No newline at end of file diff --git a/modules/Modules.PowerFx.Actions/Modules.PowerFx.Actions.csproj b/modules/Modules.PowerFx.Actions/Modules.PowerFx.Actions.csproj new file mode 100644 index 0000000..feb6008 --- /dev/null +++ b/modules/Modules.PowerFx.Actions/Modules.PowerFx.Actions.csproj @@ -0,0 +1,32 @@ + + + + PowerFx + net472 + latest + enable + true + + + + + + + + + + + True + True + Resources.resx + + + + + + PublicResXFileCodeGenerator + Resources.Designer.cs + + + + diff --git a/modules/Modules.PowerFx.Actions/Properties/Resources.Designer.cs b/modules/Modules.PowerFx.Actions/Properties/Resources.Designer.cs new file mode 100644 index 0000000..7e8e7d3 --- /dev/null +++ b/modules/Modules.PowerFx.Actions/Properties/Resources.Designer.cs @@ -0,0 +1,95 @@ +//------------------------------------------------------------------- +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------- + +namespace PowerAutomate.Desktop.Modules.PowerFx.Actions.Properties { + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + public class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + public static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("PowerAutomate.Desktop.Modules.CloudFlows.Actions.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + public static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized string similar to Perform operations related to Cloud Flows in Power Automate.. + /// + public static string CloudFlows_Description { + get { + return ResourceManager.GetString("CloudFlows_Description", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Cloud Flows. + /// + public static string CloudFlows_FriendlyName { + get { + return ResourceManager.GetString("CloudFlows_FriendlyName", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Indicates that there was a problem when executing the operation.. + /// + public static string Error_UnknownError_Description { + get { + return ResourceManager.GetString("Error_UnknownError_Description", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Operation failed. + /// + public static string Error_UnknownError_FriendlyName { + get { + return ResourceManager.GetString("Error_UnknownError_FriendlyName", resourceCulture); + } + } + } +} diff --git a/modules/Modules.PowerFx.Actions/Properties/Resources.resx b/modules/Modules.PowerFx.Actions/Properties/Resources.resx new file mode 100644 index 0000000..6bfa099 --- /dev/null +++ b/modules/Modules.PowerFx.Actions/Properties/Resources.resx @@ -0,0 +1,137 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, + PublicKeyToken=b77a5c561934e089 + + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, + PublicKeyToken=b77a5c561934e089 + + + + Cloud Flows + + + Perform operations related to Cloud Flows in Power Automate. + + + Operation failed + + + Indicates that there was a problem when executing the operation. + + \ No newline at end of file