public async Task <IActionResult> GetRelayListnerInformationAsync([HttpTrigger(AuthorizationLevel.Function, "get",
                                                                                       Route = "relay-management/relayinfo/{relayId}/listener")] HttpRequest req, string relayId, ILogger log)
        {
            if (string.IsNullOrWhiteSpace(relayId))
            {
                throw new ArgumentNullException(nameof(relayId));
            }

            HybridConnectionDto hybridConnectionDto = await _relayManagementService.GetRelayAsync(relayId);

            if (hybridConnectionDto != null)
            {
                var listenerDto = new ListenerDto()
                {
                    HybridConnectionUrl = hybridConnectionDto.HybridConnectionUrl,
                    ListenerPolicyName  = hybridConnectionDto.PolicyDtos.FirstOrDefault(x => x.PolicyType == PolicyClaim.Listen).PolicyName,
                    ListenerPolicyValue = hybridConnectionDto.PolicyDtos.FirstOrDefault(x => x.PolicyType == PolicyClaim.Listen).PolicyKey
                };
                return(new OkObjectResult(listenerDto));
            }
            else
            {
                return(new NotFoundResult());
            }
        }
        public async Task <IActionResult> PostRelayInformationAsync([HttpTrigger(AuthorizationLevel.Function, "post",
                                                                                 Route = "relay-management/")] HttpRequest req, ILogger log)
        {
            var requestBody = await new StreamReader(req.Body).ReadToEndAsync();

            if (string.IsNullOrWhiteSpace(requestBody))
            {
                throw new InvalidOperationException(nameof(requestBody));
            }

            CreateRelayStorageDto createRelayDto = JsonConvert.DeserializeObject <CreateRelayStorageDto>(requestBody);

            HybridConnectionDto hybridConnectionDto = await _relayManagementService.StoreRelayAsync(createRelayDto);

            if (hybridConnectionDto != null)
            {
                var listenerDto = new ListenerDto()
                {
                    HybridConnectionUrl = hybridConnectionDto.HybridConnectionUrl,
                    ListenerPolicyName  = hybridConnectionDto.PolicyDtos.FirstOrDefault(x => x.PolicyType == PolicyClaim.Listen).PolicyName,
                    ListenerPolicyValue = hybridConnectionDto.PolicyDtos.FirstOrDefault(x => x.PolicyType == PolicyClaim.Listen).PolicyKey
                };
                return(new OkObjectResult(listenerDto));
            }
            else
            {
                return(new BadRequestResult());
            }
        }
Ejemplo n.º 3
0
 public HybridConnection MapToHybridConnection(ListenerDto listenerDto)
 {
     return(new HybridConnection()
     {
         HybridConnectionUrl = listenerDto.HybridConnectionUrl,
         ListenerPolicyName = listenerDto.ListenerPolicyName,
         ListenerPolicyValue = listenerDto.ListenerPolicyValue
     });
 }