Skip to content

Commit 9651c13

Browse files
authored
Merge branch 'main' into gregli/regex-min
2 parents a9c5f05 + fc7cbb6 commit 9651c13

File tree

6 files changed

+30
-20
lines changed

6 files changed

+30
-20
lines changed

src/libraries/Microsoft.PowerFx.Connectors/ConnectorFunction.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -837,12 +837,12 @@ public async Task<FormulaValue> InvokeAsync(FormulaValue[] arguments, BaseRuntim
837837
}
838838
}
839839

840-
internal Task<FormulaValue> InvokeInternalAsync(FormulaValue[] arguments, BaseRuntimeConnectorContext runtimeContext, CancellationToken cancellationToken)
840+
internal Task<FormulaValue> InvokeInternalAsync(IReadOnlyList<FormulaValue> arguments, BaseRuntimeConnectorContext runtimeContext, CancellationToken cancellationToken)
841841
{
842842
return InvokeInternalAsync(arguments, runtimeContext, null, cancellationToken);
843843
}
844844

845-
internal async Task<FormulaValue> InvokeInternalAsync(FormulaValue[] arguments, BaseRuntimeConnectorContext runtimeContext, FormulaType outputTypeOverride, CancellationToken cancellationToken)
845+
internal async Task<FormulaValue> InvokeInternalAsync(IReadOnlyList<FormulaValue> arguments, BaseRuntimeConnectorContext runtimeContext, FormulaType outputTypeOverride, CancellationToken cancellationToken)
846846
{
847847
cancellationToken.ThrowIfCancellationRequested();
848848

src/libraries/Microsoft.PowerFx.Connectors/ConnectorHelperFunctions.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@ internal static string LogConnectorParameter(ConnectorParameter connectorParamet
5858
return $"{nameof(ConnectorParameter)} {connectorParameter.Name ?? Null(nameof(connectorParameter.Name))} Param.{LogConnectorType(connectorParameter.ConnectorType)}";
5959
}
6060

61-
internal static string LogArguments(FormulaValue[] arguments)
61+
internal static string LogArguments(IReadOnlyList<FormulaValue> arguments)
6262
{
63-
if (arguments == null || arguments.Length == 0)
63+
if (arguments == null || arguments.Count == 0)
6464
{
6565
return "no argument";
6666
}
6767

68-
return $"{arguments.Length} argument{(arguments.Length > 1 ? "s" : string.Empty)} {string.Join(" | ", arguments.Select(a => a.Type._type.ToAnonymousString()))}";
68+
return $"{arguments.Count} argument{(arguments.Count > 1 ? "s" : string.Empty)} {string.Join(" | ", arguments.Select(a => a.Type._type.ToAnonymousString()))}";
6969
}
7070

7171
internal static string LogFormulaValue(FormulaValue formulaValue)

src/libraries/Microsoft.PowerFx.Connectors/Execution/HttpFunctionInvoker.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public HttpFunctionInvoker(ConnectorFunction function, BaseRuntimeConnectorConte
3838
}
3939

4040
[SuppressMessage("Reliability", "CA2000:Dispose objects before losing scope", Justification = "False positive")]
41-
public async Task<HttpRequestMessage> BuildRequest(FormulaValue[] args, IConvertToUTC utcConverter, CancellationToken cancellationToken)
41+
public async Task<HttpRequestMessage> BuildRequest(IReadOnlyList<FormulaValue> args, IConvertToUTC utcConverter, CancellationToken cancellationToken)
4242
{
4343
HttpContent body = null;
4444
var path = _function.OperationPath;
@@ -206,7 +206,7 @@ public async Task<HttpRequestMessage> BuildRequest(FormulaValue[] args, IConvert
206206
return request;
207207
}
208208

209-
public Dictionary<string, FormulaValue> ConvertToNamedParameters(FormulaValue[] args)
209+
public Dictionary<string, FormulaValue> ConvertToNamedParameters(IReadOnlyList<FormulaValue> args)
210210
{
211211
// First N are required params.
212212
// Last param is a record with each field being an optional.
@@ -255,9 +255,9 @@ public Dictionary<string, FormulaValue> ConvertToNamedParameters(FormulaValue[]
255255
}
256256

257257
// Optional parameters are next and stored in a Record
258-
if (_function.OptionalParameters.Length > 0 && args.Length > _function.RequiredParameters.Length)
258+
if (_function.OptionalParameters.Length > 0 && args.Count > _function.RequiredParameters.Length)
259259
{
260-
FormulaValue optionalArg = args[args.Length - 1];
260+
FormulaValue optionalArg = args[args.Count - 1];
261261

262262
// Objects are always flattenned
263263
if (optionalArg is RecordValue record)
@@ -483,7 +483,7 @@ public async Task<FormulaValue> DecodeResponseAsync(HttpResponseMessage response
483483
_function.ReturnType);
484484
}
485485

486-
public async Task<FormulaValue> InvokeAsync(IConvertToUTC utcConverter, string cacheScope, FormulaValue[] args, HttpMessageInvoker localInvoker, CancellationToken cancellationToken, FormulaType expectedType, bool throwOnError = false)
486+
public async Task<FormulaValue> InvokeAsync(IConvertToUTC utcConverter, string cacheScope, IReadOnlyList<FormulaValue> args, HttpMessageInvoker localInvoker, CancellationToken cancellationToken, FormulaType expectedType, bool throwOnError = false)
487487
{
488488
cancellationToken.ThrowIfCancellationRequested();
489489

@@ -551,7 +551,7 @@ public ScopedHttpFunctionInvoker(DPath ns, string name, string cacheScope, HttpF
551551

552552
internal HttpFunctionInvoker Invoker => _invoker;
553553

554-
public async Task<FormulaValue> InvokeAsync(FormulaValue[] args, BaseRuntimeConnectorContext runtimeContext, FormulaType outputTypeOverride, CancellationToken cancellationToken)
554+
public async Task<FormulaValue> InvokeAsync(IReadOnlyList<FormulaValue> args, BaseRuntimeConnectorContext runtimeContext, FormulaType outputTypeOverride, CancellationToken cancellationToken)
555555
{
556556
cancellationToken.ThrowIfCancellationRequested();
557557

src/libraries/Microsoft.PowerFx.Connectors/Texl/ConnectorTexlFunction.cs

+3-4
Original file line numberDiff line numberDiff line change
@@ -88,22 +88,21 @@ public override bool TryGetParamDescription(string paramName, out string paramDe
8888

8989
public async Task<FormulaValue> InvokeAsync(FunctionInvokeInfo invokeInfo, CancellationToken cancellationToken)
9090
{
91-
FormulaValue[] args = invokeInfo.Args.ToArray(); // https://github.com/microsoft/Power-Fx/issues/2817
9291
var serviceProvider = invokeInfo.FunctionServices;
9392

9493
cancellationToken.ThrowIfCancellationRequested();
9594
BaseRuntimeConnectorContext runtimeContext = serviceProvider.GetService(typeof(BaseRuntimeConnectorContext)) as BaseRuntimeConnectorContext ?? throw new InvalidOperationException("RuntimeConnectorContext is missing from service provider");
9695

9796
try
9897
{
99-
runtimeContext.ExecutionLogger?.LogInformation($"Entering in [Texl] {ConnectorFunction.LogFunction(nameof(InvokeAsync))} with {LogArguments(args)}");
100-
FormulaValue formulaValue = await ConnectorFunction.InvokeInternalAsync(args, runtimeContext, cancellationToken).ConfigureAwait(false);
98+
runtimeContext.ExecutionLogger?.LogInformation($"Entering in [Texl] {ConnectorFunction.LogFunction(nameof(InvokeAsync))} with {LogArguments(invokeInfo.Args)}");
99+
FormulaValue formulaValue = await ConnectorFunction.InvokeInternalAsync(invokeInfo.Args, runtimeContext, cancellationToken).ConfigureAwait(false);
101100
runtimeContext.ExecutionLogger?.LogInformation($"Exiting [Texl] {ConnectorFunction.LogFunction(nameof(InvokeAsync))} returning from {nameof(ConnectorFunction.InvokeInternalAsync)} with {LogFormulaValue(formulaValue)}");
102101
return formulaValue;
103102
}
104103
catch (Exception ex)
105104
{
106-
runtimeContext.ExecutionLogger?.LogException(ex, $"Exception in [Texl] {ConnectorFunction.LogFunction(nameof(InvokeAsync))} with {LogArguments(args)} {LogException(ex)}");
105+
runtimeContext.ExecutionLogger?.LogException(ex, $"Exception in [Texl] {ConnectorFunction.LogFunction(nameof(InvokeAsync))} with {LogArguments(invokeInfo.Args)} {LogException(ex)}");
107106
throw;
108107
}
109108
}

src/libraries/Microsoft.PowerFx.Interpreter/CustomFunction/CustomTexlFunction.cs

+2-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace Microsoft.PowerFx
2525
/// </summary>
2626
internal class CustomTexlFunction : TexlFunction, IFunctionInvoker
2727
{
28-
public Func<IServiceProvider, FormulaValue[], CancellationToken, Task<FormulaValue>> _impl;
28+
public Func<IServiceProvider, IReadOnlyList<FormulaValue>, CancellationToken, Task<FormulaValue>> _impl;
2929

3030
internal BigInteger LamdaParamMask;
3131

@@ -57,8 +57,7 @@ public CustomTexlFunction(DPath ns, string name, FunctionCategories functionCate
5757
public virtual Task<FormulaValue> InvokeAsync(FunctionInvokeInfo invokeInfo, CancellationToken cancellationToken)
5858
{
5959
var serviceProvider = invokeInfo.FunctionServices;
60-
var args = invokeInfo.Args.ToArray(); // remove ToArray: https://github.com/microsoft/Power-Fx/issues/2817
61-
return _impl(serviceProvider, args, cancellationToken);
60+
return _impl(serviceProvider, invokeInfo.Args, cancellationToken);
6261
}
6362

6463
public override bool IsLazyEvalParam(TexlNode node, int index, Features features)

src/libraries/Microsoft.PowerFx.Interpreter/CustomFunction/ReflectionFunction.cs

+14-2
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ internal TexlFunction GetTexlFunction()
196196
{
197197
return new CustomSetPropertyFunction(info.NameSpace, info.Name, info.ArgNames)
198198
{
199-
_impl = args => InvokeAsync(null, args, CancellationToken.None)
199+
_impl = args => InvokeAsync(null, (IReadOnlyList<FormulaValue>)args, CancellationToken.None)
200200
};
201201
}
202202

@@ -217,12 +217,24 @@ internal string GetFunctionName()
217217
return _info.Name;
218218
}
219219

220+
[Obsolete("Soon to be removed.")]
220221
public FormulaValue Invoke(IServiceProvider serviceProvider, FormulaValue[] args)
222+
{
223+
return InvokeAsync(serviceProvider, (IReadOnlyList<FormulaValue>)args, CancellationToken.None).Result;
224+
}
225+
226+
public FormulaValue Invoke(IServiceProvider serviceProvider, IReadOnlyList<FormulaValue> args)
221227
{
222228
return InvokeAsync(serviceProvider, args, CancellationToken.None).Result;
223229
}
224230

231+
[Obsolete("Soon to be removed.")]
225232
public async Task<FormulaValue> InvokeAsync(IServiceProvider serviceProvider, FormulaValue[] args, CancellationToken cancellationToken)
233+
{
234+
return await InvokeAsync(serviceProvider, (IReadOnlyList<FormulaValue>)args, cancellationToken).ConfigureAwait(false);
235+
}
236+
237+
public async Task<FormulaValue> InvokeAsync(IServiceProvider serviceProvider, IReadOnlyList<FormulaValue> args, CancellationToken cancellationToken)
226238
{
227239
var info = Scan();
228240

@@ -241,7 +253,7 @@ public async Task<FormulaValue> InvokeAsync(IServiceProvider serviceProvider, Fo
241253
}
242254

243255
List<ErrorValue> errors = null;
244-
for (var i = 0; i < args.Length; i++)
256+
for (var i = 0; i < args.Count; i++)
245257
{
246258
object arg = args[i];
247259

0 commit comments

Comments
 (0)