public CloudServiceResource UpdateCacheService(string cacheServiceName, CacheServiceSkuType sku, string memory, Action <bool, string, string, string, Action> ConfirmAction, bool force) { CloudServiceListResponse listResponse = client.CloudServices.List(); CloudServiceResource cacheResource = null; string cloudServiceName = null; foreach (CloudServiceListResponse.CloudService cloudService in listResponse) { cacheResource = cloudService.Resources.FirstOrDefault( p => { return(p.Name.Equals(cacheServiceName) && IsCachingResource(p.Type)); }); if (cacheResource != null) { cloudServiceName = cloudService.Name; break; } } if (cacheResource == null) { throw new ArgumentException(string.Format(Properties.Resources.CacheServiceNotExisting, cacheServiceName)); } CacheSkuCountConvert convert = new CacheSkuCountConvert(sku); CacheServiceSkuType existingSkuType = cacheResource.IntrinsicSettingsSection.CacheServiceInputSection.SkuType; int existingSkuCount = cacheResource.IntrinsicSettingsSection.CacheServiceInputSection.SkuCount; int newSkuCount = convert.ToSkuCount(memory); if (existingSkuType == sku && existingSkuCount == newSkuCount) { WriteProgress("No update is needed as there is no change"); return(cacheResource); } //We will prompt only if there is data loss string promptMessage = GetPromptMessgaeIfThereIsDataLoss(existingSkuType, sku, existingSkuCount, newSkuCount); if (string.IsNullOrEmpty(promptMessage)) { force = true; } ConfirmAction( force, string.Format(Properties.Resources.UpdatingCacheService), promptMessage, cacheServiceName, () => { cacheResource.IntrinsicSettingsSection.CacheServiceInputSection.SkuCount = convert.ToSkuCount(memory); cacheResource.IntrinsicSettingsSection.CacheServiceInputSection.SkuType = sku; CacheServiceCreateParameters param = new CacheServiceCreateParameters(); param.IntrinsicSettingsSection = cacheResource.IntrinsicSettingsSection; param.ETag = cacheResource.ETag; cacheResource = ProvisionCacheService(cloudServiceName, cacheResource.Name, param, false); }); return(cacheResource); }
public void ManagedCache_ConversionWorksForPremiumSku() { CacheSkuCountConvert convert = new CacheSkuCountConvert(CacheServiceSkuType.Premium); Assert.Equal("5GB", convert.ToMemorySize(1)); Assert.Equal("10GB", convert.ToMemorySize(2)); Assert.Equal(1, convert.ToSkuCount("5GB")); Assert.Equal(30, convert.ToSkuCount("150GB")); Assert.Throws(typeof(ArgumentException), () => { convert.ToSkuCount("12MB"); }); Assert.Throws(typeof(ArgumentException), () => { convert.ToSkuCount("-1"); }); }
public void ManagedCache_ConversionWorksForStandardSku() { CacheSkuCountConvert convert = new CacheSkuCountConvert(CacheServiceSkuType.Standard); Assert.Equal("1GB", convert.ToMemorySize(1)); Assert.Equal("2GB", convert.ToMemorySize(2)); Assert.Equal(1, convert.ToSkuCount("1GB")); Assert.Equal(10, convert.ToSkuCount("10GB")); Assert.Throws(typeof(ArgumentException), () => { convert.ToSkuCount("11"); }); Assert.Throws(typeof(ArgumentException), () => { convert.ToSkuCount("foo-bar"); }); }
public void ManagedCache_ConversionWorksForBasicSku() { CacheSkuCountConvert convert = new CacheSkuCountConvert(CacheServiceSkuType.Basic); Assert.Equal("128MB", convert.ToMemorySize(1)); Assert.Equal("256MB", convert.ToMemorySize(2)); Assert.Equal(2, convert.ToSkuCount("256")); Assert.Equal(1, convert.ToSkuCount("128MB")); Assert.Equal(1, convert.ToSkuCount("128mb")); Assert.Throws(typeof(ArgumentException), () => { convert.ToSkuCount("2222"); }); Assert.Throws(typeof(ArgumentException), () => { convert.ToSkuCount("foo-bar"); }); }
public CloudServiceResource UpdateCacheService(string cacheServiceName, CacheServiceSkuType sku, string memory, Action <bool, string, string, string, Action> ConfirmAction, bool force) { string cloudServiceName = null; CloudServiceResource cacheResource = FetchCloudServiceResource(cacheServiceName, out cloudServiceName); CacheSkuCountConvert convert = new CacheSkuCountConvert(sku); CacheServiceSkuType existingSkuType = cacheResource.IntrinsicSettingsSection.CacheServiceInputSection.SkuType; int existingSkuCount = cacheResource.IntrinsicSettingsSection.CacheServiceInputSection.SkuCount; int newSkuCount = convert.ToSkuCount(memory); if (existingSkuType == sku && existingSkuCount == newSkuCount) { WriteProgress("No update is needed as there is no change"); return(cacheResource); } //We will prompt only if there is data loss string promptMessage = GetPromptMessgaeIfThereIsDataLoss(existingSkuType, sku, existingSkuCount, newSkuCount); if (string.IsNullOrEmpty(promptMessage)) { force = true; } ConfirmAction( force, string.Format(Properties.Resources.UpdatingCacheService), promptMessage, cacheServiceName, () => { cacheResource.IntrinsicSettingsSection.CacheServiceInputSection.SkuCount = convert.ToSkuCount(memory); cacheResource.IntrinsicSettingsSection.CacheServiceInputSection.SkuType = sku; CacheServiceCreateParameters param = new CacheServiceCreateParameters(); param.IntrinsicSettingsSection = cacheResource.IntrinsicSettingsSection; param.ETag = cacheResource.ETag; cacheResource = ProvisionCacheService(cloudServiceName, cacheResource.Name, param, false); }); return(cacheResource); }