public static string ReturnContent(IAssetFile assetFile)
        {
            string datastring = null;

            try
            {
                string tempPath = System.IO.Path.GetTempPath();
                string filePath = Path.Combine(tempPath, assetFile.Name);

                if (File.Exists(filePath))
                {
                    File.Delete(filePath);
                }
                assetFile.Download(filePath);

                StreamReader streamReader = new StreamReader(filePath);
                Encoding     fileEncoding = streamReader.CurrentEncoding;
                datastring = streamReader.ReadToEnd();
                streamReader.Close();

                File.Delete(filePath);
            }
            catch
            {
            }

            return(datastring);
        }
        public void ShouldDownloadToFileFromStorageEncryptedAsset()
        {
            string fileUploaded     = _smallWmv;
            string outputDirectory  = "Download" + Guid.NewGuid();
            string fileDownloaded   = Path.Combine(outputDirectory, Path.GetFileName(fileUploaded));
            var    fileUploadedInfo = new FileInfo(fileUploaded);

            IAsset     asset     = AssetTests.CreateAsset(_mediaContext, Path.GetFullPath(fileUploaded), AssetCreationOptions.StorageEncrypted);
            IAssetFile assetFile = asset.AssetFiles.First();

            Assert.AreEqual(AssetCreationOptions.StorageEncrypted, asset.Options);
            Assert.AreEqual(assetFile.Asset.Id, asset.Id);
            Assert.AreEqual(1, asset.Locators.Count);

            CleanDirectory(outputDirectory);

            Assert.IsFalse(File.Exists(fileDownloaded));

            double downloadProgress = 0;
            long   bytesDownloaded  = 0;

            assetFile.DownloadProgressChanged += (s, e) =>
            {
                Assert.AreSame(assetFile, s);

                Assert.IsNotNull(e);
                Assert.AreEqual(fileUploadedInfo.Length, e.TotalBytes);
                Assert.IsTrue(e.BytesDownloaded <= e.TotalBytes);

                downloadProgress = e.Progress;
                bytesDownloaded  = e.BytesDownloaded;
            };

            try
            {
                assetFile.Download(fileDownloaded);

                Assert.IsTrue(File.Exists(fileDownloaded));
                Assert.AreEqual(100, downloadProgress);

                var fileDownloadedInfo = new FileInfo(fileDownloaded);

                Assert.AreEqual(fileUploadedInfo.Length, fileDownloadedInfo.Length);
                Assert.AreEqual(fileDownloadedInfo.Length, bytesDownloaded);

                asset = _mediaContext.Assets.Where(a => a.Id == asset.Id).Single();
                Assert.AreEqual(1, asset.Locators.Count);
            }
            finally
            {
                if (File.Exists(fileDownloaded))
                {
                    File.Delete(fileDownloaded);
                }
            }
        }
Beispiel #3
0
        private void VerifyAndDownloadAsset(IAsset asset, int expectedFileCount)
        {
            Assert.AreEqual(expectedFileCount, asset.AssetFiles.Count(), "file count wrong");
            string     tempFile  = Path.GetTempFileName();
            IAssetFile assetFile = asset.AssetFiles.ToList()[0];

            assetFile.DownloadProgressChanged += AssetTests_OnDownloadProgress;
            assetFile.Download(tempFile);
            assetFile.DownloadProgressChanged -= AssetTests_OnDownloadProgress;

            Assert.IsTrue(CompareFiles(tempFile, _smallWmv), "Files not the same");
            Assert.AreEqual(100, _downloadProgress);
            File.Delete(tempFile);
        }
Beispiel #4
0
        //
        // When
        //

        async Task When(AssetImportsStarted e, IAssetFile file, IAssetDb db)
        {
            try
            {
                var link = e.Link.Then(HttpResource.From(_asset.File));

                await file.Download(link);

                await db.Merge(_asset);

                Then(new AssetImported(Id));
            }
            catch (Exception error)
            {
                Then(new AssetImportFailed(Id, error.ToString()));
            }
        }
Beispiel #5
0
        private static void CallUpdateUploadDownloadAndDelete(IAssetFile file, string name)
        {
            file.Update();
            file.UpdateAsync();
            var uploadFile = Path.Combine(Path.GetTempPath(), name);

            try
            {
                File.CreateText(uploadFile).Close();
                file.Upload(uploadFile);
            }
            finally
            {
                File.Delete(uploadFile);
            }
            file.Download(Path.GetTempFileName());
            file.Delete();
        }
