public static IAsset CreateAssetAndUploadSingleFile(this CloudMediaContext cloudMediaContext, AssetCreationOptions assetCreationOptions, string singleFilePath)
        {
            var fileName = Path.GetFileName(singleFilePath);

            var assetName = fileName; // +"-" + DateTime.UtcNow.ToString("o");

            var asset = cloudMediaContext.CreateEmptyAsset(assetName, assetCreationOptions);

            var assetFile = asset.AssetFiles.Create(fileName);

            //Console.WriteLine("Created assetFile {0}", assetFile.Name);

            var accessPolicy = cloudMediaContext.AccessPolicies.Create(assetName, TimeSpan.FromDays(3),
                                                                AccessPermissions.Write | AccessPermissions.List);

            var locator = cloudMediaContext.Locators.CreateLocator(LocatorType.Sas, asset, accessPolicy);

            //Console.WriteLine("Upload {0}", assetFile.Name);

            assetFile.Upload(singleFilePath);
            //Console.WriteLine("Done uploading of {0} using Upload()", assetFile.Name);

            locator.Delete();
            accessPolicy.Delete();

            return asset;
        }
示例#2
0
        static public IAsset EncodeToAdaptiveBitrateMP4s(IAsset asset, AssetCreationOptions options)
        {
            // Prepare a job with a single task to transcode the specified asset
            // into a multi-bitrate asset.

            IJob job = _context.Jobs.CreateWithSingleTask(
                MediaProcessorNames.AzureMediaEncoder,
                MediaEncoderTaskPresetStrings.H264AdaptiveBitrateMP4Set720p,
                asset,
                "Adaptive Bitrate MP4",
                options);

            Console.WriteLine("Submitting transcoding job...");


            // Submit the job and wait until it is completed.
            job.Submit();

            job = job.StartExecutionProgressTask(
                j =>
            {
                Console.WriteLine("Job state: {0}", j.State);
                Console.WriteLine("Job progress: {0:0.##}%", j.GetOverallProgress());
            },
                CancellationToken.None).Result;

            Console.WriteLine("Transcoding job finished.");

            IAsset outputAsset = job.OutputMediaAssets[0];

            return(outputAsset);
        }
        static public IAsset CreateAssetAndUploadSingleFile(AssetCreationOptions assetCreationOptions, string singleFilePath)
        {
            // For the AssetCreationOptions you can specify the following encryption options.
            //      None:  no encryption. By default, storage encryption is used. If you want to 
            //        create an unencrypted asset, you must set this option.
            //      StorageEncrypted:  storage encryption. Encrypts a clear input file 
            //        before it is uploaded to Azure storage. 
            //      CommonEncryptionProtected:  for Common Encryption Protected (CENC) files. An 
            //        example is a set of files that are already PlayReady encrypted. 

            var assetName = "UploadSingleFile_" + DateTime.UtcNow.ToString();
            var asset = CreateEmptyAsset(assetName, assetCreationOptions);

            var fileName = Path.GetFileName(singleFilePath);

            var assetFile = asset.AssetFiles.Create(fileName);

            Console.WriteLine("Created assetFile {0}", assetFile.Name);

            var accessPolicy = _context.AccessPolicies.Create(assetName, TimeSpan.FromDays(30),
                                                                AccessPermissions.Write | AccessPermissions.List);

            var locator = _context.Locators.CreateLocator(LocatorType.Sas, asset, accessPolicy);

            Console.WriteLine("Upload {0}", assetFile.Name);

            assetFile.Upload(singleFilePath);
            Console.WriteLine("Done uploading {0}", assetFile.Name);

            locator.Delete();
            accessPolicy.Delete();

            return asset;
        }
        static public IAsset CreateAssetAndUploadSingleFile(AssetCreationOptions assetCreationOptions, string singleFilePath)
        {
            CloudMediaContext _context = CloudContextHelper.GetContext();

            if (!File.Exists(singleFilePath))
            {
                Console.WriteLine("File does not exist.");
                return(null);
            }

            var    assetName  = Path.GetFileNameWithoutExtension(singleFilePath);
            IAsset inputAsset = _context.Assets.Create(assetName, assetCreationOptions);

            var assetFile = inputAsset.AssetFiles.Create(Path.GetFileName(singleFilePath));

            Console.WriteLine("Created assetFile {0}", assetFile.Name);

            var policy = _context.AccessPolicies.Create(
                assetName,
                TimeSpan.FromDays(30),
                AccessPermissions.Write | AccessPermissions.List);

            var locator = _context.Locators.CreateLocator(LocatorType.Sas, inputAsset, policy);

            Console.WriteLine("Upload {0}", assetFile.Name);

            assetFile.Upload(singleFilePath);
            Console.WriteLine("Done uploading {0}", assetFile.Name);

            locator.Delete();
            policy.Delete();

            return(inputAsset);
        }
示例#5
0
        /// <summary>
        /// Uploads the destinationPath with given path asynchronously
        /// </summary>
        /// <param name="path">The path of a destinationPath to upload</param>
        /// <param name="blobTransferClient">The <see cref="BlobTransferClient"/> which is used to upload files.</param>
        /// <param name="locator">An asset <see cref="ILocator"/> which defines permissions associated with the Asset.</param>
        /// <param name="token">A <see cref="CancellationToken"/> to use for canceling upload operation.</param>
        /// <returns>A function delegate that returns the future result to be available through the Task.</returns>
        public Task UploadAsync(string path, BlobTransferClient blobTransferClient, ILocator locator, CancellationToken token)
        {
            if (blobTransferClient == null)
            {
                throw new ArgumentNullException("blobTransferClient");
            }

            if (locator == null)
            {
                throw new ArgumentNullException("locator");
            }

            if (path == null)
            {
                throw new ArgumentNullException("path");
            }

            if (!File.Exists(path))
            {
                throw new FileNotFoundException(path);
            }

            ValidateFileName(path);

            IContentKey          contentKeyData       = null;
            FileEncryption       fileEncryption       = null;
            AssetCreationOptions assetCreationOptions = this.Asset.Options;

            if (assetCreationOptions.HasFlag(AssetCreationOptions.StorageEncrypted))
            {
                contentKeyData = this.Asset.ContentKeys.Where(c => c.ContentKeyType == ContentKeyType.StorageEncryption).FirstOrDefault();
                if (contentKeyData == null)
                {
                    throw new InvalidOperationException(String.Format(CultureInfo.InvariantCulture, StringTable.StorageEncryptionContentKeyIsMissing, this.Asset.Id));
                }

                fileEncryption = new FileEncryption(contentKeyData.GetClearKeyValue(), EncryptionUtils.GetKeyIdAsGuid(contentKeyData.Id));
            }

            EventHandler <BlobTransferProgressChangedEventArgs> handler = (s, e) => OnUploadProgressChanged(path, e);

            blobTransferClient.TransferProgressChanged += handler;

            MediaRetryPolicy retryPolicy = this.GetMediaContext().MediaServicesClassFactory.GetBlobStorageClientRetryPolicy();

            return(blobTransferClient.UploadBlob(
                       new Uri(locator.BaseUri),
                       path,
                       null,
                       fileEncryption,
                       token,
                       retryPolicy.AsAzureStorageClientRetryPolicy(),
                       () => locator.ContentAccessComponent)
                   .ContinueWith(
                       ts =>
            {
                blobTransferClient.TransferProgressChanged -= handler;
                this.PostUploadAction(ts, path, fileEncryption, assetCreationOptions, token);
            }));
        }
        /// <summary>
        /// Asynchronously creates an asset that does not contain any files and <see cref="AssetState"/> is Initialized.
        /// </summary>
        /// <param name="assetName">The asset name.</param>
        /// <param name="options">A <see cref="AssetCreationOptions"/> which will be associated with created asset.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>
        /// An <see cref="Task"/> of type <see cref="IAsset"/>created according to the specified creation <paramref name="options"/>.
        /// </returns>
        public override Task<IAsset> CreateAsync(string assetName, AssetCreationOptions options,CancellationToken cancellationToken)
        {
            AssetData emptyAsset = new AssetData
                                       {
                                           Name = assetName,
                                           Options = (int) options
                                       };

            emptyAsset.InitCloudMediaContext(this._cloudMediaContext);

            cancellationToken.ThrowIfCancellationRequested();
            DataServiceContext dataContext = this._cloudMediaContext.DataContextFactory.CreateDataServiceContext();
            dataContext.AddObject(AssetSet, emptyAsset);

            return dataContext
                .SaveChangesAsync(emptyAsset)
                .ContinueWith<IAsset>(
                    t =>
                        {
                            t.ThrowIfFaulted();
                            cancellationToken.ThrowIfCancellationRequested();

                            AssetData data = (AssetData) t.AsyncState;
                            if (options.HasFlag(AssetCreationOptions.StorageEncrypted))
                            {
                                using (var fileEncryption = new NullableFileEncryption())
                                {
                                    CreateStorageContentKey(data, fileEncryption, dataContext);
                                }
                            }

                            return data;
                        });
        }
示例#7
0
        private IAsset CreateHlsFromSmoothAsset(IAsset sourceAsset, AssetCreationOptions options)
        {
            IJob            job            = _mediaContext.Jobs.Create("Smooth to Hls Job");
            IMediaProcessor mediaProcessor = JobTests.GetMediaProcessor(_mediaContext, WindowsAzureMediaServicesTestConfiguration.MpEncryptorName);

            string smoothToHlsConfiguration = null;

            if (options == AssetCreationOptions.EnvelopeEncryptionProtected)
            {
                smoothToHlsConfiguration = File.ReadAllText(WindowsAzureMediaServicesTestConfiguration.SmoothToEncryptHlsConfig);
            }
            else
            {
                smoothToHlsConfiguration = File.ReadAllText(WindowsAzureMediaServicesTestConfiguration.SmoothToHlsConfig);
            }

            ITask task = job.Tasks.AddNew("Smooth to Hls conversion task", mediaProcessor, smoothToHlsConfiguration, TaskOptions.None);

            task.InputAssets.Add(sourceAsset);
            task.OutputAssets.AddNew("JobOutput", options);
            job.Submit();

            job.GetExecutionProgressTask(CancellationToken.None).Wait();

            job.Refresh();

            return(job.OutputMediaAssets[0]);
        }
示例#8
0
        static public IAsset CreateAssetAndUploadSingleFile(AssetCreationOptions assetCreationOptions, string singleFilePath)
        {
            // For the AssetCreationOptions you can specify the following encryption options.
            //      None:  no encryption. By default, storage encryption is used. If you want to
            //        create an unencrypted asset, you must set this option.
            //      StorageEncrypted:  storage encryption. Encrypts a clear input file
            //        before it is uploaded to Azure storage.
            //      CommonEncryptionProtected:  for Common Encryption Protected (CENC) files. An
            //        example is a set of files that are already PlayReady encrypted.

            var assetName = "UploadSingleFile_" + DateTime.UtcNow.ToString();
            var asset     = CreateEmptyAsset(assetName, assetCreationOptions);

            var fileName = Path.GetFileName(singleFilePath);

            var assetFile = asset.AssetFiles.Create(fileName);

            Console.WriteLine("Created assetFile {0}", assetFile.Name);

            var accessPolicy = _context.AccessPolicies.Create(assetName, TimeSpan.FromDays(30),
                                                              AccessPermissions.Write | AccessPermissions.List);

            var locator = _context.Locators.CreateLocator(LocatorType.Sas, asset, accessPolicy);

            Console.WriteLine("Upload {0}", assetFile.Name);

            assetFile.Upload(singleFilePath);
            Console.WriteLine("Done uploading {0}", assetFile.Name);

            locator.Delete();
            accessPolicy.Delete();

            return(asset);
        }
        private IAsset CreateAssetAndUploadSingleFile(string assetName, AssetCreationOptions options)
        {
            IAsset asset = null;

            _log.Info("Entered Find File");
            try
            {
                if (_context.Assets.Count() > 0)
                {
                    _log.Info("Searching for asset");
                    //foreach (IAsset temp in _context.Assets)
                    //{
                    //    logWriter.Info(temp.Name);
                    //}
                    asset = _context.Assets.Where(x => x.Name == assetName).First();
                    _log.Info("File available");
                }
                else
                {
                    _log.Info("No files in Assets");
                }
            }
            catch (Exception ex)
            {
                _log.Error(ex.Message, ex);
            }
            return(asset);
        }
示例#10
0
        private IAsset CreateMbrMp4Asset(AssetCreationOptions options)
        {
            IMediaProcessor encoder = JobTests.GetEncoderMediaProcessor(_mediaContext);
            IJob            job     = _mediaContext.Jobs.Create("Job for ValidateEffectiveEncryptionStatusOfMultiBitRateMP4");

            ITask adpativeBitrateTask = job.Tasks.AddNew("MP4 to Adaptive Bitrate Task",
                                                         encoder,
                                                         "H264 Adaptive Bitrate MP4 Set 720p",
                                                         TaskOptions.None);

            // Specify the input Asset
            IAsset asset = AssetTests.CreateAsset(_mediaContext, WindowsAzureMediaServicesTestConfiguration.SmallMp41, AssetCreationOptions.None);

            adpativeBitrateTask.InputAssets.Add(asset);

            // Add an output asset to contain the results of the job.
            // This output is specified as AssetCreationOptions.None, which
            // means the output asset is in the clear (unencrypted).
            IAsset abrAsset = adpativeBitrateTask.OutputAssets.AddNew("Multibitrate MP4s", options);

            job.Submit();

            job.GetExecutionProgressTask(CancellationToken.None).Wait();

            job.Refresh();

            return(job.OutputMediaAssets[0]);
        }
示例#11
0
        public static IAsset EncodeToAdaptiveBitrateMP4s(IAsset asset, AssetCreationOptions options)
        {
            // Prepare a job with a single task to transcode the specified asset
            // into a multi-bitrate asset.

            IJob job = _context.Jobs.CreateWithSingleTask(
                MediaProcessorNames.AzureMediaEncoder,
                MediaEncoderTaskPresetStrings.H264AdaptiveBitrateMP4Set720p,
                asset,
                "Adaptive Bitrate MP4",
                options);

            Console.WriteLine("Submitting transcoding job...");

            // Submit the job and wait until it is completed.
            job.Submit();

            job = job.StartExecutionProgressTask(
                j =>
                {
                    Console.WriteLine("Job state: {0}", j.State);
                    Console.WriteLine("Job progress: {0:0.##}%", j.GetOverallProgress());
                },
                CancellationToken.None).Result;

            Console.WriteLine("Transcoding job finished.");

            IAsset outputAsset = job.OutputMediaAssets[0];

            return outputAsset;
        }
示例#12
0
        static public IAsset CreateAssetAndUploadSingleFile(AssetCreationOptions assetCreationOptions, string singleFilePath)
        {
            /*
             * if (!File.Exists(singleFilePath))
             * {
             *  Console.WriteLine("File does not exist.");
             *  return null;
             * }
             */
            var    _context   = new CloudMediaContext("aamediaservice1", "uIux27Hig96nRLkGZEZcareBz0x5t2gPPA533riDgTo=");
            var    assetName  = Path.GetFileNameWithoutExtension(singleFilePath);
            IAsset inputAsset = _context.Assets.Create(assetName, assetCreationOptions);

            var assetFile = inputAsset.AssetFiles.Create(Path.GetFileName(singleFilePath));

            Console.WriteLine("Created assetFile {0}", assetFile.Name);

            var policy = _context.AccessPolicies.Create(
                assetName,
                TimeSpan.FromDays(30),
                AccessPermissions.Write | AccessPermissions.List);

            var locator = _context.Locators.CreateLocator(LocatorType.Sas, inputAsset, policy);

            Console.WriteLine("Upload {0}", assetFile.Name);

            assetFile.Upload(singleFilePath);
            Console.WriteLine("Done uploading {0}", assetFile.Name);

            locator.Delete();
            policy.Delete();

            return(inputAsset);
        }
        public static IAsset EncodeToAdaptiveBitrateMP4s(IAsset asset, AssetCreationOptions assetCreationOptions)
        {
            if (_context == null)
            {
                InitContext();
            }

            IJob job = _context.Jobs.Create(asset.Name + "-MES_H264_Multiple_Bitrate_720p");

            //get the standard media processor
            var processor = _context.MediaProcessors.Where(p => p.Name == "Media Encoder Standard").ToList().OrderBy(p => new Version(p.Version)).LastOrDefault();

            ITask task = job.Tasks.AddNew("My encoding task",
                                          processor,
                                          "H264 Multiple Bitrate 720p",
                                          TaskOptions.None);

            task.InputAssets.Add(asset);
            task.OutputAssets.AddNew(GetEncodedAssetNameByAssetName(asset.Name), AssetCreationOptions.None);

            job.Submit();
            job.GetExecutionProgressTask(System.Threading.CancellationToken.None).Wait();

            return(job.OutputMediaAssets[0]);
        }
示例#14
0
        static public IAsset CreateAssetAndUploadSingleFile(AssetCreationOptions assetCreationOptions, string singleFilePath)
        {
            var assetName = "UploadSingleFile_" + DateTime.UtcNow.ToString();
            var asset     = CreateEmptyAsset(assetName, assetCreationOptions);

            var fileName = Path.GetFileName(singleFilePath);

            var assetFile = asset.AssetFiles.Create(fileName);

            Console.WriteLine("Created assetFile {0}", assetFile.Name);

            var accessPolicy = _context.AccessPolicies.Create(assetName, TimeSpan.FromDays(30),
                                                              AccessPermissions.Write | AccessPermissions.List);

            var locator = _context.Locators.CreateLocator(LocatorType.Sas, asset, accessPolicy);

            Console.WriteLine("Upload {0}", assetFile.Name);

            assetFile.Upload(singleFilePath);
            Console.WriteLine("Done uploading {0}", assetFile.Name);

            locator.Delete();
            accessPolicy.Delete();

            return(asset);
        }
示例#15
0
        public void t()

        {
            var context = new CloudMediaContext("medulawmedia", "H9jZUXCx7zX0Jihemd4yoSDZ6XWFKiIfpCGOQiOXzIQ=");
            // The local path to the file to upload to the new asset.
            string filePath  = @"D:\DNN\Helium5\DesktopModules\MVC\purplecs\DNNGameBoard\video\17_Augmentation Mammoplasty.mp4";
            var    assetName = Path.GetFileName(filePath);
            // The options for creating the new asset.
            AssetCreationOptions assetCreationOptions = AssetCreationOptions.None;

            // Create a new asset and upload a local file using a single extension method.
            IAsset asset = context.Assets.Create(assetName, assetCreationOptions);

            var assetFile = asset.AssetFiles.Create(assetName);

            assetFile.IsPrimary = true;

            var storeage = asset.StorageAccountName;
            var policy   = context.AccessPolicies.Create(
                assetName,
                TimeSpan.FromDays(30000),
                AccessPermissions.List | AccessPermissions.Read);

            var locator = context.Locators.CreateLocator(LocatorType.Sas, asset, policy);
            var rul     = asset.Uri;

            assetFile.Upload(filePath);
            Console.WriteLine("Done uploading {0}", assetFile.Name);
            var url = locator.BaseUri + assetName + locator.ContentAccessComponent;

            locator.Delete();
            policy.Delete();
        }
        public static IAsset CreateAssetAndUploadSingleFile(string singleFilePath, AssetCreationOptions assetCreationOptions)
        {
            if (!File.Exists(singleFilePath))
            {
                return(null);
            }

            //Get original File Name
            var assetName = Path.GetFileNameWithoutExtension(singleFilePath);
            //Format file name with adding timestamp
            string uniqueAssetName = GetTimeStamp.ToString(assetName);

            if (_context == null)
            {
                InitContext();
            }

            IAsset inputAsset = null;

            try
            {
                inputAsset = _context.Assets.Create(uniqueAssetName, assetCreationOptions);
                // add asset files to this asset
                var assetFile = inputAsset.AssetFiles.Create(Path.GetFileName(singleFilePath));
                assetFile.Upload(singleFilePath);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }

            return(inputAsset);
        }
示例#17
0
        static public IAsset UploadAssetFile(AssetCreationOptions assetCreationOptions, string singleFilePath)
        {
            //Create Asset
            var assetName = Path.GetFileName(singleFilePath) + "_UTC " + DateTime.UtcNow.ToString();
            var asset     = CreateEmptyAsset(assetName, assetCreationOptions);

            //Create Asset File
            var fileName  = Path.GetFileName(singleFilePath);
            var assetFile = asset.AssetFiles.Create(fileName);

            Console.WriteLine("\tCreated assetFile {0}", assetFile.Name);

            //Create Access Policy
            var accessPolicy = context.AccessPolicies.Create(assetName, TimeSpan.FromDays(3), AccessPermissions.Write | AccessPermissions.List);

            //Create Locator
            var locator = context.Locators.CreateLocator(LocatorType.Sas, asset, accessPolicy);

            //Upload AssetFile
            Console.WriteLine("\tUploading {0}...", assetFile.Name);
            assetFile.Upload(singleFilePath);
            Console.WriteLine("\t\tDone");

            //CLeanup
            locator.Delete();
            accessPolicy.Delete();

            return(asset);
        }
        static public IAsset EncodeToAudioOnly(IAsset asset, AssetCreationOptions options)
        {
            // Load the XML (or JSON) from the local file.
            string configuration = File.ReadAllText(Path.Combine(_presetFiles, @"AudioOnlyPreset_JSON.json"));

            IJob job = _context.Jobs.CreateWithSingleTask(
                "Media Encoder Standard",
                configuration,
                asset,
                "Audio only",
                options);

            Console.WriteLine("Submitting transcoding job...");


            // Submit the job and wait until it is completed.
            job.Submit();

            job = job.StartExecutionProgressTask(
                j =>
            {
                Console.WriteLine("Job state: {0}", j.State);
                Console.WriteLine("Job progress: {0:0.##}%", j.GetOverallProgress());
            },
                CancellationToken.None).Result;

            Console.WriteLine("Transcoding job finished.");

            IAsset outputAsset = job.OutputMediaAssets[0];

            return(outputAsset);
        }
示例#19
0
        static public IAsset EncodeToAdaptiveBitrateMP4s(IAsset asset, AssetCreationOptions options)
        {
            // Prepare a job with a single task to transcode the specified asset
            // into a multi-bitrate asset.

            IJob job = _context.Jobs.CreateWithSingleTask(
                "Media Encoder Standard",
                "Adaptive Streaming",
                asset,
                "Adaptive Bitrate MP4",
                options);

            Debug.Write("Submitting transcoding job...");


            // Submit the job and wait until it is completed.
            job.Submit();

            job = job.StartExecutionProgressTask(
                j =>
            {
                Debug.Write($"Job state: {j.State}");
                Debug.Write($"Job progress: 0:0.{j.GetOverallProgress()}");
            },
                CancellationToken.None).Result;

            Debug.Write("Transcoding job finished.");

            IAsset outputAsset = job.OutputMediaAssets[0];

            return(outputAsset);
        }
示例#20
0
        public static IAsset CreateAssetAndUploadSingleFile(AssetCreationOptions assetCreationOptions, string singleFilePath)
        {
            var assetName = "UploadSingleFile_" + DateTime.UtcNow.ToString();
            var asset = CreateEmptyAsset(assetName, assetCreationOptions);

            var fileName = Path.GetFileName(singleFilePath);

            var assetFile = asset.AssetFiles.Create(fileName);

            Console.WriteLine("Created assetFile {0}", assetFile.Name);

            var accessPolicy = _context.AccessPolicies.Create(assetName, TimeSpan.FromDays(30),
                                                                AccessPermissions.Write | AccessPermissions.List);

            var locator = _context.Locators.CreateLocator(LocatorType.Sas, asset, accessPolicy);

            Console.WriteLine("Upload {0}", assetFile.Name);

            assetFile.Upload(singleFilePath);
            Console.WriteLine("Done uploading {0}", assetFile.Name);

            locator.Delete();
            accessPolicy.Delete();

            return asset;
        }
示例#21
0
        static private IAsset CreateEmptyAsset(string assetName, AssetCreationOptions assetCreationOptions)
        {
            var asset = context.Assets.Create(assetName, assetCreationOptions);

            Console.WriteLine("Asset name: " + asset.Name);
            Console.WriteLine("Time cerated: " + asset.Created.Date.ToString());
            return(asset);
        }
 /// <summary>
 /// Adds the new output asset.
 /// </summary>
 /// <param name="assetName">The asset name.</param>
 /// <param name="options">The options.</param>
 /// <returns>The new asset.</returns>
 public IAsset AddNew(string assetName, AssetCreationOptions options)
 {
     if (this._cloudMediaContext.DefaultStorageAccount == null)
     {
         throw new InvalidOperationException(StringTable.DefaultStorageAccountIsNull);
     }
     return(this.AddNew(assetName, _cloudMediaContext.DefaultStorageAccount.Name, options));
 }
 /// <summary>
 /// Creates an asset that does not contain any files and <see cref="AssetState"/> is Initialized. 
 /// </summary>
 /// <param name="assetName">The asset name.</param>
 /// <param name="options">A <see cref="AssetCreationOptions"/> which will be associated with created asset.</param>
 /// <returns>The created asset.</returns>
 public override IAsset Create(string assetName, AssetCreationOptions options)
 {
     IStorageAccount defaultStorageAccount = this.MediaContext.DefaultStorageAccount;
     if (defaultStorageAccount == null)
     {
         throw new InvalidOperationException(StringTable.DefaultStorageAccountIsNull);
     }
     return this.Create(assetName, defaultStorageAccount.Name, options);
 }
        static private IAsset CreateEmptyAsset(string assetName, AssetCreationOptions assetCreationOptions)
        {
            var asset = _context.Assets.Create(assetName, assetCreationOptions);

            Console.WriteLine("Asset name: " + asset.Name);
            Console.WriteLine("Time created: " + asset.Created.Date.ToString());

            return asset;
        }
        /// <summary>
        /// Creates the manifest asset file asynchronously.
        /// </summary>
        /// <param name="ingestManifestAsset">The parent manifest asset.</param>
        /// <param name="filePath">The file path.</param>
        /// <param name="token"><see cref="CancellationToken"/></param>
        /// <returns><see cref="Task"/>of type <see cref="IIngestManifestFile"/></returns>
        public Task <IIngestManifestFile> CreateAsync(IIngestManifestAsset ingestManifestAsset, string filePath, CancellationToken token)
        {
            if (ingestManifestAsset == null)
            {
                throw new ArgumentNullException("ingestManifestAsset");
            }

            if (string.IsNullOrWhiteSpace(filePath))
            {
                throw new ArgumentException(String.Format(CultureInfo.InvariantCulture, StringTable.ErrorCreatingIngestManifestFileEmptyFilePath));
            }

            AssetCreationOptions options = ingestManifestAsset.Asset.Options;

            Task <IIngestManifestFile> rootTask = new Task <IIngestManifestFile>(() =>
            {
                token.ThrowIfCancellationRequested();

                IngestManifestAssetCollection.VerifyManifestAsset(ingestManifestAsset);
                if (!File.Exists(filePath))
                {
                    throw new FileNotFoundException(String.Format(CultureInfo.InvariantCulture, StringTable.BulkIngestProvidedFileDoesNotExist, filePath));
                }
                FileInfo info = new FileInfo(filePath);

                DataServiceContext dataContext = this._cloudMediaContext.DataContextFactory.CreateDataServiceContext();

                // Set a MIME type based on the extension of the file name
                string mimeType = AssetFileData.GetMimeType(filePath);

                IngestManifestFileData data = new IngestManifestFileData
                {
                    Name     = info.Name,
                    MimeType = mimeType,
                    ParentIngestManifestId      = ingestManifestAsset.ParentIngestManifestId,
                    ParentIngestManifestAssetId = ingestManifestAsset.Id,
                    Path = filePath,
                };

                SetEncryptionSettings(ingestManifestAsset, info, options, data);

                dataContext.AddObject(EntitySet, data);

                Task <IIngestManifestFile> task = dataContext.SaveChangesAsync(data).ContinueWith <IIngestManifestFile>(t =>
                {
                    t.ThrowIfFaulted();
                    token.ThrowIfCancellationRequested();
                    IngestManifestFileData ingestManifestFile = (IngestManifestFileData)t.AsyncState;
                    return(ingestManifestFile);
                });

                return(task.Result);
            });

            rootTask.Start();
            return(rootTask);
        }
        private IAsset GetTestAsset(AssetCreationOptions options, AssetType assetType, AssetDeliveryProtocol protocol, AssetDeliveryPolicyType deliveryType)
        {
            IAsset asset = _mediaContext.Assets.Create("Test", options);

            AddTestAssetFiles(asset, assetType);

            AddTestDeliveryPolicies(asset, protocol, deliveryType);

            return(asset);
        }
        /// <summary>
        /// Creates an asset that does not contain any files and <see cref="AssetState"/> is Initialized.
        /// </summary>
        /// <param name="assetName">The asset name.</param>
        /// <param name="options">A <see cref="AssetCreationOptions"/> which will be associated with created asset.</param>
        /// <returns>The created asset.</returns>
        public override IAsset Create(string assetName, AssetCreationOptions options)
        {
            IStorageAccount defaultStorageAccount = this.MediaContext.DefaultStorageAccount;

            if (defaultStorageAccount == null)
            {
                throw new InvalidOperationException(StringTable.DefaultStorageAccountIsNull);
            }
            return(this.Create(assetName, defaultStorageAccount.Name, options));
        }
        /// <summary>
        /// Asynchronously creates an asset that does not contain any files and <see cref="AssetState"/> is Initialized.
        /// </summary>
        /// <param name="assetName">The asset name.</param>
        /// <param name="options">A <see cref="AssetCreationOptions"/> which will be associated with created asset.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>
        /// An <see cref="Task"/> of type <see cref="IAsset"/>created according to the specified creation <paramref name="options"/>.
        /// </returns>
        public override Task <IAsset> CreateAsync(string assetName, AssetCreationOptions options, CancellationToken cancellationToken)
        {
            IStorageAccount defaultStorageAccount = this.MediaContext.DefaultStorageAccount;

            if (defaultStorageAccount == null)
            {
                throw new InvalidOperationException(StringTable.DefaultStorageAccountIsNull);
            }
            return(this.CreateAsync(assetName, defaultStorageAccount.Name, options, cancellationToken));
        }
        /// <summary>
        /// Creates the manifest asset file asynchronously.
        /// </summary>
        /// <param name="ingestManifestAsset">The parent manifest asset.</param>
        /// <param name="filePath">The file path.</param>
        /// <param name="token"><see cref="CancellationToken"/></param>
        /// <returns><see cref="Task"/>of type <see cref="IIngestManifestFile"/></returns>
        public Task <IIngestManifestFile> CreateAsync(IIngestManifestAsset ingestManifestAsset, string filePath, CancellationToken token)
        {
            if (ingestManifestAsset == null)
            {
                throw new ArgumentNullException("ingestManifestAsset");
            }

            if (string.IsNullOrWhiteSpace(filePath))
            {
                throw new ArgumentException(String.Format(CultureInfo.InvariantCulture, StringTable.ErrorCreatingIngestManifestFileEmptyFilePath));
            }

            AssetCreationOptions options = ingestManifestAsset.Asset.Options;

            Task <IIngestManifestFile> rootTask = new Task <IIngestManifestFile>(() =>
            {
                token.ThrowIfCancellationRequested();

                IngestManifestAssetCollection.VerifyManifestAsset(ingestManifestAsset);

                IMediaDataServiceContext dataContext = this.MediaContext.MediaServicesClassFactory.CreateDataServiceContext();

                // Set a MIME type based on the extension of the file name
                string mimeType = AssetFileData.GetMimeType(filePath);

                IngestManifestFileData data = new IngestManifestFileData
                {
                    Name     = Path.GetFileName(filePath),
                    MimeType = mimeType,
                    ParentIngestManifestId      = ingestManifestAsset.ParentIngestManifestId,
                    ParentIngestManifestAssetId = ingestManifestAsset.Id,
                    Path = filePath,
                };

                SetEncryptionSettings(ingestManifestAsset, options, data);

                dataContext.AddObject(EntitySet, data);

                MediaRetryPolicy retryPolicy = this.MediaContext.MediaServicesClassFactory.GetSaveChangesRetryPolicy(dataContext as IRetryPolicyAdapter);

                Task <IIngestManifestFile> task = retryPolicy.ExecuteAsync <IMediaDataServiceResponse>(() => dataContext.SaveChangesAsync(data))
                                                  .ContinueWith <IIngestManifestFile>(t =>
                {
                    t.ThrowIfFaulted();
                    token.ThrowIfCancellationRequested();
                    IngestManifestFileData ingestManifestFile = (IngestManifestFileData)t.Result.AsyncState;
                    return(ingestManifestFile);
                });

                return(task.Result);
            });

            rootTask.Start();
            return(rootTask);
        }
        private IAsset UploadFile(string fileName, AssetCreationOptions options)
        {
            IAsset inputAsset = _context.Assets.CreateFromFile(
                fileName,
                options,
                (af, p) =>
            {
            });

            return(inputAsset);
        }
示例#31
0
        public static void UploadByBlock(string manifestName, AssetCreationOptions options, string[] files)
        {
            CloudMediaContext context  = CloudContextHelper.GetContext();
            IIngestManifest   manifest = context.IngestManifests.Create(manifestName);

            IAsset asset = context.Assets.Create(manifestName + "_Asset", options);

            IIngestManifestAsset bulkAsset = manifest.IngestManifestAssets.Create(asset, files);

            UploadBlobFile(manifest.BlobStorageUriForUpload, files);

            MonitorBulkManifest(manifest.Id);
        }
 /// <summary>
 /// Creates an asset for specified storage account. Asset does not contain any files and <see cref="AssetState" /> is Initialized.
 /// </summary>
 /// <param name="assetName">The asset name.</param>
 /// <param name="storageAccountName"></param>
 /// <param name="options">A <see cref="AssetCreationOptions" /> which will be associated with created asset.</param>
 /// <returns>
 /// The created asset.
 /// </returns>
 public override IAsset Create(string assetName, string storageAccountName, AssetCreationOptions options)
 {
     try
     {
         Task <IAsset> task = this.CreateAsync(assetName, storageAccountName, options, CancellationToken.None);
         task.Wait();
         return(task.Result);
     }
     catch (AggregateException exception)
     {
         throw exception.InnerException;
     }
 }
示例#33
0
        public async Task <IAsset> CreateAssetAndUploadSingleFile(AssetCreationOptions assetCreationOptions, string mediaTitle, string fileName, Stream mediaStream, CancellationToken token)
        {
            var inputAsset = await _cloudMediaContext.Assets.CreateAsync(mediaTitle, assetCreationOptions, token).ConfigureAwait(false);

            var assetFile = await inputAsset.AssetFiles.CreateAsync(fileName, token).ConfigureAwait(false);

            return(await Task.Run(() =>
            {
                assetFile.Upload(mediaStream);

                return inputAsset;
            }).ConfigureAwait(false));
        }
        static public IAsset CreateAssetAndUploadMultipleFiles(AssetCreationOptions assetCreationOptions, string folderPath)
        {
            CloudMediaContext _context = CloudContextHelper.GetContext();

            var assetName = "UploadMultipleFiles_" + DateTime.UtcNow.ToString();

            IAsset asset = _context.Assets.Create(assetName, assetCreationOptions);

            var accessPolicy = _context.AccessPolicies.Create(assetName, TimeSpan.FromDays(30),
                                                              AccessPermissions.Write | AccessPermissions.List);

            var locator = _context.Locators.CreateLocator(LocatorType.Sas, asset, accessPolicy);

            var blobTransferClient = new BlobTransferClient();

            blobTransferClient.NumberOfConcurrentTransfers = 20;
            blobTransferClient.ParallelTransferThreadCount = 20;

            blobTransferClient.TransferProgressChanged += blobTransferClient_TransferProgressChanged;

            var filePaths = Directory.EnumerateFiles(folderPath);

            Console.WriteLine("There are {0} files in {1}", filePaths.Count(), folderPath);

            if (!filePaths.Any())
            {
                throw new FileNotFoundException(String.Format("No files in directory, check folderPath: {0}", folderPath));
            }

            var uploadTasks = new List <Task>();

            foreach (var filePath in filePaths)
            {
                var assetFile = asset.AssetFiles.Create(Path.GetFileName(filePath));
                Console.WriteLine("Created assetFile {0}", assetFile.Name);

                // It is recommended to validate AccestFiles before upload.
                Console.WriteLine("Start uploading of {0}", assetFile.Name);
                uploadTasks.Add(assetFile.UploadAsync(filePath, blobTransferClient, locator, CancellationToken.None));
            }

            Task.WaitAll(uploadTasks.ToArray());
            Console.WriteLine("Done uploading the files");

            blobTransferClient.TransferProgressChanged -= blobTransferClient_TransferProgressChanged;

            locator.Delete();
            accessPolicy.Delete();

            return(asset);
        }
示例#35
0
        static public IAsset UploadFile(string fileName, AssetCreationOptions options)
        {
            IAsset inputAsset = _context.Assets.CreateFromFile(
                fileName,
                options,
                (af, p) =>
            {
                Console.WriteLine("Uploading '{0}' - Progress: {1:0.##}%", af.Name, p.Progress);
            });

            Console.WriteLine("Asset {0} created.", inputAsset.Id);

            return(inputAsset);
        }
示例#36
0
        static public IAsset UploadFile(string fileName, AssetCreationOptions options)
        {
            IAsset inputAsset = _context.Assets.CreateFromFile(
                fileName,
                options,
                (af, p) =>
            {
                Debug.Write($"Uploading {af.Name} - Progress: 1:0.{p.Progress}%");
            });

            Debug.Write("Asset {0} created.", inputAsset.Id);

            return(inputAsset);
        }
示例#37
0
        /// <summary>
        /// Uploads a single file.
        /// </summary>
        /// <param name="fileDir">The location of the files.</param>
        /// <param name="assetCreationOptions">
        ///  You can specify the following encryption options for the AssetCreationOptions.
        ///      None:  no encryption.
        ///      StorageEncrypted: storage encryption. Encrypts a clear input file
        ///        before it is uploaded to Azure storage.
        ///      CommonEncryptionProtected: for Common Encryption Protected (CENC) files.
        ///        For example, a set of files that are already PlayReady encrypted.
        ///      EnvelopeEncryptionProtected: for HLS with AES encryption files.
        ///        NOTE: The files must have been encoded and encrypted by Transform Manager.
        ///     </param>
        /// <returns>Returns an asset that contains a single file.</returns>
        /// </summary>
        /// <returns></returns>
        private static IAsset IngestSingleMP4File(string fileDir, AssetCreationOptions assetCreationOptions)
        {
            // Use the SDK extension method to create a new asset by
            // uploading a mezzanine file from a local path.
            IAsset asset = _context.Assets.CreateFromFile(
                fileDir,
                assetCreationOptions,
                (af, p) =>
            {
                Console.WriteLine("Uploading '{0}' - Progress: {1:0.##}%", af.Name, p.Progress);
            });

            return(asset);
        }
        /// <summary>
        /// Returns a new empty <see cref="IAsset"/> within one selected storage account from <paramref name="storageAccountNames"/> based on the default <see cref="IAccountSelectionStrategy"/>.
        /// </summary>
        /// <param name="assets">The <see cref="AssetBaseCollection"/> instance.</param>
        /// <param name="assetName">The asset name.</param>
        /// <param name="strategy">The <see cref="IAccountSelectionStrategy"/> used to select a storage account for the new output asset.</param>
        /// <param name="options">The <see cref="AssetCreationOptions"/>.</param>
        /// <returns>A new empty <see cref="IAsset"/> within one selected storage account from the provided <see cref="IAccountSelectionStrategy"/>.</returns>
        public static IAsset AddNew(this OutputAssetCollection collection, string assetName, IAccountSelectionStrategy strategy, AssetCreationOptions options)
        {
            if (collection == null)
            {
                throw new ArgumentNullException("collection");
            }

            if (strategy == null)
            {
                throw new ArgumentNullException("strategy");
            }

            string storageAccount = strategy.SelectAccountForAsset();

            return collection.AddNew(assetName, storageAccount, options);
        }
        /// <summary>
        /// Returns a <see cref="System.Threading.Tasks.Task&lt;IAsset&gt;"/> instance for a new empty <see cref="IAsset"/> asset within one selected storage account from <paramref name="storageAccountNames"/> based on the default <see cref="IAccountSelectionStrategy"/>.
        /// </summary>
        /// <param name="assets">The <see cref="AssetBaseCollection"/> instance.</param>
        /// <param name="assetName">The asset name.</param>
        /// <param name="strategy">The <see cref="IAccountSelectionStrategy"/> used to select a storage account for the new asset.</param>
        /// <param name="options">The <see cref="AssetCreationOptions"/>.</param>
        /// <param name="token">The <see cref="System.Threading.CancellationToken"/> instance used for cancellation.</param>
        /// <returns>A <see cref="System.Threading.Tasks.Task&lt;IAsset&gt;"/> instance for a new empty <see cref="IAsset"/> within one selected storage account from the given <see cref="IAccountSelectionStrategy"/>.</returns>
        public static Task<IAsset> CreateAsync(this AssetBaseCollection assets, string assetName, IAccountSelectionStrategy strategy, AssetCreationOptions options, CancellationToken token)
        {
            if (assets == null)
            {
                throw new ArgumentNullException("assets");
            }

            if (strategy == null)
            {
                throw new ArgumentNullException("strategy");
            }

            string storageAccountName = strategy.SelectAccountForAsset();

            return assets.CreateAsync(assetName, storageAccountName, options, token);
        }
        /// <summary>
        /// Returns a new empty <see cref="IAsset"/> within one selected storage account from <paramref name="storageAccountNames"/> based on the default <see cref="IAccountSelectionStrategy"/>.
        /// </summary>
        /// <param name="assets">The <see cref="AssetBaseCollection"/> instance.</param>
        /// <param name="assetName">The asset name.</param>
        /// <param name="strategy">The <see cref="IAccountSelectionStrategy"/> used to select a storage account for the new asset.</param>
        /// <param name="options">The <see cref="AssetCreationOptions"/>.</param>
        /// <returns>A new empty <see cref="IAsset"/> within one selected storage account from the provided <see cref="IAccountSelectionStrategy"/>.</returns>
        public static IAsset Create(this AssetBaseCollection assets, string assetName, IAccountSelectionStrategy strategy, AssetCreationOptions options)
        {
            if (assets == null)
            {
                throw new ArgumentNullException("assets");
            }

            if (strategy == null)
            {
                throw new ArgumentNullException("strategy");
            }

            string storageAccountName = strategy.SelectAccountForAsset();

            return assets.Create(assetName, storageAccountName, options);
        }
        public static IAsset CreateAssetAndUploadMultipleFiles(this CloudMediaContext cloudMediaContext, AssetCreationOptions assetCreationOptions, string folderPath)
        {
            var assetName = "UploadMultipleFiles_" + DateTime.UtcNow.ToString();

            var asset = cloudMediaContext.CreateEmptyAsset(assetName, assetCreationOptions);

            var accessPolicy = cloudMediaContext.AccessPolicies.Create(assetName, TimeSpan.FromDays(30),
                                                                AccessPermissions.Write | AccessPermissions.List);
            var locator = cloudMediaContext.Locators.CreateLocator(LocatorType.Sas, asset, accessPolicy);

            var blobTransferClient = new BlobTransferClient();
            blobTransferClient.NumberOfConcurrentTransfers = 20;
            blobTransferClient.ParallelTransferThreadCount = 20;

            blobTransferClient.TransferProgressChanged += blobTransferClient_TransferProgressChanged;

            var filePaths = Directory.EnumerateFiles(folderPath);

            Console.WriteLine("There are {0} files in {1}", filePaths.Count(), folderPath);

            if (!filePaths.Any())
            {
                throw new FileNotFoundException(String.Format("No files in directory, check folderPath: {0}", folderPath));
            }

            var uploadTasks = new List<Task>();
            foreach (var filePath in filePaths)
            {
                var assetFile = asset.AssetFiles.Create(Path.GetFileName(filePath));
                Console.WriteLine("Created assetFile {0}", assetFile.Name);

                // It is recommended to validate AccestFiles before upload.
                Console.WriteLine("Start uploading of {0}", assetFile.Name);
                uploadTasks.Add(assetFile.UploadAsync(filePath, blobTransferClient, locator, CancellationToken.None));
            }

            Task.WaitAll(uploadTasks.ToArray());
            Console.WriteLine("Done uploading the files");

            blobTransferClient.TransferProgressChanged -= blobTransferClient_TransferProgressChanged;

            locator.Delete();
            accessPolicy.Delete();

            return asset;
        }
        public static IAsset CreateAsset(CloudMediaContext datacontext, string filePath, AssetCreationOptions options)
        {
            IAsset asset = datacontext.Assets.Create(Guid.NewGuid().ToString(), options);
            IAccessPolicy policy = datacontext.AccessPolicies.Create("Write", TimeSpan.FromMinutes(5), AccessPermissions.Write);
            ILocator locator = datacontext.Locators.CreateSasLocator(asset, policy);
            var info = new FileInfo(filePath);
            IAssetFile file = asset.AssetFiles.Create(info.Name);
            BlobTransferClient blobTransferClient = datacontext.MediaServicesClassFactory.GetBlobTransferClient();
            blobTransferClient.NumberOfConcurrentTransfers = 5;
            blobTransferClient.ParallelTransferThreadCount = 5;
            file.UploadAsync(filePath,
                             blobTransferClient,
                             locator,
                             CancellationToken.None).Wait();
            file.IsPrimary = true;
            file.Update();

            return asset;
        }
        /// <summary>
        /// Returns a <see cref="IJob"/> instance with a single <see cref="ITask"/> ready to be submitted.
        /// </summary>
        /// <param name="jobs">The <see cref="JobBaseCollection"/> instance.</param>
        /// <param name="mediaProcessorName">The name of the media processor.</param>
        /// <param name="taskConfiguration">The task configuration.</param>
        /// <param name="inputAsset">The input <see cref="IAsset"/> instance.</param>
        /// <param name="outputAssetName">The name of the output asset.</param>
        /// <param name="outputAssetStorageAccountName">The name of the Storage Account where to store the output asset.</param>
        /// <param name="outputAssetOptions">The <see cref="AssetCreationOptions"/> of the output asset.</param>
        /// <returns>A <see cref="IJob"/> instance with a single <see cref="ITask"/> ready to be submitted.</returns>
        public static IJob CreateWithSingleTask(this JobBaseCollection jobs, string mediaProcessorName, string taskConfiguration, IAsset inputAsset, string outputAssetName, string outputAssetStorageAccountName, AssetCreationOptions outputAssetOptions)
        {
            if (jobs == null)
            {
                throw new ArgumentNullException("jobs", "The jobs collection cannot be null.");
            }

            if (inputAsset == null)
            {
                throw new ArgumentNullException("inputAsset", "The input asset cannot be null.");
            }

            MediaContextBase context = jobs.MediaContext;

            IMediaProcessor processor = context.MediaProcessors.GetLatestMediaProcessorByName(mediaProcessorName);
            if (processor == null)
            {
                throw new ArgumentException(
                    string.Format(CultureInfo.InvariantCulture, "Unknown media processor: '{0}'", mediaProcessorName), "mediaProcessorName");
            }

            IJob job = jobs.Create(string.Format(CultureInfo.InvariantCulture, "Job for {0}", inputAsset.Name));

            ITask task = job.Tasks.AddNew(
                string.Format(CultureInfo.InvariantCulture, "Task for {0}", inputAsset.Name),
                processor,
                taskConfiguration,
                TaskOptions.ProtectedConfiguration);

            task.InputAssets.Add(inputAsset);

            if (string.IsNullOrWhiteSpace(outputAssetStorageAccountName))
            {
                outputAssetStorageAccountName = context.DefaultStorageAccount.Name;
            }

            task.OutputAssets.AddNew(outputAssetName, outputAssetStorageAccountName, outputAssetOptions);

            return job;
        }
 /// <summary>
 /// Creates an asset for specified storage account. Asset does not contain any files and <see cref="AssetState" /> is Initialized.
 /// </summary>
 /// <param name="assetName">The asset name.</param>
 /// <param name="storageAccountName"></param>
 /// <param name="options">A <see cref="AssetCreationOptions" /> which will be associated with created asset.</param>
 /// <returns>
 /// The created asset.
 /// </returns>
 public override IAsset Create(string assetName, string storageAccountName, AssetCreationOptions options)
 {
     try
     {
         Task<IAsset> task = this.CreateAsync(assetName,storageAccountName, options, CancellationToken.None);
         task.Wait();
         return task.Result;
     }
     catch (AggregateException exception)
     {
         throw exception.InnerException;
     }
 }
 /// <summary>
 /// Creates an asset that does not contain any files and <see cref="AssetState"/> is Initialized. 
 /// </summary>
 /// <param name="assetName">The asset name.</param>
 /// <param name="options">A <see cref="AssetCreationOptions"/> which will be associated with created asset.</param>
 /// <returns>The created asset.</returns>
 public override IAsset Create(string assetName, AssetCreationOptions options)
 {
     return this.Create(assetName, this.MediaContext.DefaultStorageAccount.Name, options);
 }
        /// <summary>
        /// Asynchronously creates an asset for specified storage account. Asset  does not contain any files and <see cref="AssetState" /> is Initialized.
        /// </summary>
        /// <param name="assetName">The asset name.</param>
        /// <param name="storageAccountName">The storage account name</param>
        /// <param name="options">A <see cref="AssetCreationOptions" /> which will be associated with created asset.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>
        /// An <see cref="Task" /> of type <see cref="IAsset" />, where IAsset created according to the specified creation <paramref name="options" />.
        /// </returns>
        public override Task<IAsset> CreateAsync(string assetName, string storageAccountName, AssetCreationOptions options, CancellationToken cancellationToken)
        {
            AssetData emptyAsset = new AssetData
            {
                Name = assetName,
                Options = (int)options,
                StorageAccountName = storageAccountName
            };

            cancellationToken.ThrowIfCancellationRequested();
            IMediaDataServiceContext dataContext = this.MediaContext.MediaServicesClassFactory.CreateDataServiceContext();
            dataContext.AddObject(AssetSet, (IAsset)emptyAsset);

            MediaRetryPolicy retryPolicy = this.MediaContext.MediaServicesClassFactory.GetSaveChangesRetryPolicy();

            return retryPolicy.ExecuteAsync<IMediaDataServiceResponse>(() => dataContext.SaveChangesAsync(emptyAsset))
                .ContinueWith<IAsset>(
                    t =>
                    {
                        t.ThrowIfFaulted();
                        cancellationToken.ThrowIfCancellationRequested();

                        AssetData data = (AssetData)t.Result.AsyncState;
                        if (options.HasFlag(AssetCreationOptions.StorageEncrypted))
                        {
                            using (var fileEncryption = new NullableFileEncryption())
                            {
                                CreateStorageContentKey(data, fileEncryption, dataContext);
                            }
                        }

                        return data;
                    });
        }
 /// <summary>
 /// Asynchronously creates an asset that does not contain any files and <see cref="AssetState"/> is Initialized.
 /// </summary>
 /// <param name="assetName">The asset name.</param>
 /// <param name="options">A <see cref="AssetCreationOptions"/> which will be associated with created asset.</param>
 /// <param name="cancellationToken">The cancellation token.</param>
 /// <returns>
 /// An <see cref="Task"/> of type <see cref="IAsset"/>created according to the specified creation <paramref name="options"/>.
 /// </returns>
 public override Task<IAsset> CreateAsync(string assetName, AssetCreationOptions options,CancellationToken cancellationToken)
 {
     return this.CreateAsync(assetName, this.MediaContext.DefaultStorageAccount.Name, options, cancellationToken);
 }
        private async Task ProcessUploadFileAndMore(object name, int index, AssetCreationOptions assetcreationoptions, WatchFolderSettings watchfoldersettings = null, string storageaccount = null)
        {
            // If upload in the queue, let's wait our turn
            DoGridTransferWaitIfNeeded(index);

            if (storageaccount == null) storageaccount = _context.DefaultStorageAccount.Name; // no storage account or null, then let's take the default one

            TextBoxLogWriteLine("Starting upload of file '{0}'", name);
            bool Error = false;
            IAsset asset = null;
            try
            {
                asset = _context.Assets.CreateFromFile(
                                                      name as string,
                                                      storageaccount,
                                                      assetcreationoptions,
                                                      (af, p) =>
                                                      {
                                                          DoGridTransferUpdateProgress(p.Progress, index);
                                                      }
                                                      );
                AssetInfo.SetFileAsPrimary(asset, Path.GetFileName(name as string));
            }
            catch (Exception e)
            {
                Error = true;
                DoGridTransferDeclareError(index, e);
                TextBoxLogWriteLine("Error when uploading '{0}'", name, true);
                TextBoxLogWriteLine(e);
                if (watchfoldersettings != null && watchfoldersettings.SendEmailToRecipient != null)
                {
                    Program.CreateAndSendOutlookMail(watchfoldersettings.SendEmailToRecipient, "Explorer Watchfolder: upload error " + name, e.Message);
                }

            }
            if (!Error)
            {
                DoGridTransferDeclareCompleted(index, asset.Id);
                if (watchfoldersettings != null && watchfoldersettings.DeleteFile) //user checked the box "delete the file"
                {
                    try
                    {
                        File.Delete(name as string);
                        TextBoxLogWriteLine("File '{0}' deleted.", name);
                    }
                    catch (Exception e)
                    {
                        TextBoxLogWriteLine("Error when deleting '{0}'", name, true);
                        if (watchfoldersettings.SendEmailToRecipient != null) Program.CreateAndSendOutlookMail(watchfoldersettings.SendEmailToRecipient, "Explorer Watchfolder: Error when deleting " + asset.Name, e.Message);

                    }
                }

                if (watchfoldersettings != null && watchfoldersettings.JobTemplate != null) // option with watchfolder to run a job based on a job template
                {
                    string jobname = string.Format("Processing of {0} with template {1}", asset.Name, watchfoldersettings.JobTemplate.Name);
                    List<IAsset> assetlist = new List<IAsset>() { asset };
                    // if user wants to insert a workflow or other asstes as asset #0
                    if (watchfoldersettings.TypeInputExtraInput != TypeInputExtraInput.None)
                    {
                        if (watchfoldersettings.ExtraInputAssets != null) assetlist.InsertRange(0, watchfoldersettings.ExtraInputAssets);
                    }

                    TextBoxLogWriteLine(string.Format("Submitting job '{0}'", jobname));

                    // Submit the job
                    IJob job = _context.Jobs.Create(jobname, watchfoldersettings.JobTemplate, assetlist, Properties.Settings.Default.DefaultJobPriority);

                    try
                    {
                        job.Submit();
                    }
                    catch (Exception e)
                    {
                        // Add useful information to the exception
                        TextBoxLogWriteLine("There has been a problem when submitting the job '{0}'", job.Name, true);
                        TextBoxLogWriteLine(e);
                        if (watchfoldersettings.SendEmailToRecipient != null)
                        {
                            Program.CreateAndSendOutlookMail(watchfoldersettings.SendEmailToRecipient, "Explorer Watchfolder: Error when submitting job for asset " + asset.Name, e.Message);
                        }
                        return;
                    }

                    DoRefreshGridJobV(false);

                    IJob myjob = GetJob(job.Id);
                    while (myjob.State == JobState.Processing || myjob.State == JobState.Queued || myjob.State == JobState.Scheduled)
                    {
                        System.Threading.Thread.Sleep(1000);
                        myjob = GetJob(job.Id);
                    }
                    if (myjob.State == JobState.Finished)
                    {
                        // job template does not rename the output assets. As a fix, we do this:
                        int taskind = 1;
                        foreach (var task in myjob.Tasks)
                        {
                            int outputind = 1;
                            foreach (var outputasset in task.OutputAssets)
                            {
                                IAsset oasset = AssetInfo.GetAsset(outputasset.Id, _context);
                                try
                                {
                                    oasset.Name = string.Format("{0} processed with {1}", asset.Name, watchfoldersettings.JobTemplate.Name);
                                    if (myjob.Tasks.Count > 1)
                                    {
                                        oasset.Name += string.Format(" - task {0}", taskind);
                                    }
                                    if (task.OutputAssets.Count > 1)
                                    {
                                        oasset.Name += string.Format(" - output asset {0}", outputind);
                                    }
                                    oasset.Update();
                                    TextBoxLogWriteLine("Output asset {0} renamed.", oasset.Name);
                                }
                                catch (Exception e)
                                {
                                    TextBoxLogWriteLine("Error when renaming an output asset", true);
                                    TextBoxLogWriteLine(e);
                                }

                                outputind++;
                            }
                            taskind++;
                        }


                        if (watchfoldersettings.PublishOutputAssets) //user wants to publish the output asset when it has been processed by the job 
                        {
                            IAccessPolicy policy = _context.AccessPolicies.Create("AP:" + myjob.Name, TimeSpan.FromDays(Properties.Settings.Default.DefaultLocatorDurationDaysNew), AccessPermissions.Read);
                            foreach (var oasset in myjob.OutputMediaAssets)
                            {
                                ILocator MyLocator = _context.Locators.CreateLocator(LocatorType.OnDemandOrigin, oasset, policy, null);
                                if (watchfoldersettings.SendEmailToRecipient != null)
                                {
                                    IStreamingEndpoint SelectedSE = AssetInfo.GetBestStreamingEndpoint(_context);
                                    StringBuilder sb = new StringBuilder();
                                    Uri SmoothUri = MyLocator.GetSmoothStreamingUri();
                                    if (SmoothUri != null)
                                    {
                                        string playbackurl = AssetInfo.DoPlayBackWithStreamingEndpoint(PlayerType.AzureMediaPlayer, SmoothUri.AbsoluteUri, _context, this, oasset, launchbrowser: false, UISelectSEFiltersAndProtocols: false);
                                        sb.AppendLine("Link to playback the asset:");
                                        sb.AppendLine(playbackurl);
                                        sb.AppendLine();
                                    }
                                    sb.Append(AssetInfo.GetStat(oasset, SelectedSE));
                                    Program.CreateAndSendOutlookMail(watchfoldersettings.SendEmailToRecipient, "Explorer Watchfolder: Output asset published for asset " + asset.Name, sb.ToString());
                                }
                            }
                        }
                        else // no publication
                        {
                            foreach (var oasset in myjob.OutputMediaAssets)
                            {
                                if (watchfoldersettings.SendEmailToRecipient != null)
                                {
                                    StringBuilder sb = new StringBuilder();
                                    sb.Append(AssetInfo.GetStat(oasset));

                                    Program.CreateAndSendOutlookMail(watchfoldersettings.SendEmailToRecipient, "Explorer Watchfolder: asset uploaded and processed " + asset.Name, sb.ToString());
                                }
                            }

                        }
                    }
                    else  // not completed successfuly
                    {
                        if (watchfoldersettings.SendEmailToRecipient != null)
                        {
                            StringBuilder sb = new StringBuilder();
                            sb.Append((new JobInfo(job).GetStats()));
                            Program.CreateAndSendOutlookMail(watchfoldersettings.SendEmailToRecipient, "Explorer Watchfolder: job " + job.State.ToString() + " for asset " + asset.Name, sb.ToString());
                        }
                    }
                }
                else // user selected no processing. Upload successfull
                {
                    if (watchfoldersettings != null && watchfoldersettings.SendEmailToRecipient != null)
                    {
                        StringBuilder sb = new StringBuilder();
                        sb.Append(AssetInfo.GetStat(asset));
                        Program.CreateAndSendOutlookMail(watchfoldersettings.SendEmailToRecipient, "Explorer Watchfolder: upload successful " + asset.Name, sb.ToString());
                    }
                }
            }
            DoRefreshGridAssetV(false);
        }
        private void CreateEncryptUpdateDelete(AssetCreationOptions assetCreationOptions)
        {
            var manifest = _mediaContext.IngestManifests.Create(Guid.NewGuid().ToString(), _mediaContext.DefaultStorageAccount.Name);
             Assert.IsNotNull(manifest);

             IAsset asset = _mediaContext.Assets.Create(Guid.NewGuid().ToString(), assetCreationOptions);
             string tempFileName = Path.GetTempFileName();
             try
             {
                 var ingestManifestAsset = manifest.IngestManifestAssets.Create(asset, new[] {tempFileName});
                 Assert.IsNotNull(ingestManifestAsset);
                 Assert.IsNotNull(ingestManifestAsset.IngestManifestFiles);
                 Assert.IsNotNull(ingestManifestAsset.Asset);
                 Assert.AreEqual(1, ingestManifestAsset.IngestManifestFiles.Count());
                 var assetfile = ingestManifestAsset.IngestManifestFiles.FirstOrDefault();
                 Assert.IsFalse(string.IsNullOrEmpty(assetfile.Name));

                 Assert.AreEqual(IngestManifestFileState.Pending, assetfile.State);

                 var output = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()));
                 try
                 {
                     Assert.AreEqual(0, output.GetFiles().Count(), "Expecting 0 files before manifest encryption");
                     File.WriteAllText(tempFileName, Guid.NewGuid().ToString());
                     manifest.EncryptFiles(output.FullName);
                     Assert.AreEqual(1, output.GetFiles().Count(), "Expecting 1 file after manifest encryption");
                     Assert.IsTrue(output.GetFiles().FirstOrDefault().Length > 0);
                 }
                 finally
                 {
                     output.Delete(true);
                 }
                 manifest.Name = Guid.NewGuid().ToString();
                 manifest.Update();
                 assetfile.Delete();
                 ingestManifestAsset.Delete();
                 manifest.Delete();
             }
             finally
             {
                 File.Delete(tempFileName);
             }
        }
        private IAsset GetTestAsset(AssetCreationOptions options, AssetType assetType, AssetDeliveryProtocol protocol, AssetDeliveryPolicyType deliveryType)
        {
            IAsset asset = _mediaContext.Assets.Create("Test", options);

            AddTestAssetFiles(asset, assetType);

            AddTestDeliveryPolicies(asset, protocol, deliveryType);

            return asset;
        }
        private IAsset CreateMbrMp4Asset(AssetCreationOptions options)
        {
            IMediaProcessor encoder = JobTests.GetEncoderMediaProcessor(_mediaContext);
            IJob job = _mediaContext.Jobs.Create("Job for ValidateEffectiveEncryptionStatusOfMultiBitRateMP4");

            ITask adpativeBitrateTask = job.Tasks.AddNew("MP4 to Adaptive Bitrate Task",
                encoder,
                "H264 Adaptive Bitrate MP4 Set 720p",
                TaskOptions.None);

            // Specify the input Asset
            IAsset asset = AssetTests.CreateAsset(_mediaContext, WindowsAzureMediaServicesTestConfiguration.SmallMp41, AssetCreationOptions.None);
            adpativeBitrateTask.InputAssets.Add(asset);

            // Add an output asset to contain the results of the job.
            // This output is specified as AssetCreationOptions.None, which
            // means the output asset is in the clear (unencrypted).
            IAsset abrAsset = adpativeBitrateTask.OutputAssets.AddNew("Multibitrate MP4s", options);

            job.Submit();

            job.GetExecutionProgressTask(CancellationToken.None).Wait();

            job.Refresh();

            return job.OutputMediaAssets[0];
        }
 /// <summary>
 /// Asynchronously creates an asset that does not contain any files and <see cref="AssetState"/> is Initialized.
 /// </summary>
 /// <param name="assetName">The asset name.</param>
 /// <param name="options">A <see cref="AssetCreationOptions"/> which will be associated with created asset.</param>
 /// <param name="cancellationToken">The cancellation token.</param>
 /// <returns>
 /// An <see cref="Task"/> of type <see cref="IAsset"/>created according to the specified creation <paramref name="options"/>.
 /// </returns>
 public override Task<IAsset> CreateAsync(string assetName, AssetCreationOptions options, CancellationToken cancellationToken)
 {
     IStorageAccount defaultStorageAccount = this.MediaContext.DefaultStorageAccount;
     if (defaultStorageAccount == null)
     {
         throw new InvalidOperationException(StringTable.DefaultStorageAccountIsNull);
     }
     return this.CreateAsync(assetName, defaultStorageAccount.Name, options, cancellationToken);
 }
        private async Task ProcessUploadFromFolder(object folderPath, int index, AssetCreationOptions assetcreationoption, string storageaccount = null)
        {
            // If upload in the queue, let's wait our turn
            DoGridTransferWaitIfNeeded(index);
            if (storageaccount == null) storageaccount = _context.DefaultStorageAccount.Name; // no storage account or null, then let's take the default one

            var filePaths = Directory.EnumerateFiles(folderPath as string);

            TextBoxLogWriteLine("There are {0} files in {1}", filePaths.Count().ToString(), (folderPath as string));
            if (!filePaths.Any())
            {
                throw new FileNotFoundException(String.Format("No files in directory, check folderPath: {0}", folderPath));
            }
            bool Error = false;

            IAsset asset = null;

            var progress = new Dictionary<string, double>(); // used to store progress of all files
            filePaths.ToList().ForEach(f => progress[Path.GetFileName(f)] = 0d);

            try
            {
                asset = _context.Assets.CreateFromFolder(
                                                               folderPath as string,
                                                               storageaccount,
                                                               assetcreationoption,
                                                               (af, p) =>
                                                               {
                                                                   progress[af.Name] = p.Progress;
                                                                   DoGridTransferUpdateProgress(progress.ToList().Average(l => l.Value), index);
                                                               }
                                                               );
                //SetISMFileAsPrimary(asset); // no need as primary seems to be set by .CreateFromFolder
            }
            catch (Exception e)
            {
                Error = true;
                DoGridTransferDeclareError(index, e);
                TextBoxLogWriteLine("Error when uploading from {0}", folderPath, true);
            }
            if (!Error)
            {
                DoGridTransferDeclareCompleted(index, asset.Id);
            }
            DoRefreshGridAssetV(false);
        }
        /// <summary>
        /// Returns a <see cref="IJob"/> instance with a single <see cref="ITask"/> ready to be submitted.
        /// </summary>
        /// <param name="jobs">The <see cref="JobBaseCollection"/> instance.</param>
        /// <param name="mediaProcessorName">The name of the media processor.</param>
        /// <param name="taskConfiguration">The task configuration.</param>
        /// <param name="inputAsset">The input <see cref="IAsset"/> instance.</param>
        /// <param name="strategy">The <see cref="IAccountSelectionStrategy"/> instance used to pick the output asset storage account.</param>
        /// <param name="outputAssetName">The name of the output asset.</param>
        /// <param name="outputAssetOptions">The <see cref="AssetCreationOptions"/> of the output asset.</param>
        /// <returns>A <see cref="IJob"/> instance with a single <see cref="ITask"/> ready to be submitted.</returns>
        public static IJob CreateWithSingleTask(this JobBaseCollection jobs, string mediaProcessorName, string taskConfiguration, IAsset inputAsset, IAccountSelectionStrategy strategy, string outputAssetName, AssetCreationOptions outputAssetOptions)
        {
            if (strategy == null)
            {
                throw new ArgumentNullException("strategy");
            }

            string outputAssetStorageAccount = strategy.SelectAccountForAsset();

            return jobs.CreateWithSingleTask(mediaProcessorName, taskConfiguration, inputAsset, outputAssetName, outputAssetStorageAccount, outputAssetOptions);
        }
        /// <summary>
        /// Uploads a single file.
        /// </summary>
        /// <param name="fileDir">The location of the files.</param>
        /// <param name="assetCreationOptions">
        ///  You can specify the following encryption options for the AssetCreationOptions.
        ///      None:  no encryption.  
        ///      StorageEncrypted: storage encryption. Encrypts a clear input file 
        ///        before it is uploaded to Azure storage. 
        ///      CommonEncryptionProtected: for Common Encryption Protected (CENC) files. 
        ///        For example, a set of files that are already PlayReady encrypted. 
        ///      EnvelopeEncryptionProtected: for HLS with AES encryption files.
        ///        NOTE: The files must have been encoded and encrypted by Transform Manager. 
        ///     </param>
        /// <returns>Returns an asset that contains a single file.</returns>
        /// </summary>
        /// <returns></returns>
        private static IAsset IngestSingleMP4File(string fileDir, AssetCreationOptions assetCreationOptions)
        {
            // Use the SDK extension method to create a new asset by 
            // uploading a mezzanine file from a local path.
            IAsset asset = _context.Assets.CreateFromFile(
                fileDir,
                assetCreationOptions,
                (af, p) =>
                {
                    Console.WriteLine("Uploading '{0}' - Progress: {1:0.##}%", af.Name, p.Progress);
                });
 
            return asset;
        }
 /// <summary>
 /// Returns a <see cref="IJob"/> instance with a single <see cref="ITask"/> ready to be submitted.
 /// </summary>
 /// <param name="jobs">The <see cref="JobBaseCollection"/> instance.</param>
 /// <param name="mediaProcessorName">The name of the media processor.</param>
 /// <param name="taskConfiguration">The task configuration.</param>
 /// <param name="inputAsset">The input <see cref="IAsset"/> instance.</param>
 /// <param name="outputAssetName">The name of the output asset.</param>
 /// <param name="outputAssetOptions">The <see cref="AssetCreationOptions"/> of the output asset.</param>
 /// <returns>A <see cref="IJob"/> instance with a single <see cref="ITask"/> ready to be submitted.</returns>
 public static IJob CreateWithSingleTask(this JobBaseCollection jobs, string mediaProcessorName, string taskConfiguration, IAsset inputAsset, string outputAssetName, AssetCreationOptions outputAssetOptions)
 {
     return jobs.CreateWithSingleTask(mediaProcessorName, taskConfiguration, inputAsset, outputAssetName, null, outputAssetOptions);
 }
        private void DoProcessCreateBulkIngestAndEncryptFiles(string IngestName, string IngestStorage, List<BulkUpload.BulkAsset> assetFiles, string assetStorage, AssetCreationOptions creationoption, string encryptToFolder, bool GenerateAzCopy, bool GenerateSigniant, List<string> SigniantServers, string SigniantAPIKey, bool GenerateAspera)
        {
            TextBoxLogWriteLine("Creating bulk ingest '{0}'...", IngestName);
            IIngestManifest manifest = _context.IngestManifests.Create(IngestName, IngestStorage);

            // Create the assets that will be associated with this bulk ingest manifest
            foreach (var asset in assetFiles)
            {
                try
                {
                    IAsset destAsset = _context.Assets.Create(asset.AssetName, assetStorage, creationoption);
                    IIngestManifestAsset bulkAsset = manifest.IngestManifestAssets.Create(destAsset, asset.AssetFiles);
                }
                catch (Exception ex)
                {
                    TextBoxLogWriteLine("Bulk: Error when declaring asset '{0}'.", asset.AssetName, true);
                    TextBoxLogWriteLine(ex);
                    return;
                }
            }
            TextBoxLogWriteLine("Bulk: {0} asset(s) / {1} file(s) declared for bulk ingest container '{2}'.", assetFiles.Count, manifest.Statistics.PendingFilesCount, manifest.Name);


            // Encryption of files
            bool Error = false;
            if (creationoption == AssetCreationOptions.StorageEncrypted)
            {

                TextBoxLogWriteLine("Encryption of asset files for bulk upload...");
                try
                {
                    manifest.EncryptFilesAsync(encryptToFolder, CancellationToken.None).Wait();
                    TextBoxLogWriteLine("Encryption of asset files done to folder {0}.", encryptToFolder);
                    Process.Start(encryptToFolder);
                }
                catch
                {
                    TextBoxLogWriteLine("Error when encrypting files to folder '{0}'.", encryptToFolder, true);
                    Error = true;
                }
            }

            if (!Error)
            {
                TextBoxLogWriteLine("You can upload the file(s) to {0}", manifest.BlobStorageUriForUpload);
                if (creationoption == AssetCreationOptions.StorageEncrypted)
                {
                    TextBoxLogWriteLine("Encrypted files are in {0}", encryptToFolder);
                }
                if (GenerateAspera)
                {
                    string commandline = GenerateAsperaUrl(manifest);
                    var form = new EditorXMLJSON("Aspera Ingest URL", commandline, false, false, false);
                    form.Display();
                }

                if (GenerateSigniant)
                {
                    string commandline = GenerateSigniantCommandLine(manifest, assetFiles, creationoption == AssetCreationOptions.StorageEncrypted, encryptToFolder, SigniantServers, SigniantAPIKey);
                    var form = new EditorXMLJSON("Signiant Command Line", commandline, false, false, false);
                    form.Display();
                }

                if (GenerateAzCopy)
                {
                    string commandline = GenerateAzCopyCommandLine(manifest, assetFiles, creationoption == AssetCreationOptions.StorageEncrypted, encryptToFolder);
                    var form = new EditorXMLJSON("AzCopy Command Line", commandline, false, false, false);
                    form.Display();
                }
            }
            DoRefreshGridIngestManifestV(false);
        }
        public void LaunchJobs_OneJobPerInputAssetWithSpecificConfig(IMediaProcessor processor, List<IAsset> selectedassets, string jobname, int jobpriority, string taskname, string outputassetname, List<string> configuration, AssetCreationOptions myAssetCreationOptions, TaskOptions myTaskOptions, string storageaccountname = "")
        {
            // a job per asset, one task per job, but each task has a specific config
            Task.Factory.StartNew(() =>
            {
                int index = -1;

                foreach (IAsset asset in selectedassets)
                {
                    index++;
                    string jobnameloc = jobname.Replace(Constants.NameconvInputasset, asset.Name);
                    IJob myJob = _context.Jobs.Create(jobnameloc, jobpriority);
                    string config = configuration[index];

                    string tasknameloc = taskname.Replace(Constants.NameconvInputasset, asset.Name).Replace(Constants.NameconvAMEpreset, config);
                    ITask myTask = myJob.Tasks.AddNew(
                           tasknameloc,
                          processor,
                          config,
                          myTaskOptions);

                    myTask.InputAssets.Add(asset);

                    // Add an output asset to contain the results of the task
                    string outputassetnameloc = outputassetname.Replace(Constants.NameconvInputasset, asset.Name).Replace(Constants.NameconvAMEpreset, config);
                    if (storageaccountname == "")
                    {
                        myTask.OutputAssets.AddNew(outputassetnameloc, asset.StorageAccountName, myAssetCreationOptions); // let's use the same storage account than the input asset
                    }
                    else
                    {
                        myTask.OutputAssets.AddNew(outputassetnameloc, storageaccountname, myAssetCreationOptions);
                    }


                    // Submit the job and wait until it is completed. 
                    bool Error = false;
                    try
                    {
                        TextBoxLogWriteLine("Job '{0}' : submitting...", jobnameloc);
                        myJob.Submit();
                    }

                    catch (Exception ex)
                    {
                        // Add useful information to the exception
                        TextBoxLogWriteLine("Job '{0}' : problem", jobnameloc, true);
                        TextBoxLogWriteLine(ex);
                        Error = true;
                    }
                    if (!Error)
                    {
                        TextBoxLogWriteLine("Job '{0}' : submitted.", jobnameloc);
                        Task.Factory.StartNew(() => dataGridViewJobsV.DoJobProgress(myJob));
                    }
                    TextBoxLogWriteLine();
                }

                DotabControlMainSwitch(Constants.TabJobs);
                DoRefreshGridJobV(false);

            }

                );
        }
        internal static IAsset CreateSmoothAsset(CloudMediaContext mediaContext, string[] filePaths, AssetCreationOptions options)
        {
            IAsset asset = mediaContext.Assets.Create(Guid.NewGuid().ToString(), options);
            IAccessPolicy policy = mediaContext.AccessPolicies.Create("Write", TimeSpan.FromMinutes(5), AccessPermissions.Write);
            ILocator locator = mediaContext.Locators.CreateSasLocator(asset, policy);
            var blobclient = new BlobTransferClient
            {
                NumberOfConcurrentTransfers = 5,
                ParallelTransferThreadCount = 5
            };

            foreach (string filePath in filePaths)
            {
                var info = new FileInfo(filePath);
                IAssetFile file = asset.AssetFiles.Create(info.Name);
                file.UploadAsync(filePath, blobclient, locator, CancellationToken.None).Wait();
                if (WindowsAzureMediaServicesTestConfiguration.SmallIsm == filePath)
                {
                    file.IsPrimary = true;
                    file.Update();
                }
            }
            return asset;
        }
        public void LaunchJobs(IMediaProcessor processor, List<IAsset> selectedassets, string jobname, int jobpriority, string taskname, string outputassetname, List<string> configuration, AssetCreationOptions myAssetCreationOptions, TaskOptions myTaskOptions, string storageaccountname = "")
        {
            foreach (IAsset asset in selectedassets)
            {
                string jobnameloc = jobname.Replace(Constants.NameconvInputasset, asset.Name);
                IJob myJob = _context.Jobs.Create(jobnameloc, jobpriority);
                foreach (string config in configuration)
                {
                    string tasknameloc = taskname.Replace(Constants.NameconvInputasset, asset.Name).Replace(Constants.NameconvAMEpreset, config);
                    ITask myTask = myJob.Tasks.AddNew(
                           tasknameloc,
                          processor,
                          config,
                          myTaskOptions);

                    myTask.InputAssets.Add(asset);

                    // Add an output asset to contain the results of the task
                    string outputassetnameloc = outputassetname.Replace(Constants.NameconvInputasset, asset.Name).Replace(Constants.NameconvAMEpreset, config);
                    if (storageaccountname == "")
                    {
                        myTask.OutputAssets.AddNew(outputassetnameloc, asset.StorageAccountName, myAssetCreationOptions); // let's use the same storage account than the input asset
                    }
                    else
                    {
                        myTask.OutputAssets.AddNew(outputassetnameloc, storageaccountname, myAssetCreationOptions);
                    }
                }


                // Submit the job and wait until it is completed. 
                try
                {
                    myJob.Submit();
                }
                catch (Exception e)
                {
                    // Add useful information to the exception
                    if (selectedassets.Count < 5)  // only if 4 or less jobs submitted
                    {
                        MessageBox.Show(string.Format("There has been a problem when submitting the job '{0}'", jobnameloc) + Constants.endline + Constants.endline + Program.GetErrorMessage(e), "Job Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                    // Add useful information to the exception
                    TextBoxLogWriteLine("There has been a problem when submitting the job {0}.", jobnameloc, true);
                    TextBoxLogWriteLine(e);
                    return;
                }
                TextBoxLogWriteLine("Job '{0}' submitted.", jobnameloc);
                Task.Factory.StartNew(() => dataGridViewJobsV.DoJobProgress(myJob));
            }
            DotabControlMainSwitch(Constants.TabJobs);
            DoRefreshGridJobV(false);
        }