public override void ExecuteCmdlet() { switch (ParameterSetName) { case GetIotHubParameterSet: IotHubDescription iotHubDescription = this.IotHubClient.IotHubResource.Get(this.ResourceGroupName, this.Name); this.WriteObject(IotHubUtils.ToPSIotHub(iotHubDescription), false); break; case ListIotHubsByRGParameterSet: if (string.IsNullOrEmpty(this.ResourceGroupName)) { IEnumerable <IotHubDescription> iotHubDescriptionsBySubscription = this.IotHubClient.IotHubResource.ListBySubscription(); this.WriteObject(IotHubUtils.ToPSIotHubs(iotHubDescriptionsBySubscription), true); break; } else { IEnumerable <IotHubDescription> iotHubDescriptions = this.IotHubClient.IotHubResource.ListByResourceGroup(this.ResourceGroupName); this.WriteObject(IotHubUtils.ToPSIotHubs(iotHubDescriptions), true); break; } default: throw new ArgumentException("BadParameterSetName"); } }
public override void ExecuteCmdlet() { if (ParameterSetName.Equals(InputObjectParameterSet)) { this.ResourceGroupName = this.InputObject.Resourcegroup; this.Name = this.InputObject.Name; } if (ParameterSetName.Equals(ResourceIdParameterSet)) { this.ResourceGroupName = IotHubUtils.GetResourceGroupName(this.ResourceId); this.Name = IotHubUtils.GetIotHubName(this.ResourceId); } if (ShouldProcess(this.Name, Properties.Resources.ManualFailoverIotHub)) { IotHubDescription iotHubDescription = this.IotHubClient.IotHubResource.Get(this.ResourceGroupName, this.Name); PSIotHub psIotHub = IotHubUtils.ToPSIotHub(iotHubDescription); string failoverRegion = psIotHub.Properties.Locations.FirstOrDefault(loc => loc.Role.Equals("secondary", StringComparison.OrdinalIgnoreCase)).Location; FailoverInput failoverInput = new FailoverInput(failoverRegion); this.IotHubClient.IotHub.ManualFailover(this.Name, this.ResourceGroupName, failoverInput.FailoverRegion); if (this.PassThru.IsPresent) { WriteObject(true); } } }
public override void ExecuteCmdlet() { if (ShouldProcess(Name, ResourceProperties.Resources.AddIotHub)) { var iotHubDescription = new IotHubDescription() { Resourcegroup = this.ResourceGroupName, Subscriptionid = this.DefaultContext.Subscription.Id.ToString(), Location = this.Location, Sku = new IotHubSkuInfo() { Name = this.SkuName.ToString(), Capacity = this.Units } }; if (this.Properties != null) { iotHubDescription.Properties = IotHubUtils.ToIotHubProperties(this.Properties); } this.IotHubClient.IotHubResource.CreateOrUpdate(this.ResourceGroupName, this.Name, iotHubDescription); IotHubDescription updatedIotHubDescription = this.IotHubClient.IotHubResource.Get(this.ResourceGroupName, this.Name); this.WriteObject(IotHubUtils.ToPSIotHub(updatedIotHubDescription), false); } }
public override void ExecuteCmdlet() { if (ShouldProcess(Name, ResourceProperties.Resources.AddIotHub)) { var iotHubDescription = new IotHubDescription() { Location = this.Location, Sku = new IotHubSkuInfo() { Name = this.SkuName.ToString(), Capacity = this.Units } }; if (this.IsParameterBound(c => c.Tag)) { iotHubDescription.Tags = this.Tag.Cast <DictionaryEntry>().ToDictionary(kvp => (string)kvp.Key, kvp => (string)kvp.Value); } if (this.Properties != null) { iotHubDescription.Properties = IotHubUtils.ToIotHubProperties(this.Properties); } this.IotHubClient.IotHubResource.CreateOrUpdate(this.ResourceGroupName, this.Name, iotHubDescription); IotHubDescription updatedIotHubDescription = this.IotHubClient.IotHubResource.Get(this.ResourceGroupName, this.Name); this.WriteObject(IotHubUtils.ToPSIotHub(updatedIotHubDescription), false); } }
public override void ExecuteCmdlet() { if (ShouldProcess(Name, Properties.Resources.UpdateIotHub)) { IotHubDescription iotHubDescription = this.IotHubClient.IotHubResource.Get(this.ResourceGroupName, this.Name); if (!this.Reset.IsPresent) { foreach (var tag in iotHubDescription.Tags) { if (!this.Tag.ContainsKey(tag.Key)) { this.Tag.Add(tag.Key, tag.Value); } } } iotHubDescription = this.IotHubClient.IotHubResource.Update(this.ResourceGroupName, this.Name, IotHubUtils.ToTagsResource(this.Tag.Cast <DictionaryEntry>().ToDictionary(kvp => (string)kvp.Key, kvp => (string)kvp.Value))); this.WriteObject(IotHubUtils.ToPSIotHub(iotHubDescription), false); } }
public override void ExecuteCmdlet() { if (ShouldProcess(Name, Properties.Resources.UpdateIotHub)) { IotHubDescription iotHubDescription = this.IotHubClient.IotHubResource.Get(this.ResourceGroupName, this.Name); switch (ParameterSetName) { case UpdateSkuParameterSet: var psIotHubSku = new PSIotHubSkuInfo() { Name = this.SkuName, Capacity = this.Units }; iotHubDescription.Sku = IotHubUtils.ToIotHubSku(psIotHubSku); break; case UpdateEventHubEndpointPropertiesParameterSet: iotHubDescription.Properties.EventHubEndpoints["events"].RetentionTimeInDays = this.EventHubRetentionTimeInDays; break; case UpdateFileUploadPropertiesParameterSet: iotHubDescription.Properties.EnableFileUploadNotifications = this.EnableFileUploadNotifications; if (this.FileUploadStorageConnectionString != null) { iotHubDescription.Properties.StorageEndpoints["$default"].ConnectionString = this.FileUploadStorageConnectionString; } if (this.FileUploadContainerName != null) { iotHubDescription.Properties.StorageEndpoints["$default"].ContainerName = this.FileUploadContainerName; } if (this.FileUploadSasUriTtl != null) { iotHubDescription.Properties.StorageEndpoints["$default"].SasTtlAsIso8601 = this.FileUploadSasUriTtl; } if (this.FileUploadNotificationTtl != null) { iotHubDescription.Properties.MessagingEndpoints["fileNotifications"].TtlAsIso8601 = this.FileUploadNotificationTtl; } if (this.FileUploadNotificationMaxDeliveryCount != null) { iotHubDescription.Properties.MessagingEndpoints["fileNotifications"].MaxDeliveryCount = (int)this.FileUploadNotificationMaxDeliveryCount; } break; case UpdateCloudToDevicePropertiesParameterSet: if (this.CloudToDevice != null) { iotHubDescription.Properties.CloudToDevice = IotHubUtils.ToCloudToDeviceProperties(this.CloudToDevice); } break; case UpdateRoutingPropertiesParameterSet: if (this.RoutingProperties != null) { iotHubDescription.Properties.Routing = IotHubUtils.ToRoutingProperties(this.RoutingProperties); } break; case UpdateRoutePropertiesParameterSet: if (this.Routes != null) { iotHubDescription.Properties.Routing.Routes = IotHubUtils.ToRouteProperties(this.Routes); } break; case UpdateFallbackRoutePropertyParameterSet: if (this.FallbackRoute != null) { iotHubDescription.Properties.Routing.FallbackRoute = IotHubUtils.ToFallbackRouteProperty(this.FallbackRoute); } break; default: throw new ArgumentException("BadParameterSetName"); } this.IotHubClient.IotHubResource.CreateOrUpdate(this.ResourceGroupName, this.Name, iotHubDescription); IotHubDescription updatedIotHubDescription = this.IotHubClient.IotHubResource.Get(this.ResourceGroupName, this.Name); this.WriteObject(IotHubUtils.ToPSIotHub(updatedIotHubDescription), false); } }