/// <summary>
 /// Returns the corresponding <see cref="ContainerConfiguration"/>.
 /// If the container does not exist, it tries to read it from the Azure's configuration container by calling ReadConfiguration.
 /// </summary>
 /// <param name="containerName">Name of the container configuration</param>
 /// <param name="autoRefresh">If true, the configuration will automatically refresh by reading its state from the azure storage. Hence, all new configurations will be reflected here automatically.</param>
 /// <returns></returns>
 public static ContainerConfiguration GetConfiguration(string containerName, bool autoRefresh)
 {
     if (ContainerConfigurations.ContainsKey(containerName))
     {
         return(ContainerConfigurations[containerName]);
     }
     else
     {
         ContainerConfiguration container = ContainerConfiguration.ReadConfiguration(containerName, /*SessionState.GetInstance()*/ null, autoRefresh);
         if (container != null)
         {
             ContainerConfigurations[containerName] = container;
             ICloudBlob blob = container.GetConfigurationContainer().GetBlockBlobReference(ConstPool.CURRENT_CONFIGURATION_BLOB_NAME);
             if (blob.Exists())
             {
                 //we break possible leases that are left from last run
                 //TODO: Remove me
                 try
                 {
                     blob.BreakLease(new TimeSpan(1));
                 }
                 catch
                 {
                 }
             }
         }
         return(container);
     }
 }
예제 #2
0
        /// <summary>
        /// Read an already created configuration of a CapCloudBlobContainer from the Azure's configuration blob.
        /// </summary>
        /// <param name="capCloudBlobContainerName">Name of the CapCloudBlobContainer</param>
        /// <param name="sessionState">session state of the SLAEngine. This state is used for registering, and unregistering newly added/removed replicas</param>
        /// <param name="autoRefresh">if true, it will automatically refresh the configuration by reading it periodically from the cloud storage.</param>
        /// <returns></returns>
        public static ContainerConfiguration ReadConfiguration(string capCloudBlobContainerName, SessionState sessionState, bool autoRefresh)
        {
            ContainerConfiguration result = new ContainerConfiguration(capCloudBlobContainerName, sessionState);

            //reads new configuration
            result.ReadConfiguration();
            if (autoRefresh)
            {
                refreshConfigurationTask = Task.Factory.StartNew(() => result.RefreshConfigurationPeriodically());
            }

            if (result.PrimaryServers != null && result.PrimaryServers.Count > 0)
            {
                return(result);
            }
            else
            {
                return(null);
            }
        }