/// <summary> /// Returns a <see cref="System.Threading.Tasks.Task<IAsset>"/> instance for a new <see cref="IAsset"/> with the file in <paramref name="filePath"/>. /// </summary> /// <param name="assets">The <see cref="AssetBaseCollection"/> instance.</param> /// <param name="filePath">The path to the file to upload to the new <see cref="IAsset"/>.</param> /// <param name="storageAccountName">The name of the storage account where to store the new <see cref="IAsset"/>.</param> /// <param name="options">The <see cref="AssetCreationOptions"/>.</param> /// <param name="uploadProgressChangedCallback">A callback to report the upload progress of the file.</param> /// <param name="cancellationToken">The <see cref="System.Threading.CancellationToken"/> instance used for cancellation.</param> /// <returns>A <see cref="System.Threading.Tasks.Task<IAsset>"/> instance for a new <see cref="IAsset"/> with the file in <paramref name="filePath"/>.</returns> public static async Task <IAsset> CreateFromFileAsync(this AssetBaseCollection assets, string filePath, string storageAccountName, AssetCreationOptions options, Action <IAssetFile, UploadProgressChangedEventArgs> uploadProgressChangedCallback, CancellationToken cancellationToken) { if (assets == null) { throw new ArgumentNullException("assets", "The assets collection cannot be null."); } MediaContextBase context = assets.MediaContext; string assetName = Path.GetFileName(filePath); if (string.IsNullOrWhiteSpace(storageAccountName)) { storageAccountName = context.DefaultStorageAccount.Name; } IAsset asset = await assets.CreateAsync(assetName, storageAccountName, options, cancellationToken).ConfigureAwait(false); ILocator sasLocator = await context.Locators.CreateAsync(LocatorType.Sas, asset, AccessPermissions.Write | AccessPermissions.List, DefaultAccessPolicyDuration).ConfigureAwait(false); EventHandler <UploadProgressChangedEventArgs> uploadProgressChangedHandler = (s, e) => { IAssetFile assetFile = (IAssetFile)s; UploadProgressChangedEventArgs eventArgs = e; if (uploadProgressChangedCallback != null) { uploadProgressChangedCallback(assetFile, eventArgs); } }; await asset.CreateAssetFileFromLocalFileAsync(filePath, sasLocator, uploadProgressChangedHandler, cancellationToken).ConfigureAwait(false); await sasLocator.DeleteAsync().ConfigureAwait(false); return(asset); }
private void file_UploadProgressChanged(object sender, Microsoft.WindowsAzure.MediaServices.Client.UploadProgressChangedEventArgs e) { progressBarUpload.BeginInvoke(new Action(() => progressBarUpload.Value = (int)e.Progress), null); }
private void MyUploadProgressChanged(object sender, UploadProgressChangedEventArgs e) { try { progressBarUpload.BeginInvoke(new Action(() => progressBarUpload.Value = (int)e.Progress), null); } catch { } }
static void AssetFile_UploadProgressChanged(object sender, UploadProgressChangedEventArgs e) { // 現在のファイル・アップロード状況を出力します Console.WriteLine("★{1}/{2} bytes の {0}% アップロード ", e.Progress, e.BytesUploaded, e.TotalBytes); }
private static void AssertUploadedFile(string originalFolderPath, string fileName, UploadProgressChangedEventArgs uploadProgressChangedEventArgs) { var expected = new FileInfo(Path.Combine(originalFolderPath, fileName)); Assert.AreEqual(expected.Length, uploadProgressChangedEventArgs.BytesUploaded); Assert.AreEqual(expected.Length, uploadProgressChangedEventArgs.TotalBytes); Assert.AreEqual(100, uploadProgressChangedEventArgs.Progress); }