private static string AcquireLease(Microsoft.WindowsAzure.StorageClient.CloudBlockBlob blob, NLog.Logger logger) { try { var creds = blob.ServiceClient.Credentials; var transformedUri = new Uri(creds.TransformUri(blob.Uri.ToString())); var req = BlobRequest.Lease(transformedUri, AzureBlobLeaseTimeout, // timeout (in seconds) Microsoft.WindowsAzure.StorageClient.Protocol.LeaseAction.Acquire, // as opposed to "break" "release" or "renew" null); // name of the existing lease, if any blob.ServiceClient.Credentials.SignRequest(req); using (var response = req.GetResponse()) { return(response.Headers["x-ms-lease-id"]); } } catch (WebException e) { if (null != logger) { logger.ErrorException("AcquireLease, blob: " + blob, e); } return(null); } }
public static string AcquireLease(this CloudBlob blob, int leaseLengthSeconds) { var request = BlobRequest.Lease(new Uri(blob.ServiceClient.Credentials.TransformUri(blob.Uri.AbsoluteUri)), leaseLengthSeconds, LeaseAction.Acquire, null); blob.ServiceClient.Credentials.SignRequest(request); using (var response = request.GetResponse()) return(response.Headers["x-ms-lease-id"]); }
public void LeaseOperation(CloudBlob blob, string leaseId, LeaseAction action, int timeout) { var creds = blob.ServiceClient.Credentials; var transformedUri = new Uri(creds.TransformUri(blob.Uri.ToString())); var request = BlobRequest.Lease(transformedUri, timeout, action, leaseId); creds.SignRequest(request); request.GetResponse().Close(); }
private static void DoLeaseOperation(CloudBlob blob, string leaseId, LeaseAction action) { var creds = blob.ServiceClient.Credentials; var transformedUri = new Uri(creds.TransformUri(blob.Uri.ToString())); var req = BlobRequest.Lease(transformedUri, 60, action, leaseId); creds.SignRequest(req); req.GetResponse().Close(); }
private static void DoLeaseOperation(CloudBlob blob, string leaseId, LeaseAction action) { var credentials = blob.ServiceClient.Credentials; var request = BlobRequest.Lease(new Uri(credentials.TransformUri(blob.Uri.AbsoluteUri)), 90, action, leaseId); credentials.SignRequest(request); request.GetResponse().Close(); }
public static void ReleaseLease(this CloudBlob blob, string leaseId) { var creds = blob.ServiceClient.Credentials; var transformedUri = new Uri(creds.TransformUri(blob.Uri.ToString())); var req = BlobRequest.Lease(transformedUri, 0, LeaseAction.Release, leaseId); blob.ServiceClient.Credentials.SignRequest(req); using (var response = req.GetResponse()) { } }
public bool AcquireLock(PessimisticConcurrencyContext lockContext) { var request = BlobRequest.Lease(this.GetUri(lockContext.ObjectId), BlobRequestTimeout, LeaseAction.Acquire, null); this.Account.Credentials.SignRequest(request); // add extra headers not supported by SDK - not supported by emulator yet (SDK 1.7) ////request.Headers["x-ms-version"] = "2012-02-12"; ////request.Headers.Add("x-ms-lease-duration", lockContext.Duration.TotalSeconds.ToString()); try { using (var response = request.GetResponse()) { if (response is HttpWebResponse && HttpStatusCode.Created.Equals((response as HttpWebResponse).StatusCode)) { lockContext.LockId = response.Headers["x-ms-lease-id"]; return(true); } else { return(false); } } } catch (WebException e) { this._logger.LogWarning("Warning acquiring blob '{0}' lease: {1}", lockContext.ObjectId, e.Message); if (WebExceptionStatus.ProtocolError.Equals(e.Status)) { if (e.Response is HttpWebResponse) { if (HttpStatusCode.NotFound.Equals((e.Response as HttpWebResponse).StatusCode)) { lockContext.LockId = null; return(true); } else if (HttpStatusCode.Conflict.Equals((e.Response as HttpWebResponse).StatusCode)) { lockContext.LockId = null; return(false); } } throw; } return(false); } catch (Exception e) { this._logger.LogError("Error acquiring blob '{0}' lease: {1}", lockContext.ObjectId, e.Message); throw; } }
public static string AcquireLease(this CloudBlob blob) { var creds = blob.ServiceClient.Credentials; var transformedUri = new Uri(creds.TransformUri(blob.Uri.AbsoluteUri)); var req = BlobRequest.Lease(transformedUri, 90, LeaseAction.Acquire, null); blob.ServiceClient.Credentials.SignRequest(req); using (var response = req.GetResponse()) { return(response.Headers["x-ms-lease-id"]); } }
public string AcquireLease(CloudBlob blob, int timeout) { var creds = blob.ServiceClient.Credentials; var transformedUri = new Uri(creds.TransformUri(blob.Uri.ToString())); var request = BlobRequest.Lease(transformedUri, timeout, LeaseAction.Acquire, null); blob.ServiceClient.Credentials.SignRequest(request); using (var response = request.GetResponse()) { return(response.Headers["x-ms-lease-id"]); } }
public static string AcquireLease(this CloudBlob blob) { var creds = blob.ServiceClient.Credentials; var transformedUri = new Uri(creds.TransformUri(blob.Uri.ToString())); var req = BlobRequest.Lease(transformedUri, 60, // timeout (in seconds) LeaseAction.Acquire, // as opposed to "break" "release" or "renew" null); // name of the existing lease, if any blob.ServiceClient.Credentials.SignRequest(req); using (var response = req.GetResponse()) { return(response.Headers["x-ms-lease-id"]); } }
public static void DoLeaseOperation(VLogger logger, CloudBlob blob, string leaseId, LeaseAction action, int AzureBlobLeaseTimeout) { try { if (blob == null || leaseId == null) { return; } var creds = blob.ServiceClient.Credentials; var transformedUri = new Uri(creds.TransformUri(blob.Uri.ToString())); var req = BlobRequest.Lease(transformedUri, AzureBlobLeaseTimeout, action, leaseId); creds.SignRequest(req); req.GetResponse().Close(); } catch (WebException e) { Utils.structuredLog(logger, "WebException", e.Message + ". DoLeaseOperation, blob: " + blob.Name + ", leaseId: " + leaseId + ", action " + action); } }
static string AcquireLease(CloudBlob blob) { var creds = blob.ServiceClient.Credentials; var transformedUri = new Uri(creds.TransformUri(blob.Uri.AbsoluteUri)); var req = BlobRequest.Lease(transformedUri, 10, LeaseAction.Acquire, null); req.Headers.Add("x-ms-lease-duration", "60"); creds.SignRequest(req); HttpWebResponse response; try { response = (HttpWebResponse)req.GetResponse(); } catch (WebException we) { var statusCode = ((HttpWebResponse)we.Response).StatusCode; switch (statusCode) { case HttpStatusCode.Conflict: case HttpStatusCode.NotFound: case HttpStatusCode.RequestTimeout: case HttpStatusCode.InternalServerError: return(null); default: throw; } } try { return(response.StatusCode == HttpStatusCode.Created ? response.Headers["x-ms-lease-id"] : null); } finally { response.Close(); } }
public void ReleaseLock(PessimisticConcurrencyContext lockContext) { if (string.IsNullOrWhiteSpace(lockContext.LockId)) { throw new ArgumentNullException("lockContext.LockId", "LockId cannot be null or empty"); } var request = BlobRequest.Lease(this.GetUri(lockContext.ObjectId), BlobRequestTimeout, LeaseAction.Release, lockContext.LockId); this.Account.Credentials.SignRequest(request); using (var response = request.GetResponse()) { if (response is HttpWebResponse && !HttpStatusCode.OK.Equals((response as HttpWebResponse).StatusCode)) { this._logger.LogError("Error releasing blob '{0}' lease: {1}", lockContext.ObjectId, (response as HttpWebResponse).StatusDescription); throw new InvalidOperationException((response as HttpWebResponse).StatusDescription); } } }
static bool DoLeaseOperation(CloudBlob blob, string leaseId, LeaseAction action) { var creds = blob.ServiceClient.Credentials; var transformedUri = new Uri(creds.TransformUri(blob.Uri.ToString())); var req = BlobRequest.Lease(transformedUri, 10, action, leaseId); creds.SignRequest(req); HttpWebResponse response; try { response = (HttpWebResponse)req.GetResponse(); } catch (WebException we) { var statusCode = ((HttpWebResponse)we.Response).StatusCode; switch (statusCode) { case HttpStatusCode.Conflict: case HttpStatusCode.NotFound: case HttpStatusCode.RequestTimeout: case HttpStatusCode.InternalServerError: return(false); default: throw; } } try { var expectedCode = action == LeaseAction.Break ? HttpStatusCode.Accepted : HttpStatusCode.OK; return(response.StatusCode == expectedCode); } finally { response.Close(); } }
public static string AcquireLease(VLogger logger, CloudBlockBlob blob, int AzureBlobLeaseTimeout) { try { var creds = blob.ServiceClient.Credentials; var transformedUri = new Uri(creds.TransformUri(blob.Uri.ToString())); var req = BlobRequest.Lease(transformedUri, AzureBlobLeaseTimeout, // timeout (in seconds) LeaseAction.Acquire, // as opposed to "break" "release" or "renew" null); // name of the existing lease, if any blob.ServiceClient.Credentials.SignRequest(req); using (var response = req.GetResponse()) { return(response.Headers["x-ms-lease-id"]); } } catch (WebException e) { Utils.structuredLog(logger, "WebException", e.Message + ". AcquireLease, blob: " + blob); return(null); } }
private static void DoLeaseOperation(CloudBlob blob, string leaseId, Microsoft.WindowsAzure.StorageClient.Protocol.LeaseAction action, NLog.Logger logger) { try { if (blob == null || leaseId == null) { return; } var creds = blob.ServiceClient.Credentials; var transformedUri = new Uri(creds.TransformUri(blob.Uri.ToString())); var req = BlobRequest.Lease(transformedUri, AzureBlobLeaseTimeout, action, leaseId); creds.SignRequest(req); req.GetResponse().Close(); } catch (WebException e) { if (null != logger) { logger.ErrorException("DoLeaseOperation, blob: " + blob.Name + ", leaseId: " + leaseId + ", action " + action, e); } } }