/// <summary>
 /// Creates a new instance of the service class.
 /// </summary>
 /// <param name="clusterOperator"></param>
 /// <param name="mailer"></param>
 /// <param name="stateManager"></param>
 /// <param name="serviceContext"></param>
 /// <param name="config"></param>
 public ClusterService(
     IClusterOperator clusterOperator,
     ISendMail mailer,
     IApplicationDeployService applicationDeployService,
     IReliableStateManager stateManager,
     StatefulServiceContext serviceContext,
     ClusterConfig config)
     : base(serviceContext, stateManager as IReliableStateManagerReplica)
 {
     this.config = config;
     this.clusterOperator = clusterOperator;
     this.applicationDeployService = applicationDeployService;
     this.mailer = mailer;
 }
        /// <summary>
        /// Updates the service's ClusterConfig instance with new settings from the given ConfigurationSettings.
        /// </summary>
        /// <param name="settings">
        /// The ConfigurationSettings object comes from the Settings.xml file in the service's Config package.
        /// </param>
        private void UpdateClusterConfigSettings(ConfigurationSettings settings)
        {
            // All of these settings are required.
            // If anything is missing, fail fast.
            // If a setting is missing after a service upgrade, allow this to throw so the upgrade will fail and roll back.
            KeyedCollection <string, ConfigurationProperty> clusterConfigParameters = settings.Sections["ClusterConfigSettings"].Parameters;

            ClusterConfig newConfig = new ClusterConfig();

            newConfig.RefreshInterval                  = TimeSpan.Parse(clusterConfigParameters["RefreshInterval"].Value);
            newConfig.MinimumClusterCount              = Int32.Parse(clusterConfigParameters["MinimumClusterCount"].Value);
            newConfig.MaximumClusterCount              = Int32.Parse(clusterConfigParameters["MaximumClusterCount"].Value);
            newConfig.MaximumUsersPerCluster           = Int32.Parse(clusterConfigParameters["MaximumUsersPerCluster"].Value);
            newConfig.MaximumClusterUptime             = TimeSpan.Parse(clusterConfigParameters["MaximumClusterUptime"].Value);
            newConfig.UserCapacityHighPercentThreshold = Double.Parse(clusterConfigParameters["UserCapacityHighPercentThreshold"].Value);
            newConfig.UserCapacityLowPercentThreshold  = Double.Parse(clusterConfigParameters["UserCapacityLowPercentThreshold"].Value);

            this.config = newConfig;
        }
        /// <summary>
        /// Updates the service's ClusterConfig instance with new settings from the given ConfigurationSettings.
        /// </summary>
        /// <param name="settings">
        /// The ConfigurationSettings object comes from the Settings.xml file in the service's Config package.
        /// </param>
        private void UpdateClusterConfigSettings(ConfigurationSettings settings)
        {
            // All of these settings are required. 
            // If anything is missing, fail fast.
            // If a setting is missing after a service upgrade, allow this to throw so the upgrade will fail and roll back.
            KeyedCollection<string, ConfigurationProperty> clusterConfigParameters = settings.Sections["ClusterConfigSettings"].Parameters;

            ClusterConfig newConfig = new ClusterConfig();
            newConfig.RefreshInterval = TimeSpan.Parse(clusterConfigParameters["RefreshInterval"].Value);
            newConfig.MinimumClusterCount = Int32.Parse(clusterConfigParameters["MinimumClusterCount"].Value);
            newConfig.MaximumClusterCount = Int32.Parse(clusterConfigParameters["MaximumClusterCount"].Value);
            newConfig.MaximumUsersPerCluster = Int32.Parse(clusterConfigParameters["MaximumUsersPerCluster"].Value);
            newConfig.MaximumClusterUptime = TimeSpan.Parse(clusterConfigParameters["MaximumClusterUptime"].Value);
            newConfig.UserCapacityHighPercentThreshold = Double.Parse(clusterConfigParameters["UserCapacityHighPercentThreshold"].Value);
            newConfig.UserCapacityLowPercentThreshold = Double.Parse(clusterConfigParameters["UserCapacityLowPercentThreshold"].Value);

            this.config = newConfig;
        }