private string unit; //MB or GB
 public CacheSkuCountConvert(CacheServiceSkuType sku)
 {
     skuName = sku;
     if (sku == CacheServiceSkuType.Basic)
     {
         min       = 128;
         max       = 1024;
         increment = 128;
         unit      = "MB";
     }
     else if (sku == CacheServiceSkuType.Standard)
     {
         min       = 1;
         max       = 10;
         increment = 1;
         unit      = "GB";
     }
     else
     {
         min       = 5;
         max       = 150;
         increment = 5;
         unit      = "GB";
     }
 }
Пример #2
0
        public object GetDynamicParameters(CacheServiceSkuType sku)
        {
            RuntimeDefinedParameter memoryParameter = CreateCacheMemoryDynamicParameter(sku);

            _parameters[MemoryParameterName] = memoryParameter;
            return(_parameters);
        }
 private string unit; //MB or GB
 public CacheSkuCountConvert(CacheServiceSkuType sku)
 {
     skuName = sku;
     if (sku == CacheServiceSkuType.Basic)
     {
         min = 128;
         max = 1024;
         increment = 128;
         unit = "MB";
     }
     else if (sku == CacheServiceSkuType.Standard)
     {
         min = 1;
         max = 10;
         increment = 1;
         unit = "GB";
     }
     else
     {
         min = 5;
         max = 150;
         increment = 5;
         unit = "GB";
     }
 }
        public void ConstructCorrectDynamicParameterBasedOnCurrentSku()
        {
            //Arrange
            CacheServiceSkuType skuType = CacheServiceSkuType.Standard;
            int    expectedValueNumber  = 10;
            string minValue             = "1GB";
            string maxValue             = "10GB";
            string secondMinValue       = "2GB";
            string memoryParameterName  = "Memory";
            MemoryDynamicParameterSet memoryDynamicParameter = new MemoryDynamicParameterSet();

            //Act
            RuntimeDefinedParameterDictionary parameters = memoryDynamicParameter.GetDynamicParameters(skuType)
                                                           as RuntimeDefinedParameterDictionary;
            RuntimeDefinedParameter parameter = parameters[memoryParameterName];

            //Assert
            Assert.Equal(memoryParameterName, parameter.Name);
            Assert.Equal(2, parameter.Attributes.Count);
            Assert.True(parameter.Attributes[1] is ValidateSetAttribute);
            ValidateSetAttribute validateSetAttribute = parameter.Attributes[1] as ValidateSetAttribute;

            Assert.Equal(expectedValueNumber, validateSetAttribute.ValidValues.Count);
            Assert.Equal(minValue, validateSetAttribute.ValidValues[0]);
            Assert.Equal(secondMinValue, validateSetAttribute.ValidValues[1]);
            Assert.Equal(maxValue, validateSetAttribute.ValidValues[expectedValueNumber - 1]);
        }
Пример #5
0
        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 GetCorrectDefaultMemoryValueFromDynamicParameter()
        {
            //Arrange
            CacheServiceSkuType       skuType = CacheServiceSkuType.Basic;
            MemoryDynamicParameterSet memoryDynamicParameter = new MemoryDynamicParameterSet();

            //Act
            memoryDynamicParameter.GetDynamicParameters(skuType);
            string memoryValue = memoryDynamicParameter.GetMemoryValue(skuType);

            //Assert
            Assert.Equal("128MB", memoryValue);
        }
Пример #7
0
        private string GetPromptMessgaeIfThereIsDataLoss(CacheServiceSkuType existingSkuType,
                                                         CacheServiceSkuType newSkuType,
                                                         int existingSkuCount,
                                                         int newSkuCount)
        {
            string promptMsg = string.Empty;

            if (existingSkuType != newSkuType)
            {
                promptMsg = Properties.Resources.PromptOnCachePlanChange;
            }
            else if (existingSkuCount > newSkuCount)
            {
                promptMsg = Properties.Resources.PromptOnCacheMemoryReduce;
            }
            return(promptMsg);
        }
        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;
        }
        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);
        }
Пример #10
0
        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);
        }
Пример #11
0
        public CloudServiceResource CreateCacheService (
            string subscriptionID,
            string cacheServiceName, 
            string location,
            CacheServiceSkuType sku, 
            string memorySize)
        {
            WriteProgress(Properties.Resources.InitializingCacheParameters);
            CacheServiceCreateParameters param = InitializeParameters(location, sku, memorySize);

            WriteProgress(Properties.Resources.CreatingPrerequisites);
            string cloudServiceName = EnsureCloudServiceExists(subscriptionID, location);

            WriteProgress(Properties.Resources.VerifyingCacheServiceName);
            if (!(client.CacheServices.CheckNameAvailability(cloudServiceName,cacheServiceName).Available))
            {
                throw new ArgumentException(Properties.Resources.CacheServiceNameUnavailable);
            }

            CloudServiceResource cacheResource = ProvisionCacheService(cloudServiceName, cacheServiceName, param, true);

            return cacheResource;
        }
