当前位置: 首页>>代码示例>>C#>>正文


C# CloudMediaContext类代码示例

本文整理汇总了C#中CloudMediaContext的典型用法代码示例。如果您正苦于以下问题:C# CloudMediaContext类的具体用法?C# CloudMediaContext怎么用?C# CloudMediaContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


CloudMediaContext类属于命名空间,在下文中一共展示了CloudMediaContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ClassInit

        public static void ClassInit(TestContext context)
        {
            //CreateCounters();

            _mediaContext = WindowsAzureMediaServicesTestConfiguration.CreateCloudMediaContext();
            IContentKeyAuthorizationPolicyOption policyOption = null;

            for (int i = 0; i < 10; i++)
            {
                byte[] expectedKey = null;
                IContentKey contentKey = GetKeyDeliveryUrlTests.CreateTestKey(_mediaContext, ContentKeyType.EnvelopeEncryption, out expectedKey);

                policyOption = ContentKeyAuthorizationPolicyOptionTests.CreateOption(_mediaContext, String.Empty, ContentKeyDeliveryType.BaselineHttp, null, null, ContentKeyRestrictionType.Open);

                List<IContentKeyAuthorizationPolicyOption> options = new List<IContentKeyAuthorizationPolicyOption>
                {
                    policyOption
                };

                GetKeyDeliveryUrlTests.CreateTestPolicy(_mediaContext, String.Empty, options, ref contentKey);

                Uri keyDeliveryServiceUri = contentKey.GetKeyDeliveryUrl(ContentKeyDeliveryType.BaselineHttp);

                Assert.IsNotNull(keyDeliveryServiceUri);
                string rawkey = EncryptionUtils.GetKeyIdAsGuid(contentKey.Id).ToString();
                _testData.Add(new Tuple<Uri, string, string>(keyDeliveryServiceUri, TokenServiceClient.GetAuthTokenForKey(rawkey), GetKeyDeliveryUrlTests.GetString(expectedKey)));
            }
        }
开发者ID:shushengli,项目名称:azure-sdk-for-media-services,代码行数:28,代码来源:KeyDeliveryUrlStressTest.cs

示例2: TestADTokenProvider

 public void TestADTokenProvider()
 {
     var provider = new AzureADTokenProvider();
     var uri = new Uri(ConfigurationManager.AppSettings["MediaServicesUri"]);
     var context = new CloudMediaContext(uri, provider);
     var asset = context.Assets.FirstOrDefault();
 }
开发者ID:Azure,项目名称:azure-sdk-for-media-services,代码行数:7,代码来源:AzureADTokenProviderTest.cs

示例3: CreateTestKey

        public static IContentKey CreateTestKey(CloudMediaContext mediaContext, ContentKeyType contentKeyType, out byte[] key, string name = "")
        {
            key = ContentKeyTests.GetRandomBuffer(16);
            IContentKey contentKey = mediaContext.ContentKeys.Create(Guid.NewGuid(), key, name, contentKeyType);

            return contentKey;
        }
开发者ID:chayu,项目名称:azure-sdk-for-media-services,代码行数:7,代码来源:GetKeyDeliveryUrlTests.cs

示例4: AddingAdditionalFilesToAssetInManifest

        public void AddingAdditionalFilesToAssetInManifest()
        {
            IIngestManifest ingestManifestCreated = CreateManifestWithAssetsAndVerifyIt(_context);
            _context = WindowsAzureMediaServicesTestConfiguration.CreateCloudMediaContext();
            var ingestManifestRefreshed = _context.IngestManifests.Where(c => c.Id == ingestManifestCreated.Id).FirstOrDefault();
            Assert.IsNotNull(ingestManifestRefreshed.Statistics);
            Assert.IsNotNull(ingestManifestCreated.Statistics);
            Assert.AreEqual(2, ingestManifestRefreshed.Statistics.PendingFilesCount);

            AddFileToExistingManifestAssetInfo(_context, ingestManifestCreated.Id);
            _context = WindowsAzureMediaServicesTestConfiguration.CreateCloudMediaContext();
            ingestManifestRefreshed = _context.IngestManifests.Where(c => c.Id == ingestManifestCreated.Id).FirstOrDefault();
            Assert.AreEqual(3, ingestManifestRefreshed.Statistics.PendingFilesCount);
        }
