internal static TableResult TableOperationPreProcess <T>(TableResult result, TableOperation operation, HttpResponseMessage resp, Exception ex, StorageCommandBase <T> cmd, OperationContext ctx) { result.HttpStatusCode = (int)resp.StatusCode; if (operation.OperationType == TableOperationType.Retrieve) { if (resp.StatusCode != HttpStatusCode.OK && resp.StatusCode != HttpStatusCode.NotFound) { throw new StorageException(cmd.CurrentResult, string.Format(SR.UnexpectedResponseCode, HttpStatusCode.OK.ToString() + " or " + HttpStatusCode.NotFound.ToString(), resp.StatusCode.ToString()), null); } } else { if (ex != null) { throw ex; } else if (operation.OperationType == TableOperationType.Insert) { if (operation.EchoContent) { if (resp.StatusCode != HttpStatusCode.Created) { throw ex; } } else { if (resp.StatusCode != HttpStatusCode.NoContent) { throw ex; } } } else { if (resp.StatusCode != HttpStatusCode.NoContent) { throw ex; } } } if (resp.Headers.ETag != null) { result.Etag = resp.Headers.ETag.ToString(); if (operation.Entity != null) { operation.Entity.ETag = result.Etag; } } return(result); }
internal static T ProcessExpectedStatusCodeNoException <T>(HttpStatusCode[] expectedStatusCodes, HttpStatusCode actualStatusCode, T retVal, StorageCommandBase <T> cmd, Exception ex) { if (ex != null) { throw ex; } bool foundExpectedStatusCode = false; StringBuilder expectedStatusCodeString = null; foreach (HttpStatusCode expectedStatusCode in expectedStatusCodes) { if (actualStatusCode == expectedStatusCode) { foundExpectedStatusCode = true; break; } expectedStatusCodeString.Append(expectedStatusCode); expectedStatusCodeString.Append(","); } if (!foundExpectedStatusCode) { throw new StorageException(cmd.CurrentResult, string.Format(CultureInfo.InvariantCulture, SR.UnexpectedResponseCode, expectedStatusCodeString.ToString().TrimEnd(','), actualStatusCode.ToString()), null); } return(retVal); }
internal static void ValidateResponseStreamMd5AndLength <T>(long?length, string md5, StorageCommandBase <T> cmd) { if (cmd.StreamCopyState == null) { throw new StorageException( cmd.CurrentResult, SR.ContentMD5NotCalculated, null) { IsRetryable = false }; } if (length.HasValue && (cmd.StreamCopyState.Length != length.Value)) { throw new StorageException( cmd.CurrentResult, string.Format(CultureInfo.InvariantCulture, SR.IncorrectNumberOfBytes, length, cmd.StreamCopyState.Length), null) { IsRetryable = false }; } if ((md5 != null) && (cmd.StreamCopyState.Md5 != null) && (cmd.StreamCopyState.Md5 != md5)) { throw new StorageException( cmd.CurrentResult, SR.MD5MismatchError, null) { IsRetryable = false }; } }
internal static T ProcessExpectedStatusCodeNoException <T>(HttpStatusCode[] expectedStatusCodes, HttpResponseMessage resp, T retVal, StorageCommandBase <T> cmd, Exception ex) { return(ProcessExpectedStatusCodeNoException(expectedStatusCodes, resp != null ? resp.StatusCode : HttpStatusCode.Unused, retVal, cmd, ex)); }
internal static T ProcessExpectedStatusCodeNoException <T>(HttpStatusCode expectedStatusCode, HttpStatusCode actualStatusCode, T retVal, StorageCommandBase <T> cmd, Exception ex) { if (ex != null) { throw ex; } if (actualStatusCode != expectedStatusCode) { throw new StorageException(cmd.CurrentResult, string.Format(CultureInfo.InvariantCulture, SR.UnexpectedResponseCode, expectedStatusCode, actualStatusCode), null); } return(retVal); }
internal static T ProcessExpectedStatusCodeNoException <T>(HttpStatusCode[] expectedStatusCodes, HttpStatusCode actualStatusCode, T retVal, StorageCommandBase <T> cmd, Exception ex) { if (ex != null) { throw ex; } if (!expectedStatusCodes.Contains(actualStatusCode)) { string expectedStatusCodeString = string.Join(",", expectedStatusCodes); throw new StorageException(cmd.CurrentResult, string.Format(CultureInfo.InvariantCulture, SR.UnexpectedResponseCode, expectedStatusCodeString, actualStatusCode.ToString()), null); } return(retVal); }
private void ApplyToStorageCommandCommon <T>(StorageCommandBase <T> cmd) { throw new System.NotImplementedException(); }
internal static void ValidateResponseStreamMd5AndLength <T>(long?length, string md5, StorageCommandBase <T> cmd) { throw new System.NotImplementedException(); }
internal static T ProcessExpectedStatusCodeNoException <T>(HttpStatusCode[] expectedStatusCodes, HttpStatusCode actualStatusCode, T retVal, StorageCommandBase <T> cmd, Exception ex) { throw new System.NotImplementedException(); }
internal static TableResult TableOperationPreProcess <T>(TableResult result, TableOperation operation, HttpWebResponse resp, Exception ex, StorageCommandBase <T> cmd, OperationContext ctx) { result.HttpStatusCode = (int)resp.StatusCode; if (operation.OperationType == TableOperationType.Retrieve) { if (resp.StatusCode != HttpStatusCode.OK && resp.StatusCode != HttpStatusCode.NotFound) { throw StorageException.TranslateException(ex, cmd.CurrentResult); } } else { if (ex != null) { throw StorageException.TranslateException(ex, cmd.CurrentResult); } else if (operation.OperationType == TableOperationType.Insert) { if (resp.StatusCode != HttpStatusCode.Created) { throw StorageException.TranslateException(ex, cmd.CurrentResult); } } else { if (resp.StatusCode != HttpStatusCode.NoContent) { throw StorageException.TranslateException(ex, cmd.CurrentResult); } } } string etag = HttpResponseParsers.GetETag(resp); if (etag != null) { result.Etag = etag; if (operation.Entity != null) { operation.Entity.ETag = result.Etag; } } return(result); }
public static HttpContent BuildContentFromStream <T>(Stream stream, long offset, long?length, string md5, StorageCommandBase <T> cmd, OperationContext operationContext) { stream.Seek(offset, SeekOrigin.Begin); HttpContent retContent = new RetryableStreamContent(stream); retContent.Headers.ContentLength = length; if (md5 != null) { retContent.Headers.ContentMD5 = Convert.FromBase64String(md5); } return(retContent); }
internal static T ProcessExpectedStatusCodeNoException <T>(HttpStatusCode expectedStatusCode, HttpWebResponse resp, T retVal, StorageCommandBase <T> cmd, Exception ex, OperationContext operationContext) { return(ProcessExpectedStatusCodeNoException(expectedStatusCode, resp != null ? resp.StatusCode : HttpStatusCode.Unused, retVal, cmd, ex, operationContext)); }