public override void ExecuteCmdlet() { if (ShouldProcess(Name, Resources.CreateNewAnalysisServicesServer)) { try { if (AnalysisServicesClient.GetServer(ResourceGroupName, Name) != null) { throw new CloudException(string.Format(Resources.AnalysisServerExists, Name)); } } catch (CloudException ex) { if (ex.Body != null && !string.IsNullOrEmpty(ex.Body.Code) && ex.Body.Code == "ResourceNotFound" || ex.Message.Contains("ResourceNotFound")) { // server does not exists so go ahead and create one } else if (ex.Body != null && !string.IsNullOrEmpty(ex.Body.Code) && ex.Body.Code == "ResourceGroupNotFound" || ex.Message.Contains("ResourceGroupNotFound")) { // resource group not found, let create throw error don't throw from here } else { // all other exceptions should be thrown throw; } } var availableSkus = AnalysisServicesClient.ListSkusForNew(); if (!availableSkus.Value.Any(v => v.Name == Sku)) { throw new InvalidOperationException(string.Format(Resources.InvalidSku, Sku, String.Join(",", availableSkus.Value.Select(v => v.Name)))); } var createdServer = AnalysisServicesClient.CreateOrUpdateServer(ResourceGroupName, Name, Location, Sku, Tag, Administrator, null, BackupBlobContainerUri); WriteObject(AzureAnalysisServicesServer.FromAnalysisServicesServer(createdServer)); } }
public override void ExecuteCmdlet() { if (ShouldProcess(Name, Resources.CreateNewAnalysisServicesServer)) { try { if (AnalysisServicesClient.GetServer(ResourceGroupName, Name) != null) { throw new CloudException(string.Format(Resources.AnalysisServerExists, Name)); } } catch (CloudException ex) { if (ex.Body != null && !string.IsNullOrEmpty(ex.Body.Code) && ex.Body.Code == "ResourceNotFound" || ex.Message.Contains("ResourceNotFound")) { // server does not exists so go ahead and create one } else if (ex.Body != null && !string.IsNullOrEmpty(ex.Body.Code) && ex.Body.Code == "ResourceGroupNotFound" || ex.Message.Contains("ResourceGroupNotFound")) { // resource group not found, let create throw error don't throw from here } else { // all other exceptions should be thrown throw; } } var availableSkus = AnalysisServicesClient.ListSkusForNew(); if (!availableSkus.Value.Any(v => v.Name == Sku)) { throw new InvalidOperationException(string.Format(Resources.InvalidSku, Sku, String.Join(",", availableSkus.Value.Select(v => v.Name)))); } IPv4FirewallSettings setting = null; if (FirewallConfig != null) { setting = new IPv4FirewallSettings(new List <IPv4FirewallRule>(), "False"); setting.EnablePowerBIService = FirewallConfig.EnablePowerBIService.ToString(); if (FirewallConfig.FirewallRules != null) { foreach (var rule in FirewallConfig.FirewallRules) { setting.FirewallRules.Add(new IPv4FirewallRule() { FirewallRuleName = rule.FirewallRuleName, RangeStart = rule.RangeStart, RangeEnd = rule.RangeEnd }); } } } if (!MyInvocation.BoundParameters.ContainsKey("ReadonlyReplicaCount")) { ReadonlyReplicaCount = 0; } var createdServer = AnalysisServicesClient.CreateOrUpdateServer(ResourceGroupName, Name, Location, Sku, Tag, Administrator, null, BackupBlobContainerUri, ReadonlyReplicaCount, DefaultConnectionMode, setting, GatewayResourceId); WriteObject(AzureAnalysisServicesServer.FromAnalysisServicesServer(createdServer)); } }