当前位置: 首页>>代码示例>>C#>>正文


C# CloudBlob.FetchAttributes方法代码示例

本文整理汇总了C#中Microsoft.WindowsAzure.StorageClient.CloudBlob.FetchAttributes方法的典型用法代码示例。如果您正苦于以下问题:C# CloudBlob.FetchAttributes方法的具体用法?C# CloudBlob.FetchAttributes怎么用?C# CloudBlob.FetchAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.WindowsAzure.StorageClient.CloudBlob的用法示例。


在下文中一共展示了CloudBlob.FetchAttributes方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DoEvery

 public static void DoEvery(CloudBlob blob, TimeSpan interval, Action action)
 {
     while (true)
     {
         var lastPerformed = DateTimeOffset.MinValue;
         using (var arl = new AutoRenewLease(blob))
         {
             if (arl.HasLease)
             {
                 blob.FetchAttributes();
                 DateTimeOffset.TryParseExact(blob.Metadata["lastPerformed"], "R", CultureInfo.CurrentCulture, DateTimeStyles.AdjustToUniversal, out lastPerformed);
                 if (DateTimeOffset.UtcNow >= lastPerformed + interval)
                 {
                     action();
                     lastPerformed = DateTimeOffset.UtcNow;
                     blob.Metadata["lastPerformed"] = lastPerformed.ToString("R");
                     blob.SetMetadata(arl.leaseId);
                 }
             }
         }
         var timeLeft = (lastPerformed + interval) - DateTimeOffset.UtcNow;
         var minimum = TimeSpan.FromSeconds(5); // so we're not polling the leased blob too fast
         Thread.Sleep(
             timeLeft > minimum
             ? timeLeft
             : minimum);
     }
 }
开发者ID:sushant2517,项目名称:WazStorageExtensions,代码行数:28,代码来源:AutoRenewLease.cs

示例2: BlobExists

        /// <summary>
        /// Check whether the specified blob exists
        /// </summary>
        /// <param name="blob">Blob to check</param>
        /// <returns>true if specified blob exists, and false if it doesn't</returns>
        private static bool BlobExists(CloudBlob blob)
        {
            try
            {
                // try fetching Attributes
                blob.FetchAttributes();
                return true;
            }
            catch (StorageClientException e)
            {
                if (e.ErrorCode == StorageErrorCode.ResourceNotFound)
                {
                    // if failed with ResourceNotFound error code, then the blob doesn't exist
                    return false;
                }
                else
                {
                    // something else went wrong
                    //throw;
                    Console.Write(e);
                    return false;

                }
            }
            catch (Exception e)
            {
                Console.Write(e);
                return false;
            }
        }
开发者ID:fashaikh,项目名称:ChronoZoom,代码行数:35,代码来源:Common.cs

示例3: Read

        public static void Read(BlobRequestOptions mapped, CloudBlob blob, ReaderDelegate reader)
        {
            blob.FetchAttributes(mapped);
            var props = MapFetchedAttrbitues(blob);

            var compression = blob.Properties.ContentEncoding ?? "";
            var md5 = blob.Metadata[LokadHashFieldName];

            switch (compression)
            {
                case "gzip":
                    using (var stream = blob.OpenRead(mapped))
                    {
                        ReadAndVerifyHash(stream, s =>
                            {
                                // important is not to flush the decompression stream
                                using (var decompress = new GZipStream(s, CompressionMode.Decompress, true))
                                {
                                    reader(props, decompress);
                                }
                            }, md5);
                    }

                    break;
                case "":
                    using (var stream = blob.OpenRead(mapped))
                    {
                        ReadAndVerifyHash(stream, s => reader(props, s), md5);
                    }
                    break;
                default:
                    var error = string.Format("Unsupported ContentEncoding '{0}'", compression);
                    throw new InvalidOperationException(error);
            }
        }
开发者ID:higheredgrowth,项目名称:lokad-cqrs,代码行数:35,代码来源:BlobStorageUtil.cs

示例4: CopyContents

        /// <summary>
        /// Copies the full binary contents of the given blob to the given HTTP response.
        /// </summary>
        private static void CopyContents(CloudBlob blob, HttpResponseBase response, long offset = 0)
        {
            blob.FetchAttributes();

            response.BufferOutput = false;
            response.AddHeader("Content-Length", blob.Attributes.Properties.Length.ToString());
            response.Flush();

            using (var reader = blob.OpenRead())
            {
                reader.Seek(offset, System.IO.SeekOrigin.Begin);

                byte[] buffer = new byte[1024 * 4]; // 4KB buffer
                while (reader.CanRead)
                {
                    int numBytes = reader.Read(buffer, 0, buffer.Length);

                    if (numBytes <= 0)
                        break;

                    response.BinaryWrite(buffer);
                    response.Flush();
                }
            }
        }