Beispiel #6
0
        /// <summary>
        /// Verifies the and download asset.
        /// </summary>
        /// <param name="asset">The asset.</param>
        /// <param name="expectedFileCount">The expected file count.</param>
        private void VerifyAndDownloadAssetFile(IAssetFile assetFile, IAsset asset, string uploadedFile)
        {
            string downloadPathForWamsSdk = Guid.NewGuid().ToString();

            try
            {
                _downloadProgress = 0;
                //Downloading using WAMS SDK
                assetFile.DownloadProgressChanged += AssetTests_OnDownloadProgress;
                assetFile.Download(downloadPathForWamsSdk);
                assetFile.DownloadProgressChanged -= AssetTests_OnDownloadProgress;
                Assert.AreEqual(100, _downloadProgress);
                var fileUploadedInfo   = new FileInfo(uploadedFile);
                var fileDownloadedInfo = new FileInfo(downloadPathForWamsSdk);
                Assert.AreEqual(fileUploadedInfo.Length, fileDownloadedInfo.Length);
            }
            finally
            {
                if (File.Exists(downloadPathForWamsSdk))
                {
                    File.Delete(downloadPathForWamsSdk);
                }
            }
        }
        private static void CallUpdateUploadDownloadAndDelete(IAssetFile file, string name)
        {
            file.Update();
            file.UpdateAsync();
            var uploadFile = Path.Combine(Path.GetTempPath(), name);
            try
            {

                File.CreateText(uploadFile).Close();
                file.Upload(uploadFile);
            }
            finally
            {
                File.Delete(uploadFile);
            }
            file.Download(Path.GetTempFileName());
            file.Delete();
        }
 private void ProcessDownloadFileToAsset(IAssetFile assetFile, string destfolderpath)
 {
     try
     {
         assetFile.DownloadProgressChanged += MyDownloadProgressChanged;
         assetFile.Download(destfolderpath);
     }
     catch (Exception ex)
     {
         throw;
     }
 }
        /// <summary>
        /// Verifies the and download asset.
        /// </summary>
        /// <param name="asset">The asset.</param>
        /// <param name="expectedFileCount">The expected file count.</param>
        private void VerifyAndDownloadAssetFile(IAssetFile assetFile, IAsset asset, string uploadedFile)
        {
            string downloadPathForWamsSdk = Guid.NewGuid().ToString();
            try
            {
                _downloadProgress = 0;
                //Downloading using WAMS SDK
                assetFile.DownloadProgressChanged += AssetTests_OnDownloadProgress;
                assetFile.Download(downloadPathForWamsSdk);
                assetFile.DownloadProgressChanged -= AssetTests_OnDownloadProgress;
                Assert.AreEqual(100, _downloadProgress);
                var fileUploadedInfo = new FileInfo(uploadedFile);
                var fileDownloadedInfo = new FileInfo(downloadPathForWamsSdk);
                Assert.AreEqual(fileUploadedInfo.Length, fileDownloadedInfo.Length);

            }
            finally
            {
                if (File.Exists(downloadPathForWamsSdk))
                {
                    File.Delete(downloadPathForWamsSdk);
                }
            }
        }
        private void UploadTTML(SearchServiceClient serviceClient, string indexName, IAsset myAsset)
        {
            List <IndexAction <videotext> > data = new List <IndexAction <videotext> >();

            SearchIndexClient indexClient = serviceClient.Indexes.GetClient(indexName);

            IAssetFile myTTML  = (from f in myAsset.AssetFiles select f).Where(f => f.Name.EndsWith("ttml")).FirstOrDefault();
            ILocator   locator = (from l in myAsset.Locators select l).Where(l => l.Type == LocatorType.OnDemandOrigin).FirstOrDefault();

            if (locator == null)
            {
                locator = CreateStreamingLocator(myAsset.Id);
            }
            IAssetFile ismfile = (from f in myAsset.AssetFiles select f).Where(f => f.Name.EndsWith("ism")).FirstOrDefault();

            XmlDocument xmlDoc = new XmlDocument();

            try
            {
                myTTML.Download(myRequest.ProcessInstanceId);
                xmlDoc.Load(myRequest.ProcessInstanceId);
                File.Delete(myRequest.ProcessInstanceId);
            }
            catch (Exception X)
            {
                if (File.Exists(myRequest.ProcessInstanceId))
                {
                    File.Delete(myRequest.ProcessInstanceId);
                }
                Trace.TraceError("Error on UploadTTML TTML file don't exist or XML error");
                throw X;
            }

            int sentenceID = 0;

            foreach (XmlNode item in xmlDoc.SelectNodes("/").Item(0).ChildNodes.Item(1).ChildNodes.Item(1).ChildNodes.Item(0).ChildNodes)
            {
                string begin = item.Attributes["begin"].Value;
                string end   = item.Attributes["end"].Value;
                string txt   = item.InnerText;

                data.Add(IndexAction.Upload(
                             new videotext {
                    assetid         = myAsset.Id,
                    begin           = begin,
                    end             = end,
                    id              = string.Format("{0}-{1}", myRequest.ProcessInstanceId, sentenceID),
                    text            = txt,
                    title           = myAsset.Name,
                    recognizability = 0.0,
                    url             = locator.Path + ismfile.Name + "/manifest"
                }));
                sentenceID += 1;
            }

            var batch = IndexBatch.New(data);

            try
            {
                indexClient.Documents.Index(batch);
            }
            catch (IndexBatchException e)
            {
                Trace.TraceError(
                    "Failed to index some of the documents: {0}",
                    String.Join(", ", e.IndexingResults.Where(r => !r.Succeeded).Select(r => r.Key)));
                throw e;
            }
        }