public static void CancelCardReservationsExceedingMaxConcurrentTickets(IDictionary <CardDetail, ICardTuneReservationTicket> tickets, ICollection <CardDetail> freeCards, IDictionary <int, ITvCardHandler> cards) { if (freeCards != null && freeCards.Count > 0) { IDictionary <int, CardDetail> freeCardsDict = new Dictionary <int, CardDetail>(); foreach (CardDetail cardDetail in freeCards) { if (!freeCardsDict.ContainsKey(cardDetail.Id)) { freeCardsDict.Add(cardDetail.Id, cardDetail); } } if (freeCardsDict.Count > 2) { Log.Info( "CancelCardReservationsExceedingMaxConcurrentTickets: cancel excess tickets, only 2 allowed at a time but found {0}", tickets.Count); while (freeCardsDict.Count > 2) { CardDetail cardDetailForReservation = freeCardsDict.Values.LastOrDefault(); if (cardDetailForReservation != null) { int idcard = cardDetailForReservation.Card.IdCard; CancelCardReservationAndRemoveTicket(cardDetailForReservation, tickets, cards); freeCardsDict.Remove(cardDetailForReservation.Id); } } } } }
private void LogNumberOfOtherUsersFound(CardDetail cardDetail) { if (LogEnabled && cardDetail.Card.IdCard > 0) { var tvController = _controller as TVController; if (tvController != null) { ITvCardHandler card = tvController.CardCollection[cardDetail.Card.IdCard]; Log.Info("Controller: card:{0} type:{1} users: {2}", cardDetail.Card.IdCard, card.Type, cardDetail.NumberOfOtherUsers); } } }
public static void CancelCardReservationAndRemoveTicket(CardDetail cardDetail, IDictionary <CardDetail, ICardTuneReservationTicket> tickets, IDictionary <int, ITvCardHandler> cards) { if (cardDetail != null && tickets != null) { ICardTuneReservationTicket ticket; bool hasTicket = tickets.TryGetValue(cardDetail, out ticket); if (hasTicket) { tickets.Remove(cardDetail); ITvCardHandler cardHandler = cards[cardDetail.Id]; CancelCardReservation(cardHandler, ticket); } } }
public static ICardTuneReservationTicket RequestCardReservation(IUser user, CardDetail cardDetail, TVController tvController, ICardReservation cardResImpl, int idChannel) { ICardTuneReservationTicket ticket = null; int idCard = cardDetail.Card.IdCard; IUser userCopy = user.Clone() as User; if (userCopy != null) { IDictionary <int, ITvCardHandler> cards = tvController.CardCollection; userCopy.CardId = idCard; ITvCardHandler tvcard = cards[idCard]; ticket = cardResImpl.RequestCardTuneReservation(tvcard, cardDetail.TuningDetail, userCopy, idChannel); } return(ticket); }
public static void CancelCardReservationsBasedOnMaxCardsLimit(IDictionary <CardDetail, ICardTuneReservationTicket> tickets, ICollection <CardDetail> freeCards, int maxCards, IDictionary <int, ITvCardHandler> cards) { int exceedingCardsCount = freeCards.Count() - maxCards; if (exceedingCardsCount > 0) { if (tickets != null && tickets.Count > 0) { while (freeCards.Count() > exceedingCardsCount) { CardDetail cardDetailForReservation = freeCards.LastOrDefault(); if (cardDetailForReservation != null) { int idcard = cardDetailForReservation.Card.IdCard; CancelCardReservationAndRemoveTicket(cardDetailForReservation, tickets, cards); } freeCards.Remove(cardDetailForReservation); } } } }
private static void CancelMissingCardReservation(IEnumerable <CardDetail> freeCards, CardDetail cardDetailForReservation, IDictionary <CardDetail, ICardTuneReservationTicket> tickets, IDictionary <int, ITvCardHandler> cards) { int idcard = cardDetailForReservation.Card.IdCard; if (freeCards != null && !freeCards.Any(t => t.Card.IdCard == idcard)) { CancelCardReservationAndRemoveTicket(cardDetailForReservation, tickets, cards); } }
/// <summary> /// Gets a list of all available cards which can receive the channel specified /// List is sorted. /// </summary> /// <returns>list containg all cards which can receive the channel</returns> public List <CardDetail> GetAvailableCardsForChannel(Dictionary <int, ITvCardHandler> cards, Channel dbChannel, ref IUser user, out Dictionary <int, TvResult> cardsUnAvailable) { Stopwatch stopwatch = Stopwatch.StartNew(); cardsUnAvailable = new Dictionary <int, TvResult>(); try { //Log.Info("GetFreeCardsForChannel st {0}", Environment.StackTrace); //construct list of all cards we can use to tune to the new channel var cardsAvailable = new List <CardDetail>(); if (LogEnabled) { Log.Info("Controller: find card for channel {0}", dbChannel.DisplayName); } //get the tuning details for the channel List <IChannel> tuningDetails = _businessLayer.GetTuningChannelsByDbChannel(dbChannel); bool isValidTuningDetails = IsValidTuningDetails(tuningDetails); if (!isValidTuningDetails) { //no tuning details?? if (LogEnabled) { Log.Info("Controller: No tuning details for channel:{0}", dbChannel.DisplayName); } return(cardsAvailable); } if (LogEnabled) { Log.Info("Controller: got {0} tuning details for {1}", tuningDetails.Count, dbChannel.DisplayName); } int number = 0; Dictionary <int, ITvCardHandler> .ValueCollection cardHandlers = cards.Values; foreach (IChannel tuningDetail in tuningDetails) { cardsUnAvailable.Clear(); number++; if (LogEnabled) { Log.Info("Controller: channel #{0} {1} ", number, tuningDetail.ToString()); } foreach (ITvCardHandler cardHandler in cardHandlers) { int cardId = cardHandler.DataBaseCard.IdCard; if (cardsUnAvailable.ContainsKey(cardId)) { if (LogEnabled) { Log.Info("Controller: card:{0} has already been queried, skipping.", cardId); } continue; } if (!CanCardTuneChannel(cardHandler, dbChannel, tuningDetail)) { AddCardUnAvailable(ref cardsUnAvailable, cardId, TvResult.ChannelNotMappedToAnyCard); continue; } if (!CanCardDecodeChannel(cardHandler, tuningDetail)) { AddCardUnAvailable(ref cardsUnAvailable, cardId, TvResult.ChannelIsScrambled); continue; } //ok card could be used to tune to this channel bool isSameTransponder = IsSameTransponder(cardHandler, tuningDetail); if (LogEnabled) { Log.Info("Controller: card:{0} type:{1} can tune to channel", cardId, cardHandler.Type); } int nrOfOtherUsers = NumberOfOtherUsersOnCard(cardHandler, user); if (LogEnabled) { Log.Info("Controller: card:{0} type:{1} users: {2}", cardId, cardHandler.Type, nrOfOtherUsers); } CardDetail cardInfo = new CardDetail(cardId, cardHandler.DataBaseCard, tuningDetail, isSameTransponder, nrOfOtherUsers); cardsAvailable.Add(cardInfo); } } //sort cards cardsAvailable.Sort(); if (LogEnabled) { Log.Info("Controller: found {0} card(s) for channel", cardsAvailable.Count); } return(cardsAvailable); } catch (Exception ex) { Log.Write(ex); return(null); } finally { stopwatch.Stop(); Log.Info("AdvancedCardAllocation.GetAvailableCardsForChannel took {0} msec", stopwatch.ElapsedMilliseconds); } }