public override void ExecuteCmdlet() { if (ShouldProcess(this.Key, Properties.Resources.UpdateIotHubMessageEnrichment)) { IotHubDescription iotHubDescription; if (ParameterSetName.Equals(InputObjectParameterSet)) { this.ResourceGroupName = this.InputObject.Resourcegroup; this.Name = this.InputObject.Name; iotHubDescription = IotHubUtils.ConvertObject <PSIotHub, IotHubDescription>(this.InputObject); } else { if (ParameterSetName.Equals(ResourceIdParameterSet)) { this.ResourceGroupName = IotHubUtils.GetResourceGroupName(this.ResourceId); this.Name = IotHubUtils.GetIotHubName(this.ResourceId); } iotHubDescription = this.IotHubClient.IotHubResource.Get(this.ResourceGroupName, this.Name); } EnrichmentProperties enrichProp = iotHubDescription.Properties.Routing.Enrichments.FirstOrDefault(x => x.Key.Equals(this.Key.Trim(), StringComparison.OrdinalIgnoreCase)); if (enrichProp != null) { if (!string.IsNullOrEmpty(this.Value)) { enrichProp.Value = this.Value; } if (this.Endpoint != null) { IList <string> endpointNames = new List <string>(); foreach (string endpoint in this.Endpoint) { endpointNames.Add(endpoint.Trim()); } enrichProp.EndpointNames = endpointNames; } this.IotHubClient.IotHubResource.CreateOrUpdate(this.ResourceGroupName, this.Name, iotHubDescription); IotHubDescription updatedIotHubDescription = this.IotHubClient.IotHubResource.Get(this.ResourceGroupName, this.Name); this.WriteObject(IotHubUtils.ToPSEnrichmentMetadata(updatedIotHubDescription.Properties.Routing.Enrichments.FirstOrDefault(x => x.Key.Equals(this.Key, StringComparison.OrdinalIgnoreCase))), false); } else { throw new ArgumentException(string.Format(Properties.Resources.MessageEnrichmentKeyMissing, this.Key)); } } }
public static PSEnrichmentMetadata ToPSEnrichmentMetadata(EnrichmentProperties enrichmentProperties) { return ConvertObject<EnrichmentProperties, PSEnrichmentMetadata>(enrichmentProperties); }