-
Notifications
You must be signed in to change notification settings - Fork 1
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
1 parent
fa18aa5
commit 5e72433
Showing
2 changed files
with
38 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
32 changes: 32 additions & 0 deletions
32
...ExpressionParser/Functions/Implementations/ConversionFunctions/DataUriToBinaryFunction.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,32 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Text; | ||
using Parser.ExpressionParser.Functions.Base; | ||
using Parser.ExpressionParser.Functions.CustomException; | ||
|
||
namespace Parser.ExpressionParser.Functions.Implementations.ConversionFunctions | ||
{ | ||
public class DataUriToBinaryFunction : Function | ||
{ | ||
public DataUriToBinaryFunction() : base("dataUriToBinary") | ||
{ | ||
} | ||
|
||
public override ValueContainer ExecuteFunction(params ValueContainer[] parameters) | ||
{ | ||
if (parameters.Length == 0) | ||
{ | ||
throw InvalidTemplateException.BuildInvalidLanguageFunction("SomeActon", "dataUriToBinary"); | ||
} | ||
|
||
return parameters[0].Type() switch | ||
{ | ||
ValueContainer.ValueType.String => | ||
new ValueContainer(Encoding.UTF8.GetBytes(parameters[0].GetValue<string>()) | ||
.Aggregate("", (s, b) => s + Convert.ToString(b, 2).PadLeft(8, '0'))), | ||
_ => throw new PowerAutomateMockUpException( | ||
$"Array function can only operate on strings, not {parameters[0].Type()}.") | ||
}; | ||
} | ||
} | ||
} |