Skip to content

Commit

Permalink
Module: HTML (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
jfevia authored Jul 5, 2024
1 parent 7507787 commit 0010347
Show file tree
Hide file tree
Showing 19 changed files with 881 additions and 196 deletions.
64 changes: 64 additions & 0 deletions modules/Modules.HTML.Actions/ConvertDataTableToHtmlTableAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// --------------------------------------------------------------
// Copyright (c) Jesus Fernandez. All Rights Reserved.
// --------------------------------------------------------------

using System;
using System.Data;
using System.Diagnostics.CodeAnalysis;
using System.Text;
using Microsoft.PowerPlatform.PowerAutomate.Desktop.Actions.SDK;
using Microsoft.PowerPlatform.PowerAutomate.Desktop.Actions.SDK.Attributes;

namespace PowerAutomate.Desktop.Modules.HTML.Actions;

[Action(Id = "ConvertDataTableToHtmlTable")]
[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 ConvertDataTableToHtmlTableAction : ActionBase
{
[InputArgument]
public DataTable DataTable { get; set; } = null!;

[OutputArgument]
public string HtmlTable { get; set; } = null!;

public override void Execute(ActionContext context)
{
Debugger.Launch();

try
{
var html = new StringBuilder();
html.Append("<table>");
html.Append("<tr>");
foreach (DataColumn column in DataTable.Columns)
{
html.Append("<th>").Append(column.ColumnName).Append("</th>");
}

html.Append("</tr>");

foreach (DataRow row in DataTable.Rows)
{
html.Append("<tr>");
foreach (var item in row.ItemArray)
{
html.Append("<td>").Append(item).Append("</td>");
}

html.Append("</tr>");
}

html.Append("</table>");
HtmlTable = html.ToString();
}
catch (Exception ex)
{
throw new ActionException(ErrorCodes.Unknown, ex.Message, ex);
}
}
}
56 changes: 56 additions & 0 deletions modules/Modules.HTML.Actions/ConvertListToHtmlListAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// --------------------------------------------------------------
// Copyright (c) Jesus Fernandez. All Rights Reserved.
// --------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Text;
using Microsoft.PowerPlatform.PowerAutomate.Desktop.Actions.SDK;
using Microsoft.PowerPlatform.PowerAutomate.Desktop.Actions.SDK.Attributes;

namespace PowerAutomate.Desktop.Modules.HTML.Actions;

[Action(Id = "ConvertListToHtmlList")]
[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 ConvertListToHtmlListAction : ActionBase
{
[OutputArgument(Order = 1)]
public string HtmlList { get; set; } = null!;

[InputArgument(Order = 0)]
[DefaultValue(false)]
public bool IsOrdered { get; set; }

[InputArgument(Order = 1)]
public List<object> List { get; set; } = null!;

public override void Execute(ActionContext context)
{
Debugger.Launch();

try
{
var rootTag = IsOrdered ? "ol" : "ul";
var html = new StringBuilder();
html.Append($"<{rootTag}>");
foreach (var item in List)
{
html.Append("<li>").Append(item).Append("</li>");
}

html.Append($"</{rootTag}>");
HtmlList = html.ToString();
}
catch (Exception ex)
{
throw new ActionException(ErrorCodes.Unknown, ex.Message, ex);
}
}
}
16 changes: 16 additions & 0 deletions modules/Modules.HTML.Actions/Debugger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// --------------------------------------------------------------
// Copyright (c) Jesus Fernandez. All Rights Reserved.
// --------------------------------------------------------------

using System.Diagnostics;

namespace PowerAutomate.Desktop.Modules.HTML.Actions;

internal static class Debugger
{
[Conditional("DEBUG")]
public static void Launch()
{
System.Diagnostics.Debugger.Launch();
}
}
10 changes: 10 additions & 0 deletions modules/Modules.HTML.Actions/ErrorCodes.cs
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.HTML.Actions;

internal static class ErrorCodes
{
public const string Unknown = "UnknownError";
}
35 changes: 35 additions & 0 deletions modules/Modules.HTML.Actions/Modules.HTML.Actions.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<AssemblyTitle>HTML</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" />
</ItemGroup>

<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
</ItemGroup>

<ItemGroup>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>

</Project>
Loading

0 comments on commit 0010347

Please sign in to comment.