예제 #1
0
        private static void AddFileToExistingManifestAssetInfo(CloudMediaContext context, string id)
        {
            IIngestManifest ingestManifest = context.IngestManifests.Where(c => c.Id == id).FirstOrDefault();

            Assert.IsNotNull(ingestManifest);
            Assert.IsNotNull(ingestManifest.IngestManifestAssets);
            int expectedFilesCount = context.IngestManifestFiles.Where(c => c.ParentIngestManifestId == ingestManifest.Id).Count();


            foreach (IIngestManifestAsset assetInfo in ingestManifest.IngestManifestAssets)
            {
                Assert.IsNotNull(assetInfo.IngestManifestFiles);
                //Enumerating through all files
                foreach (IIngestManifestFile file in assetInfo.IngestManifestFiles)
                {
                    VerifyManifestFile(file);
                }

                //Adding new file to collection
            }
            var firstOrDefault = ingestManifest.IngestManifestAssets.FirstOrDefault();

            Assert.IsNotNull(firstOrDefault);

            IIngestManifestFile addedFile = firstOrDefault.IngestManifestFiles.Create(InterviewWmv);

            VerifyManifestFile(addedFile);
            expectedFilesCount++;
            int filesCountFinal = context.IngestManifestFiles.Where(c => c.ParentIngestManifestId == ingestManifest.Id).Count();

            Assert.AreEqual(expectedFilesCount, filesCountFinal);
        }
예제 #2
0
        public void ListAssetsAndFilesForNewlyCreatedManifests()
        {
            IIngestManifest ingestManifest = CreateEmptyManifestAndVerifyIt();

            IAsset asset = _mediaContext.Assets.Create("name", AssetCreationOptions.None);

            Assert.IsNotNull(asset);
            IIngestManifestAsset ingestManifestAsset = ingestManifest.IngestManifestAssets.Create(asset, new[] { TestFile1 });

            VerifyManifestAsset(ingestManifestAsset);
            IIngestManifestAsset firstAsset = ingestManifest.IngestManifestAssets.FirstOrDefault();

            VerifyManifestAsset(firstAsset);
            Assert.AreEqual(ingestManifestAsset.Id, firstAsset.Id);

            _mediaContext = WindowsAzureMediaServicesTestConfiguration.CreateCloudMediaContext();
            IIngestManifest sameIngestManifest = _mediaContext.IngestManifests.Where(c => c.Id == ingestManifest.Id).FirstOrDefault();

            Assert.IsNotNull(sameIngestManifest);
            Assert.AreEqual(1, sameIngestManifest.IngestManifestAssets.Count(), "Manifest asset count is not matching expecting value 1");
            firstAsset = sameIngestManifest.IngestManifestAssets.FirstOrDefault();
            VerifyManifestAsset(firstAsset);
            Assert.AreEqual(1, firstAsset.IngestManifestFiles.Count(), "Manifest file count is not matching expecting value 1");
            IIngestManifestFile firstFile = firstAsset.IngestManifestFiles.FirstOrDefault();

            Assert.AreEqual("text/plain", firstFile.MimeType, "IngestManifestFile's MimeType is wrong");
            VerifyManifestFile(firstFile);
        }
예제 #3
0
        public void EncryptManifestTestDisableOverwriteExistingFile()
        {
            CloudMediaContext context = WindowsAzureMediaServicesTestConfiguration.CreateCloudMediaContext();
            var sourcePath            = DeploymentFolder1;

            Assert.IsTrue(Directory.Exists(sourcePath));
            List <string>   files                 = Directory.EnumerateFiles(sourcePath, "*.txt").ToList();
            const string    manifestName          = "Manifest 1";
            IIngestManifest ingestManifestCreated = context.IngestManifests.Create(manifestName);

            //Adding manifest asset info with multiple file
            IAsset emptyAsset = context.Assets.Create(Guid.NewGuid().ToString(), AssetCreationOptions.StorageEncrypted);

            IIngestManifestAsset ingestManifestAsset = ingestManifestCreated.IngestManifestAssets.Create(emptyAsset, files.ToArray());

            var path = @".\Resources\TestFiles\" + Guid.NewGuid();

            try
            {
                Directory.CreateDirectory(path);
                string dupFileName = Path.Combine(path, Path.GetFileName(files[0]));
                File.WriteAllText(dupFileName, "");
                ingestManifestCreated.EncryptFiles(path, false);
            }
            catch (AggregateException ax)
            {
                var expectedExcpetion = ax.GetBaseException() as IOException;
                throw expectedExcpetion;
            }
            finally
            {
                AssetFilesTests.CleanDirectory(path);
            }
        }