开发者ID:robertogg,项目名称:Demos,代码行数:28,代码来源:LogFetcher.cs

示例5: 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

示例6: Exists

 public bool Exists(CloudBlob blob)
 {
     try
     {
         blob.FetchAttributes();
         return true;
     }
     catch (StorageClientException e)
     {
         if (e.ErrorCode == StorageErrorCode.ResourceNotFound)
         {
             return false;
         }
         else
         {
             throw;
         }
     }
 }
开发者ID:kpantos,项目名称:WebCapturer,代码行数:19,代码来源:WorkerRole.cs

示例7: DownloadBlobInParallel

 private void DownloadBlobInParallel(CloudBlob blob, Stream stream)
 {
     try
     {
         blob.FetchAttributes();
         var order = new List<string>();
         var blocksToDownload = new Queue<Block>();
         CalculateBlocks(blocksToDownload, (int)blob.Properties.Length, order);
         ExecuteInParallel(() => AsLongAsThereAre(blocksToDownload, block =>
         {
             var s = DownloadBlockFromBlob(blob, block, blocksToDownload); if (s == null) return;
             var buffer = new byte[BlockSize];
             ExtractBytesFromBlockIntoBuffer(buffer, s, block);
             lock (stream)
             {
                 stream.Position = block.Offset;
                 stream.Write(buffer, 0,block.Length);
             }
         }));
         stream.Seek(0, SeekOrigin.Begin);
     }
     catch (StorageClientException ex) // to handle race conditions between multiple active instances.
     {
         logger.Warn(ex.Message);
     }
     catch (StorageServerException ex) // prevent azure hickups from hurting us.
     {
         logger.Warn(ex.Message);
     }
 }
开发者ID:ChristianLennartsson,项目名称:NServiceBus,代码行数:30,代码来源:BlobStorageDataBus.cs

示例8: DownloadBlobInParallel

 private void DownloadBlobInParallel(CloudBlob blob, Stream stream)
 {
     blob.FetchAttributes();
     var order = new List<string>();
     var blocksToDownload = new Queue<Block>();
     CalculateBlocks(blocksToDownload, (int)blob.Properties.Length, order);
     ExecuteInParallel(() => AsLongAsThereAre(blocksToDownload, block =>
     {
         var s = DownloadBlockFromBlob(blob, block, blocksToDownload); if (s == null) return;
         var buffer = new byte[BlockSize];
         ExtractBytesFromBlockIntoBuffer(buffer, s, block);
         lock (stream)
         {
             stream.Position = block.Offset;
             stream.Write(buffer, 0,block.Length);
         }
     }));
     stream.Seek(0, SeekOrigin.Begin);
 }
开发者ID:robbentley46,项目名称:NServiceBus,代码行数:19,代码来源:BlobStorageDataBus.cs

示例9: FetchMetadataIfMissing

 private static void FetchMetadataIfMissing(CloudBlob blob)
 {
     if(blob.Metadata.Count == 0)
     {
         try
         {
             blob.FetchAttributes();
         } catch(StorageClientException stEx)
         {
             if (stEx.ErrorCode == StorageErrorCode.BlobNotFound || stEx.ErrorCode == StorageErrorCode.ResourceNotFound)
                 return;
             throw;
         }
     }
 }
开发者ID:rodmjay,项目名称:TheBallOnAzure,代码行数:15,代码来源:StorageSupport.cs

示例10: Exists

 static bool Exists(CloudBlob blob)
 {
     try
     {
         blob.FetchAttributes();
         return true;
     }
     catch (StorageClientException e)
     {
         switch (e.ErrorCode)
         {
             case StorageErrorCode.ContainerNotFound:
             case StorageErrorCode.ResourceNotFound:
                 return false;
         }
         throw;
     }
 }
开发者ID:Lokad,项目名称:lokad-data-platform,代码行数:18,代码来源:AzureEventStore.cs