Пример #12
0
        public CloudServiceResource CreateCacheService(
            string subscriptionID,
            string cacheServiceName,
            string location,
            CacheServiceSkuType sku,
            string memorySize)
        {
            WriteProgress(Properties.Resources.InitializingCacheParameters);
            CacheServiceCreateParameters param = InitializeParameters(location, sku, memorySize);

            WriteProgress(Properties.Resources.CreatingPrerequisites);
            string cloudServiceName = EnsureCloudServiceExists(subscriptionID, location);

            WriteProgress(Properties.Resources.VerifyingCacheServiceName);
            if (!(client.CacheServices.CheckNameAvailability(cloudServiceName, cacheServiceName).Available))
            {
                throw new ArgumentException(Properties.Resources.CacheServiceNameUnavailable);
            }

            CloudServiceResource cacheResource = ProvisionCacheService(cloudServiceName, cacheServiceName, param, true);

            return(cacheResource);
        }
Пример #13
0
        public void InitializeAllFieldsFromResponseObject()
        {
            //Arrange
            string testState            = "Started";
            string testSubState         = "Active";
            string testName             = "Dummy";
            string testLocation         = "West US";
            CacheServiceSkuType testSku = CacheServiceSkuType.Premium;
            int    testSkuCount         = 2;//This will be mapped to 10GB display value
            string expectedMemoryInfo   = "10GB";

            CloudServiceResource resource = new CloudServiceResource();

            resource.State    = testState;
            resource.SubState = testSubState;
            resource.Name     = testName;

            IntrinsicSettings intrinsic = new IntrinsicSettings();

            IntrinsicSettings.CacheServiceInput cacheInput = new IntrinsicSettings.CacheServiceInput();
            intrinsic.CacheServiceInputSection = cacheInput;
            resource.IntrinsicSettingsSection  = intrinsic;
            cacheInput.Location = testLocation;
            cacheInput.SkuCount = testSkuCount;
            cacheInput.SkuType  = testSku;

            //Act
            PSCacheService service = new PSCacheService(resource);

            //Assert
            Assert.Equal(testSubState, service.State);
            Assert.Equal(testName, service.Name);
            Assert.Equal(testLocation, service.Location);
            Assert.Equal(expectedMemoryInfo, service.Memory);
            Assert.Equal(testSku, service.Sku);
        }
        private RuntimeDefinedParameter CreateCacheMemoryDynamicParameter(CacheServiceSkuType sku)
        {
            var parameter = new RuntimeDefinedParameter
            {
                Name = MemoryParameterName,
                ParameterType = typeof(string),
            };

            // add the [parameter] attribute  
            var parameterAttribute = new ParameterAttribute
            {
                Mandatory = false,
            };

            parameter.Attributes.Add(parameterAttribute);

            string[] values = (new CacheSkuCountConvert(sku)).GetValueList();
            parameter.Attributes.Add(new ValidateSetAttribute(values)
            {
                IgnoreCase = true
            });

            return parameter;
        }
        private RuntimeDefinedParameter CreateCacheMemoryDynamicParameter(CacheServiceSkuType sku)
        {
            var parameter = new RuntimeDefinedParameter
            {
                Name          = MemoryParameterName,
                ParameterType = typeof(string),
            };

            // add the [parameter] attribute
            var parameterAttribute = new ParameterAttribute
            {
                Mandatory = false,
            };

            parameter.Attributes.Add(parameterAttribute);

            string[] values = (new CacheSkuCountConvert(sku)).GetValueList();
            parameter.Attributes.Add(new ValidateSetAttribute(values)
            {
                IgnoreCase = true
            });

            return(parameter);
        }
Пример #16
0
        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;
        }
Пример #17
0
 private string GetPromptMessgaeIfThereIsDataLoss(CacheServiceSkuType existingSkuType, 
     CacheServiceSkuType newSkuType, 
     int existingSkuCount, 
     int newSkuCount)
 {
     string promptMsg = string.Empty;
     if (existingSkuType != newSkuType)
     {
         promptMsg = Properties.Resources.PromptOnCachePlanChange;
     }
     else if (existingSkuCount > newSkuCount)
     {
         promptMsg = Properties.Resources.PromptOnCacheMemoryReduce;
     }
     return promptMsg;
 }
Пример #18
0
        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;
        }
Пример #19
0
        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;
        }
Пример #20
0
        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 object GetDynamicParameters(CacheServiceSkuType sku)
 {
     RuntimeDefinedParameter memoryParameter = CreateCacheMemoryDynamicParameter(sku);
     _parameters[MemoryParameterName] = memoryParameter;
     return _parameters;
 }