本文整理汇总了C#中System.Web.HttpRequestBase.GetUserHostAddressFromCloudflare方法的典型用法代码示例。如果您正苦于以下问题:C# HttpRequestBase.GetUserHostAddressFromCloudflare方法的具体用法?C# HttpRequestBase.GetUserHostAddressFromCloudflare怎么用?C# HttpRequestBase.GetUserHostAddressFromCloudflare使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.HttpRequestBase
的用法示例。
在下文中一共展示了HttpRequestBase.GetUserHostAddressFromCloudflare方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetAkamaiLiveEventClipDetails
public static AkamaiFlowPlayerPluginClipDetails GetAkamaiLiveEventClipDetails(int episodeId, int assetId, HttpRequestBase req, System.Security.Principal.IPrincipal thisUser, bool isMobileAllowed, bool removeIpFromToken = false)
{
AkamaiFlowPlayerPluginClipDetails clipDetails = null;
var offeringId = Helpers.GlobalConfig.offeringId;
var videoUrl = string.Empty;
var canPlay = false;
var countryCode = Helpers.MyUtility.getCountry(req.GetUserHostAddressFromCloudflare()).getCode();
var context = new IPTV2Entities();
var offering = context.Offerings.Find(offeringId);
var episode = context.Episodes.Find(episodeId);
var asset = context.Assets.Find(assetId);
var cdnId = 2; // akamai's cdn id
if (!req.Browser.IsMobileDevice)
cdnId = 3; // akamai hdn
if (GlobalConfig.IsIosHLSCdnEnabled)
{
if (!req.Browser.IsMobileDevice && !MyUtility.IsDeviceHtml5Capable(req))
cdnId = 3; // akamai hdn
else // get IOS stream
{
if (MyUtility.IsAndroid(req) && !MyUtility.IsDeviceHtml5Capable(req)) { cdnId = 3; }
else { cdnId = 5; }
}
}
if ((episode != null) & (asset != null))
{
clipDetails = new AkamaiFlowPlayerPluginClipDetails { EpisodeId = episodeId, AssetId = assetId, UserId = (thisUser.Identity.IsAuthenticated ? thisUser.Identity.Name : null) };
canPlay = clipDetails.IsFree = (episode.PreviewAssets.FirstOrDefault(a => a.AssetId == asset.AssetId) != null) | (episode.FreeAssets.FirstOrDefault(a => a.AssetId == asset.AssetId) != null);
// check with anonymous default package
var packageId = GlobalConfig.AnonymousDefaultPackageId;
if (!canPlay)
{
canPlay = User.IsAssetEntitled(context, offeringId, packageId, episodeId, assetId, countryCode, RightsType.Online);
}
else
{
clipDetails.IsFree = true;
}
// check user's access rights
if (!canPlay && thisUser.Identity.IsAuthenticated)
{
var user = context.Users.FirstOrDefault(u => u.UserId == new System.Guid(thisUser.Identity.Name));
if (user != null)
{
// check access from default logged in user package
packageId = Helpers.GlobalConfig.LoggedInDefaultPackageId;
canPlay = User.IsAssetEntitled(context, offeringId, packageId, episodeId, assetId, countryCode, RightsType.Online);
if (!canPlay)
{
// check if user has entitlements that can play the video
canPlay = user.CanPlayVideo(offering, episode, asset, RightsType.Online);
}
else
{
clipDetails.IsFree = true;
}
}
}
// get asset URL
var assetCdn = asset.AssetCdns.FirstOrDefault(a => a.CdnId == cdnId);
if (assetCdn != null)
{
var hlsPrefixPattern = GlobalConfig.hlsLiveStreamPrefixPattern;
var hlsSuffixPattern = GlobalConfig.hlsLiveStreamSuffixPattern;
var zeriPrefixPattern = GlobalConfig.zeriLiveStreamPrefixPattern;
var zeriSuffixPattern = GlobalConfig.zeriLiveStreamSuffixPattern;
var httpPrefixPatternMobile = GlobalConfig.httpLiveStreamPrefixPatternMobile;
//if (req.Browser.IsMobileDevice)
//{
// videoUrl = assetCdn.CdnReference.Replace(zeriPrefixPattern, httpPrefixPatternMobile);
//}
//else
//{
// videoUrl = assetCdn.CdnReference.Replace(hlsPrefixPattern, zeriPrefixPattern).Replace(hlsSuffixPattern, zeriSuffixPattern);
//}
if (cdnId == 3) //Akamai HDN means Flash based.
videoUrl = assetCdn.CdnReference;
else
videoUrl = assetCdn.CdnReference.Replace(hlsPrefixPattern, httpPrefixPatternMobile);
string ipAddress = string.Empty;
if (!req.IsLocal)
ipAddress = req.GetUserHostAddressFromCloudflare();
int snippetStart = 0;
int snippetEnd = 0;
//.........这里部分代码省略.........
示例2: GetAkamaiClipDetails
public static AkamaiFlowPlayerPluginClipDetails GetAkamaiClipDetails(int episodeId, int assetId, HttpRequestBase req, System.Security.Principal.IPrincipal thisUser, bool isIosAllowed)
{
AkamaiFlowPlayerPluginClipDetails clipDetails = null;
var offeringId = Helpers.GlobalConfig.offeringId;
var videoUrl = string.Empty;
var canPlay = false;
var countryCode = Helpers.MyUtility.getCountry(req.GetUserHostAddressFromCloudflare()).getCode();
var context = new IPTV2Entities();
var offering = context.Offerings.Find(offeringId);
var episode = context.Episodes.Find(episodeId);
var asset = context.Assets.Find(assetId);
var cdnId = 2; // akamai's cdn id
if ((episode != null) & (asset != null))
{
clipDetails = new AkamaiFlowPlayerPluginClipDetails { EpisodeId = episodeId, AssetId = assetId, UserId = (thisUser.Identity.IsAuthenticated ? thisUser.Identity.Name : null) };
canPlay = clipDetails.IsFree = (episode.PreviewAssets.FirstOrDefault(a => a.AssetId == asset.AssetId) != null) | (episode.FreeAssets.FirstOrDefault(a => a.AssetId == asset.AssetId) != null);
// check with anonymous default package
var packageId = GlobalConfig.AnonymousDefaultPackageId;
if (!canPlay)
{
canPlay = User.IsAssetEntitled(context, offeringId, packageId, episodeId, assetId, countryCode, RightsType.Online);
}
else
{
clipDetails.IsFree = true;
}
// check user's access rights
if (!canPlay && thisUser.Identity.IsAuthenticated)
{
var user = context.Users.FirstOrDefault(u => u.UserId == new System.Guid(thisUser.Identity.Name));
if (user != null)
{
// check access from default logged in user package
packageId = Helpers.GlobalConfig.LoggedInDefaultPackageId;
canPlay = User.IsAssetEntitled(context, offeringId, packageId, episodeId, assetId, countryCode, RightsType.Online);
if (!canPlay)
{
// check if user has entitlements that can play the video
canPlay = user.CanPlayVideo(offering, episode, asset, RightsType.Online);
}
else
{
clipDetails.IsFree = true;
}
}
}
// get asset URL
var assetCdn = asset.AssetCdns.FirstOrDefault(a => a.CdnId == cdnId);
if (assetCdn != null)
{
var hlsPrefixPattern = GlobalConfig.hlsPrefixPattern;
var hlsSuffixPattern = GlobalConfig.hlsSuffixPattern;
var zeriPrefixPattern = GlobalConfig.zeriPrefixPattern;
var zeriSuffixPattern = GlobalConfig.zeriSuffixPattern;
var httpPrefixPatternMobile = GlobalConfig.httpPrefixPatternMobile;
bool isIpad = IsIpad(req);
bool isIos = IsIos(req);
if (isIos)
{
videoUrl = assetCdn.CdnReference.Replace(hlsPrefixPattern, httpPrefixPatternMobile);
//string limitUrl = "b=-" + (isIpad ? "5000,1100" : "5000,700") + "-"; // iPad up to 1Mbps, iPhone/iPod up to 500Kbps
//videoUrl = (videoUrl.EndsWith(".m3u8") ? "?" : "&") + limitUrl;
if (isIpad)
videoUrl = videoUrl.Replace(",1300000,1500000,", ","); // max 1Mbps
else
videoUrl = videoUrl.Replace(",800000,1000000,1300000,1500000,", ","); // max 500kbps
}
else
{
videoUrl = assetCdn.CdnReference.Replace(hlsPrefixPattern, zeriPrefixPattern).Replace(hlsSuffixPattern, zeriSuffixPattern);
}
// videoUrl = !isMobileUse ? assetCdn.CdnReference.Replace(hlsPrefixPattern, zeriPrefixPattern).Replace(hlsSuffixPattern, zeriSuffixPattern) : assetCdn.CdnReference.Replace(hlsPrefixPattern, httpPrefixPatternMobile);
//videoUrl = assetCdn.CdnReference.Replace(hlsPrefixPattern, zeriPrefixPattern).Replace(hlsSuffixPattern, zeriSuffixPattern);
string ipAddress = string.Empty;
if (!req.IsLocal)
ipAddress = req.GetUserHostAddressFromCloudflare();
int snippetStart = 0;
int snippetEnd = 0;
if (!canPlay)
{
if ((asset.SnippetStart != null) && (asset.SnippetEnd != null) && (asset.SnippetEnd > asset.SnippetStart))
{
//DateTime baseTime = new DateTime(1900, 1, 1, 0, 0, 0);
//DateTime startTime = new DateTime(1900, 1, 1, asset.SnippetStart.Value.Hours, asset.SnippetStart.Value.Minutes, asset.SnippetStart.Value.Seconds);
//DateTime endTime = new DateTime(1900, 1, 1, asset.SnippetEnd.Value.Hours, asset.SnippetEnd.Value.Minutes, asset.SnippetEnd.Value.Seconds);
//snippetStart = Convert.ToInt32(Microsoft.VisualBasic.DateAndTime.DateDiff(Microsoft.VisualBasic.DateInterval.Second, baseTime, startTime));
//.........这里部分代码省略.........
示例3: GetAkamaiProgressiveClipDetails_M3U8
public static AkamaiFlowPlayerPluginClipDetails GetAkamaiProgressiveClipDetails_M3U8(int episodeId, int assetId, HttpRequestBase req, System.Security.Principal.IPrincipal thisUser, Progressive progressive, VideoQualityCdnReference? quality = null)
{
AkamaiFlowPlayerPluginClipDetails clipDetails = null;
var offeringId = Helpers.GlobalConfig.offeringId;
var videoUrl = string.Empty;
var canPlay = false;
var countryCode = Helpers.MyUtility.getCountry(req.GetUserHostAddressFromCloudflare()).getCode();
string uCountryCode = countryCode;
var context = new IPTV2Entities();
var offering = context.Offerings.Find(offeringId);
var episode = context.Episodes.Find(episodeId);
var asset = context.Assets.Find(assetId);
var cdnId = 2; // akamai's cdn id
if (quality != null)
cdnId = (int)quality;
if ((episode != null) & (asset != null))
{
clipDetails = new AkamaiFlowPlayerPluginClipDetails { EpisodeId = episodeId, AssetId = assetId, UserId = (thisUser.Identity.IsAuthenticated ? thisUser.Identity.Name : null) };
canPlay = clipDetails.IsFree = (episode.PreviewAssets.FirstOrDefault(a => a.AssetId == asset.AssetId) != null) | (episode.FreeAssets.FirstOrDefault(a => a.AssetId == asset.AssetId) != null);
// check with anonymous default package
var packageId = GlobalConfig.AnonymousDefaultPackageId;
if (!canPlay)
{
canPlay = User.IsAssetEntitled(context, offeringId, packageId, episodeId, assetId, countryCode, RightsType.Online);
}
else
{
clipDetails.IsFree = true;
}
// check user's access rights
if (!canPlay && thisUser.Identity.IsAuthenticated)
{
var user = context.Users.FirstOrDefault(u => u.UserId == new System.Guid(thisUser.Identity.Name));
if (user != null)
{
uCountryCode = user.CountryCode;
// check access from default logged in user package
packageId = Helpers.GlobalConfig.LoggedInDefaultPackageId;
canPlay = User.IsAssetEntitled(context, offeringId, packageId, episodeId, assetId, countryCode, RightsType.Online);
if (!canPlay)
{
// check if user has entitlements that can play the video
//canPlay = user.CanPlayVideo(offering, episode, asset, RightsType.Online);
if (GlobalConfig.IsTVERegionBlockingEnabled)
{
var userCountryCode = MyUtility.GetCountryCodeViaIp();
int GomsSubsidiaryId = 0;
if (GlobalConfig.UseGomsSubsidiaryForTVECheck)
GomsSubsidiaryId = ContextHelper.GetGomsSubsidiaryIdOfCountry(context, userCountryCode);
else
GomsSubsidiaryId = -1;
//var GomsSubsidiaryId = ContextHelper.GetGomsSubsidiaryIdOfCountry(context, userCountryCode);
var IncludePackageIds = MyUtility.StringToIntList(GlobalConfig.CanPlayIncludedPackageIds);
var ExcludePackageIds = MyUtility.StringToIntList(GlobalConfig.CanPlayExcludedPackageIds);
canPlay = user.CanPlayVideo(offering, episode, asset, RightsType.Online, ExcludePackageIds, IncludePackageIds, userCountryCode, GomsSubsidiaryId);
if (GlobalConfig.IsTVEIpCheckEnabled)
{
try
{
string ip = GlobalConfig.IpWhiteList;
string[] IpAddresses = ip.Split(';');
//if (IpAddresses.Contains(req.GetUserHostAddressFromCloudflare()))
canPlay = user.CanPlayVideo(offering, episode, asset, RightsType.Online);
}
catch (Exception e) { MyUtility.LogException(e, "AkamaiToken canPlay IP Whitelisting"); }
}
}
else
canPlay = user.CanPlayVideo(offering, episode, asset, RightsType.Online);
}
else
{
clipDetails.IsFree = true;
}
}
}
// get asset URL
var assetCdn = asset.AssetCdns.FirstOrDefault(a => a.CdnId == cdnId);
if (assetCdn != null)
{
var hlsPrefixPattern = GlobalConfig.hlsProgressivePrefixPattern;
var hlsSuffixPattern = GlobalConfig.hlsProgressiveSuffixPattern;
var zeriPrefixPattern = GlobalConfig.zeriProgressivePrefixPattern;
var zeriSuffixPattern = GlobalConfig.zeriProgressiveSuffixPattern;
var httpPrefixPatternMobile = GlobalConfig.httpProgressivePrefixPatternMobile;
bool isIpad = IsIpad(req);
bool isIos = IsIos(req);
videoUrl = assetCdn.CdnReference.Replace(hlsPrefixPattern, String.Empty).Replace(hlsSuffixPattern, zeriSuffixPattern);
var ProgressiveHDBitrate = GlobalConfig.PMDHDBitrate;
//.........这里部分代码省略.........
示例4: GetAkamaiClipDetailsHD_M3U8
public static AkamaiFlowPlayerPluginClipDetails GetAkamaiClipDetailsHD_M3U8(int episodeId, int assetId, HttpRequestBase req, System.Security.Principal.IPrincipal thisUser)
{
AkamaiFlowPlayerPluginClipDetails clipDetails = null;
var offeringId = Helpers.GlobalConfig.offeringId;
var videoUrl = string.Empty;
var canPlay = false;
var countryCode = Helpers.MyUtility.getCountry(req.GetUserHostAddressFromCloudflare()).getCode();
string uCountryCode = countryCode;
var context = new IPTV2Entities();
var offering = context.Offerings.Find(offeringId);
var episode = context.Episodes.Find(episodeId);
var asset = context.Assets.Find(assetId);
var cdnId = 6; // akamaiHD cdn id
if ((episode != null) & (asset != null))
{
clipDetails = new AkamaiFlowPlayerPluginClipDetails { EpisodeId = episodeId, AssetId = assetId, UserId = (thisUser.Identity.IsAuthenticated ? thisUser.Identity.Name : null) };
canPlay = clipDetails.IsFree = (episode.PreviewAssets.FirstOrDefault(a => a.AssetId == asset.AssetId) != null) | (episode.FreeAssets.FirstOrDefault(a => a.AssetId == asset.AssetId) != null);
// check with anonymous default package
var packageId = GlobalConfig.AnonymousDefaultPackageId;
if (!canPlay)
{
canPlay = User.IsAssetEntitled(context, offeringId, packageId, episodeId, assetId, countryCode, RightsType.Online);
}
else
{
clipDetails.IsFree = true;
}
// check user's access rights
if (!canPlay && thisUser.Identity.IsAuthenticated)
{
var user = context.Users.FirstOrDefault(u => u.UserId == new System.Guid(thisUser.Identity.Name));
if (user != null)
{
uCountryCode = user.CountryCode;
// check access from default logged in user package
packageId = Helpers.GlobalConfig.LoggedInDefaultPackageId;
canPlay = User.IsAssetEntitled(context, offeringId, packageId, episodeId, assetId, countryCode, RightsType.Online);
if (!canPlay)
{
// check if user has entitlements that can play the video
//canPlay = user.CanPlayVideo(offering, episode, asset, RightsType.Online);
if (GlobalConfig.IsTVERegionBlockingEnabled)
{
var userCountryCode = MyUtility.GetCountryCodeViaIp();
int GomsSubsidiaryId = 0;
if (GlobalConfig.UseGomsSubsidiaryForTVECheck)
GomsSubsidiaryId = ContextHelper.GetGomsSubsidiaryIdOfCountry(context, userCountryCode);
else
GomsSubsidiaryId = -1;
//var GomsSubsidiaryId = ContextHelper.GetGomsSubsidiaryIdOfCountry(context, userCountryCode);
var IncludePackageIds = MyUtility.StringToIntList(GlobalConfig.CanPlayIncludedPackageIds);
var ExcludePackageIds = MyUtility.StringToIntList(GlobalConfig.CanPlayExcludedPackageIds);
canPlay = user.CanPlayVideo(offering, episode, asset, RightsType.Online, ExcludePackageIds, IncludePackageIds, userCountryCode, GomsSubsidiaryId);
if (GlobalConfig.IsTVEIpCheckEnabled)
{
try
{
string ip = GlobalConfig.IpWhiteList;
string[] IpAddresses = ip.Split(';');
if (IpAddresses.Contains(req.GetUserHostAddressFromCloudflare()))
canPlay = user.CanPlayVideo(offering, episode, asset, RightsType.Online);
}
catch (Exception e) { MyUtility.LogException(e, "AkamaiToken canPlay IP Whitelisting"); }
}
}
else
canPlay = user.CanPlayVideo(offering, episode, asset, RightsType.Online);
}
else
{
clipDetails.IsFree = true;
}
}
}
// get asset URL
var assetCdn = asset.AssetCdns.FirstOrDefault(a => a.CdnId == cdnId);
if (assetCdn != null)
{
var hlsPrefixPattern = GlobalConfig.hlsPrefixPattern;
var hlsSuffixPattern = GlobalConfig.hlsSuffixPattern;
var zeriPrefixPattern = GlobalConfig.zeriPrefixPattern;
var zeriSuffixPattern = GlobalConfig.zeriSuffixPattern;
var httpPrefixPatternMobile = GlobalConfig.httpPrefixPatternMobile;
bool isIpad = IsIpad(req);
bool isIos = IsIos(req);
//if (req.Browser.IsMobileDevice)
//{
// if ((String.Compare(uCountryCode, "HK", true) == 0) || (String.Compare(countryCode, "HK", true) == 0))
// videoUrl = videoUrl.Replace(",500000,800000,1000000,1300000,1500000,", ","); // If HK, maximum of 300kbps only
//.........这里部分代码省略.........
示例5: GetAkamaiLiveEventClipDetails_M3U8
public static AkamaiFlowPlayerPluginClipDetails GetAkamaiLiveEventClipDetails_M3U8(int episodeId, int assetId, HttpRequestBase req, System.Security.Principal.IPrincipal thisUser, bool isMobileAllowed, string CountryCodeOverride = "", bool RemoveIpFromToken = false)
{
AkamaiFlowPlayerPluginClipDetails clipDetails = null;
var offeringId = Helpers.GlobalConfig.offeringId;
var videoUrl = string.Empty;
var canPlay = false;
var countryCode = Helpers.MyUtility.getCountry(req.GetUserHostAddressFromCloudflare()).getCode();
if (!String.IsNullOrEmpty(CountryCodeOverride))
countryCode = CountryCodeOverride;
string uCountryCode = countryCode;
var context = new IPTV2Entities();
var offering = context.Offerings.Find(offeringId);
var episode = context.Episodes.Find(episodeId);
var asset = context.Assets.Find(assetId);
var cdnId = 3; // akamai LIVE cdnId
cdnId = GlobalConfig.UseJWPlayer ? 7 : 3;
//if HLS is enabled, get IOS HLS cdnId
if (GlobalConfig.IsIosHLSCdnEnabled)
if (req.Browser.IsMobileDevice)
cdnId = 5;
//Check if asset is available or not. If not revert back to the original cdnId (akamai LIVE)
try
{
if (context.AssetCdns.Count(a => a.AssetId == assetId && a.CdnId == cdnId) <= 0)
cdnId = GlobalConfig.UseJWPlayer ? 7 : 3;
}
catch (Exception) { }
if ((episode != null) & (asset != null))
{
clipDetails = new AkamaiFlowPlayerPluginClipDetails { EpisodeId = episodeId, AssetId = assetId, UserId = (thisUser.Identity.IsAuthenticated ? thisUser.Identity.Name : null) };
canPlay = clipDetails.IsFree = (episode.PreviewAssets.FirstOrDefault(a => a.AssetId == asset.AssetId) != null) | (episode.FreeAssets.FirstOrDefault(a => a.AssetId == asset.AssetId) != null);
// check with anonymous default package
var packageId = GlobalConfig.AnonymousDefaultPackageId;
if (!canPlay)
{
canPlay = User.IsAssetEntitled(context, offeringId, packageId, episodeId, assetId, countryCode, RightsType.Online);
}
else
{
clipDetails.IsFree = true;
}
// check user's access rights
if (!canPlay && thisUser.Identity.IsAuthenticated)
{
var user = context.Users.FirstOrDefault(u => u.UserId == new System.Guid(thisUser.Identity.Name));
if (user != null)
{
uCountryCode = user.CountryCode;
if (!String.IsNullOrEmpty(CountryCodeOverride))
uCountryCode = CountryCodeOverride;
// check access from default logged in user package
packageId = Helpers.GlobalConfig.LoggedInDefaultPackageId;
canPlay = User.IsAssetEntitled(context, offeringId, packageId, episodeId, assetId, countryCode, RightsType.Online);
if (!canPlay)
{
// check if user has entitlements that can play the video
canPlay = user.CanPlayVideo(offering, episode, asset, RightsType.Online);
}
else
{
clipDetails.IsFree = true;
}
}
}
// get asset URL
var assetCdn = asset.AssetCdns.FirstOrDefault(a => a.CdnId == cdnId);
if (assetCdn != null)
{
var hlsPrefixPattern = GlobalConfig.hlsLiveStreamPrefixPattern;
var hlsSuffixPattern = GlobalConfig.hlsLiveStreamSuffixPattern;
var zeriPrefixPattern = GlobalConfig.zeriLiveStreamPrefixPattern;
var zeriSuffixPattern = GlobalConfig.zeriLiveStreamSuffixPattern;
var httpPrefixPatternMobile = GlobalConfig.httpLiveStreamPrefixPatternMobile;
if (cdnId == 3) //Akamai HDN means Flash based.
videoUrl = assetCdn.CdnReference;
else
videoUrl = assetCdn.CdnReference.Replace(hlsPrefixPattern, httpPrefixPatternMobile);
if (!String.IsNullOrEmpty(videoUrl))
{
videoUrl = videoUrl.Trim();
}
string ipAddress = string.Empty;
if (!req.IsLocal)
ipAddress = req.GetUserHostAddressFromCloudflare();
int snippetStart = 0;
//.........这里部分代码省略.........
示例6: GetAkamaiProgressiveViaAdaptiveClipDetails
public static AkamaiFlowPlayerPluginClipDetails GetAkamaiProgressiveViaAdaptiveClipDetails(int episodeId, int assetId, HttpRequestBase req, System.Security.Principal.IPrincipal thisUser, Progressive progressive, VideoQualityCdnReference? quality = null)
{
AkamaiFlowPlayerPluginClipDetails clipDetails = null;
var offeringId = Helpers.GlobalConfig.offeringId;
var videoUrl = string.Empty;
var canPlay = false;
var countryCode = Helpers.MyUtility.getCountry(req.GetUserHostAddressFromCloudflare()).getCode();
var context = new IPTV2Entities();
var offering = context.Offerings.Find(offeringId);
var episode = context.Episodes.Find(episodeId);
var asset = context.Assets.Find(assetId);
var cdnId = 2; // akamai's cdn id
if (quality != null)
cdnId = (int)quality;
if ((episode != null) & (asset != null))
{
clipDetails = new AkamaiFlowPlayerPluginClipDetails { EpisodeId = episodeId, AssetId = assetId, UserId = (thisUser.Identity.IsAuthenticated ? thisUser.Identity.Name : null) };
canPlay = clipDetails.IsFree = (episode.PreviewAssets.FirstOrDefault(a => a.AssetId == asset.AssetId) != null) | (episode.FreeAssets.FirstOrDefault(a => a.AssetId == asset.AssetId) != null);
// check with anonymous default package
var packageId = GlobalConfig.AnonymousDefaultPackageId;
if (!canPlay)
{
canPlay = User.IsAssetEntitled(context, offeringId, packageId, episodeId, assetId, countryCode, RightsType.Online);
}
else
{
clipDetails.IsFree = true;
}
// check user's access rights
if (!canPlay && thisUser.Identity.IsAuthenticated)
{
var user = context.Users.FirstOrDefault(u => u.UserId == new System.Guid(thisUser.Identity.Name));
if (user != null)
{
// check access from default logged in user package
packageId = Helpers.GlobalConfig.LoggedInDefaultPackageId;
canPlay = User.IsAssetEntitled(context, offeringId, packageId, episodeId, assetId, countryCode, RightsType.Online);
if (!canPlay)
{
// check if user has entitlements that can play the video
//canPlay = user.CanPlayVideo(offering, episode, asset, RightsType.Online);
if (GlobalConfig.IsTVERegionBlockingEnabled)
{
var userCountryCode = MyUtility.GetCountryCodeViaIp();
int GomsSubsidiaryId = 0;
if (GlobalConfig.UseGomsSubsidiaryForTVECheck)
GomsSubsidiaryId = ContextHelper.GetGomsSubsidiaryIdOfCountry(context, userCountryCode);
else
GomsSubsidiaryId = -1;
//var GomsSubsidiaryId = ContextHelper.GetGomsSubsidiaryIdOfCountry(context, userCountryCode);
var IncludePackageIds = MyUtility.StringToIntList(GlobalConfig.CanPlayIncludedPackageIds);
var ExcludePackageIds = MyUtility.StringToIntList(GlobalConfig.CanPlayExcludedPackageIds);
canPlay = user.CanPlayVideo(offering, episode, asset, RightsType.Online, ExcludePackageIds, IncludePackageIds, userCountryCode, GomsSubsidiaryId);
if (GlobalConfig.IsTVEIpCheckEnabled)
{
try
{
string ip = GlobalConfig.IpWhiteList;
string[] IpAddresses = ip.Split(';');
if (IpAddresses.Contains(req.GetUserHostAddressFromCloudflare()))
canPlay = user.CanPlayVideo(offering, episode, asset, RightsType.Online);
}
catch (Exception e) { MyUtility.LogException(e, "AkamaiToken canPlay IP Whitelisting"); }
}
}
else
canPlay = user.CanPlayVideo(offering, episode, asset, RightsType.Online);
}
else
{
clipDetails.IsFree = true;
}
}
}
// get asset URL
var assetCdn = asset.AssetCdns.FirstOrDefault(a => a.CdnId == cdnId);
if (assetCdn != null)
{
var hlsPrefixPattern = GlobalConfig.hlsPrefixPattern;
var hlsSuffixPattern = GlobalConfig.hlsSuffixPattern;
var zeriPrefixPattern = GlobalConfig.zeriPrefixPattern;
var zeriSuffixPattern = GlobalConfig.zeriSuffixPattern;
var httpPrefixPatternMobile = GlobalConfig.httpPrefixPatternMobile;
bool isIpad = IsIpad(req);
bool isIos = IsIos(req);
if (isIos)
{
videoUrl = assetCdn.CdnReference.Replace(hlsPrefixPattern, httpPrefixPatternMobile);
//string limitUrl = "b=-" + (isIpad ? "5000,1100" : "5000,700") + "-"; // iPad up to 1Mbps, iPhone/iPod up to 500Kbps
//.........这里部分代码省略.........
示例7: CanPlayVideo
public static bool CanPlayVideo(IPTV2Entities context, Offering offering, Episode episode, Asset asset, System.Security.Principal.IPrincipal thisUser, HttpRequestBase req)
{
bool IsUserEntitled = false;
var profiler = MiniProfiler.Current;
using (profiler.Step("ContextHelper.CanPlayVideo"))
{
string CountryCode = GlobalConfig.DefaultCountry;
try
{
CountryCode = MyUtility.getCountry(req.GetUserHostAddressFromCloudflare()).getCode();
}
catch (Exception) { }
var packageId = GlobalConfig.AnonymousDefaultPackageId;
if (!IsUserEntitled)
IsUserEntitled = User.IsAssetEntitled(context, offering.OfferingId, packageId, episode.EpisodeId, asset.AssetId, CountryCode, RightsType.Online);
else
IsUserEntitled = true;
// check user's access rights
if (!IsUserEntitled && thisUser.Identity.IsAuthenticated)
{
var user = context.Users.FirstOrDefault(u => u.UserId == new System.Guid(thisUser.Identity.Name));
if (user != null)
{
// check access from default logged in user package
packageId = GlobalConfig.LoggedInDefaultPackageId;
IsUserEntitled = User.IsAssetEntitled(context, offering.OfferingId, packageId, episode.EpisodeId, asset.AssetId, user.CountryCode, RightsType.Online);
if (!IsUserEntitled)
{
if (GlobalConfig.IsTVERegionBlockingEnabled)
{
var userCountryCode = MyUtility.GetCountryCodeViaIp();
int GomsSubsidiaryId = 0;
if (GlobalConfig.UseGomsSubsidiaryForTVECheck)
GomsSubsidiaryId = ContextHelper.GetGomsSubsidiaryIdOfCountry(context, userCountryCode);
else
GomsSubsidiaryId = -1;
//var GomsSubsidiaryId = ContextHelper.GetGomsSubsidiaryIdOfCountry(context, userCountryCode);
//IsUserEntitled = user.CanPlayVideo(offering, episode, asset, RightsType.Online); // check if user has entitlements that can play the video
var IncludePackageIds = MyUtility.StringToIntList(GlobalConfig.CanPlayIncludedPackageIds);
var ExcludePackageIds = MyUtility.StringToIntList(GlobalConfig.CanPlayExcludedPackageIds);
IsUserEntitled = user.CanPlayVideo(offering, episode, asset, RightsType.Online, ExcludePackageIds, IncludePackageIds, userCountryCode, GomsSubsidiaryId);
if (GlobalConfig.IsTVEIpCheckEnabled)
{
try
{
string ip = GlobalConfig.IpWhiteList;
string[] IpAddresses = ip.Split(';');
if (IpAddresses.Contains(req.GetUserHostAddressFromCloudflare()))
IsUserEntitled = user.CanPlayVideo(offering, episode, asset, RightsType.Online);
}
catch (Exception e) { MyUtility.LogException(e, "ContextHelper IsUserEntitled IP Whitelisting"); }
}
}
else
IsUserEntitled = user.CanPlayVideo(offering, episode, asset, RightsType.Online);
}
else
IsUserEntitled = true;
}
}
}
////Check for subclips
//int snippetStart = 0;
//int snippetEnd = 0;
//AkamaiFlowPlayerPluginClipDetails clipDetails = null;
//if (!IsUserEntitled)
//{
// if ((asset.SnippetStart != null) && (asset.SnippetEnd != null) && (asset.SnippetEnd > asset.SnippetStart))
// {
// snippetStart = Convert.ToInt32(asset.SnippetStart.Value.TotalSeconds);
// snippetEnd = Convert.ToInt32(asset.SnippetEnd.Value.TotalSeconds);
// }
// else
// {
// snippetStart = 0;
// snippetEnd = GlobalConfig.snippetEnd;
// }
// clipDetails.PromptToSubscribe = true;
//}
//else
// clipDetails.PromptToSubscribe = false;
//clipDetails.SubClip = (snippetStart + snippetEnd > 0) ? new SubClip { Start = snippetStart, End = snippetEnd } : null;
//if (clipDetails.SubClip != null)
// IsUserEntitled = false;
//else
// IsUserEntitled = true;
return IsUserEntitled;
}