本文整理汇总了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;
}
示例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);
}
}
示例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;
}
}
示例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;
}