示例11: HandlePublicBlobRequestWithCacheSupport

 private static void HandlePublicBlobRequestWithCacheSupport(HttpContext context, CloudBlob blob, HttpResponse response)
 {
     // Set the cache request properties as IIS will include them regardless for now
     // even when we wouldn't want them on 304 response...
     response.Cache.SetMaxAge(TimeSpan.FromMinutes(0));
     response.Cache.SetCacheability(HttpCacheability.Private);
     var request = context.Request;
     blob.FetchAttributes();
     string ifNoneMatch = request.Headers["If-None-Match"];
     string ifModifiedSince = request.Headers["If-Modified-Since"];
     if (ifNoneMatch != null)
     {
         if (ifNoneMatch == blob.Properties.ETag)
         {
             response.ClearContent();
             response.StatusCode = 304;
             return;
         }
     }
     else if (ifModifiedSince != null)
     {
         DateTime ifModifiedSinceValue;
         if (DateTime.TryParse(ifModifiedSince, out ifModifiedSinceValue))
         {
             ifModifiedSinceValue = ifModifiedSinceValue.ToUniversalTime();
             if (blob.Properties.LastModifiedUtc <= ifModifiedSinceValue)
             {
                 response.ClearContent();
                 response.StatusCode = 304;
                 return;
             }
         }
     }
     var fileName = blob.Name.Contains("/MediaContent/") ?
         request.Path : blob.Name;
     response.ContentType = StorageSupport.GetMimeType(fileName);
     //response.Cache.SetETag(blob.Properties.ETag);
     response.Headers.Add("ETag", blob.Properties.ETag);
     response.Cache.SetLastModified(blob.Properties.LastModifiedUtc);
     blob.DownloadToStream(response.OutputStream);
 }
开发者ID:kallex,项目名称:Caloom,代码行数:41,代码来源:AnonymousBlobStorageHandler.cs

示例12: BreakTestLeaseIfExists

 private static void BreakTestLeaseIfExists(CloudBlob blob)
 {
     blob.FetchAttributes();
     if (blob.Metadata.AllKeys.Contains(leasedForTestTag))
         BreakLease(blob);
 }
开发者ID:amido,项目名称:Amido.Testing,代码行数:6,代码来源:BlobStorage.cs

示例13: ListBlobs

        public static List<CloudBlob> ListBlobs()
        {
            List<IListBlobItem> blobItemList = null;

            List<CloudBlob> blobList = null;

            try
            {
                string storageAccountConnection = string.Empty;

                storageAccountConnection = ConfigurationManager.AppSettings["StorageAccount.ConnectionString"].ToString();

                Logger.Write("Storage Connection: " + storageAccountConnection);

                // If you want to use Windows Azure cloud storage account, use the following
                // code (after uncommenting) instead of the code above.
                cloudStorageAccount = CloudStorageAccount.Parse(storageAccountConnection);

                Logger.Write("Blob Uri: " + cloudStorageAccount.BlobEndpoint.AbsoluteUri);

                // Create the blob client, which provides
                // authenticated access to the Blob service.
                blobClient = cloudStorageAccount.CreateCloudBlobClient();

                string deploymentPackageFolderString = string.Empty;

                deploymentPackageFolderString = ConfigurationManager.AppSettings["DeploymentPackageFolder"].ToString();

                Logger.Write("Deployment Package Folder: " + deploymentPackageFolderString);

                // Get the container reference.
                blobContainer = blobClient.GetContainerReference(deploymentPackageFolderString);

                // Create the container if it does not exist.
                blobContainer.CreateIfNotExist();

                // Set permissions on the container.
                containerPermissions = new BlobContainerPermissions();

                // This sample sets the container to have public blobs. Your application
                // needs may be different. See the documentation for BlobContainerPermissions
                // for more information about blob container permissions.
                containerPermissions.PublicAccess = BlobContainerPublicAccessType.Blob;

                blobContainer.SetPermissions(containerPermissions);

                BlobRequestOptions blobReqOptions = new BlobRequestOptions();

                blobReqOptions.BlobListingDetails = BlobListingDetails.All;
                blobReqOptions.Timeout = new TimeSpan(0, 5, 0);
                blobReqOptions.UseFlatBlobListing = true;

                blobItemList = blobContainer.ListBlobs(blobReqOptions).ToList();

                if (blobList == null)
                {
                    blobList = new List<CloudBlob>();
                }

                foreach (IListBlobItem blobItem in blobItemList)
                {
                    Logger.Write("Blob Uri: " + blobItem.Uri.ToString());

                    CloudBlob blobEntry = new CloudBlob(blobItem.Uri.ToString());

                    blobEntry.FetchAttributes();

                    blobList.Add(blobEntry);
                }
            }
            catch (System.Exception ex)
            {
                Logger.Write(string.Format("Error in List<IListBlobItem> ListBlobs()  Error: {0}", ex.Message));

                blobList = null;
            }

            return blobList;
        }
开发者ID:yonglehou,项目名称:Bermuda,代码行数:79,代码来源:AzureStorageUtility.cs


注:本文中的Microsoft.WindowsAzure.StorageClient.CloudBlob.FetchAttributes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。