public static string GetAzureResource(PSEndpointType psEndpointType, string connectionString, string containerName) { if (string.IsNullOrEmpty(connectionString)) { return(null); } Regex r = null; string azureResource = string.Empty; switch (psEndpointType) { case PSEndpointType.EventHub: case PSEndpointType.ServiceBusQueue: case PSEndpointType.ServiceBusTopic: r = new Regex(@"(.*?)sb://(?<resourceType>\S+).servicebus.windows.net(.*?)EntityPath=(?<name>\S+)", RegexOptions.IgnoreCase); Match match1 = r.Match(connectionString); azureResource = match1.Success ? string.Format("{0}/{1}", match1.Groups["resourceType"].Value, match1.Groups["name"].Value) : null; break; case PSEndpointType.AzureStorageContainer: r = new Regex(@"(.*?)AccountName=(?<resourceType>\S+);AccountKey=(.*?)", RegexOptions.IgnoreCase); Match match2 = r.Match(connectionString); azureResource = match2.Success ? string.Format("{0}/{1}", match2.Groups["resourceType"].Value, containerName) : null; break; } return(azureResource); }
private void WriteEndpointObject(IotHubDescription iotHubDescription, PSEndpointType psEndpointType, string endpointName) { switch (psEndpointType) { case PSEndpointType.EventHub: if (string.IsNullOrEmpty(endpointName)) { if (iotHubDescription.Properties.Routing.Endpoints.EventHubs.Count == 1) { this.WriteObject(IotHubUtils.ToPSRoutingEventHubEndpoint(iotHubDescription.Properties.Routing.Endpoints.EventHubs[0]), false); } else { this.WriteObject(IotHubUtils.ToPSRoutingEventHubProperties(iotHubDescription.Properties.Routing.Endpoints.EventHubs), true); } } else { this.WriteObject(IotHubUtils.ToPSRoutingEventHubEndpoint(iotHubDescription.Properties.Routing.Endpoints.EventHubs.FirstOrDefault(x => x.Name.Equals(endpointName, StringComparison.OrdinalIgnoreCase))), false); } break; case PSEndpointType.ServiceBusQueue: if (string.IsNullOrEmpty(endpointName)) { if (iotHubDescription.Properties.Routing.Endpoints.ServiceBusQueues.Count == 1) { this.WriteObject(IotHubUtils.ToPSRoutingServiceBusQueueEndpoint(iotHubDescription.Properties.Routing.Endpoints.ServiceBusQueues[0]), false); } else { this.WriteObject(IotHubUtils.ToPSRoutingServiceBusQueueEndpointProperties(iotHubDescription.Properties.Routing.Endpoints.ServiceBusQueues), true); } } else { this.WriteObject(IotHubUtils.ToPSRoutingServiceBusQueueEndpoint(iotHubDescription.Properties.Routing.Endpoints.ServiceBusQueues.FirstOrDefault(x => x.Name.Equals(endpointName, StringComparison.OrdinalIgnoreCase))), false); } break; case PSEndpointType.ServiceBusTopic: if (string.IsNullOrEmpty(endpointName)) { if (iotHubDescription.Properties.Routing.Endpoints.ServiceBusTopics.Count == 1) { this.WriteObject(IotHubUtils.ToPSRoutingServiceBusTopicEndpoint(iotHubDescription.Properties.Routing.Endpoints.ServiceBusTopics[0]), false); } else { this.WriteObject(IotHubUtils.ToPSRoutingServiceBusTopicEndpointProperties(iotHubDescription.Properties.Routing.Endpoints.ServiceBusTopics), true); } } else { this.WriteObject(IotHubUtils.ToPSRoutingServiceBusTopicEndpoint(iotHubDescription.Properties.Routing.Endpoints.ServiceBusTopics.FirstOrDefault(x => x.Name.Equals(endpointName, StringComparison.OrdinalIgnoreCase))), false); } break; case PSEndpointType.AzureStorageContainer: if (string.IsNullOrEmpty(endpointName)) { if (iotHubDescription.Properties.Routing.Endpoints.StorageContainers.Count == 1) { this.WriteObject(IotHubUtils.ToPSRoutingStorageContainerEndpoint(iotHubDescription.Properties.Routing.Endpoints.StorageContainers[0]), false); } else { this.WriteObject(IotHubUtils.ToPSRoutingStorageContainerProperties(iotHubDescription.Properties.Routing.Endpoints.StorageContainers), true); } } else { this.WriteObject(IotHubUtils.ToPSRoutingStorageContainerEndpoint(iotHubDescription.Properties.Routing.Endpoints.StorageContainers.FirstOrDefault(x => x.Name.Equals(endpointName, StringComparison.OrdinalIgnoreCase))), false); } break; } }