/// <summary>
        /// 同步执行函数
        /// </summary>
        public static void InvokeFunction(FunctionGraphClient client)
        {
            InvokeFunctionRequest req = new InvokeFunctionRequest
            {
                FunctionUrn        = "urn:fss:cn-north-7:46b6f338fc3445b8846c71dfb1fbd9e8:nction:CsharpSdkTest:csharpSdkTest",
                XCffLogType        = "tail",
                XCFFRequestVersion = "v1",
                Body = new Dictionary <string, object>
                {
                    { "k", "v" }
                }
            };

            try
            {
                InvokeFunctionResponse resp = client.InvokeFunction(req);
                Console.WriteLine("InvokeFunction Body=" + JsonConvert.SerializeObject(resp));
                Console.WriteLine("InvokeFunction StatusCode=" + resp.HttpStatusCode);
            }
            catch (ClientRequestException e)
            {
                Console.WriteLine(e.HttpStatusCode);
                Console.WriteLine(e.ErrorCode);
                Console.WriteLine(e.ErrorMsg);
            }
            catch (ConnectionException e)
            {
                Console.WriteLine(e.ErrorMessage);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
        protected override void ProcessRecord()
        {
            base.ProcessRecord();
            InvokeFunctionRequest request;

            if (ParameterSetName.Contains(FromFileSet))
            {
                InvokeFunctionBody = System.IO.File.OpenRead(GetAbsoluteFilePath(InvokeFunctionBodyFromFile));
            }


            try
            {
                request = new InvokeFunctionRequest
                {
                    FunctionId         = FunctionId,
                    InvokeFunctionBody = InvokeFunctionBody,
                    FnIntent           = FnIntent,
                    FnInvokeType       = FnInvokeType,
                    OpcRequestId       = OpcRequestId
                };

                response = client.InvokeFunction(request).GetAwaiter().GetResult();
                HandleOutput();

                FinishProcessing(response);
            }
            catch (Exception ex)
            {
                TerminatingErrorDuringExecution(ex);
            }
        }
示例#3
0
        /**
         * Invokes a function.
         *
         * @param fnInvokeClient the service client to use to delete the Function.
         * @param function the Function to invoke.
         * @param payload the payload to pass to the function.
         */
        private static async Task <string> InvokeFunction(FunctionsInvokeClient fnInvokeClient, FunctionSummary function, string payload)
        {
            string response = null;

            try
            {
                logger.Info($"Invoking function endpoint: {function.InvokeEndpoint}");

                // Configure the client to use the assigned function endpoint.
                fnInvokeClient.SetEndpoint(function.InvokeEndpoint);
                var invokeFunctionRequest = new InvokeFunctionRequest
                {
                    FunctionId         = function.Id,
                    InvokeFunctionBody = GenerateStreamFromString(payload)
                };

                // Invoke the function
                var invokeFunctionResponse = await fnInvokeClient.InvokeFunction(invokeFunctionRequest);

                // Handle the response
                response = new StreamReader(invokeFunctionResponse.InputStream).ReadToEnd();
            }
            catch (Exception e)
            {
                logger.Error($"Failed to invoke function: {e}");
            }

            return(response);
        }
        /// <summary>
        /// Invokes a function
        /// </summary>
        /// <param name="request">The request object containing the details to send. Required.</param>
        /// <param name="retryConfiguration">The retry configuration that will be used by to send this request. Optional.</param>
        /// <param name="cancellationToken">The cancellation token to cancel this operation. Optional.</param>
        /// <returns>A response object containing details about the completed operation</returns>
        /// <example>Click <a href="https://docs.cloud.oracle.com/en-us/iaas/tools/dot-net-examples/latest/functions/InvokeFunction.cs.html">here</a> to see an example of how to use InvokeFunction API.</example>
        public async Task <InvokeFunctionResponse> InvokeFunction(InvokeFunctionRequest request, RetryConfiguration retryConfiguration = null, CancellationToken cancellationToken = default)
        {
            logger.Trace("Called invokeFunction");
            Uri                uri            = new Uri(this.restClient.GetEndpoint(), System.IO.Path.Combine(basePathWithoutHost, "/functions/{functionId}/actions/invoke".Trim('/')));
            HttpMethod         method         = new HttpMethod("POST");
            HttpRequestMessage requestMessage = Converter.ToHttpRequestMessage(uri, method, request);

            requestMessage.Headers.Add("Accept", "*/*");
            GenericRetrier      retryingClient = Retrier.GetPreferredRetrier(retryConfiguration, this.retryConfiguration);
            HttpResponseMessage responseMessage;

            try
            {
                if (retryingClient != null)
                {
                    responseMessage = await retryingClient.MakeRetryingCall(this.restClient.HttpSend, requestMessage, cancellationToken).ConfigureAwait(false);
                }
                else
                {
                    responseMessage = await this.restClient.HttpSend(requestMessage).ConfigureAwait(false);
                }
                this.restClient.CheckHttpResponseMessage(requestMessage, responseMessage);

                return(Converter.FromHttpResponseMessage <InvokeFunctionResponse>(responseMessage));
            }
            catch (Exception e)
            {
                logger.Error($"InvokeFunction failed with error: {e.Message}");
                throw;
            }
        }
示例#5
0
        /// <summary>
        /// 同步执行函数。
        /// </summary>
        public async Task <InvokeFunctionResponse> InvokeFunctionAsync(InvokeFunctionRequest invokeFunctionRequest)
        {
            Dictionary <string, string> urlParam = new Dictionary <string, string>();

            urlParam.Add("function_urn", invokeFunctionRequest.FunctionUrn.ToString());
            string              urlPath  = HttpUtils.AddUrlPath("/v2/{project_id}/fgs/functions/{function_urn}/invocations", urlParam);
            SdkRequest          request  = HttpUtils.InitSdkRequest(urlPath, "application/json", invokeFunctionRequest);
            HttpResponseMessage response = await DoHttpRequestAsync("POST", request);

            return(JsonUtils.DeSerialize <InvokeFunctionResponse>(response));
        }
示例#6
0
 /// <summary>
 /// Invokes the function.
 /// </summary>
 /// <returns>The function.</returns>
 /// <param name="invokeFunctionRequest">Invoke function request.</param>
 public InvokeFunctionResponse InvokeFunction(InvokeFunctionRequest invokeFunctionRequest)
 {
     return(this.DoRequestCommon <InvokeFunctionResponse>(invokeFunctionRequest.GenHttpRequest(Config)));
 }