/// <summary> /// Get store from container identifier /// </summary> /// <param name="containerIdentifier">Container identifier</param> /// <returns>CB store</returns> public async Task <CBStore> GetStore(ContainerIdentifier containerIdentifier) { ContainerDescriptor containerDescriptor = ContainerDescriptorProvider.Containers[containerIdentifier]; string azureStorageConnectionString = await this.connectionStringProvider.GetBlobsAzureStorageConnectionString(containerDescriptor.AzureStorageInstanceType); string azureCdnUrl = await this.connectionStringProvider.GetAzureCdnUrl(containerDescriptor.AzureCdnInstanceType); string uniqueStoreIdentity = string.Join(":", azureStorageConnectionString, azureCdnUrl); // cachedStoreObjects is a thread-safe dictionary (ConcurrentDictionary). If uniqueStoreIdentity is not present // in cachedStoreObjects, try adding it. Since GetStore can be called concurrently by // different threads, it is possible for two (or more) threads to attempt inserting uniqueStoreIdentity // concurrently in the cachedStoreObjects. That's ok, because the call to TryAdd is guaranteed to be thread-safe. // One of the threads will not be able to insert (i.e., TryAdd will return false), but the code will happily execute // and fall through to the return statement. // This code makes no use of locking on the common path (i.e., reads of cachedStoreObjects). if (!cachedStoreObjects.ContainsKey(uniqueStoreIdentity)) { AzureBlobStorage azureBlobStorage = new AzureBlobStorage(azureStorageConnectionString); azureBlobStorage.BlobRequestOptions = AzureStorageConfiguration.GetBlobRequestOptions(); AzureCdn azureCdn = new AzureCdn(azureCdnUrl); CBStore store = new CBStore(azureBlobStorage, azureCdn); cachedStoreObjects.TryAdd(uniqueStoreIdentity, store); } return(cachedStoreObjects[uniqueStoreIdentity]); }
/// <summary> /// Initialize queue descriptors /// </summary> private static void Initalize() { ContainerDescriptor blobsContainer = new ContainerDescriptor() { ContainerName = ContainerIdentifier.Blobs.ToString().ToLower(), AzureStorageInstanceType = AzureStorageInstanceType.Default, AzureCdnInstanceType = AzureCdnInstanceType.Default }; ContainerDescriptor imagesContainer = new ContainerDescriptor() { ContainerName = ContainerIdentifier.Images.ToString().ToLower(), AzureStorageInstanceType = AzureStorageInstanceType.Default, AzureCdnInstanceType = AzureCdnInstanceType.Default }; Add(ContainerIdentifier.Blobs, blobsContainer); Add(ContainerIdentifier.Images, imagesContainer); }
/// <summary> /// Add container descriptor for container identifier /// </summary> /// <param name="containerIdentifier">Container identifier</param> /// <param name="containerDescriptor">Container descriptor</param> private static void Add(ContainerIdentifier containerIdentifier, ContainerDescriptor containerDescriptor) { containers.Add(containerIdentifier, containerDescriptor); }
/// <summary> /// Get container name for container identifier /// </summary> /// <param name="containerIdentifier">Container identifier</param> /// <returns>Container name</returns> public string GetContainerName(ContainerIdentifier containerIdentifier) { ContainerDescriptor containerDescriptor = ContainerDescriptorProvider.Containers[containerIdentifier]; return(containerDescriptor.ContainerName); }