public Hashtable InvokeFunction()

in src/PowerShell/PowerShellManager.cs [204:275]


        public Hashtable InvokeFunction(
            AzFunctionInfo functionInfo,
            Hashtable triggerMetadata,
            TraceContext traceContext,
            RetryContext retryContext,
            IList<ParameterBinding> inputData,
            FunctionInvocationPerformanceStopwatch stopwatch,
            OpenTelemetryInvocationContext otelContext)
        {
            var outputBindings = FunctionMetadata.GetOutputBindingHashtable(_pwsh.Runspace.InstanceId);
            var durableFunctionsUtils = new DurableController(functionInfo.DurableFunctionInfo, _pwsh, Logger);

            try
            {
                durableFunctionsUtils.InitializeBindings(inputData, out bool hasExternalDFsdk);
                Logger.Log(isUserOnlyLog: false, LogLevel.Trace, String.Format(PowerShellWorkerStrings.UtilizingExternalDurableSDK, hasExternalDFsdk));

                ImportEntryPointModule(functionInfo);

                // This cmdlet must be run in the same .InvokeAndClearCommands() run as the function code itself
                // If it is not, the Activity.Current context that we are trying to preserve is dropped
                _openTelemetryController.AddStartOpenTelemetryInvocationCommand(otelContext);

                AddEntryPointInvocationCommand(functionInfo);
                stopwatch.OnCheckpoint(FunctionInvocationPerformanceStopwatch.Checkpoint.FunctionCodeReady);

                var orchestrationParamName = durableFunctionsUtils.GetOrchestrationParameterName();
                SetInputBindingParameterValues(functionInfo, inputData, orchestrationParamName, triggerMetadata, traceContext, retryContext);
                stopwatch.OnCheckpoint(FunctionInvocationPerformanceStopwatch.Checkpoint.InputBindingValuesReady);

                stopwatch.OnCheckpoint(FunctionInvocationPerformanceStopwatch.Checkpoint.InvokingFunctionCode);
                Logger.Log(isUserOnlyLog: false, LogLevel.Trace, CreateInvocationPerformanceReportMessage(functionInfo.FuncName, stopwatch));

                try
                {
                    if (functionInfo.DurableFunctionInfo.IsOrchestrationFunction)
                    {
                        return durableFunctionsUtils.InvokeOrchestrationFunction();
                    }
                    else
                    {
                        var isActivityFunction = functionInfo.DurableFunctionInfo.IsActivityFunction;
                        if (!isActivityFunction && !FunctionInfoUtilities.hasAssistantSkillTrigger(functionInfo))
                        {
                            _pwsh.AddCommand(Utils.TracePipelineObjectCmdlet);
                        }
                        return ExecuteUserCode(isActivityFunction || FunctionInfoUtilities.hasAssistantSkillTrigger(functionInfo), outputBindings);
                    }
                }
                catch (RuntimeException e)
                {
                    ErrorAnalysisLogger.Log(Logger, e.ErrorRecord, isException: true);
                    Logger.Log(isUserOnlyLog: true, LogLevel.Error, GetFunctionExceptionMessage(e));
                    throw;
                }
                catch (Exception e)
                {
                    if (e.Data.Contains(Utils.IsOrchestrationFailureKey) && e.InnerException is IContainsErrorRecord inner)
                    {
                        Logger.Log(isUserOnlyLog: true, LogLevel.Error, GetFunctionExceptionMessage(inner));
                    }
                    throw;
                }
            }
            finally
            {
                _openTelemetryController.StopOpenTelemetryInvocation(otelContext);
                durableFunctionsUtils.AfterFunctionInvocation();
                outputBindings.Clear();
                ResetRunspace();
            }
        }