/// <summary> /// Implementation of the StartCopyFromBlob method. Result is a BlobAttributes object derived from the response headers. /// </summary> /// <param name="blob">The blob.</param> /// <param name="attributes">The attributes.</param> /// <param name="source">The URI of the source blob.</param> /// <param name="sourceAccessCondition">An object that represents the access conditions for the source blob. If null, no condition is used.</param> /// <param name="destAccessCondition">An object that represents the access conditions for the destination blob. If null, no condition is used.</param> /// <param name="options">An object that specifies any additional options for the request.</param> /// <returns> /// A <see cref="RESTCommand{T}" /> that starts to copy the blob. /// </returns> /// <exception cref="System.ArgumentException">sourceAccessCondition</exception> internal static RESTCommand <string> StartCopyFromBlobImpl(ICloudBlob blob, BlobAttributes attributes, Uri source, AccessCondition sourceAccessCondition, AccessCondition destAccessCondition, BlobRequestOptions options) { if (sourceAccessCondition != null && !string.IsNullOrEmpty(sourceAccessCondition.LeaseId)) { throw new ArgumentException(SR.LeaseConditionOnSource, "sourceAccessCondition"); } RESTCommand <string> putCmd = new RESTCommand <string>(blob.ServiceClient.Credentials, attributes.Uri); putCmd.ApplyRequestOptions(options); putCmd.BuildRequestDelegate = (uri, builder, serverTimeout, ctx) => BlobHttpWebRequestFactory.CopyFrom(uri, serverTimeout, source, sourceAccessCondition, destAccessCondition, ctx); putCmd.SetHeaders = (r, ctx) => BlobHttpWebRequestFactory.AddMetadata(r, attributes.Metadata); putCmd.SignRequest = blob.ServiceClient.AuthenticationHandler.SignRequest; putCmd.PreProcessResponse = (cmd, resp, ex, ctx) => { HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.Accepted, resp, null /* retVal */, cmd, ex, ctx); CopyState state = BlobHttpResponseParsers.GetCopyAttributes(resp); attributes.Properties = BlobHttpResponseParsers.GetProperties(resp); attributes.Metadata = BlobHttpResponseParsers.GetMetadata(resp); attributes.CopyState = state; return(state.CopyId); }; return(putCmd); }
public static void AssertAreEqual(CopyState expected, CopyState actual) { if (expected == null) { Assert.IsNull(actual); } else { Assert.IsNotNull(actual); Assert.AreEqual(expected.BytesCopied, actual.BytesCopied); Assert.AreEqual(expected.CompletionTime, actual.CompletionTime); Assert.AreEqual(expected.CopyId, actual.CopyId); Assert.AreEqual(expected.Source, actual.Source); Assert.AreEqual(expected.Status, actual.Status); Assert.AreEqual(expected.TotalBytes, actual.TotalBytes); } }
public static void AssertAreEqual(CopyState copy1, CopyState copy2) { if (copy1 == null) { Assert.IsNull(copy2); } else { Assert.IsNotNull(copy2); Assert.AreEqual(copy1.BytesCopied, copy2.BytesCopied); Assert.AreEqual(copy1.CompletionTime, copy2.CompletionTime); Assert.AreEqual(copy1.CopyId, copy2.CopyId); Assert.AreEqual(copy1.Source, copy2.Source); Assert.AreEqual(copy1.Status, copy2.Status); Assert.AreEqual(copy1.TotalBytes, copy2.TotalBytes); } }
private String CopyStateText(CopyState state) { if (state == null) { return String.Empty; } else { switch(state.Status) { case CopyStatus.Pending: return "Pending"; case CopyStatus.Success: return "Success"; case CopyStatus.Aborted: return "Aborted"; case CopyStatus.Failed: return "Failed"; case CopyStatus.Invalid: return "Invalid"; default: return "Other"; } } }
public HostedAzureCopyState(CopyState copyState) { _copyState = copyState; }
private void UpdateTransferProgress(CopyState copyState) { if (null != copyState && copyState.TotalBytes.HasValue) { Debug.Assert( copyState.BytesCopied.HasValue, "BytesCopied cannot be null as TotalBytes is not null."); if (this.approachingFinish == false && copyState.TotalBytes - copyState.BytesCopied <= Constants.CopyApproachingFinishThresholdInBytes) { this.approachingFinish = true; } if (this.TransferContext != null) { long bytesTransferred = copyState.BytesCopied.Value; this.UpdateProgressAddBytesTransferred(bytesTransferred - this.lastBytesCopied); this.lastBytesCopied = bytesTransferred; } } }
private void HandleFetchCopyStateResult(CopyState copyState) { if (null == copyState) { // Reach here, the destination should already exist. string exceptionMessage = string.Format( CultureInfo.CurrentCulture, Resources.FailedToRetrieveCopyStateForObjectException, this.DestUri.ToString()); throw new TransferException( TransferErrorCode.FailToRetrieveCopyStateForObject, exceptionMessage); } else { // Verify we are monitoring the right blob copying process. if (!this.TransferJob.CopyId.Equals(copyState.CopyId)) { throw new TransferException( TransferErrorCode.MismatchCopyId, Resources.MismatchFoundBetweenLocalAndServerCopyIdsException); } if (CopyStatus.Success == copyState.Status) { this.UpdateTransferProgress(copyState); this.DisposeStatusRefreshTimer(); this.SetFinished(); } else if (CopyStatus.Pending == copyState.Status) { this.UpdateTransferProgress(copyState); // Wait a period to restart refresh the status. this.RestartTimer(); } else { string exceptionMessage = string.Format( CultureInfo.CurrentCulture, Resources.FailedToAsyncCopyObjectException, this.GetSourceUri().ToString(), this.DestUri.ToString(), copyState.Status.ToString(), copyState.StatusDescription); // CopyStatus.Invalid | Failed | Aborted throw new TransferException( TransferErrorCode.AsyncCopyFailed, exceptionMessage); } } }