开发者ID:quintinb,项目名称:azure-sdk-for-media-services,代码行数:14,代码来源:IngestManifestTests.cs

示例5: CreateTestPolicy

        public static IContentKeyAuthorizationPolicy CreateTestPolicy(CloudMediaContext mediaContext, string name, List<IContentKeyAuthorizationPolicyOption> policyOptions, ref IContentKey contentKey)
        {
            IContentKeyAuthorizationPolicy contentKeyAuthorizationPolicy = mediaContext.ContentKeyAuthorizationPolicies.CreateAsync(name).Result;

            foreach (IContentKeyAuthorizationPolicyOption option in policyOptions)
            {
                contentKeyAuthorizationPolicy.Options.Add(option);
            }

            // Associate the content key authorization policy with the content key
            contentKey.AuthorizationPolicyId = contentKeyAuthorizationPolicy.Id;
            contentKey = contentKey.UpdateAsync().Result;

            return contentKeyAuthorizationPolicy;
        }
开发者ID:shushengli,项目名称:azure-sdk-for-media-services,代码行数:15,代码来源:GetKeyDeliveryUrlTests.cs

示例6: CreateTestKeyWithSpecified

        public static IContentKey CreateTestKeyWithSpecified(string keyIdentifier, CloudMediaContext mediaContext, ContentKeyType contentKeyType, string name = "")
        {
            var keyId = EncryptionUtils.GetKeyIdAsGuid(keyIdentifier);
            SymmetricAlgorithm symmetricAlgorithm = new AesCryptoServiceProvider();
            if ((contentKeyType == ContentKeyType.CommonEncryption) ||
                (contentKeyType == ContentKeyType.EnvelopeEncryption))
            {
                symmetricAlgorithm.KeySize = EncryptionUtils.KeySizeInBitsForAes128;
            }
            else
            {
                symmetricAlgorithm.KeySize = EncryptionUtils.KeySizeInBitsForAes256;
            }
            IContentKey contentKey = mediaContext.ContentKeys.Create(keyId, symmetricAlgorithm.Key, name, contentKeyType);

            return contentKey;
        }
开发者ID:chayu,项目名称:azure-sdk-for-media-services,代码行数:17,代码来源:GetKeyDeliveryUrlTests.cs

示例7: CreateOption

        public static IContentKeyAuthorizationPolicyOption CreateOption(CloudMediaContext dataContext, string optionName, ContentKeyDeliveryType deliveryType, string requirements, string configuration, ContentKeyRestrictionType restrictionType)
        {
            var restrictions = new List<ContentKeyAuthorizationPolicyRestriction>
                {
                    new ContentKeyAuthorizationPolicyRestriction { Requirements = requirements, Name = "somename" }
                };

            restrictions[0].SetKeyRestrictionTypeValue(restrictionType);

            IContentKeyAuthorizationPolicyOption option = dataContext.ContentKeyAuthorizationPolicyOptions.Create(
                optionName,
                deliveryType,
                restrictions,
                configuration);

            return option;
        }
开发者ID:shushengli,项目名称:azure-sdk-for-media-services,代码行数:17,代码来源:ContentKeyAuthorizationPolicyOptionTests.cs

示例8: CreateAndSubmitOneTaskJob

 public static IJob CreateAndSubmitOneTaskJob(CloudMediaContext context, string name, IMediaProcessor mediaProcessor, string preset, IAsset asset, TaskOptions options)
 {
     IJob job = context.Jobs.Create(name);
     job.Priority = InitialJobPriority;
     ITask task = job.Tasks.AddNew("Task1", mediaProcessor, preset, options);
     task.InputAssets.Add(asset);
     task.OutputAssets.AddNew("Output asset", AssetCreationOptions.None);
     DateTime timebeforeSubmit = DateTime.UtcNow;
     job.Submit();
     Assert.AreEqual(1, job.Tasks.Count, "Job contains unexpected amount of tasks");
     Assert.AreEqual(1, job.InputMediaAssets.Count, "Job contains unexpected total amount of input assets");
     Assert.AreEqual(1, job.OutputMediaAssets.Count, "Job contains unexpected total amount of output assets");
     Assert.AreEqual(1, job.Tasks[0].InputAssets.Count, "job.Task[0] contains unexpected amount of input assets");
     Assert.AreEqual(1, job.Tasks[0].OutputAssets.Count, "job.Task[0] contains unexpected amount of output assets");
     Assert.IsFalse(String.IsNullOrEmpty(job.Tasks[0].InputAssets[0].Id), "Asset Id is Null or empty");
     Assert.IsFalse(String.IsNullOrEmpty(job.Tasks[0].OutputAssets[0].Id), "Asset Id is Null or empty");
     return job;
 }
