public async virtual Task <ProfileCreateOrUpdateOperation> CreateOrUpdateAsync(bool waitForCompletion, string profileName, ProfileData profile, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(profileName, nameof(profileName)); if (profile == null) { throw new ArgumentNullException(nameof(profile)); } using var scope = _profileClientDiagnostics.CreateScope("ProfileCollection.CreateOrUpdate"); scope.Start(); try { var response = await _profileRestClient.CreateAsync(Id.SubscriptionId, Id.ResourceGroupName, profileName, profile, cancellationToken).ConfigureAwait(false); var operation = new ProfileCreateOrUpdateOperation(ArmClient, _profileClientDiagnostics, Pipeline, _profileRestClient.CreateCreateRequest(Id.SubscriptionId, Id.ResourceGroupName, profileName, profile).Request, response); if (waitForCompletion) { await operation.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false); } return(operation); } catch (Exception e) { scope.Failed(e); throw; } }
public virtual ProfileCreateOrUpdateOperation CreateOrUpdate(bool waitForCompletion, string profileName, ProfileData profile, CancellationToken cancellationToken = default) { if (profileName == null) { throw new ArgumentNullException(nameof(profileName)); } if (profile == null) { throw new ArgumentNullException(nameof(profile)); } using var scope = _clientDiagnostics.CreateScope("ProfileCollection.CreateOrUpdate"); scope.Start(); try { var response = _profilesRestClient.Create(Id.SubscriptionId, Id.ResourceGroupName, profileName, profile, cancellationToken); var operation = new ProfileCreateOrUpdateOperation(this, _clientDiagnostics, Pipeline, _profilesRestClient.CreateCreateRequest(Id.SubscriptionId, Id.ResourceGroupName, profileName, profile).Request, response); if (waitForCompletion) { operation.WaitForCompletion(cancellationToken); } return(operation); } catch (Exception e) { scope.Failed(e); throw; } }
public async Task CreateAfdRules() { #region Snippet:Managing_AfdRules_CreateAnAzureFrontDoorRule // Create a new azure front door profile string AfdProfileName = "myAfdProfile"; var input1 = new ProfileData("Global", new Models.Sku { Name = SkuName.StandardAzureFrontDoor }); ProfileCreateOrUpdateOperation lro1 = await resourceGroup.GetProfiles().CreateOrUpdateAsync(true, AfdProfileName, input1); Profile AfdProfile = lro1.Value; // Get the rule set collection from the specific azure front door profile and create a rule set string ruleSetName = "myAfdRuleSet"; AfdRuleSetCreateOrUpdateOperation lro2 = await AfdProfile.GetAfdRuleSets().CreateOrUpdateAsync(true, ruleSetName); AfdRuleSet ruleSet = lro2.Value; // Get the rule collection from the specific rule set and create a rule string ruleName = "myAfdRule"; AfdRuleData input3 = new AfdRuleData { Order = 1 }; input3.Conditions.Add(new DeliveryRuleRequestUriCondition(new RequestUriMatchConditionParameters(RequestUriMatchConditionParametersOdataType.MicrosoftAzureCdnModelsDeliveryRuleRequestUriConditionParameters, RequestUriOperator.Any))); input3.Actions.Add(new DeliveryRuleCacheExpirationAction(new CacheExpirationActionParameters(CacheExpirationActionParametersOdataType.MicrosoftAzureCdnModelsDeliveryRuleCacheExpirationActionParameters, CacheBehavior.Override, CacheType.All) { CacheDuration = "00:00:20" })); AfdRuleCreateOrUpdateOperation lro3 = await ruleSet.GetAfdRules().CreateOrUpdateAsync(true, ruleName, input3); AfdRule rule = lro3.Value; #endregion Snippet:Managing_AfdRules_CreateAnAzureFrontDoorRule }
public async Task CreateOriginGroups() { #region Snippet:Managing_OriginGroups_CreateAnOriginGroup // Create a new cdn profile string profileName = "myProfile"; var input1 = new ProfileData(AzureLocation.WestUS, new Models.Sku { Name = SkuName.StandardMicrosoft }); ProfileCreateOrUpdateOperation lro1 = await resourceGroup.GetProfiles().CreateOrUpdateAsync(true, profileName, input1); Profile profile = lro1.Value; // Get the cdn endpoint collection from the specific profile and create an endpoint string endpointName = "myEndpoint"; var input2 = new CdnEndpointData(AzureLocation.WestUS) { IsHttpAllowed = true, IsHttpsAllowed = true, OptimizationType = OptimizationType.GeneralWebDelivery }; DeepCreatedOrigin deepCreatedOrigin = new DeepCreatedOrigin("myOrigin") { HostName = "testsa4dotnetsdk.blob.core.windows.net", Priority = 3, Weight = 100 }; input2.Origins.Add(deepCreatedOrigin); CdnEndpointCreateOrUpdateOperation lro2 = await profile.GetCdnEndpoints().CreateOrUpdateAsync(true, endpointName, input2); CdnEndpoint endpoint = lro2.Value; // Get the cdn origin group collection from the specific endpoint and create an origin group string originGroupName = "myOriginGroup"; var input3 = new CdnOriginGroupData(); input3.Origins.Add(new WritableSubResource { Id = new ResourceIdentifier($"{endpoint.Id}/origins/myOrigin") }); CdnOriginGroupCreateOrUpdateOperation lro3 = await endpoint.GetCdnOriginGroups().CreateOrUpdateAsync(true, originGroupName, input3); CdnOriginGroup originGroup = lro3.Value; #endregion Snippet:Managing_OriginGroups_CreateAnOriginGroup }