TvController_GetUsersForCard() public static method

public static TvController_GetUsersForCard ( int cardId ) : IUser[]
cardId int
return IUser[]
Example #1
0
        public static bool CardFreeOrUsingSameTransponder(TvDatabase.Card card, TvDatabase.Channel channel, IUser userToIgnore)
        {
            IUser[] cardUsers = TvServerPlugin.TvController_GetUsersForCard(card.IdCard);
            if (cardUsers != null)
            {
                TvDatabase.TuningDetail tuning = Utility.FindTuningDetailOnCard(channel, card.IdCard);

                HashSet <int> activeChannels = new HashSet <int>();

                foreach (IUser cardUser in cardUsers)
                {
                    if (userToIgnore == null ||
                        cardUser.Name != userToIgnore.Name)
                    {
                        if (!cardUser.Name.Equals("epg", StringComparison.InvariantCultureIgnoreCase))
                        {
                            activeChannels.Add(cardUser.IdChannel);
                            if (!Utility.IsSameTransponder(card.IdCard, tuning, cardUser.IdChannel))
                            {
                                return(false);
                            }
                        }
                    }
                }

                return(activeChannels.Contains(channel.IdChannel) ||
                       card.DecryptLimit == 0 ||
                       activeChannels.Count < card.DecryptLimit);
            }
            return(true);
        }
 private bool EnsureCardFree(bool allowOtherArgusUser, ref string errorMessage, out bool argusIsRecordingOnCard)
 {
     argusIsRecordingOnCard = false;
     IUser[] cardUsers = TvServerPlugin.TvController_GetUsersForCard(_recordOnCard.IdCard);
     if (cardUsers != null)
     {
         TvDatabase.TuningDetail tuning = Utility.FindTuningDetailOnCard(_channel, _recordOnCard.IdCard);
         foreach (IUser cardUser in cardUsers)
         {
             if (!cardUser.Name.Equals("epg", StringComparison.InvariantCultureIgnoreCase))
             {
                 if (cardUser.Name.StartsWith("ArgusTV"))
                 {
                     if (!allowOtherArgusUser &&
                         !Utility.IsSameTransponder(_recordOnCard.IdCard, tuning, cardUser.IdChannel))
                     {
                         // Seems another ARGUS TV user is using this card, but on a different
                         // transponder!  Normally this should never happen, but in rare conditions
                         // we need to be able to handle this.
                         errorMessage           = "Card is in use by previous recording";
                         argusIsRecordingOnCard = true;
                         return(false);
                     }
                 }
                 else
                 {
                     IUser tmpUser = cardUser;
                     if (TvServerPlugin.TvController_IsRecording(ref tmpUser))
                     {
                         if (!TvServerPlugin.TvController_StopRecording(ref tmpUser))
                         {
                             errorMessage = "Failed to stop recording on channel " + _channel.DisplayName;
                             return(false);
                         }
                     }
                     else if (TvServerPlugin.TvController_IsTimeShifting(ref tmpUser))
                     {
                         if (!Utility.IsSameTransponder(_recordOnCard.IdCard, tuning, tmpUser.IdChannel))
                         {
                             if (!TvServerPlugin.TvController_StopTimeShifting(ref tmpUser, TvStoppedReason.RecordingStarted))
                             {
                                 errorMessage = "Failed to stop timeshifting on channel " + _channel.DisplayName;
                                 return(false);
                             }
                         }
                     }
                 }
             }
         }
     }
     return(true);
 }
        public override LiveStream[] GetLiveStreams()
        {
            List <LiveStream> liveStreams = new List <LiveStream>();

            lock (_liveStreamsLock)
            {
                try
                {
                    // Get cards in reverse priority.
                    List <TvDatabase.Card> cards = Utility.GetAllCards();
                    cards.Sort(delegate(TvDatabase.Card c1, TvDatabase.Card c2) { return(-c1.Priority.CompareTo(c2.Priority)); });

                    // Get the list of live streams from TV Server
                    Dictionary <string, IUser> mpStreamUsers = new Dictionary <string, IUser>();
                    foreach (TvDatabase.Card card in cards)
                    {
                        IUser[] cardUsers = TvServerPlugin.TvController_GetUsersForCard(card.IdCard);
                        if (cardUsers != null)
                        {
                            foreach (IUser user in cardUsers)
                            {
                                if (user.Name.StartsWith(_argusLiveUserName))
                                {
                                    IUser tve3User = user;
                                    if (TvServerPlugin.TvController_IsTimeShifting(ref tve3User))
                                    {
                                        mpStreamUsers.Add(TvServerPlugin.TvController_GetStreamingUrl(tve3User), tve3User);
                                    }
                                }
                            }
                        }
                    }

                    // Now loop our own list and check if all those streams are indeed still up.
                    List <string> keysToRemove = new List <string>();

                    foreach (LiveStream stream in _liveStreams.Values)
                    {
                        if (mpStreamUsers.ContainsKey(stream.RtspUrl))
                        {
                            liveStreams.Add(stream);
                        }
                        else
                        {
                            keysToRemove.Add(stream.RtspUrl);
                        }
                    }

                    // Remove streams that no longer exist.
                    foreach (string keyToRemove in keysToRemove)
                    {
                        _liveStreams.Remove(keyToRemove);
                        _liveStreamUsers.Remove(keyToRemove);
                    }

                    // Check if there are any live streams within MP that we don't know about.
                    // If so, stop those streams (they may be left-overs from client crashes).
                    foreach (string rtspUrl in mpStreamUsers.Keys)
                    {
                        if (!_liveStreams.ContainsKey(rtspUrl))
                        {
                            IUser tve3User = mpStreamUsers[rtspUrl];
                            TvServerPlugin.TvController_StopTimeShifting(ref tve3User, TvStoppedReason.KickedByAdmin);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Log(TraceEventType.Error, ex.Message);
                }
            }
            return(liveStreams.ToArray());
        }