开发者ID:votrongdao,项目名称:azure-sdk-for-media-services,代码行数:18,代码来源:JobTests.cs

示例9: CreateAsset

        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;
        }
开发者ID:Ginichen,项目名称:azure-sdk-for-media-services,代码行数:19,代码来源:AssetTests.cs

示例10: VerifyFileAndContentKeyMetadataForStorageEncryption

        public static void VerifyFileAndContentKeyMetadataForStorageEncryption(IAsset asset, CloudMediaContext dataContext)
        {
            IAsset assetFromServer = Enumerable.First(dataContext.Assets.Where(c => c.Id == asset.Id));

            Assert.IsTrue(assetFromServer.Options == AssetCreationOptions.StorageEncrypted);

            foreach (IAssetFile file in asset.AssetFiles)
            {
                // ensure that the file is marked as encrypted and has data for
                // the encryption fields
                string fileInfo = string.Format("File {0}, Asset {1}", file.Id, file.Asset.Id);
                Assert.IsTrue(file.IsEncrypted, "IsEncrypted is not set." + fileInfo);
                Assert.IsNotNull(file.InitializationVector, "InitializationVector is not set" + fileInfo);
                Assert.IsNotNull(file.EncryptionKeyId, "EncryptionKeyId is not set" + fileInfo);
                Assert.IsTrue(file.EncryptionScheme == FileEncryption.SchemeName, "EncryptionScheme does not match expected value" + fileInfo);
                Assert.IsTrue(file.EncryptionVersion == FileEncryption.SchemeVersion, "EncryptionVersion does not match expected" + fileInfo);

                // ensure that the local settings match those stored on the server
                VerifyEncryptionSettingsMatch(file, assetFromServer, ContentKeyType.StorageEncryption);
            }
        }
开发者ID:shushengli,项目名称:azure-sdk-for-media-services,代码行数:21,代码来源:ContentKeyTests.cs

示例11: ClassInit

        public static void ClassInit(TestContext context)
        {
            CreateCounters();
            InitilizeChallenges();
            _mediaContext = WindowsAzureMediaServicesTestConfiguration.CreateCloudMediaContext();
            IContentKeyAuthorizationPolicyOption policyOption = null;

            PlayReadyLicenseResponseTemplate responseTemplate = new PlayReadyLicenseResponseTemplate();
            responseTemplate.LicenseTemplates.Add(new PlayReadyLicenseTemplate());
            string licenseTemplate = MediaServicesLicenseTemplateSerializer.Serialize(responseTemplate);

            IContentKeyAuthorizationPolicy contentKeyAuthorizationPolicy = _mediaContext.ContentKeyAuthorizationPolicies.CreateAsync("PerfTest"+Guid.NewGuid().ToString()).Result;

            policyOption = ContentKeyAuthorizationPolicyOptionTests.CreateOption(_mediaContext, String.Empty,
                ContentKeyDeliveryType.PlayReadyLicense, null, licenseTemplate, ContentKeyRestrictionType.Open);
            contentKeyAuthorizationPolicy.Options.Add(policyOption);

            foreach (var tuple in _keys)
            {
                IContentKey contentKey =
                _mediaContext.ContentKeys.Where(c => c.Id == tuple.Item1)
                    .FirstOrDefault();
                if (contentKey != null)
                {
                    contentKey.Delete();

                }
                contentKey = GetKeyDeliveryUrlTests.CreateTestKeyWithSpecified(tuple.Item1,
                   _mediaContext, ContentKeyType.CommonEncryption);

                // Associate the content key authorization policy with the content key
                contentKey.AuthorizationPolicyId = contentKeyAuthorizationPolicy.Id;
                contentKey = contentKey.UpdateAsync().Result;
                Uri keyDeliveryServiceUri = contentKey.GetKeyDeliveryUrl(ContentKeyDeliveryType.PlayReadyLicense);
                Assert.IsNotNull(keyDeliveryServiceUri);
                _testData.Add(new Tuple<Uri, string>(keyDeliveryServiceUri, contentKey.Id));
            }
        }
