/// <summary>
        /// Invoke a regular function or an activity function.
        /// </summary>
        private Hashtable InvokeSingleActivityFunction(AzFunctionInfo functionInfo, InvocationRequest invocationRequest)
        {
            // Bundle all TriggerMetadata into Hashtable to send down to PowerShell
            var triggerMetadata = new Hashtable(StringComparer.OrdinalIgnoreCase);

            foreach (var dataItem in invocationRequest.TriggerMetadata)
            {
                // MapField<K, V> is case-sensitive, but powershell is case-insensitive,
                // so for keys differ only in casing, the first wins.
                if (!triggerMetadata.ContainsKey(dataItem.Key))
                {
                    triggerMetadata.Add(dataItem.Key, dataItem.Value.ToObject());
                }
            }

            return(_powerShellManager.InvokeFunction(
                       functionInfo,
                       triggerMetadata,
                       invocationRequest.InputData));
        }
Пример #2
0
        public void InvokeBasicFunctionWithTriggerMetadataWorks()
        {
            var logger  = new ConsoleLogger();
            var manager = new PowerShellManager(logger);

            manager.InitializeRunspace();

            string path = System.IO.Path.Join(
                AppDomain.CurrentDomain.BaseDirectory,
                "Unit/PowerShell/TestScripts/testBasicFunctionWithTriggerMetadata.ps1");

            Hashtable triggerMetadata = new Hashtable(StringComparer.OrdinalIgnoreCase)
            {
                { TestInputBindingName, TestStringData }
            };

            var       functionInfo = GetAzFunctionInfo(path, string.Empty);
            Hashtable result       = manager.InvokeFunction(functionInfo, triggerMetadata, TestInputData);

            Assert.Equal(TestStringData, result[TestOutputBindingName]);
        }
Пример #3
0
        /// <summary>
        /// Invoke a regular function or an activity function.
        /// </summary>
        private Hashtable InvokeSingleActivityFunction(PowerShellManager psManager, AzFunctionInfo functionInfo, InvocationRequest invocationRequest)
        {
            const string InvocationId      = "InvocationId";
            const string FunctionDirectory = "FunctionDirectory";
            const string FunctionName      = "FunctionName";

            // Bundle all TriggerMetadata into Hashtable to send down to PowerShell
            Hashtable triggerMetadata = null;

            if (functionInfo.HasTriggerMetadataParam)
            {
                triggerMetadata = new Hashtable(StringComparer.OrdinalIgnoreCase);
                foreach (var dataItem in invocationRequest.TriggerMetadata)
                {
                    // MapField<K, V> is case-sensitive, but powershell is case-insensitive,
                    // so for keys differ only in casing, the first wins.
                    if (!triggerMetadata.ContainsKey(dataItem.Key))
                    {
                        triggerMetadata.Add(dataItem.Key, dataItem.Value.ToObject());
                    }
                }

                if (!triggerMetadata.ContainsKey(InvocationId))
                {
                    triggerMetadata.Add(InvocationId, invocationRequest.InvocationId);
                }
                if (!triggerMetadata.ContainsKey(FunctionDirectory))
                {
                    triggerMetadata.Add(FunctionDirectory, functionInfo.FuncDirectory);
                }
                if (!triggerMetadata.ContainsKey(FunctionName))
                {
                    triggerMetadata.Add(FunctionName, functionInfo.FuncName);
                }
            }

            return(psManager.InvokeFunction(functionInfo, triggerMetadata, invocationRequest.InputData));
        }
Пример #4
0
 private static Hashtable InvokeFunction(PowerShellManager powerShellManager, AzFunctionInfo functionInfo, Hashtable triggerMetadata = null)
 {
     return(powerShellManager.InvokeFunction(functionInfo, triggerMetadata, null, s_testInputData, new FunctionInvocationPerformanceStopwatch()));
 }
Пример #5
0
        internal StreamingMessage ProcessInvocationRequest(StreamingMessage request)
        {
            InvocationRequest invocationRequest = request.InvocationRequest;

            // Assume success unless something bad happens
            var status = new StatusResult()
            {
                Status = StatusResult.Types.Status.Success
            };
            var response = new StreamingMessage()
            {
                RequestId          = request.RequestId,
                InvocationResponse = new InvocationResponse()
                {
                    InvocationId = invocationRequest.InvocationId,
                    Result       = status
                }
            };

            // Invoke powershell logic and return hashtable of out binding data
            try
            {
                // Load information about the function
                var functionInfo = _functionLoader.GetFunctionInfo(invocationRequest.FunctionId);

                // Bundle all TriggerMetadata into Hashtable to send down to PowerShell
                var triggerMetadata = new Hashtable(StringComparer.OrdinalIgnoreCase);
                foreach (var dataItem in invocationRequest.TriggerMetadata)
                {
                    // MapField<K, V> is case-sensitive, but powershell is case-insensitive,
                    // so for keys differ only in casing, the first wins.
                    if (!triggerMetadata.ContainsKey(dataItem.Key))
                    {
                        triggerMetadata.Add(dataItem.Key, dataItem.Value.ToObject());
                    }
                }

                // Set the RequestId and InvocationId for logging purposes
                Hashtable result = null;
                result = _powerShellManager.InvokeFunction(
                    functionInfo.ScriptPath,
                    functionInfo.EntryPoint,
                    triggerMetadata,
                    invocationRequest.InputData);

                // Set out binding data and return response to be sent back to host
                foreach (KeyValuePair <string, BindingInfo> binding in functionInfo.OutputBindings)
                {
                    // if one of the bindings is '$return' we need to set the ReturnValue
                    if (string.Equals(binding.Key, "$return", StringComparison.OrdinalIgnoreCase))
                    {
                        response.InvocationResponse.ReturnValue = result[binding.Key].ToTypedData();
                        continue;
                    }

                    ParameterBinding paramBinding = new ParameterBinding()
                    {
                        Name = binding.Key,
                        Data = result[binding.Key].ToTypedData()
                    };

                    response.InvocationResponse.OutputData.Add(paramBinding);
                }
            }
            catch (Exception e)
            {
                status.Status    = StatusResult.Types.Status.Failure;
                status.Exception = e.ToRpcException();
            }

            return(response);
        }