Exemplo n.º 1
0
        public static async Task CreateSignalRServiceIfNotExists(this ISignalRManagementClient managementClient, ILogger logger, AppySignalRParameters parameters)
        {
            logger.Info($"Creating SignalR Service with name {parameters.ServiceName} in group {parameters.ResourceGroupName}");
            var locationName           = parameters.ServiceRegion.Name;
            var nameAvailabilityParams = new NameAvailabilityParameters(SignalRResourceType, parameters.ServiceName);
            var availability           = await managementClient.SignalR.CheckNameAvailabilityAsync(locationName, nameAvailabilityParams);

            if (availability.NameAvailable == false)
            {
                logger.Info($"SignalR Service with name {parameters.ServiceName} already exists in group {parameters.ResourceGroupName}");
                // TODO (compare parameters and update with CreateOrUpdateAsync)
                return;
            }

            var tags = new Dictionary <string, string>
            {
                { "description", parameters.Description },
            };
            var createParameters = new SignalRCreateParameters
            {
                Location = locationName,
                Sku      = parameters.ResourceSku,
                Tags     = tags
            };
            await managementClient.SignalR.CreateOrUpdateAsync(parameters.ResourceGroupName, parameters.ServiceName, createParameters);

            logger.Info($"Created SignalR Service with name {parameters.ServiceName} in group {parameters.ResourceGroupName}");
        }
Exemplo n.º 2
0
        public async Task <SignalRResource> CreateAsync(
            IResourceGroup resourceGroup,
            string signalRName,
            IDictionary <string, string> tags   = default,
            CancellationToken cancellationToken = default
            )
        {
            try {
                tags = tags ?? new Dictionary <string, string>();

                Log.Information($"Creating SignalR Service: {signalRName} ...");

                // Constructor of SignalRFeature will set Flag to "ServiceMode".
                // Bug report for adding feature to explicitly set the Flag to "ServiceMode":
                // https://github.com/Azure/azure-sdk-for-net/issues/8806
                var serviceModeFeature = new SignalRFeature {
                    Value = "Default"
                };

                var signalRCreateParameters = new SignalRCreateParameters()
                {
                    Location = resourceGroup.RegionName,
                    Tags     = tags,

                    Sku = new ResourceSku {
                        Name     = "Standard_S1",
                        Tier     = "Standard",
                        Capacity = 1,
                    },
                    Properties = new SignalRCreateOrUpdateProperties {
                        HostNamePrefix = signalRName,
                        Features       = new List <SignalRFeature> {
                            serviceModeFeature
                        }
                    }
                };

                signalRCreateParameters.Validate();

                var signalR = await _signalRManagementClient
                              .SignalR
                              .CreateOrUpdateAsync(
                    resourceGroup.Name,
                    signalRName,
                    signalRCreateParameters,
                    cancellationToken
                    );

                Log.Information($"Created SignalR Service: {signalRName}");

                return(signalR);
            }
            catch (Exception ex) {
                Log.Error(ex, $"Failed ot create SignalR Service: {signalRName}");
                throw;
            }
        }
Exemplo n.º 3
0
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            RunCmdlet(() =>
            {
                ResolveResourceGroupName(required: false);
                ResourceGroupName = ResourceGroupName ?? Name;

                if (ShouldProcess($"SignalR service {ResourceGroupName}/{Name}", "new"))
                {
                    PromptParameter(nameof(ResourceGroupName), ResourceGroupName);
                    PromptParameter(nameof(Name), Name);

                    if (Location == null)
                    {
                        Location = GetLocationFromResourceGroup();
                        PromptParameter(nameof(Location), null, true, Location, "(from resource group location)");
                    }
                    else
                    {
                        PromptParameter(nameof(Location), Location);
                    }

                    PromptParameter(nameof(Sku), Sku, true, DefaultSku);
                    PromptParameter(nameof(UnitCount), UnitCount);
                    PromptParameter(nameof(Tag), Tag == null ? null : JsonConvert.SerializeObject(Tag));
                    PromptParameter(nameof(ServiceMode), ServiceMode);

                    IList <string> origins = ParseAndCheckAllowedOrigins(AllowedOrigin);
                    PromptParameter(nameof(AllowedOrigin), origins == null ? null : JsonConvert.SerializeObject(origins));

                    Sku = Sku ?? DefaultSku;

                    IList <SignalRFeature> features = ServiceMode == null ? null : new List <SignalRFeature> {
                        new SignalRFeature(value: ServiceMode)
                    };
                    SignalRCorsSettings cors = AllowedOrigin == null ? null : new SignalRCorsSettings(allowedOrigins: origins);

                    var parameters = new SignalRCreateParameters(
                        location: Location,
                        tags: Tag,
                        sku: new ResourceSku(name: Sku, capacity: UnitCount),
                        properties: new SignalRCreateOrUpdateProperties(features: features, cors: cors));

                    Client.SignalR.CreateOrUpdate(ResourceGroupName, Name, parameters);

                    var signalr = Client.SignalR.Get(ResourceGroupName, Name);
                    WriteObject(new PSSignalRResource(signalr));
                }
            });
        }
 /// <summary>
 /// Create a new SignalR service and update an exiting SignalR service.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The name of the resource group that contains the resource. You can obtain
 /// this value from the Azure Resource Manager API or the portal.
 /// </param>
 /// <param name='resourceName'>
 /// The name of the SignalR resource.
 /// </param>
 /// <param name='parameters'>
 /// Parameters for the create or update operation
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <SignalRResource> BeginCreateOrUpdateAsync(this ISignalROperations operations, string resourceGroupName, string resourceName, SignalRCreateParameters parameters = default(SignalRCreateParameters), CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.BeginCreateOrUpdateWithHttpMessagesAsync(resourceGroupName, resourceName, parameters, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
 /// <summary>
 /// Create a new SignalR service and update an exiting SignalR service.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The name of the resource group that contains the resource. You can obtain
 /// this value from the Azure Resource Manager API or the portal.
 /// </param>
 /// <param name='resourceName'>
 /// The name of the SignalR resource.
 /// </param>
 /// <param name='parameters'>
 /// Parameters for the create or update operation
 /// </param>
 public static SignalRResource BeginCreateOrUpdate(this ISignalROperations operations, string resourceGroupName, string resourceName, SignalRCreateParameters parameters = default(SignalRCreateParameters))
 {
     return(operations.BeginCreateOrUpdateAsync(resourceGroupName, resourceName, parameters).GetAwaiter().GetResult());
 }