/// <inheritdoc /> public ulong GetRight(RightsType rightsType) { var isInstance = RightsHelper.IsInstanceRight(rightsType); //forces the null user check var pullThis = User; if (isInstance && InstanceUser == null) { return(0); } var rightsEnum = RightsHelper.RightToType(rightsType); // use the api versions because they're the ones that contain the actual properties var typeToCheck = isInstance ? typeof(InstanceUser) : typeof(User); var nullableType = typeof(Nullable <>); var nullableRightsType = nullableType.MakeGenericType(rightsEnum); var prop = typeToCheck.GetProperties().Where(x => x.PropertyType == nullableRightsType).First(); var right = prop.GetMethod.Invoke(isInstance ? (object)InstanceUser : User, Array.Empty <object>()); if (right == null) { throw new InvalidOperationException("A user right was null!"); } return((ulong)right); }
/// <summary> /// Sell rights for a particular parcel /// </summary> /// <param name="bp"></param> /// <param name="buyerId"></param> /// <param name="rightsType"></param> /// <param name="price"></param> public void SellRights(BuyPoint bp, UUID buyerId, RightsType rightsType, int price) { Player buyer = GetPlayer(buyerId); Player sellingPlayer = null; if (rightsType == RightsType.Water) { sellingPlayer = bp.WaterRightsOwner; } else { sellingPlayer = bp.DevelopmentRightsOwner; } m_log.InfoFormat( "[WATER WARS]: Starting process of player {0} selling {1} rights on {2} to {3} for {4}", sellingPlayer.Name, rightsType, bp.Name, buyer.Name, price); if (m_controller.AttachedToVe) { new AskLandBuyerInteraction( m_controller, m_controller.HudManager.m_playerIdToHud[sellingPlayer.Uuid], m_controller.HudManager.m_playerIdToHud[buyer.Uuid], bp, price, rightsType); } else { m_controller.State.SellRights(bp, buyer, rightsType, price); } }
public void FillCache(IPTV2Entities context, int offeringId, int serviceId, IEnumerable<int> categoryIds, RightsType rightsType, TimeSpan cacheDuration) { var countries = context.Countries; var offering = context.Offerings.FirstOrDefault(o => o.OfferingId == offeringId); var service = offering.Services.FirstOrDefault(s => s.PackageId == serviceId); // fill cache of all categories foreach (int categoryId in categoryIds) { try { var cat = context.CategoryClasses.FirstOrDefault(c => c.CategoryId == categoryId && c is Category); if (cat != null) { var category = (Category)cat; foreach (var c in countries) { try { // loop and fill cache for 1 hour var shows = service.GetAllShowIds(c.Code, category, rightsType, false); var cacheKey = service.GetCacheKey(c.Code, category, rightsType); DataCache.Cache.Put(cacheKey, shows, cacheDuration); } catch (Exception) { } } } } catch (Exception) { } } }
public void TriggerLandRightsSold(BuyPoint bp, Player buyer, Player seller, RightsType type, int salePrice, bool success) { if (OnLandRightsSold != null) { OnLandRightsSold(bp, buyer, seller, type, salePrice, success); } }
public SortedSet<Package> GetPackages(Offering offering, String countryCode, RightsType rightsType) { var packages = new SortedSet<Package>(); foreach (var p in offering.PackageSubscriptionProducts) { if (p.IsAllowed(countryCode)) { foreach (var package in p.Packages) { bool isInPackage = false; switch (rightsType) { case RightsType.IPTV: isInPackage = package.Package.GetAllIptvShowIds(countryCode).Contains(CategoryId); break; case RightsType.Online: isInPackage = package.Package.GetAllOnlineShowIds(countryCode).Contains(CategoryId); break; case RightsType.Mobile: isInPackage = package.Package.GetAllMobileShowIds(countryCode).Contains(CategoryId); break; default: throw new Exception("Invalid RightsType."); } if (isInPackage && package.Package is Package) { packages.Add((Package)package.Package); } } } } return (packages.Count > 0 ? packages : null); }
public void FillCache(IPTV2Entities context, int offeringId, RightsType rightsType, TimeSpan cacheDuration) { var packageList = context.PackageTypes.Where(p => p.OfferingId == offeringId).ToList(); var countries = context.Countries.ToList(); // fill cache of all packages long totalSize = 0; foreach (var p in packageList) { foreach (var c in countries) { // loop and fill cache for 1 hour // fill show IDs var shows = p.GetAllShowIds(c.Code, rightsType, false); var cacheKey = p.GetCacheKey(c.Code, rightsType); DataCache.Cache.Put(cacheKey, shows, cacheDuration); totalSize += GetObjectSize(shows); // fill channel IDs cacheKey = p.GetChannelsCacheKey(c.Code, rightsType); var channels = p.GetAllChannelIds(c.Code, rightsType, false); DataCache.Cache.Put(cacheKey, channels, cacheDuration); } } }
private string RightTypeToString(RightsType rightsType) { string value = $"-{rightsType.ToString().ToLower()}"; value = value.Replace("own", "-own"); value = value.Replace("group", "-group"); return(value); }
public async Task <bool> IsRightAsync(WebAppUser user, RightsType rightsType, string idForm) { bool result; string right = RightTypeToString(rightsType); IList <Claim> claims = await GetClaimsAsync(user); result = claims.Where(x => x.Type == idForm && x.Value == right).Any(); return(result); }
public AskLandBuyerInteraction( WaterWarsController controller, HudView playerHud, HudView targetPlayerHud, BuyPoint bp, int salePrice, RightsType rightsToSell) : base(controller, playerHud, targetPlayerHud) { m_bp = bp; if (!m_controller.Game.Players.TryGetValue(playerHud.UserId, out m_p)) return; if (!m_controller.Game.Players.TryGetValue(targetPlayerHud.UserId, out m_targetPlayer)) return; m_salePrice = salePrice; m_rightsToSell = rightsToSell; AskBuyer(); }
public AskLandBuyerInteraction( WaterWarsController controller, HudView playerHud, HudView targetPlayerHud, BuyPoint bp, int salePrice, RightsType rightsToSell) : base(controller, playerHud, targetPlayerHud) { m_bp = bp; if (!m_controller.Game.Players.TryGetValue(playerHud.UserId, out m_p)) { return; } if (!m_controller.Game.Players.TryGetValue(targetPlayerHud.UserId, out m_targetPlayer)) { return; } m_salePrice = salePrice; m_rightsToSell = rightsToSell; AskBuyer(); }
protected void ProcessGeneralParcelSold( BuyPoint bp, Player buyer, Player seller, RightsType type, int price, int waterRights, bool success) { if (null == m_xtw) { return; } lock (this) { RecordEventStart(ParcelSoldElement); RecordBuyPointReference(bp); m_xtw.WriteStartElement(BuyerElement); RecordPlayerReference(buyer); m_xtw.WriteEndElement(); m_xtw.WriteStartElement(SellerElement); RecordPlayerReference(seller); m_xtw.WriteEndElement(); m_xtw.WriteElementString(PriceElement, price.ToString()); m_xtw.WriteElementString(WaterRightsElement, waterRights.ToString()); m_xtw.WriteElementString(SucceededElement, success.ToString()); RecordEventEnd(); } }
/// <summary> /// 作者:Vincen /// 时间:2014.04.16 /// 描述:获取权限列表,通过权限类型 /// </summary> /// <param name="rightsType"></param> /// <returns></returns> public static List<Rights> GetRightsListByRightsType(RightsType rightsType) { var Db = new EmeEntities(dbRead); var rtype = CommonHelper.To<int>(rightsType); return Db.Rights.Where(p => p.RightsType == rtype && p.Status == ConvertEnum.StatusTypeForActive).OrderBy(p => p.OrderNum).ToList(); }
/// <summary> /// 作者:Vincen /// 时间:2014.05.08 /// 描述:获取权限列表 /// </summary> /// <param name="rightsType"></param> /// <param name="parentId"></param> /// <returns></returns> public static List<Rights> GetRightsList(RightsType rightsType, int parentId) { var Db = new EmeEntities(dbRead); var rtype = CommonHelper.To<int>(rightsType); return Db.Rights.Where(p => p.RightsType == rtype && p.ParentId == parentId && p.Status == ConvertEnum.StatusTypeForActive).ToList(); }
/// <summary> /// 作者:Vincen /// 时间:2014.05.08 /// 描述:For 获取菜单列表 /// </summary> /// <param name="rightsType"></param> /// <param name="area"></param> /// <param name="controller"></param> /// <param name="view"></param> /// <returns></returns> public static Rights GetRightsForMenu(RightsType rightsType, string area, string controller, string view) { var Db = new EmeEntities(dbRead); var rtype = CommonHelper.To<int>(rightsType); var model = Db.Rights.FirstOrDefault(p => p.RightsType >= rtype && p.Areas.Equals(area, StringComparison.CurrentCultureIgnoreCase) && p.Controllers.Equals(controller, StringComparison.CurrentCultureIgnoreCase) && p.Views.Equals(view, StringComparison.CurrentCultureIgnoreCase) && p.Status == ConvertEnum.StatusTypeForActive); if (model != null && model.RightsType == CommonHelper.To<int>(rightsType)) { return model; } if (model != null) { var parent = Db.Rights.SingleOrDefault(p => p.Id == model.ParentId); if (parent != null) { return GetRightsForMenu(rightsType, parent.Areas, parent.Controllers, parent.Views); } } return model; }
public void FillCacheOfAllSubscriptionProducts(IPTV2Entities context, int offeringId, RightsType rightsType, TimeSpan cacheDuration) { SortedSet<SubscriptionProductC> productCs = null; string cacheKey = "SPC:O:" + offeringId.ToString(); var products = context.Products.Where(p => p.OfferingId == offeringId && p is SubscriptionProduct && p.StatusId == 1); if (products.Count() > 0) { productCs = new SortedSet<SubscriptionProductC>(); foreach (var product in products) { productCs.Add(SubscriptionProductC.Load(context, offeringId, product.ProductId, false)); } DataCache.Cache.Put(cacheKey, productCs, cacheDuration); } }
/// <summary> /// Check if a given <paramref name="rightsType"/> is meant for an <see cref="Models.Instance"/> /// </summary> /// <param name="rightsType">The <see cref="RightsType"/> to check</param> /// <returns><see langword="true"/> if <paramref name="rightsType"/> is an instance right, <see langword="false"/> otherwise</returns> public static bool IsInstanceRight(RightsType rightsType) => !(rightsType == RightsType.Administration || rightsType == RightsType.InstanceManager);
public virtual void SellRights(BuyPoint bp, Player buyer, RightsType type, int salePrice) { throw new NotImplementedException(); }
public void FillCache(IPTV2Entities context, int offeringId, RightsType rightsType, TimeSpan cacheDuration) { SubscriptionProductC.LoadAll(context, offeringId, true, cacheDuration); }
public SortedSet<int> GetShowProductIds(Offering offering, String countryCode, RightsType rightsType, bool useCache) { SortedSet<int> showProductList = null; var cache = DataCache.Cache; var cacheKey = GetShowProductIdsCacheKey(offering.OfferingId, countryCode, rightsType); if (useCache) { showProductList = (SortedSet<int>)cache[cacheKey]; } if (showProductList == null) { showProductList = new SortedSet<int>(); var showProducts = GetShowProducts(offering, countryCode, rightsType); if (showProducts != null) foreach (var showProduct in showProducts) { showProductList.Add(showProduct.ProductId); } showProductList = showProductList.Count > 0 ? showProductList : null; if (useCache && showProductList != null) { cache.Put(cacheKey, showProductList, DataCache.CacheDuration); } } return showProductList; }
public string GetShowProductIdsCacheKey(int offeringId, String countryCode, RightsType rightsType) { return "SSPId:O:" + offeringId.ToString() + "Cat:" + CategoryId.ToString() + ";C:" + countryCode + ";R:" + rightsType.ToString(); }
protected void ProcessParcelSold( BuyPoint bp, Player buyer, Player seller, RightsType type, int price, bool success) { ProcessGeneralParcelSold(bp, buyer, seller, type, price, 0, success); }
public void AddRights(int HabboId, RightsType Type) { Rights.Add(HabboId, Type); }
public Boolean HasRights(int HabboId, RightsType Type) { if (Rights.ContainsKey(HabboId)) { if (Type.Equals(RightsType.Founder)) { return Rights[HabboId].Equals(RightsType.Founder); } if (Type.Equals(RightsType.Rights)) { return Rights[HabboId].Equals(RightsType.Rights) || Rights[HabboId].Equals(RightsType.Founder); } } return false; }
/// <summary> /// 作者:Vincen /// 时间:2014.04.23 /// 描述:获取权限列表,通过用户编号和权限类型 /// </summary> /// <param name="userId"></param> /// <param name="rightsType"></param> /// <returns></returns> public static List<Rights> GetUserRightsList(int userId, RightsType rightsType) { var Db = new EmeEntities(); var user = Db.User.SingleOrDefault(p => p.Id == userId); if (null == user) { return new List<Rights>(); } var rType = CommonHelper.To<int>(rightsType); if (user.IsOverwriteRights) { var query1 = from a in Db.Rights join b in Db.UserRights on a.Id equals b.RightsId where b.UserId == userId && b.Status == ConvertEnum.StatusTypeForActive && a.RightsType == rType select a; return query1.Distinct().AsNoTracking().ToList(); } var query2 = from a in Db.Rights join b in Db.RoleRights on a.Id equals b.RightsId join c in Db.JobRoles on b.RoleId equals c.RoleId join d in Db.UserJob on c.JobId equals d.JobId where d.UserId == userId && d.Status == ConvertEnum.StatusTypeForActive && a.RightsType == rType select a; return query2.Distinct().AsNoTracking().ToList(); }
public void FillCacheOfAllPackageAndProduct(IPTV2Entities context, int offeringId, string DefaultCurrency, RightsType rightsType, TimeSpan cacheDuration) { var categories = context.CategoryClasses.Where(c => c.StatusId == 1 && c is Show).ToList(); var countries = context.Countries.ToList(); var offering = context.Offerings.Find(offeringId); foreach (var category in categories) { var categoryId = category.CategoryId; foreach (var country in countries) { try { var countryCode = country.Code; string cacheKey = "SGPP:Cat:" + categoryId.ToString() + ";C:" + countryCode; //create helper class for displaying content to the View List<ShowAlacarteProduct> showAlarcarteProducts = new List<ShowAlacarteProduct>(); //create helper class for displaying content to the View List<ShowPackageGroupProduct> showPackageGroupProductList = new List<ShowPackageGroupProduct>(); ShowPackageProductPrices showPackageProductPrices = new ShowPackageProductPrices(); string currencyCode = PackageCacheRefresher.GetCurrencyOrDefault(countryCode, DefaultCurrency); var show = (Show)category; var packageProductIds = show.GetPackageProductIds(offering, countryCode, RightsType.Online); var showProductIds = show.GetShowProductIds(offering, countryCode, RightsType.Online); var subscriptionProductC = SubscriptionProductC.LoadAll(context, offering.OfferingId) .Where(p => p.IsAllowed(countryCode)); string AlaCarteCacheKey = "SALACARTEPRD:Cat:" + categoryId.ToString() + ";C:" + countryCode; var cacheItem = DataCache.Cache.GetCacheItem(AlaCarteCacheKey); if (cacheItem != null) { showAlarcarteProducts = (List<ShowAlacarteProduct>)DataCache.Cache[AlaCarteCacheKey]; } else { if (showProductIds != null) { var showProducts = from product in subscriptionProductC join id in showProductIds on product.ProductId equals id where product.IsForSale select product; //show product with alacarte subscription var aLaCarteProducts = from showproducts in showProducts join subcription in show.Products on showproducts.ProductId equals subcription.ProductId select new { ALaCarteSubscriptionTypeId = subcription.Product.ALaCarteSubscriptionTypeId, ProductPrices = showproducts.ProductPrices, Duration = showproducts.Duration, DurationInDays = showproducts.DurationInDays, DurationType = showproducts.DurationType, ProductId = showproducts.ProductId, CategoryId = subcription.CategoryId }; foreach (var item in aLaCarteProducts) { showAlarcarteProducts.Add(new ShowAlacarteProduct { ALaCarteSubscriptionTypeId = item.ALaCarteSubscriptionTypeId, Duration = item.Duration, DurationInDays = item.DurationInDays, DurationType = item.DurationType, CurrencyCode = currencyCode, ProductId = item.ProductId, CategoryId = item.CategoryId, ProductPrices = item.ProductPrices.Where(p => p.CurrencyCode == currencyCode).ToList() }); } } } string PackageCacheKey = "SPKGPRD:Cat:" + categoryId.ToString() + ";C:" + countryCode; var PackageCacheItem = DataCache.Cache.GetCacheItem(PackageCacheKey); if (PackageCacheItem != null) { showPackageGroupProductList = (List<ShowPackageGroupProduct>)DataCache.Cache[PackageCacheKey]; } else { if (packageProductIds != null) { //join the packageproduct to get the packageID var packageProducts = from product in subscriptionProductC join id in packageProductIds on product.ProductId equals id where product.IsForSale select product; var packageGroupProducts = from product in packageProducts group product by product.ProductGroupId into ProductGroup orderby ProductGroup.Key select new { GroupId = ProductGroup.Key, Products = ( from product2 in ProductGroup orderby product2.DurationInDays descending select new Product2 { ProductId = product2.ProductId, Description = product2.Description, Duration = product2.Duration, DurationInDays = product2.DurationInDays, DurationType = product2.DurationType, ProductPrice = product2.ProductPrices.FirstOrDefault(p => p.CurrencyCode == currencyCode) } ) }; foreach (var item in packageGroupProducts) { showPackageGroupProductList.Add(new ShowPackageGroupProduct { ProductGroupId = item.GroupId, Product2 = item.Products.ToList() }); } } } //Upgradable Products showPackageProductPrices.ShowAlacarteProductList = showAlarcarteProducts; showPackageProductPrices.ShowPackageGroupProductList = showPackageGroupProductList; DataCache.Cache.Put(cacheKey, showPackageProductPrices, cacheDuration); } catch (Exception e) { Trace.TraceInformation(e.Message); } } } }
public override void SellRights(BuyPoint bp, Player buyer, RightsType type, int salePrice) { Player seller = Player.None; if (type == RightsType.Development || type == RightsType.Combined) seller = bp.DevelopmentRightsOwner; else seller = bp.WaterRightsOwner; if (!bp.OwnerActions.ContainsKey("SellDevelopmentRights")) throw new WaterWarsGameLogicException( "Player {0} tried to sell development rights on {1} in {2} but they have already sold game assets to the economy on this parcel", seller.Name, bp.Name, bp.Location.RegionName); if (buyer.Money < salePrice) throw new WaterWarsGameLogicException( "Player {0} tried to buy {1} rights for {2} from {3} for {4} but they only have {5}", buyer, type, bp, seller, salePrice, buyer.Money); m_log.InfoFormat( "[WATER WARS]: Player {0} selling {1} rights of {2} to {3} for {4}", seller, type, bp, buyer, salePrice); // Perform the transaction if (type == RightsType.Water || type == RightsType.Combined) bp.WaterRightsOwner = buyer; buyer.Money -= salePrice; buyer.LandCostsThisTurn += salePrice; seller.Money += salePrice; seller.LandRevenueThisTurn += salePrice; // If we're selling development rights then we also need to remove any game assets already on the parcel if (type == RightsType.Development || type == RightsType.Combined) { lock (bp.GameAssets) { foreach (AbstractGameAsset asset in bp.GameAssets.Values) m_controller.Dispatcher.RemoveGameAssetView(asset); } bp.RemoveAllGameAssets(); } if (type == RightsType.Development || type == RightsType.Combined) TransferDevelopmentRights(bp, buyer); m_controller.EventManager.TriggerLandRightsSold(bp, buyer, seller, type, salePrice, true); buyer.TriggerChanged(); seller.TriggerChanged(); bp.TriggerChanged(); // FIXME: Should be done via event subscription. UpdateHudStatus(buyer); UpdateHudStatus(seller); m_controller.Events.PostToAll( string.Format(SELL_RIGHTS_CRAWL_MSG, seller.Name, type, bp.Name, bp.Location.RegionName, buyer.Name), EventLevel.Crawl); }
public void FillCacheOfAllPackageProducts(IPTV2Entities context, int offeringId, string DefaultCurrency, RightsType rightsType, TimeSpan cacheDuration) { var categories = context.CategoryClasses.Where(c => c.StatusId == 1 && c is Show).ToList(); var countries = context.Countries.ToList(); var offering = context.Offerings.Find(offeringId); foreach (var category in categories) { var categoryId = category.CategoryId; foreach (var country in countries) { try { var countryCode = country.Code; string cacheKey = "SPKGPRD:Cat:" + categoryId.ToString() + ";C:" + countryCode; List<ShowPackageGroupProduct> showPackageGroupProductList = new List<ShowPackageGroupProduct>(); string currencyCode = PackageCacheRefresher.GetCurrencyOrDefault(countryCode, DefaultCurrency); var show = (Show)category; var packageProductIds = show.GetPackageProductIds(offering, countryCode, RightsType.Online); var subscriptionProductC = SubscriptionProductC.LoadAll(context, offering.OfferingId) .Where(p => p.IsAllowed(countryCode)); if (packageProductIds != null) { //join the packageproduct to get the packageID var packageProducts = from product in subscriptionProductC join id in packageProductIds on product.ProductId equals id where product.IsForSale select product; var packageGroupProducts = from product in packageProducts group product by product.ProductGroupId into ProductGroup orderby ProductGroup.Key select new { GroupId = ProductGroup.Key, Products = ( from product2 in ProductGroup orderby product2.DurationInDays descending select new Product2 { ProductId = product2.ProductId, Description = product2.Description, Duration = product2.Duration, DurationInDays = product2.DurationInDays, DurationType = product2.DurationType, ProductPrice = product2.ProductPrices.FirstOrDefault(p => p.CurrencyCode == currencyCode) } ) }; foreach (var item in packageGroupProducts) { showPackageGroupProductList.Add(new ShowPackageGroupProduct { ProductGroupId = item.GroupId, Product2 = item.Products.ToList() }); } } DataCache.Cache.Put(cacheKey, showPackageGroupProductList, cacheDuration); } catch (Exception e) { Trace.TraceInformation(e.Message); } } } }
public SortedSet<int> GetPackageProductIds(Offering offering, String countryCode, RightsType rightsType, bool useCache) { SortedSet<int> packageProductList = null; var cache = DataCache.Cache; var cacheKey = GetPackageProductIdsCacheKey(offering.OfferingId, countryCode, rightsType); if (useCache) { packageProductList = (SortedSet<int>)cache[cacheKey]; } if (packageProductList == null) { packageProductList = new SortedSet<int>(); var packageProducts = GetPackageProducts(offering, countryCode, rightsType); if (packageProducts != null) { foreach (var packageProduct in packageProducts) { packageProductList.Add(packageProduct.ProductId); } } packageProductList = packageProductList.Count > 0 ? packageProductList : null; if (useCache && packageProductList != null) { cache.Put(cacheKey, packageProductList, DataCache.CacheDuration); } } return packageProductList; }
public SortedSet<int> GetShowProductIds(Offering offering, String countryCode, RightsType rightsType) { return GetShowProductIds(offering, countryCode, rightsType, true); }
/// <summary> /// Sell rights for a particular parcel /// </summary> /// <param name="bp"></param> /// <param name="buyerId"></param> /// <param name="rightsType"></param> /// <param name="price"></param> public void SellRights(BuyPoint bp, UUID buyerId, RightsType rightsType, int price) { Player buyer = GetPlayer(buyerId); Player sellingPlayer = null; if (rightsType == RightsType.Water) sellingPlayer = bp.WaterRightsOwner; else sellingPlayer = bp.DevelopmentRightsOwner; m_log.InfoFormat( "[WATER WARS]: Starting process of player {0} selling {1} rights on {2} to {3} for {4}", sellingPlayer.Name, rightsType, bp.Name, buyer.Name, price); if (m_controller.AttachedToVe) new AskLandBuyerInteraction( m_controller, m_controller.HudManager.m_playerIdToHud[sellingPlayer.Uuid], m_controller.HudManager.m_playerIdToHud[buyer.Uuid], bp, price, rightsType); else m_controller.State.SellRights(bp, buyer, rightsType, price); }
public SortedSet<ShowSubscriptionProduct> GetShowProducts(Offering offering, String countryCode, RightsType rightsType) { var products = new SortedSet<ShowSubscriptionProduct>(); if (StatusId == 1) { bool isAllowed = false; switch (rightsType) { case RightsType.IPTV: isAllowed = IsIptvAllowed(countryCode); break; case RightsType.Mobile: isAllowed = IsMobileAllowed(countryCode); break; case RightsType.Online: isAllowed = IsOnlineAllowed(countryCode); break; default: throw new Exception("Invalid rightsType."); } if (isAllowed) { var productShows = Products.Where(p => (p.Product.OfferingId == offering.OfferingId) && (p.Product.StatusId == 1)); foreach (var p in productShows) { products.Add(p.Product); } } } return (products.Count > 0 ? products : null); }
/// <summary> /// Map a given <paramref name="rightsType"/> to its respective <see cref="Enum"/> <see cref="Type"/> /// </summary> /// <param name="rightsType">The <see cref="RightsType"/> to lookup</param> /// <returns>The <see cref="Enum"/> <see cref="Type"/> of the given <paramref name="rightsType"/></returns> public static Type RightToType(RightsType rightsType) => TypeMap[rightsType];
public SortedSet<PackageSubscriptionProduct> GetPackageProducts(Offering offering, String countryCode, RightsType rightsType, bool useCache, TimeSpan cacheDuration) { var products = new SortedSet<PackageSubscriptionProduct>(); foreach (var p in offering.PackageSubscriptionProducts) { if (p.IsAllowed(countryCode)) { foreach (var package in p.Packages) { bool isInPackage = false; switch (rightsType) { case RightsType.IPTV: isInPackage = package.Package.GetAllChannelIds(countryCode, RightsType.IPTV, useCache, cacheDuration).Contains(ChannelId); break; case RightsType.Online: isInPackage = package.Package.GetAllChannelIds(countryCode, RightsType.Online, useCache, cacheDuration).Contains(ChannelId); break; case RightsType.Mobile: isInPackage = package.Package.GetAllChannelIds(countryCode, RightsType.Mobile, useCache, cacheDuration).Contains(ChannelId); break; default: throw new Exception("Invalid RightsType."); } if (isInPackage) { products.Add(p); } } } } return (products.Count > 0 ? products : null); }
public void FillCacheOfAllAlaCarteProducts(IPTV2Entities context, int offeringId, string DefaultCurrency, RightsType rightsType, TimeSpan cacheDuration) { var categories = context.CategoryClasses.Where(c => c.StatusId == 1 && c is Show).ToList(); var countries = context.Countries.ToList(); var offering = context.Offerings.Find(offeringId); foreach (var category in categories) { var categoryId = category.CategoryId; foreach (var country in countries) { try { var countryCode = country.Code; string cacheKey = "SALACARTEPRD:Cat:" + categoryId.ToString() + ";C:" + countryCode; List<ShowAlacarteProduct> showAlarcarteProducts = new List<ShowAlacarteProduct>(); string currencyCode = PackageCacheRefresher.GetCurrencyOrDefault(countryCode, DefaultCurrency); var show = (Show)category; var showProductIds = show.GetShowProductIds(offering, countryCode, RightsType.Online); var subscriptionProductC = SubscriptionProductC.LoadAll(context, offering.OfferingId) .Where(p => p.IsAllowed(countryCode)); if (showProductIds != null) { var showProducts = from product in subscriptionProductC join id in showProductIds on product.ProductId equals id where product.IsForSale select product; //show product with alacarte subscription var aLaCarteProducts = from showproducts in showProducts join subcription in show.Products on showproducts.ProductId equals subcription.ProductId select new { ALaCarteSubscriptionTypeId = subcription.Product.ALaCarteSubscriptionTypeId, ProductPrices = showproducts.ProductPrices, Duration = showproducts.Duration, DurationInDays = showproducts.DurationInDays, DurationType = showproducts.DurationType, ProductId = showproducts.ProductId, CategoryId = subcription.CategoryId }; foreach (var item in aLaCarteProducts) { showAlarcarteProducts.Add(new ShowAlacarteProduct { ALaCarteSubscriptionTypeId = item.ALaCarteSubscriptionTypeId, Duration = item.Duration, DurationInDays = item.DurationInDays, DurationType = item.DurationType, CurrencyCode = currencyCode, ProductId = item.ProductId, CategoryId = item.CategoryId, ProductPrices = item.ProductPrices.Where(p => p.CurrencyCode == currencyCode).ToList() }); } } DataCache.Cache.Put(cacheKey, showAlarcarteProducts, cacheDuration); } catch (Exception e) { Trace.TraceInformation(e.Message); } } } }
public string GetPackageProductIdsCacheKey(int offeringId, String countryCode, RightsType rightsType) { return "CPPId:O:" + offeringId.ToString() + "Ch:" + ChannelId.ToString() + ";C:" + countryCode + ";R:" + rightsType.ToString(); }
public void TriggerLandRightsSold(BuyPoint bp, Player buyer, Player seller, RightsType type, int salePrice, bool success) { if (OnLandRightsSold != null) OnLandRightsSold(bp, buyer, seller, type, salePrice, success); }
/// <summary> /// Gets the role claim name used for a given <paramref name="rightsType"/> and <paramref name="right"/> /// </summary> /// <param name="rightsType">The <see cref="RightsType"/></param> /// <param name="right">The right value</param> /// <returns>A <see cref="string"/> representing the claim role name</returns> public static string RoleName(RightsType rightsType, Enum right) { var enumType = RightToType(rightsType); return(String.Concat(enumType.Name, '.', Enum.GetName(enumType, right))); }
public SortedSet<int> GetPackageProductIds(Offering offering, String countryCode, RightsType rightsType, bool useCache) { return GetPackageProductIds(offering, countryCode, rightsType, useCache, DataCache.CacheDuration); }
/// <summary> /// Gets the role claim name used for a given <paramref name="rightsType"/> and <paramref name="right"/> /// </summary> /// <param name="rightsType">The <see cref="RightsType"/></param> /// <param name="right">The right value</param> /// <returns>A <see cref="string"/> representing the claim role name</returns> public static string RoleName(RightsType rightsType, Enum right) { var enumType = typeMap[rightsType]; return(String.Concat(enumType.Name, '.', Enum.GetName(enumType, right))); }
public override void SellRights(BuyPoint bp, Player buyer, RightsType type, int salePrice) { Player seller = Player.None; if (type == RightsType.Development || type == RightsType.Combined) { seller = bp.DevelopmentRightsOwner; } else { seller = bp.WaterRightsOwner; } if (!bp.OwnerActions.ContainsKey("SellDevelopmentRights")) { throw new WaterWarsGameLogicException( "Player {0} tried to sell development rights on {1} in {2} but they have already sold game assets to the economy on this parcel", seller.Name, bp.Name, bp.Location.RegionName); } if (buyer.Money < salePrice) { throw new WaterWarsGameLogicException( "Player {0} tried to buy {1} rights for {2} from {3} for {4} but they only have {5}", buyer, type, bp, seller, salePrice, buyer.Money); } m_log.InfoFormat( "[WATER WARS]: Player {0} selling {1} rights of {2} to {3} for {4}", seller, type, bp, buyer, salePrice); // Perform the transaction if (type == RightsType.Water || type == RightsType.Combined) { bp.WaterRightsOwner = buyer; } buyer.Money -= salePrice; buyer.LandCostsThisTurn += salePrice; seller.Money += salePrice; seller.LandRevenueThisTurn += salePrice; // If we're selling development rights then we also need to remove any game assets already on the parcel if (type == RightsType.Development || type == RightsType.Combined) { lock (bp.GameAssets) { foreach (AbstractGameAsset asset in bp.GameAssets.Values) { m_controller.Dispatcher.RemoveGameAssetView(asset); } } bp.RemoveAllGameAssets(); } if (type == RightsType.Development || type == RightsType.Combined) { TransferDevelopmentRights(bp, buyer); } m_controller.EventManager.TriggerLandRightsSold(bp, buyer, seller, type, salePrice, true); buyer.TriggerChanged(); seller.TriggerChanged(); bp.TriggerChanged(); // FIXME: Should be done via event subscription. UpdateHudStatus(buyer); UpdateHudStatus(seller); m_controller.Events.PostToAll( string.Format(SELL_RIGHTS_CRAWL_MSG, seller.Name, type, bp.Name, bp.Location.RegionName, buyer.Name), EventLevel.Crawl); }
protected void ProcessGeneralParcelSold( BuyPoint bp, Player buyer, Player seller, RightsType type, int price, int waterRights, bool success) { if (null == m_xtw) return; lock (this) { RecordEventStart(ParcelSoldElement); RecordBuyPointReference(bp); m_xtw.WriteStartElement(BuyerElement); RecordPlayerReference(buyer); m_xtw.WriteEndElement(); m_xtw.WriteStartElement(SellerElement); RecordPlayerReference(seller); m_xtw.WriteEndElement(); m_xtw.WriteElementString(PriceElement, price.ToString()); m_xtw.WriteElementString(WaterRightsElement, waterRights.ToString()); m_xtw.WriteElementString(SucceededElement, success.ToString()); RecordEventEnd(); } }