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


C# IAsset.GetMediaContext方法代码示例

本文整理汇总了C#中IAsset.GetMediaContext方法的典型用法代码示例。如果您正苦于以下问题:C# IAsset.GetMediaContext方法的具体用法?C# IAsset.GetMediaContext怎么用?C# IAsset.GetMediaContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IAsset的用法示例。


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

示例1: CreatedTemporaryOnDemandLocator

        public static ILocator CreatedTemporaryOnDemandLocator(IAsset asset)
        {
            ILocator tempLocator = null;
            try
            {
                var locatorTask = Task.Factory.StartNew(() =>
                {
                    tempLocator = asset.GetMediaContext().Locators.Create(LocatorType.OnDemandOrigin, asset, AccessPermissions.Read, TimeSpan.FromHours(1));
                });
                locatorTask.Wait();
            }
            catch
            {

            }

            return tempLocator;
        }
开发者ID:flvlef,项目名称:Azure-Media-Services-Explorer,代码行数:18,代码来源:Program.cs

示例2: CopyDynamicEncryption

        public static async Task CopyDynamicEncryption(IAsset sourceAsset, IAsset destinationAsset, bool RewriteLAURL)
        {
            var SourceContext = sourceAsset.GetMediaContext();
            var DestinationContext = destinationAsset.GetMediaContext();

            // let's copy the keys
            foreach (var key in sourceAsset.ContentKeys)
            {
                IContentKey clonedkey = DestinationContext.ContentKeys.Where(k => k.Id == key.Id).FirstOrDefault();
                if (clonedkey == null) // key does not exist in target account
                {
                    try
                    {
                        clonedkey = DestinationContext.ContentKeys.Create(new Guid(key.Id.Replace(Constants.ContentKeyIdPrefix, "")), key.GetClearKeyValue(), key.Name, key.ContentKeyType);
                    }
                    catch
                    {
                        // we cannot create the key but the guid is taken.
                        throw new Exception(String.Format("Key {0} is not in the account but it cannot be created (same key id already exists in the datacenter? ", key.Id));
                    }

                }
                destinationAsset.ContentKeys.Add(clonedkey);

                if (key.AuthorizationPolicyId != null)
                {
                    IContentKeyAuthorizationPolicy sourcepolicy = SourceContext.ContentKeyAuthorizationPolicies.Where(ap => ap.Id == key.AuthorizationPolicyId).FirstOrDefault();
                    if (sourcepolicy != null) // there is one
                    {
                        IContentKeyAuthorizationPolicy clonedpolicy = (clonedkey.AuthorizationPolicyId != null) ? DestinationContext.ContentKeyAuthorizationPolicies.Where(ap => ap.Id == clonedkey.AuthorizationPolicyId).FirstOrDefault() : null;
                        if (clonedpolicy == null)
                        {
                            clonedpolicy = await DestinationContext.ContentKeyAuthorizationPolicies.CreateAsync(sourcepolicy.Name);

                            foreach (var opt in sourcepolicy.Options)
                            {
                                IContentKeyAuthorizationPolicyOption policyOption =
                                    DestinationContext.ContentKeyAuthorizationPolicyOptions.Create(opt.Name, opt.KeyDeliveryType, opt.Restrictions, opt.KeyDeliveryConfiguration);

                                clonedpolicy.Options.Add(policyOption);
                            }
                            clonedpolicy.Update();
                        }
                        clonedkey.AuthorizationPolicyId = clonedpolicy.Id;
                    }
                }
                clonedkey.Update();
            }

            //let's copy the policies
            foreach (var delpol in sourceAsset.DeliveryPolicies)
            {
                Dictionary<AssetDeliveryPolicyConfigurationKey, string> assetDeliveryPolicyConfiguration = new Dictionary<AssetDeliveryPolicyConfigurationKey, string>();
                foreach (var s in delpol.AssetDeliveryConfiguration)
                {
                    string val = s.Value;
                    string ff = AssetDeliveryPolicyConfigurationKey.PlayReadyLicenseAcquisitionUrl.ToString();

                    if (RewriteLAURL &&
                        (s.Key.ToString().Equals(AssetDeliveryPolicyConfigurationKey.PlayReadyLicenseAcquisitionUrl.ToString())
                        ||
                        s.Key.ToString().Equals(AssetDeliveryPolicyConfigurationKey.EnvelopeKeyAcquisitionUrl.ToString())
                        ))
                    {
                        // let's change the LA URL to use the account in the other datacenter
                        val = val.Replace(SourceContext.Credentials.ClientId, DestinationContext.Credentials.ClientId);
                    }
                    assetDeliveryPolicyConfiguration.Add(s.Key, val);
                }
                var clonetargetpolicy = DestinationContext.AssetDeliveryPolicies.Create(delpol.Name, delpol.AssetDeliveryPolicyType, delpol.AssetDeliveryProtocol, assetDeliveryPolicyConfiguration);
                destinationAsset.DeliveryPolicies.Add(clonetargetpolicy);
            }
        }
开发者ID:sk-bln,项目名称:Azure-Media-Services-Explorer,代码行数:73,代码来源:DynamicEncryption.cs

示例3: GetURIs

        public static IEnumerable<Uri> GetURIs(IAsset asset)
        {
            var _context = asset.GetMediaContext();
            IEnumerable<Uri> ValidURIs;
            var ismFile = asset.AssetFiles.AsEnumerable().Where(f => f.Name.EndsWith(".ism")).OrderByDescending(f => f.IsPrimary).FirstOrDefault();
            if (ismFile != null)
            {
                var locators = asset.Locators.Where(l => l.Type == LocatorType.OnDemandOrigin && l.ExpirationDateTime > DateTime.UtcNow).OrderByDescending(l => l.ExpirationDateTime);

                var template = new UriTemplate("{contentAccessComponent}/{ismFileName}/manifest");
                ValidURIs = locators.SelectMany(l =>
                    _context
                        .StreamingEndpoints
                        .AsEnumerable()
                          .OrderByDescending(o => o.CdnEnabled)
                        .Select(
                            o =>
                                template.BindByPosition(new Uri("http://" + o.HostName), l.ContentAccessComponent,
                                    ismFile.Name)))
                    .ToArray();

                return ValidURIs;
            }
            else
            {
                return null;
            }
        }
开发者ID:flvlef,项目名称:Azure-Media-Services-Explorer,代码行数:28,代码来源:Program.cs

示例4: CreateEnvelopeTypeContentKey

        static public IContentKey CreateEnvelopeTypeContentKey(IAsset asset, byte[] contentKey, Guid? keyId = null)
        {
            if (keyId == null) keyId = Guid.NewGuid();

            IContentKey key = asset.GetMediaContext().ContentKeys.Create(
                                    (Guid)keyId,
                                    contentKey,
                                    "ContentKey Envelope",
                                    ContentKeyType.EnvelopeEncryption);
            // Associate the key with the asset.
            asset.ContentKeys.Add(key);

            return key;
        }
开发者ID:sk-bln,项目名称:Azure-Media-Services-Explorer,代码行数:14,代码来源:DynamicEncryption.cs


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