Skip to content

Updated sample so that it has status of upload and download #254

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 58 additions & 5 deletions samples/DataMovementSamples/DataMovementSamples/Samples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,30 @@ private static async Task BlobUploadSample()
UploadOptions options = new UploadOptions();

SingleTransferContext context = new SingleTransferContext();
int transferSuccess = 0;
context.SetAttributesCallbackAsync = async (source, destination) =>
{
CloudBlob destBlob = destination as CloudBlob;
destBlob.Properties.ContentType = "image/png";
};

context.ShouldOverwriteCallbackAsync = TransferContext.ForceOverwrite;
context.FileTransferred += (object sender, TransferEventArgs args) =>
{
Interlocked.Increment(ref transferSuccess);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to set a bool here instead of incrementing an int. But Interlocked just wouldn't let me do it through Interlocked.Exchange

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

};

// Start the upload
await TransferManager.UploadAsync(sourceFileName, destinationBlob, options, context);
Console.WriteLine("File {0} is uploaded to {1} successfully.", sourceFileName, destinationBlob.Uri.ToString());

// Check for successful upload
if(transferSuccess > 0)
{
Console.WriteLine("File {0} is uploaded to {1} successfully.", sourceFileName, destinationBlob.Uri.ToString());
}
else
{
Console.WriteLine("File {0} has failed to be uploaded (File has failed or has been skipped).", sourceFileName);
}
}

/// <summary>
Expand All @@ -121,10 +134,31 @@ private static async Task FileUploadSample()

// Create the destination CloudFile instance
CloudFile destinationFile = await Util.GetCloudFileAsync(ShareName, destinationFileName);
SingleTransferContext context = new SingleTransferContext();
int transferSuccess = 0;
context.SetAttributesCallbackAsync = async (source, destination) =>
{
CloudFile destFile = destination as CloudFile;
destFile.Properties.ContentType = "image/png";
};
context.ShouldOverwriteCallbackAsync = TransferContext.ForceOverwrite;
context.FileTransferred += (object sender, TransferEventArgs args) =>
{
Interlocked.Increment(ref transferSuccess);
};

// Start the upload
await TransferManager.UploadAsync(sourceFileName, destinationFile);
Console.WriteLine("File {0} is uploaded to {1} successfully.", sourceFileName, destinationFile.Uri.ToString());
await TransferManager.UploadAsync(sourceFileName, destinationFile, null /* options */, context);

// Check for successful upload
if (transferSuccess > 0)
{
Console.WriteLine("File {0} is uploaded to {1} successfully.", sourceFileName, destinationFile.Uri.ToString());
}
else
{
Console.WriteLine("File {0} has failed to be uploaded (File has failed or has been skipped).", sourceFileName);
}
}

/// <summary>
Expand All @@ -150,6 +184,17 @@ private static async Task BlobCopySample()

TransferCheckpoint checkpoint = null;
SingleTransferContext context = new SingleTransferContext();
int transferSuccess = 0;
context.SetAttributesCallbackAsync = async (source, destination) =>
{
CloudFile destBlob = destination as CloudFile;
destBlob.Properties.ContentType = "image/png";
};
context.ShouldOverwriteCallbackAsync = TransferContext.ForceOverwrite;
context.FileTransferred += (object sender, TransferEventArgs args) =>
{
Interlocked.Increment(ref transferSuccess);
};

// Start the transfer
try
Expand Down Expand Up @@ -187,7 +232,15 @@ private static async Task BlobCopySample()
// Resume transfer from the stored checkpoint
Console.WriteLine("Resume the cancelled transfer.");
await TransferManager.CopyAsync(sourceBlob, destinationBlob, CopyMethod.ServiceSideSyncCopy, null /* options */, resumeContext);
Console.WriteLine("CloudBlob {0} is copied to {1} successfully.", sourceBlob.Uri.ToString(), destinationBlob.Uri.ToString());
// Check for successful upload
if (transferSuccess > 0)
{
Console.WriteLine("CloudBlob {0} is copied to {1} successfully.", sourceBlob.Uri.ToString(), destinationBlob.Uri.ToString());
}
else
{
Console.WriteLine("CloudBlob {0} has failed to be copied to {1} (Blob has failed or has been skipped).", sourceBlob.Uri.ToString(), destinationBlob.Uri.ToString());
}
}

/// <summary>
Expand Down