Ejemplo n.º 1
0
        public void FilePathToName(string filePath)
        {
            string name = AzureUtils.FilePathToName(filePath);

            Assert.StartsWith("media", name);
            Assert.EndsWith(".yml", name);
        }
        public T GetValue(string filePath, Func <string, T> populateFunction)
        {
            T cacheValue = this.GetValue(filePath, true);

            if (cacheValue != null)
            {
                return(cacheValue);
            }

            if (!this.azureManager.FileExists(filePath))
            {
                return(default(T));
            }

            string name  = AzureUtils.FilePathToName(filePath);
            var    mutex = new Mutex(false, $"blob-{name}");

            try
            {
                mutex.WaitOne();
                T cacheValueAgain = this.GetValue(filePath, true);
                if (cacheValueAgain != null)
                {
                    return(cacheValueAgain);
                }

                T calculatedValue = populateFunction(filePath);
                this.AddOrUpdateCache(filePath, calculatedValue);
                return(calculatedValue);
            }
            finally
            {
                mutex.ReleaseMutex();
            }
        }
        public Stream GetFileStream(string filePath, bool openRead = true)
        {
            string name = AzureUtils.FilePathToName(filePath);

            CloudBlockBlob cloudBlockBlob = this.cloudBlobContainer.GetBlockBlobReference(name);

            return(openRead ? cloudBlockBlob.OpenRead() : cloudBlockBlob.OpenWrite());
        }
        public bool FileExists(string filePath)
        {
            string name = AzureUtils.FilePathToName(filePath);

            return(this.azureProvider.BlobExists(name));
        }