當前位置: 首頁>>代碼示例>>C#>>正文


C# CloudBlobContainer.GetBlobReference方法代碼示例

本文整理匯總了C#中Microsoft.WindowsAzure.StorageClient.CloudBlobContainer.GetBlobReference方法的典型用法代碼示例。如果您正苦於以下問題:C# CloudBlobContainer.GetBlobReference方法的具體用法?C# CloudBlobContainer.GetBlobReference怎麽用?C# CloudBlobContainer.GetBlobReference使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Microsoft.WindowsAzure.StorageClient.CloudBlobContainer的用法示例。


在下文中一共展示了CloudBlobContainer.GetBlobReference方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: EnsureGzipFiles

        public const int CacheControlOneWeekExpiration = 7 * 24 * 60 * 60; // 1 week

        #endregion Fields

        #region Methods

        /// <summary>
        ///   Finds all js and css files in a container and creates a gzip compressed
        ///   copy of the file with ".gzip" appended to the existing blob name
        /// </summary>
        public static void EnsureGzipFiles(
            CloudBlobContainer container,
            int cacheControlMaxAgeSeconds)
        {
            string cacheControlHeader = "public, max-age=" + cacheControlMaxAgeSeconds.ToString();

            var blobInfos = container.ListBlobs(
                new BlobRequestOptions() { UseFlatBlobListing = true });
            Parallel.ForEach(blobInfos, (blobInfo) =>
            {
                string blobUrl = blobInfo.Uri.ToString();
                CloudBlob blob = container.GetBlobReference(blobUrl);

                // only create gzip copies for css and js files
                string extension = Path.GetExtension(blobInfo.Uri.LocalPath);
                if (extension != ".css" && extension != ".js")
                    return;

                // see if the gzip version already exists
                string gzipUrl = blobUrl + ".gzip";
                CloudBlob gzipBlob = container.GetBlobReference(gzipUrl);
                if (gzipBlob.Exists())
                    return;

                // create a gzip version of the file
                using (MemoryStream memoryStream = new MemoryStream())
                {
                    // push the original blob into the gzip stream
                    using (GZipStream gzipStream = new GZipStream(
                        memoryStream, CompressionMode.Compress, CompressionLevel.BestCompression))
                    using (BlobStream blobStream = blob.OpenRead())
                    {
                        blobStream.CopyTo(gzipStream);
                    }

                    // the gzipStream MUST be closed before its safe to read from the memory stream
                    byte[] compressedBytes = memoryStream.ToArray();

                    // upload the compressed bytes to the new blob
                    gzipBlob.UploadByteArray(compressedBytes);

                    // set the blob headers
                    gzipBlob.Properties.CacheControl = cacheControlHeader;
                    gzipBlob.Properties.ContentType = GetContentType(extension);
                    gzipBlob.Properties.ContentEncoding = "gzip";
                    gzipBlob.SetProperties();
                }
            });
        }
開發者ID:joelfillmore,項目名稱:JFLibrary,代碼行數:59,代碼來源:CloudBlobUtility.cs

示例2: UploadBlob

        private static void UploadBlob(CloudBlobContainer container, string blobName, string filename)
        {
            CloudBlob blob = container.GetBlobReference(blobName);
 
            using (FileStream fileStream = File.OpenRead(filename))
                blob.UploadFromStream(fileStream);
        }
開發者ID:jonbgallant,項目名稱:Neo4j.Azure.Server,代碼行數:7,代碼來源:Program.cs

示例3: deleteFromBlob

 public void deleteFromBlob(string uri, string blobname)
 {
     CloudStorageAccount storageAccount;
     storageAccount = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("BlobConnectionString"));
     blobClient = storageAccount.CreateCloudBlobClient();
     blobContainer = blobClient.GetContainerReference(blobname);
     var blob = blobContainer.GetBlobReference(uri);
     blob.DeleteIfExists();
 }
開發者ID:bcary,項目名稱:Vestn_Backend,代碼行數:9,代碼來源:BlobStorageAccessor.cs

示例4: SaveToAzureBlob

 /// <summary>
 /// Save the data table to the given azure blob. This will overwrite an existing blob.
 /// </summary>
 /// <param name="table">instance of table to save</param>
 /// <param name="container">conatiner</param>
 /// <param name="blobName">blob name</param>
 public static void SaveToAzureBlob(this DataTable table, CloudBlobContainer container, string blobName)
 {
     var blob = container.GetBlobReference(blobName);
     using (BlobStream stream = blob.OpenWrite())
     using (TextWriter writer = new StreamWriter(stream))
     {
         table.SaveToStream(writer);
     }
 }
開發者ID:bmegias,項目名稱:DataTable,代碼行數:15,代碼來源:AzureDataTableExtensions.cs

示例5: AzureTapeStream

        public AzureTapeStream(string name, string connectionString, string containerName, ITapeStreamSerializer serializer)
        {
            _serializer = serializer;

            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString);
            blobClient = storageAccount.CreateCloudBlobClient();
            container = blobClient.GetContainerReference(containerName);
            container.CreateIfNotExist();

            _blob = container.GetBlobReference(name);
        }
開發者ID:stemarie,項目名稱:CqrsSiteEngine,代碼行數:11,代碼來源:AzureTapeStream.cs

示例6: AzureStorageSourceDataCollection

        public AzureStorageSourceDataCollection(CloudBlobContainer container, string blobRootPath)
        {
            mContainer = container;
            mBlobRootPath = blobRootPath;

            Names
                .Where(i => mContainer.GetBlobReference(mBlobRootPath + "/" + i.Value + ".txt") != null)
                .ForEach(i => mStreams.Add(i.Key, ((Func<string, Stream>)GetStream).Curry()(i.Value)));

            var missing = Required.Except(mStreams.Keys);
            if (missing.Count() > 0)
                throw new ArgumentOutOfRangeException("Missing mandatory data.");
        }
開發者ID:mbmccormick,項目名稱:GTFSEngine,代碼行數:13,代碼來源:AzureStorageSourceDataCollection.cs

示例7: UploadWithMd5

 static void UploadWithMd5(CloudBlobContainer container, string name, string path)
 {
     var blob = container.GetBlobReference(name);
     blob.Properties.ContentMD5 = GetMd5(path);
     semaphore.WaitOne();
     var stream = File.OpenRead(path);
     Interlocked.Increment(ref count);
     blob.BeginUploadFromStream(stream, (ar) => {
         blob.EndUploadFromStream(ar);
         stream.Close();
         semaphore.Release();
         Interlocked.Decrement(ref count);
     }, null);
 }
開發者ID:smarx,項目名稱:SyncToContainer,代碼行數:14,代碼來源:Program.cs

示例8: CopyFromBlobToLocal

 private void CopyFromBlobToLocal(CloudBlobContainer blobContainer, LocalResource localStorage, string blobName)
 {
     CloudBlob node = blobContainer.GetBlobReference(blobName);
     using (BlobStream nodestream = node.OpenRead()) {
         var nodefile = Path.Combine(localStorage.RootPath, blobName);
         if (!System.IO.File.Exists(nodefile)) {
             using (var fileStream = new FileStream(nodefile, FileMode.CreateNew)) {
                 nodestream.CopyTo(fileStream);
                 fileStream.Flush();
                 fileStream.Close();
             }
         }
     }
 }
開發者ID:vquaiato,項目名稱:nodeonazure,代碼行數:14,代碼來源:WorkerRole.cs

示例9: Mutex

        // The mutex must already exists
        public Mutex(CloudBlobContainer container, string mutexName, Exception e)
        {
            blob = container.GetBlobReference(mutexName);

            byte[] b1 = { 1 };
            BlobRequestOptions requestOpt = new BlobRequestOptions();
            bool keepGoing = true;
            string oldEtag = "";
            int lastChange = 0;
            do
            {
                byte[] b;
                string eTag;
                try
                {
                    blob.FetchAttributes();
                    eTag = blob.Attributes.Properties.ETag;
                    if (eTag != oldEtag)
                    {
                        lastChange = Environment.TickCount;
                        oldEtag = eTag;
                    }
                    b = blob.DownloadByteArray();
                }
                catch (Exception)
                {
                    throw e;
                }

                requestOpt.AccessCondition = AccessCondition.IfMatch(eTag);
                if (b[0] == 0 || Environment.TickCount - lastChange > 3000) // on ne peut garder un lock plus de 3 s
                {
                    try
                    {
                        blob.UploadByteArray(b1, requestOpt);
                        keepGoing = false;
                    }
                    catch (StorageClientException ex)
                    {
                        if (ex.ErrorCode != StorageErrorCode.ConditionFailed)
                            throw;
                    }
                }
                else
                    Thread.Sleep(50);   // constante arbitraire
            } while (keepGoing);
        }
開發者ID:ismaelbelghiti,項目名稱:Tigwi,代碼行數:48,代碼來源:Mutex.cs

示例10: ReadFromAzureBlob

        /// <summary>
        /// Read a data table from azure blob. This will read the entire blob into memory and return a mutable data table.
        /// </summary>
        /// <param name="builder">builder</param>
        /// <param name="container">conatiner</param>
        /// <param name="blobName">blob name</param>
        /// <returns>in-memory mutable datatable from blob</returns>
        public static MutableDataTable ReadFromAzureBlob(this DataTableBuilder builder, CloudBlobContainer container, string blobName)
        {
            CloudBlob blob = container.GetBlobReference(blobName);
            if (!Exists(blob))
            {
                string containerName = container.Name;
                string accountName = container.ServiceClient.Credentials.AccountName;
                throw new FileNotFoundException(string.Format("container.blob {0}.{0} does not exist on the storage account '{2}'", containerName, blobName, accountName));
            }

            // We're returning a MutableDataTable (which is in-memory) anyways, so fine to download into an in-memory buffer.
            // Avoid downloading to a file because Azure nodes may not have a local file resource.
            string content = blob.DownloadText();

            var stream = new StringReader(content);
            return DataTable.New.Read(stream);
        }
開發者ID:munissor,項目名稱:DataTable,代碼行數:24,代碼來源:AzureExtensions.cs

示例11: SetUp

 public void SetUp()
 {
     blobSettings = new LeaseBlockBlobSettings
     {
         ConnectionString = "UseDevelopmentStorage=true",
         ContainerName = "test" + Guid.NewGuid().ToString("N"),
         BlobPath = "lease.blob",
         ReAquirePreviousTestLease = false,
         RetryCount = 2,
         RetryInterval = TimeSpan.FromMilliseconds(250)
     };
     maximumStopDurationEstimateSeconds = 10;
     var storageAccount = CloudStorageAccount.Parse("UseDevelopmentStorage=true");
     var client = storageAccount.CreateCloudBlobClient();
     container = client.GetContainerReference(blobSettings.ContainerName);
     container.CreateIfNotExist();
     leaseBlob = container.GetBlobReference(blobSettings.BlobPath);
     leaseBlob.UploadByteArray(new byte[0]);
 }
開發者ID:amido,項目名稱:Amido.Testing,代碼行數:19,代碼來源:BlobLeasingTests.cs

示例12: DownloadText

 public string DownloadText(CloudBlobContainer cloudBlobContainer, string blobName)
 {
     return cloudBlobContainer.GetBlobReference(blobName).DownloadText();
 }
開發者ID:rgardler,項目名稱:dpp,代碼行數:4,代碼來源:BlobStorageWrapper.cs

示例13: DownloadByteArray

 public byte[] DownloadByteArray(CloudBlobContainer cloudBlobContainer, string blobName)
 {
     return cloudBlobContainer.GetBlobReference(blobName).DownloadByteArray();
 }
開發者ID:rgardler,項目名稱:dpp,代碼行數:4,代碼來源:BlobStorageWrapper.cs

示例14: DeleteIfExists

 public bool DeleteIfExists(CloudBlobContainer cloudBlobContainer, string blobName)
 {
     return cloudBlobContainer.GetBlobReference(blobName).DeleteIfExists();
 }
開發者ID:rgardler,項目名稱:dpp,代碼行數:4,代碼來源:BlobStorageWrapper.cs

示例15: Rename

 public bool Rename(CloudBlobContainer cloudBlobContainer, string oldBlobName, string newBlobName)
 {
     var oldCloudBlob = cloudBlobContainer.GetBlobReference(oldBlobName);
     cloudBlobContainer.GetBlobReference(newBlobName).CopyFromBlob(oldCloudBlob);
     return oldCloudBlob.DeleteIfExists();
 }
開發者ID:rgardler,項目名稱:dpp,代碼行數:6,代碼來源:BlobStorageWrapper.cs


注:本文中的Microsoft.WindowsAzure.StorageClient.CloudBlobContainer.GetBlobReference方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。