예제 #4
0
        private static void VerifyManifestDeletion(string id)
        {
            CloudMediaContext context      = WindowsAzureMediaServicesTestConfiguration.CreateCloudMediaContext();
            IIngestManifest   expectedNull = context.IngestManifests.Where(c => c.Id == id).FirstOrDefault();

            Assert.IsNull(expectedNull, "Manifest has not been deleted as expected");
        }
        private static void EncryptFilesDecryptAndCompare(List <string> files)
        {
            CloudMediaContext context = WindowsAzureMediaServicesTestConfiguration.CreateCloudMediaContext();
            //Creating empty manifest
            const string    manifestName          = "Manifest 1";
            IIngestManifest ingestManifestCreated = context.IngestManifests.Create(manifestName);

            //Adding manifest asset info with multiple file
            IAsset emptyAsset = context.Assets.Create(Guid.NewGuid().ToString(), AssetCreationOptions.StorageEncrypted);

            IIngestManifestAsset ingestManifestAsset = ingestManifestCreated.IngestManifestAssets.CreateAsync(emptyAsset, files.ToArray(), CancellationToken.None).Result;

            var path = @".\Resources\TestFiles\" + Guid.NewGuid();

            Directory.CreateDirectory(path);
            ingestManifestCreated.EncryptFiles(path);

            Dictionary <string, string> filePaths = new Dictionary <string, string>();

            foreach (var filePath in files)
            {
                FileInfo fileInfo = new FileInfo(filePath);
                filePaths.Add(fileInfo.Name, filePath);
            }


            foreach (var assetFile in ingestManifestAsset.IngestManifestFiles)
            {
                var encryptedPath = Path.Combine(path, assetFile.Name);
                Assert.IsTrue(File.Exists(encryptedPath));
                var decryptedPath = DecryptedFile(assetFile, encryptedPath, context);
                Assert.IsTrue(AssetTests.CompareFiles(decryptedPath, filePaths[assetFile.Name]), "Original file and Decrypted are not same");
            }
        }
        public void ShouldThrowKeyNotFoundExceptionDuringEncryptIfKeyIsMissing()
        {
            var sourcePath = DeploymentFolder1;

            Assert.IsTrue(Directory.Exists(sourcePath));
            List <string> files = Directory.EnumerateFiles(sourcePath, "*.txt").ToList();

            //Creating empty manifest
            const string    manifestName          = "Manifest 1";
            IIngestManifest ingestManifestCreated = _context.IngestManifests.Create(manifestName);

            //Adding manifest asset info with multiple file
            IAsset emptyAsset = _context.Assets.Create(Guid.NewGuid().ToString(), AssetCreationOptions.StorageEncrypted);

            IIngestManifestAsset ingestManifestAsset = ingestManifestCreated.IngestManifestAssets.CreateAsync(emptyAsset, files.ToArray(), CancellationToken.None).Result;

            Assert.IsNotNull(ingestManifestAsset);

            //According to last REST implementation breaking a link
            //also deleting a key on server side if no other links are found
            emptyAsset.ContentKeys.RemoveAt(0);

            var path = @".\Resources\TestFiles\" + Guid.NewGuid();

            Directory.CreateDirectory(path);
            try
            {
                ingestManifestCreated.EncryptFiles(path);
            }
            catch (AggregateException ex)
            {
                Assert.AreEqual(1, ex.InnerExceptions.Count);
                throw ex.InnerExceptions[0];
            }
        }
