Created
December 15, 2025 21:19
-
-
Save wsilveiranz/df5fed7b1f2470b281ccbb9a5e3745c1 to your computer and use it in GitHub Desktop.
Custom Code dynamic port sample
This file contains hidden or 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
| //------------------------------------------------------------ | |
| // Copyright (c) Microsoft Corporation. All rights reserved. | |
| //------------------------------------------------------------ | |
| using System; | |
| using System.Collections.Generic; | |
| using System.Threading.Tasks; | |
| using Newtonsoft.Json.Linq; | |
| using Microsoft.Azure.Functions.Extensions.Workflows; | |
| using Microsoft.Azure.Functions.Worker; | |
| using Microsoft.Extensions.Logging; | |
| using System.Text.Json.Nodes; | |
| namespace FourthCoffee.APIs | |
| { | |
| /// <summary> | |
| /// Represents the DynamicPort flow invoked function. | |
| /// </summary> | |
| public class DynamicPort | |
| { | |
| private readonly ILogger<DynamicPort> logger; | |
| public DynamicPort(ILoggerFactory loggerFactory) | |
| { | |
| logger = loggerFactory.CreateLogger<DynamicPort>(); | |
| } | |
| /// <summary> | |
| /// Executes the logic app workflow. | |
| /// </summary> | |
| /// <param name="destinationSystem">The destination system.</param> | |
| /// <param name="input">The input data.</param> | |
| [Function("DynamicPort")] | |
| public Task<TaskResult> Run([WorkflowActionTrigger] string destinationSystem, JsonObject input) | |
| { | |
| logger.LogInformation($"DynamicPort function executed for destination system: {destinationSystem}"); | |
| try | |
| { | |
| // Simulate retrieving destination system info based on the provided destinationSystem parameter - this can be a database call or configuration lookup | |
| var destination = GetDestinationSystemInfo(destinationSystem); | |
| logger.LogInformation($"Retrieved destination system info: {destination.SystemName}, {destination.Endpoint}, {destination.Port}, {destination.AuthenticationMethod}"); | |
| // Simulate sending data to the destination system - this can be an API call, database operation, etc. | |
| var result = SendDataToDestination(destination, input); | |
| return Task.FromResult(new TaskResult | |
| { | |
| Status = true, | |
| Data = result, | |
| Message = "DynamicPort executed successfully" | |
| }); | |
| } | |
| catch (Exception ex) | |
| { | |
| logger.LogError(ex, "Error occurred while executing DynamicPort function."); | |
| return Task.FromResult(new TaskResult | |
| { | |
| Status = false, | |
| Data = null, | |
| Message = $"Error: {ex.Message}" | |
| }); | |
| } | |
| } | |
| /// <summary> | |
| /// Represents the weather information for DynamicPort. | |
| /// </summary> | |
| public class TaskResult | |
| { | |
| public bool Status { get; set; } | |
| public JsonObject Data { get; set; } | |
| public string Message { get; set; } | |
| } | |
| public class DestinationSystemInfo | |
| { | |
| public string SystemName { get; set; } | |
| public string Endpoint { get; set; } | |
| public int Port { get; set; } | |
| public string AuthenticationMethod { get; set; } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment