当前位置: 首页>>代码示例>>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;未经允许,请勿转载。