예제 #7
0
        private Task <IIngestManifestAsset> CreateAsync(IIngestManifest ingestManifest, IAsset asset, CancellationToken token, Action <IngestManifestAssetData> continueWith)
        {
            IngestManifestCollection.VerifyManifest(ingestManifest);

            IMediaDataServiceContext dataContext = MediaContext.MediaServicesClassFactory.CreateDataServiceContext();
            var data = new IngestManifestAssetData
            {
                ParentIngestManifestId = ingestManifest.Id
            };


            dataContext.AddObject(IngestManifestAssetCollection.EntitySet, data);
            dataContext.AttachTo(AssetCollection.AssetSet, asset);
            dataContext.SetLink(data, "Asset", asset);

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

            Task <IIngestManifestAsset> task = retryPolicy.ExecuteAsync <IMediaDataServiceResponse>(() => dataContext.SaveChangesAsync(data))
                                               .ContinueWith <IIngestManifestAsset>(t =>
            {
                t.ThrowIfFaulted();
                token.ThrowIfCancellationRequested();
                IngestManifestAssetData ingestManifestAsset = (IngestManifestAssetData)t.Result.AsyncState;
                continueWith(ingestManifestAsset);
                return(ingestManifestAsset);
            }, TaskContinuationOptions.ExecuteSynchronously);

            return(task);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="IngestManifestAssetCollection"/> class.
 /// </summary>
 /// <param name="cloudMediaContext">The <seealso cref="CloudMediaContext"/> instance.</param>
 /// <param name="parentIngestManifest">parent manifest if collection associated with manifest </param>
 internal IngestManifestAssetCollection(CloudMediaContext cloudMediaContext, IIngestManifest parentIngestManifest)
 {
     _cloudMediaContext    = cloudMediaContext;
     _dataContext          = _cloudMediaContext.DataContextFactory.CreateDataServiceContext();
     _parentIngestManifest = parentIngestManifest;
     _query = new Lazy <IQueryable <IIngestManifestAsset> >(() => _dataContext.CreateQuery <IngestManifestAssetData>(EntitySet));
 }
예제 #9
0
        private static void VerifyAssetStateAndDelete(IngestManifestState expectedState, string id)
        {
            IIngestManifest ingestManifest = WindowsAzureMediaServicesTestConfiguration.CreateCloudMediaContext().IngestManifests.Where(c => c.Id == id).FirstOrDefault();

            Assert.IsNotNull(ingestManifest);
            Assert.AreEqual(expectedState, ingestManifest.State);
            ingestManifest.Delete();
        }
예제 #10
0
        private static void VerifyNameForExitingManifest(IIngestManifest ingestManifest, string newName, string id)
        {
            CloudMediaContext context = WindowsAzureMediaServicesTestConfiguration.CreateCloudMediaContext();
            IIngestManifest   updatedIngestManifest = context.IngestManifests.Where(c => c.Id == id).FirstOrDefault();

            Assert.IsNotNull(updatedIngestManifest);
            Assert.AreSame(newName, ingestManifest.Name);
        }
 public BulkContainerInfo(Mainform mainform, CloudMediaContext context, IIngestManifest manifest)
 {
     InitializeComponent();
     this.Icon  = Bitmaps.Azure_Explorer_ico;
     MyMainForm = mainform;
     MyContext  = context;
     _manifest  = manifest;
 }
 public BulkContainerInfo(Mainform mainform, CloudMediaContext context, IIngestManifest manifest)
 {
     InitializeComponent();
     this.Icon = Bitmaps.Azure_Explorer_ico;
     MyMainForm = mainform;
     MyContext = context;
     _manifest = manifest;
 }
예제 #13
0
        private static void VerifyExistenceofAssetsAndFilesForManifest(IIngestManifest ingestManifest, CloudMediaContext context)
        {
            int assetsCount = context.IngestManifestAssets.Where(c => c.ParentIngestManifestId == ingestManifest.Id).Count();
            int filescount  = context.IngestManifestFiles.Where(c => c.ParentIngestManifestId == ingestManifest.Id).Count();

            Assert.IsTrue(assetsCount > 0, "When manifest is empty we are expecting to have associated assets");
            Assert.IsTrue(filescount > 0, "When manifest is empty we are expecting to have associated files");
        }
예제 #14
0
        public void CreateEmptyBulkIngestManifestAsync()
        {
            CloudMediaContext      context        = WindowsAzureMediaServicesTestConfiguration.CreateCloudMediaContext();
            const string           manifestName   = "";
            Task <IIngestManifest> taskManifest   = context.IngestManifests.CreateAsync(manifestName);
            IIngestManifest        ingestManifest = taskManifest.Result;

            Assert.IsTrue(String.IsNullOrEmpty(ingestManifest.Name));
        }
예제 #15
0
        private IIngestManifest CreateEmptyManifestAndVerifyIt()
        {
            const string    manifestName   = "TestManifest";
            IIngestManifest ingestManifest = _mediaContext.IngestManifests.Create(manifestName);

            Assert.IsNotNull(ingestManifest);
            Assert.IsFalse(String.IsNullOrEmpty(ingestManifest.Id), "Manifest Id is null or empty");
            Assert.AreEqual(IngestManifestState.Inactive, ingestManifest.State, "Unexpected manifest state.Expected value is InActive");
            Assert.AreEqual(0, ingestManifest.IngestManifestAssets.Count(), "Newly created asset should not contain any assets");
            Assert.AreEqual(0, _mediaContext.IngestManifestAssets.Where(c => c.ParentIngestManifestId == ingestManifest.Id).Count(), "Newly created asset should not contain any assets");
            return(ingestManifest);
        }
예제 #16
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);
        }
예제 #17
0
        public void DeleteManifestShouldDeleteAllManifestAssetsAndFiles()
        {
            CloudMediaContext context        = WindowsAzureMediaServicesTestConfiguration.CreateCloudMediaContext();
            IIngestManifest   ingestManifest = CreateManifestWithAssetsAndVerifyIt(context);

            VerifyExistenceofAssetsAndFilesForManifest(ingestManifest, context);
            ingestManifest.Delete();
            context = WindowsAzureMediaServicesTestConfiguration.CreateCloudMediaContext();
            int assetsCount = context.IngestManifestAssets.Where(c => c.ParentIngestManifestId == ingestManifest.Id).Count();
            int filescount  = context.IngestManifestFiles.Where(c => c.ParentIngestManifestId == ingestManifest.Id).Count();

            Assert.AreEqual(0, assetsCount, "There are assets belonging to manifest after manifest deletion");
            Assert.AreEqual(0, filescount, "There are files belonging to manifest assets after manifest deletion");
        }
예제 #18
0
        public void CreateEmptyManifestAndDeleteIt()
        {
            IIngestManifest ingestManifest = CreateEmptyManifestAndVerifyIt();
            string          id             = ingestManifest.Id;

            ingestManifest.Delete();
            VerifyManifestDeletion(id);
            ingestManifest = CreateEmptyManifestAndVerifyIt();
            id             = ingestManifest.Id;
            Assert.IsFalse(String.IsNullOrEmpty(ingestManifest.Name));
            Task t = ingestManifest.DeleteAsync();

            t.Wait();
            VerifyManifestDeletion(id);
        }
예제 #19
0
        public void AddingAdditionalFilesToAssetInManifest()
        {
            IIngestManifest ingestManifestCreated = CreateManifestWithAssetsAndVerifyIt(_mediaContext);

            _mediaContext = WindowsAzureMediaServicesTestConfiguration.CreateCloudMediaContext();
            var ingestManifestRefreshed = _mediaContext.IngestManifests.Where(c => c.Id == ingestManifestCreated.Id).FirstOrDefault();

            Assert.IsNotNull(ingestManifestRefreshed.Statistics);
            Assert.IsNotNull(ingestManifestCreated.Statistics);
            Assert.AreEqual(2, ingestManifestRefreshed.Statistics.PendingFilesCount);

            AddFileToExistingManifestAssetInfo(_mediaContext, ingestManifestCreated.Id);
            _mediaContext           = WindowsAzureMediaServicesTestConfiguration.CreateCloudMediaContext();
            ingestManifestRefreshed = _mediaContext.IngestManifests.Where(c => c.Id == ingestManifestCreated.Id).FirstOrDefault();
            Assert.AreEqual(3, ingestManifestRefreshed.Statistics.PendingFilesCount);
        }
예제 #20
0
        public void TestIngestManifestCreateRetry()
        {
            var expected = new IngestManifestData {
                Name = "testData"
            };
            var fakeException   = new WebException("test", WebExceptionStatus.ConnectionClosed);
            var dataContextMock = TestMediaServicesClassFactory.CreateSaveChangesMock(fakeException, 2, expected);

            dataContextMock.Setup((ctxt) => ctxt.AddObject("ContentKeyAuthorizationPolicies", It.IsAny <object>()));

            _mediaContext.MediaServicesClassFactory = new TestMediaServicesClassFactory(dataContextMock.Object);

            IIngestManifest actual = _mediaContext.IngestManifests.CreateAsync(expected.Name, "some storage").Result;

            Assert.AreEqual(expected.Name, actual.Name);
            dataContextMock.Verify((ctxt) => ctxt.SaveChangesAsync(It.IsAny <object>()), Times.Exactly(2));
        }
예제 #21
0
        public void CreateEmptyManifestAndUpdateIt()
        {
            IIngestManifest ingestManifest = CreateEmptyManifestAndVerifyIt();
            string          newName        = "New Name 1";
            string          id             = ingestManifest.Id;

            ingestManifest.Name = newName;
            ingestManifest.Update();
            VerifyNameForExitingManifest(ingestManifest, newName, id);

            //Async Update
            newName             = "New Name 2";
            ingestManifest.Name = newName;
            Task t = ingestManifest.UpdateAsync();

            t.Wait();
            VerifyNameForExitingManifest(ingestManifest, newName, id);
        }
예제 #22
0
        public void AddingAdditionalAssetInfoesToExistingManifest()
        {
            CloudMediaContext context = WindowsAzureMediaServicesTestConfiguration.CreateCloudMediaContext();
            IIngestManifest   ingestManifestCreated = CreateManifestWithAssetsAndVerifyIt(context);

            context = WindowsAzureMediaServicesTestConfiguration.CreateCloudMediaContext();

            IIngestManifest ingestManifest = context.IngestManifests.Where(c => c.Id == ingestManifestCreated.Id).FirstOrDefault();

            Assert.AreNotSame(0, ingestManifest.IngestManifestAssets.Count());
            IAsset asset1 = context.Assets.Create("Asset1", AssetCreationOptions.StorageEncrypted);
            Task <IIngestManifestAsset> task1 = ingestManifest.IngestManifestAssets.CreateAsync(asset1, new string[1] {
                InterviewWmv
            }, CancellationToken.None);

            IIngestManifestAsset assetInfo1 = task1.Result;

            Assert.AreEqual(1, assetInfo1.IngestManifestFiles.Count());
        }
        private static IIngestManifest CreateManifestWithAssetsAndVerifyIt(CloudMediaContext context)
        {
            //Creating empty manifest
            const string    manifestName   = "Manifest 1";
            IIngestManifest ingestManifest = context.IngestManifests.Create(manifestName);

            Assert.AreEqual(IngestManifestState.Inactive, ingestManifest.State, "Expecting empty manifest to be inactive");
            //Adding manifest asset info with multiple file
            IAsset asset2 = context.Assets.Create(Guid.NewGuid().ToString(), AssetCreationOptions.StorageEncrypted);
            var    files2 = new string[2] {
                TestFile1, TestFile2
            };
            IIngestManifestAsset ingestManifestAssetInfo2 = ingestManifest.IngestManifestAssets.Create(asset2, files2);

            Assert.AreEqual(1, asset2.ContentKeys.Count, "No keys associated with asset");
            VerifyManifestAsset(ingestManifestAssetInfo2);

            Assert.AreEqual(2, ingestManifestAssetInfo2.IngestManifestFiles.Count(), "Files collection size is not matching expectations");
            return(ingestManifest);
        }
예제 #24
0
        static void MonitorBulkManifest(string manifestID)
        {
            bool bContinue = true;

            if (consoleWriteLock == null)
            {
                consoleWriteLock = new object();
            }

            while (bContinue)
            {
                CloudMediaContext context  = CloudContextHelper.GetContext();
                IIngestManifest   manifest = context.IngestManifests.Where(m => m.Id == manifestID).FirstOrDefault();

                if (manifest != null)
                {
                    lock (consoleWriteLock)
                    {
                        Console.WriteLine("\nWaiting on all file uploads.");
                        Console.WriteLine("PendingFilesCount  : {0}", manifest.Statistics.PendingFilesCount);
                        Console.WriteLine("FinishedFilesCount : {0}", manifest.Statistics.FinishedFilesCount);
                        Console.WriteLine("{0}% complete.\n", (float)manifest.Statistics.FinishedFilesCount / (float)(manifest.Statistics.FinishedFilesCount + manifest.Statistics.PendingFilesCount) * 100);

                        if (manifest.Statistics.PendingFilesCount == 0)
                        {
                            Console.WriteLine("Completed\n");
                            bContinue = false;
                        }
                    }

                    if (manifest.Statistics.FinishedFilesCount < manifest.Statistics.PendingFilesCount)
                    {
                        Thread.Sleep(60000);
                    }
                }
                else // Manifest is null
                {
                    bContinue = false;
                }
            }
        }
예제 #25
0
        public void DeleteAssetShouldDeleteAllManifestAssetsFiles()
        {
            CloudMediaContext context        = WindowsAzureMediaServicesTestConfiguration.CreateCloudMediaContext();
            IIngestManifest   ingestManifest = CreateManifestWithAssetsAndVerifyIt(context);

            VerifyExistenceofAssetsAndFilesForManifest(ingestManifest, context);

            IIngestManifestAsset asset = ingestManifest.IngestManifestAssets.FirstOrDefault();

            VerifyManifestAsset(asset);
            int filescount = context.IngestManifestFiles.Where(c => c.ParentIngestManifestAssetId == asset.Id).Count();

            Assert.IsTrue(filescount > 0, "Expecting to have files for given asset");
            asset.Delete();

            context = WindowsAzureMediaServicesTestConfiguration.CreateCloudMediaContext();
            VerifyAssetIsNotExist(asset, context);

            filescount = context.IngestManifestFiles.Where(c => c.ParentIngestManifestAssetId == asset.Id).Count();
            Assert.AreEqual(0, filescount, "There are files belonging to manifest assets after asset deletion");
        }
예제 #26
0
        public IIngestManifest SetManifest(string manifestId, string assetName, string storageAccount, bool storageEncryption,
                                           bool multipleFileAsset, bool uploadBulkIngest, string[] fileNames)
        {
            IIngestManifest manifest = null;

            if (!string.IsNullOrEmpty(manifestId))
            {
                manifest = GetEntityById(MediaEntity.Manifest, manifestId) as IIngestManifest;
            }
            if (manifest == null && uploadBulkIngest)
            {
                string manifestName = Guid.NewGuid().ToString();
                manifest = _media.IngestManifests.Create(manifestName, storageAccount);
            }
            if (manifest != null)
            {
                foreach (IIngestManifestAsset manifestAsset in manifest.IngestManifestAssets)
                {
                    manifestAsset.Delete();
                }
                AssetCreationOptions creationOptions = storageEncryption ? AssetCreationOptions.StorageEncrypted : AssetCreationOptions.None;
                if (multipleFileAsset)
                {
                    IAsset asset = _media.Assets.Create(assetName, storageAccount, creationOptions);
                    manifest.IngestManifestAssets.Create(asset, fileNames);
                }
                else
                {
                    foreach (string fileName in fileNames)
                    {
                        IAsset asset = _media.Assets.Create(fileName, storageAccount, creationOptions);
                        manifest.IngestManifestAssets.Create(asset, new string[] { fileName });
                    }
                }
            }
            return(manifest);
        }
예제 #27
0
        public static async Task <object> Run([HttpTrigger(WebHookType = "genericJson")] HttpRequestMessage req, TraceWriter log)
        {
            log.Info($"Webhook was triggered!");

            string jsonContent = await req.Content.ReadAsStringAsync();

            dynamic data = JsonConvert.DeserializeObject(jsonContent);

            log.Info("Request : " + jsonContent);

            var attachedstoragecred = KeyHelper.ReturnStorageCredentials();

            // Validate input objects
            if (data.assetId == null)
            {
                return(req.CreateResponse(HttpStatusCode.BadRequest, new { error = "Please pass assetId in the input object" }));
            }

            if (data.targetStorageAccountName == null)
            {
                return(req.CreateResponse(HttpStatusCode.BadRequest, new { error = "Please pass targetStorageAccountName in the input object" }));
            }
            if (data.targetStorageAccountKey == null)
            {
                return(req.CreateResponse(HttpStatusCode.BadRequest, new { error = "Please pass targetStorageAccountKey in the input object" }));
            }
            if (data.targetContainer == null)
            {
                return(req.CreateResponse(HttpStatusCode.BadRequest, new { error = "Please pass targetContainer in the input object" }));
            }

            string targetStorageAccountName = data.targetStorageAccountName;
            string targetStorageAccountKey  = data.targetStorageAccountKey;
            string targetContainer          = data.targetContainer;
            string startsWith = data.startsWith;
            string endsWith   = data.endsWith;


            log.Info("Input - targetStorageAccountName : " + targetStorageAccountName);
            log.Info("Input - targetStorageAccountKey : " + targetStorageAccountKey);
            log.Info("Input - targetContainer : " + targetContainer);
            string assetId = data.assetId;

            IAsset          asset    = null;
            IIngestManifest manifest = null;

            MediaServicesCredentials amsCredentials = new MediaServicesCredentials();

            log.Info($"Using Azure Media Service Rest API Endpoint : {amsCredentials.AmsRestApiEndpoint}");

            try
            {
                AzureAdTokenCredentials tokenCredentials = new AzureAdTokenCredentials(amsCredentials.AmsAadTenantDomain,
                                                                                       new AzureAdClientSymmetricKey(amsCredentials.AmsClientId, amsCredentials.AmsClientSecret),
                                                                                       AzureEnvironments.AzureCloudEnvironment);

                AzureAdTokenProvider tokenProvider = new AzureAdTokenProvider(tokenCredentials);

                _context = new CloudMediaContext(amsCredentials.AmsRestApiEndpoint, tokenProvider);


                // Find the Asset
                asset = _context.Assets.Where(a => a.Id == assetId).FirstOrDefault();
                if (asset == null)
                {
                    return(req.CreateResponse(HttpStatusCode.BadRequest, new { error = "Asset not found" }));
                }


                string storname = amsCredentials.StorageAccountName;
                string storkey  = amsCredentials.StorageAccountKey;
                if (asset.StorageAccountName != amsCredentials.StorageAccountName)
                {
                    if (attachedstoragecred.ContainsKey(asset.StorageAccountName)) // asset is using another storage than default but we have the key
                    {
                        storname = asset.StorageAccountName;
                        storkey  = attachedstoragecred[storname];
                    }
                    else // we don't have the key for that storage
                    {
                        log.Info($"Face redaction Asset is in {asset.StorageAccountName} and key is not provided in MediaServicesAttachedStorageCredentials application settings");
                        return(req.CreateResponse(HttpStatusCode.BadRequest, new
                        {
                            error = "Storage key is missing"
                        }));
                    }
                }


                // Setup blob container
                CloudBlobContainer sourceBlobContainer      = CopyBlobHelpers.GetCloudBlobContainer(storname, storkey, asset.Uri.Segments[1]);
                CloudBlobContainer destinationBlobContainer = CopyBlobHelpers.GetCloudBlobContainer(targetStorageAccountName, targetStorageAccountKey, targetContainer);
                destinationBlobContainer.CreateIfNotExists();

                var files = asset.AssetFiles.ToList().Where(f => ((string.IsNullOrEmpty(endsWith) || f.Name.EndsWith(endsWith)) && (string.IsNullOrEmpty(startsWith) || f.Name.StartsWith(startsWith))));

                foreach (var file in files)
                {
                    CloudBlob sourceBlob      = sourceBlobContainer.GetBlockBlobReference(file.Name);
                    CloudBlob destinationBlob = destinationBlobContainer.GetBlockBlobReference(file.Name);
                    CopyBlobHelpers.CopyBlobAsync(sourceBlob, destinationBlob);
                    log.Info($"Start copy of file : {file.Name}");
                }
            }
            catch (Exception ex)
            {
                string message = ex.Message + ((ex.InnerException != null) ? Environment.NewLine + MediaServicesHelper.GetErrorMessage(ex) : "");
                log.Info($"ERROR: Exception {message}");
                return(req.CreateResponse(HttpStatusCode.InternalServerError, new { error = message }));
            }

            return(req.CreateResponse(HttpStatusCode.OK));
        }
 private static void VerifyNameForExitingManifest(IIngestManifest ingestManifest, string newName, string id)
 {
     CloudMediaContext context = WindowsAzureMediaServicesTestConfiguration.CreateCloudMediaContext();
     IIngestManifest updatedIngestManifest = context.IngestManifests.Where(c => c.Id == id).FirstOrDefault();
     Assert.IsNotNull(updatedIngestManifest);
     Assert.AreSame(newName, ingestManifest.Name);
 }
 private static void VerifyExistenceofAssetsAndFilesForManifest(IIngestManifest ingestManifest, CloudMediaContext context)
 {
     int assetsCount = context.IngestManifestAssets.Where(c => c.ParentIngestManifestId == ingestManifest.Id).Count();
     int filescount = context.IngestManifestFiles.Where(c => c.ParentIngestManifestId == ingestManifest.Id).Count();
     Assert.IsTrue(assetsCount > 0, "When manifest is empty we are expecting to have associated assets");
     Assert.IsTrue(filescount > 0, "When manifest is empty we are expecting to have associated files");
 }
        private static string CreateManifestEncryptFiles(out List<IIngestManifestFile> files, out IIngestManifest ingestManifestCreated)
        {
            CloudMediaContext context = WindowsAzureMediaServicesTestConfiguration.CreateCloudMediaContext();
            ingestManifestCreated = CreateManifestWithAssetsAndVerifyIt(context);
            var path = @".\Resources\TestFiles\" + Guid.NewGuid();
            Directory.CreateDirectory(path);
            ingestManifestCreated.EncryptFilesAsync(path, CancellationToken.None).Wait();

            var manifestid = ingestManifestCreated.Id;
            //returning all encrypted files
            files = context.IngestManifestFiles.Where(c => c.ParentIngestManifestId == manifestid && c.IsEncrypted == true).ToList();
            Assert.AreEqual(2, files.Count);
            return path;
        }
예제 #31
0
 /// <summary>
 /// Initializes a new instance of the <see cref="IngestManifestAssetCollection"/> class.
 /// </summary>
 /// <param name="cloudMediaContext">The <seealso cref="CloudMediaContext"/> instance.</param>
 /// <param name="parentIngestManifest">parent manifest if collection associated with manifest </param>
 internal IngestManifestAssetCollection(MediaContextBase cloudMediaContext, IIngestManifest parentIngestManifest) : base(cloudMediaContext)
 {
     _dataContext          = MediaContext.MediaServicesClassFactory.CreateDataServiceContext();
     _parentIngestManifest = parentIngestManifest;
     _query = new Lazy <IQueryable <IIngestManifestAsset> >(() => _dataContext.CreateQuery <IIngestManifestAsset, IngestManifestAssetData>(EntitySet));
 }
예제 #32
0
        /// <summary>
        /// Creates the manifest asset asyncroniously
        /// </summary>
        /// <param name="ingestManifest">The manifest where asset will be defined.</param>
        /// <param name="asset">The destination asset for which uploaded and processed files will be associated.</param>
        /// <param name="files">The files which needs to be uploaded and processed.</param>
        /// <param name="token"><see cref="CancellationToken"/>.</param>
        /// <returns><see cref="Task"/> of type <see cref="IIngestManifestAsset"/></returns>
        private Task <IIngestManifestAsset> CreateAsync(IIngestManifest ingestManifest, IAsset asset, string[] files, CancellationToken token)
        {
            if (ingestManifest == null)
            {
                throw new ArgumentNullException("ingestManifest");
            }
            Action <IngestManifestAssetData> continueWith = (IngestManifestAssetData manifestData) =>
            {
                Task <IIngestManifestFile>[] tasks = new Task <IIngestManifestFile> [files.Count()];
                int i = 0;

                foreach (string file in files)
                {
                    token.ThrowIfCancellationRequested();

                    tasks[i] = ((IIngestManifestAsset)manifestData).IngestManifestFiles.CreateAsync(file, token);

                    i++;
                }

                Task continueTask = Task.Factory.ContinueWhenAll(
                    tasks,
                    (fileTasks) =>
                {
                    //Updating statistic
                    var _this = MediaContext.IngestManifests.Where(c => c.Id == _parentIngestManifest.Id).FirstOrDefault();
                    if (_this != null)
                    {
                        ((IngestManifestData)_parentIngestManifest).Statistics = _this.Statistics;
                    }
                    else
                    {
                        throw new DataServiceClientException(String.Format(CultureInfo.InvariantCulture, StringTable.BulkIngestManifest404, _parentIngestManifest.Id), 404);
                    }

                    List <Exception> exceptions = new List <Exception>();

                    foreach (Task <IIngestManifestFile> task in fileTasks)
                    {
                        if (task.IsFaulted)
                        {
                            if (task.Exception != null)
                            {
                                exceptions.AddRange(task.Exception.InnerExceptions);
                            }
                            continue;
                        }
                        if (task.IsCanceled)
                        {
                            if (task.Exception != null)
                            {
                                exceptions.Add(task.Exception.Flatten());
                            }
                        }
                        IngestManifestData ingestManifestData = ((IngestManifestData)ingestManifest);
                        if (task.Result != null)
                        {
                            if (!ingestManifestData.TrackedFilesPaths.ContainsKey(task.Result.Id))
                            {
                                ingestManifestData.TrackedFilesPaths.TryAdd(task.Result.Id, ((IngestManifestFileData)task.Result).Path);
                            }
                            else
                            {
                                ingestManifestData.TrackedFilesPaths[task.Result.Id] = ((IngestManifestFileData)task.Result).Path;
                            }
                        }
                        else
                        {
                            //We should not be here if task successfully completed and not cancelled
                            exceptions.Add(new NullReferenceException(StringTable.BulkIngestNREForFileTaskCreation));
                        }
                    }

                    if (exceptions.Count > 0)
                    {
                        var exception = new AggregateException(exceptions.ToArray());
                        throw exception;
                    }
                },
                    TaskContinuationOptions.ExecuteSynchronously);
                continueTask.Wait();
            };

            return(CreateAsync(ingestManifest, asset, token, continueWith));
        }
 private static string GenerateAsperaUrl(IIngestManifest im)
 {
     string storKey = "InsertStorageKey";
     if (im.StorageAccountName == _context.DefaultStorageAccount.Name && !string.IsNullOrEmpty(_credentials.StorageKey))
     {
         storKey = _credentials.StorageKey;
     }
     return "azu://" + im.StorageAccountName + ":" + storKey + "@" + im.BlobStorageUriForUpload.Substring(im.BlobStorageUriForUpload.IndexOf(".") + 1);
 }
        private static string GenerateSigniantCommandLine(IIngestManifest im, List<BulkUpload.BulkAsset> assetFiles, bool fileencrypted, string encryptedfilefolder, List<string> signantservers, string APIKey)
        {
            string storKey = "InsertStorageKey";
            if (im.StorageAccountName == _context.DefaultStorageAccount.Name && !string.IsNullOrEmpty(_credentials.StorageKey))
            {
                storKey = _credentials.StorageKey;
            }
            string server = signantservers[0];
            if (signantservers.Count == 2)
            {
                server = server + " --server " + signantservers[1];  // secondary server
            }
            var command = string.Format(@"sigcli --apikey {0} --direction upload --server {1} --account-name {2} --access-key {3} --container {4}",
                             APIKey,
                             server,
                             im.StorageAccountName,
                             storKey,
                             (new Uri(im.BlobStorageUriForUpload)).PathAndQuery.Substring(1));

            if (!fileencrypted)
            {
                foreach (var asset in assetFiles)
                {
                    foreach (var file in asset.AssetFiles)
                    {
                        command = command + string.Format(@" ""{0}""", file);
                    }
                }
            }
            else
            {
                foreach (var asset in im.IngestManifestAssets)
                {
                    foreach (var file in asset.IngestManifestFiles)
                    {
                        command = command + string.Format(@" ""{0}""", Path.Combine(encryptedfilefolder, file.Name));
                    }
                }
            }

            return command;
        }
        private static string GenerateAzCopyCommandLine(IIngestManifest im, List<BulkUpload.BulkAsset> assetFiles, bool fileencrypted, string encryptedfilefolder)
        {
            StringBuilder command = new StringBuilder();
            string storKey = "InsertStorageKey";
            if (im.StorageAccountName == _context.DefaultStorageAccount.Name && !string.IsNullOrEmpty(_credentials.StorageKey))
            {
                storKey = _credentials.StorageKey;
            }


            if (!fileencrypted)
            {
                foreach (var asset in assetFiles)
                {
                    foreach (var file in asset.AssetFiles)
                    {
                        command.AppendLine(
                          string.Format(@"AzCopy /Source:""{0}"" /Dest:{1} /DestKey:{2} /Pattern:""{3}""",
                          Path.GetDirectoryName(file),
                          im.BlobStorageUriForUpload,
                          storKey,
                          Path.GetFileName(file)
                          )
                          );
                    }
                }
            }
            else
            {
                foreach (var asset in im.IngestManifestAssets)
                {
                    foreach (var file in asset.IngestManifestFiles)
                    {
                        command.AppendLine(
                            string.Format(@"AzCopy /Source:""{0}"" /Dest:{1} /DestKey:{2} /Pattern:""{3}""",
                            encryptedfilefolder,
                            im.BlobStorageUriForUpload,
                            storKey,
                            im.StorageAccountName,
                            file.Name
                            )
                            );
                    }
                }
            }

            return command.ToString();
        }
 private void DoBulkContainerInfo(IIngestManifest manifest)
 {
     if (manifest != null)
     {
         var form = new BulkContainerInfo(this, _context, manifest);
         if (form.ShowDialog() == DialogResult.OK)
         {
             manifest.Name = form.IngestManifestName;
             Task.Run(async () =>
             {
                 await manifest.UpdateAsync();
                 DoRefreshGridIngestManifestV(false);
             }
    );
         }
     }
 }
예제 #37
0
        public void DeleteInactiveExistingManifest()
        {
            IIngestManifest ingestManifest = CreateEmptyManifestAndVerifyIt();

            VerifyAssetStateAndDelete(IngestManifestState.Inactive, ingestManifest.Id);
        }
예제 #38
0
        public void DeleteActiveExistingManifest()
        {
            IIngestManifest ingestManifest = CreateManifestWithAssetsAndVerifyIt(_mediaContext);

            ingestManifest.Delete();
        }