コード例 #1
0
        private void DoDelete(Microsoft.WindowsAzure.Storage.Blob.DeleteSnapshotsOption deleteSnapshotsOption = DeleteSnapshotsOption.None, Microsoft.WindowsAzure.Storage.AccessCondition accessCondition = null, Microsoft.WindowsAzure.Storage.Blob.BlobRequestOptions options = null, Microsoft.WindowsAzure.Storage.OperationContext operationContext = null)
        {
            bool done = false;

            while (!done)
            {
                using (PrimaryCloudBlobLease lease = new PrimaryCloudBlobLease(this.Name, configuration, true))
                {
                    if (lease.HasLease)
                    {
                        Dictionary <ICloudBlob, IAsyncResult> results = new Dictionary <ICloudBlob, IAsyncResult>();
                        foreach (string serverName in configuration.PrimaryServers)
                        {
                            watch.Start();
                            ICloudBlob blob = ClientRegistry.GetCloudBlob(serverName, configuration.Name, Name);
                            results[blob] = blob.BeginDelete(deleteSnapshotsOption, lease.getAccessConditionWithLeaseId(accessCondition), options, operationContext, null, null);
                            ServerState ss = slaEngine.Monitor.GetServerState(serverName);
                            ss.AddRtt(watch.ElapsedMilliseconds);
                            slaEngine.Session.RecordObjectWritten(Name, Timestamp(blob), ss);
                        }

                        foreach (ICloudBlob blob in results.Keys)
                        {
                            blob.EndDelete(results[blob]);
                        }
                        done = true;
                    }
                }
            }
        }
コード例 #2
0
        public async Task <bool> DeleteBlobAsync(string containerName, string blobName)
        {
            try
            {
                CloudBlobContainer container = _blobClient.GetContainerReference(containerName);
                ICloudBlob         blob      = container.GetBlobReferenceFromServer(blobName);
                var futureRes = blob.BeginDelete(null, null);
                var retVal    =
                    await Task.Factory.FromAsync(futureRes, res =>
                {
                    try
                    {
                        blob.EndDelete(res);
                        return(true);
                    }
                    catch (StorageException ex)
                    {
                        if (ex.RequestInformation.HttpStatusCode == 404)
                        {
                            return(false);
                        }
                        throw;
                    }
                });

                return(retVal);
            }
            catch (StorageException ex)
            {
                if (ex.RequestInformation.HttpStatusCode == 404)
                {
                    return(false);
                }

                throw;
            }
        }