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 PSCacheService(CloudServiceResource resource) { Name = resource.Name; State = resource.SubState; Location = resource.IntrinsicSettingsSection.CacheServiceInputSection.Location; Sku = resource.IntrinsicSettingsSection.CacheServiceInputSection.SkuType; int skuCount = resource.IntrinsicSettingsSection.CacheServiceInputSection.SkuCount; CacheSkuCountConvert convert = new CacheSkuCountConvert(Sku); Memory = convert.ToMemorySize(skuCount); }
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 PSCacheService(CloudServiceResource resource) { Name = resource.Name; State = resource.SubState; Location = resource.IntrinsicSettingsSection.CacheServiceInputSection.Location; Sku = resource.IntrinsicSettingsSection.CacheServiceInputSection.SkuType; int skuCount = resource.IntrinsicSettingsSection.CacheServiceInputSection.SkuCount; CacheSkuCountConvert convert = new CacheSkuCountConvert(Sku); Memory = convert.ToMemorySize(skuCount); }
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 PSCacheServiceWithNamedCaches(CloudServiceResource resource) { Name = resource.Name; State = resource.SubState; Location = resource.IntrinsicSettingsSection.CacheServiceInputSection.Location; Sku = resource.IntrinsicSettingsSection.CacheServiceInputSection.SkuType; int skuCount = resource.IntrinsicSettingsSection.CacheServiceInputSection.SkuCount; CacheSkuCountConvert convert = new CacheSkuCountConvert(Sku); Memory = convert.ToMemorySize(skuCount); NamedCaches = new List<PSNamedCachesAttributes>(); foreach (IntrinsicSettings.CacheServiceInput.NamedCache namedCache in resource.IntrinsicSettingsSection.CacheServiceInputSection.NamedCaches) { NamedCaches.Add(new PSNamedCachesAttributes(namedCache)); } }
public PSCacheServiceWithNamedCaches(CloudServiceResource resource) { Name = resource.Name; State = resource.SubState; Location = resource.IntrinsicSettingsSection.CacheServiceInputSection.Location; Sku = resource.IntrinsicSettingsSection.CacheServiceInputSection.SkuType; int skuCount = resource.IntrinsicSettingsSection.CacheServiceInputSection.SkuCount; CacheSkuCountConvert convert = new CacheSkuCountConvert(Sku); Memory = convert.ToMemorySize(skuCount); NamedCaches = new List <PSNamedCachesAttributes>(); foreach (IntrinsicSettings.CacheServiceInput.NamedCache namedCache in resource.IntrinsicSettingsSection.CacheServiceInputSection.NamedCaches) { NamedCaches.Add(new PSNamedCachesAttributes(namedCache)); } }
public string GetMemoryValue(CacheServiceSkuType sku) { RuntimeDefinedParameter memoryParameter; string memory = string.Empty; if (_parameters.TryGetValue(MemoryParameterName, out memoryParameter)) { if (memoryParameter != null && memoryParameter.Value != null) { memory = memoryParameter.Value.ToString(); } } if (string.IsNullOrEmpty(memory)) { memory = new CacheSkuCountConvert(sku).ToMemorySize(1); } return memory; }
private static CacheServiceCreateParameters InitializeParameters(string location, CacheServiceSkuType sku, string memorySize) { CacheServiceCreateParameters param = new CacheServiceCreateParameters(); IntrinsicSettings settings = new IntrinsicSettings(); IntrinsicSettings.CacheServiceInput input = new IntrinsicSettings.CacheServiceInput(); settings.CacheServiceInputSection = input; param.Settings = settings; const int CacheMemoryObjectSize = 1024; Models.CacheSkuCountConvert convert = new Models.CacheSkuCountConvert(sku); input.Location = location; input.SkuCount = convert.ToSkuCount(memorySize); input.ServiceVersion = "1.0.0"; input.ObjectSizeInBytes = CacheMemoryObjectSize; input.SkuType = sku; return(param); }
public string GetMemoryValue(CacheServiceSkuType sku) { RuntimeDefinedParameter memoryParameter; string memory = string.Empty; if (_parameters.TryGetValue(MemoryParameterName, out memoryParameter)) { if (memoryParameter != null && memoryParameter.Value != null) { memory = memoryParameter.Value.ToString(); } } if (string.IsNullOrEmpty(memory)) { memory = new CacheSkuCountConvert(sku).ToMemorySize(1); } return(memory); }
private static CacheServiceCreateParameters InitializeParameters(string location, CacheServiceSkuType sku, string memorySize) { CacheServiceCreateParameters param = new CacheServiceCreateParameters(); IntrinsicSettings settings = new IntrinsicSettings(); IntrinsicSettings.CacheServiceInput input = new IntrinsicSettings.CacheServiceInput(); settings.CacheServiceInputSection = input; param.Settings = settings; const int CacheMemoryObjectSize = 1024; Models.CacheSkuCountConvert convert = new Models.CacheSkuCountConvert(sku); input.Location = location; input.SkuCount = convert.ToSkuCount(memorySize); input.ServiceVersion = "1.0.0"; input.ObjectSizeInBytes = CacheMemoryObjectSize; input.SkuType = sku; return param; }
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; }
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) && p.Type == CacheResourceType; }); 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; }