开发者ID:shushengli,项目名称:azure-sdk-for-media-services,代码行数:38,代码来源:PlayReadyStressTest.cs

示例12: VerifyExistenceofAssetsAndFilesForManifest

 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");
 }
开发者ID:quintinb,项目名称:azure-sdk-for-media-services,代码行数:7,代码来源:IngestManifestTests.cs

示例13: VerifyAssetIsNotExist

 private void VerifyAssetIsNotExist(IIngestManifestAsset asset, CloudMediaContext context)
 {
     Assert.AreEqual(0, context.IngestManifestAssets.Where(c => c.Id == asset.Id).Count(), "Manifest Asset exists.Expected result that asset is not returned by REST API");
 }
开发者ID:quintinb,项目名称:azure-sdk-for-media-services,代码行数:4,代码来源:IngestManifestTests.cs

示例14: CreateManifestWithAssetsAndVerifyIt

        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;
        }
开发者ID:quintinb,项目名称:azure-sdk-for-media-services,代码行数:16,代码来源:IngestManifestTests.cs

示例15: DecryptedFile

        private static string DecryptedFile(IIngestManifestFile ingestManifestFile, string encryptedPath, CloudMediaContext context)
        {
            IIngestManifestAsset ingestManifestAsset = context.IngestManifestAssets.Where(a => a.Id == ingestManifestFile.ParentIngestManifestAssetId).FirstOrDefault();
            Assert.IsNotNull(ingestManifestAsset);

            IList<IContentKey> keys = ingestManifestAsset.Asset.ContentKeys.Where(c => c.ContentKeyType == ContentKeyType.StorageEncryption).ToList();
            Assert.AreEqual(1, keys.Count, "Expecting only one storage key per asset");
            IContentKey key = keys.FirstOrDefault();
            Assert.IsNotNull(ingestManifestAsset);

            Guid keyId = EncryptionUtils.GetKeyIdAsGuid(key.Id);
            FileEncryption fileEncryption = new FileEncryption(key.GetClearKeyValue(), keyId);

            ulong iv = Convert.ToUInt64(ingestManifestFile.InitializationVector, CultureInfo.InvariantCulture);
            var decryptedPath = @".\Resources\TestFiles\Decrypted" + Guid.NewGuid();
            if (!Directory.Exists(decryptedPath))
            {
                Directory.CreateDirectory(decryptedPath);
            }

            decryptedPath = Path.Combine(decryptedPath, ingestManifestFile.Name);
            FileInfo fileInfo = new FileInfo(encryptedPath);
            var maxblocksize = GetBlockSize(fileInfo.Length);
            List<string> blockList = new List<string>();
            int numberOfthreads = 1;
            var queue = PreapreDownloadQueue(maxblocksize, fileInfo.Length, ref numberOfthreads, out blockList);

            using (var fs = new FileStream(decryptedPath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read))
            {
                KeyValuePair<int, int> block;
                while (queue.TryDequeue(out block))
                {
                    fs.Seek(block.Key * maxblocksize, SeekOrigin.Begin);
                    using (FileStream stream = File.OpenRead(encryptedPath))
                    {
                        byte[] buffer = new byte[block.Value];
                        stream.Seek(block.Key * maxblocksize, SeekOrigin.Begin);
                        int read = stream.Read(buffer, 0, (int)block.Value);
                        if (fileEncryption != null)
                        {
                            lock (fileEncryption)
                            {
                                using (FileEncryptionTransform encryptor = fileEncryption.GetTransform(iv, block.Key * maxblocksize))
                                {
                                    encryptor.TransformBlock(inputBuffer: buffer, inputOffset: 0, inputCount: buffer.Length, outputBuffer: buffer, outputOffset: 0);
                                }
                            }
                        }

                        fs.Write(buffer, 0, buffer.Length);
                    }
                }
            }
            return decryptedPath;
        }
开发者ID:quintinb,项目名称:azure-sdk-for-media-services,代码行数:55,代码来源:IngestManifestTests.cs


注:本文中的CloudMediaContext类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。