Esempio n. 1
0
        /// <summary>
        /// Stops the grabbing epg.
        /// </summary>
        /// <param name="user">User</param>
        public void Stop(IUser user)
        {
            Log.Epg("EpgGrabbing: Stop - user {0}", user.Name);
            if (_cardHandler.IsLocal == false)
            {
                // RemoteControl.HostName = _cardHandler.DataBaseCard.ReferencedServer().HostName;
                // RemoteControl.Instance.StopGrabbingEpg();
                return;
            }
            ITvCardContext context = _cardHandler.Card.Context as ITvCardContext;

            if (context != null)
            {
                context.Remove(user);
                if (context.ContainsUsersForSubchannel(user.SubChannel) == false)
                {
                    if (user.SubChannel > -1)
                    {
                        _cardHandler.Card.FreeSubChannel(user.SubChannel);
                    }
                }
            }
            else
            {
                Log.Epg("EpgGrabbing: Stop - context == null");
            }

            _cardHandler.Card.IsEpgGrabbing = false;
        }
 /// <summary>
 /// Unlocks this card.
 /// </summary>
 /// <param name="user">The user.</param>
 ///
 public void Unlock(IUser user)
 {
     if (_cardHandler.Card != null)
     {
         ITvCardContext context = _cardHandler.Card.Context as ITvCardContext;
         context.Remove(user);
     }
 }
        private bool BeforeTune(IChannel channel, ref IUser user, out TvResult result)
        {
            result = TvResult.UnknownError;
            //@FIX this fails for back-2-back recordings
            //if (CurrentDbChannel(ref user) == idChannel && idChannel >= 0)
            //{
            //  return true;
            //}
            Log.Debug("card: user: {0}:{1}:{2} tune {3}", user.Name, user.CardId, user.SubChannel, channel.ToString());
            _cardHandler.Card.CamType = (CamType)_cardHandler.DataBaseCard.CamType;
            _cardHandler.SetParameters();

            //check if transponder differs
            ITvCardContext context = _cardHandler.Card.Context as ITvCardContext;

            if (_cardHandler.Card.SubChannels.Length > 0)
            {
                if (IsTunedToTransponder(channel) == false)
                {
                    if (context.IsOwner(user) || user.IsAdmin)
                    {
                        Log.Debug("card: to different transponder");

                        //remove all subchannels, except for this user...
                        IUser[] users = context.Users;
                        for (int i = 0; i < users.Length; ++i)
                        {
                            if (users[i].Name != user.Name)
                            {
                                Log.Debug("  stop subchannel: {0} user: {1}", i, users[i].Name);

                                //fix for b2b mantis; http://mantis.team-mediaportal.com/view.php?id=1112
                                if (users[i].IsAdmin)
                                // if we are stopping an on-going recording/schedule (=admin), we have to make sure that we remove the schedule also.
                                {
                                    Log.Debug("user is scheduler: {0}", users[i].Name);
                                    int recScheduleId = RemoteControl.Instance.GetRecordingSchedule(users[i].CardId,
                                                                                                    users[i].IdChannel);

                                    if (recScheduleId > 0)
                                    {
                                        Schedule schedule = Schedule.Retrieve(recScheduleId);
                                        Log.Info("removing schedule with id: {0}", schedule.IdSchedule);
                                        RemoteControl.Instance.StopRecordingSchedule(schedule.IdSchedule);
                                        schedule.Delete();
                                    }
                                }
                                else
                                {
                                    _cardHandler.Card.FreeSubChannel(users[i].SubChannel);
                                    context.Remove(users[i]);
                                }
                            }
                        }
                    }
                    else
                    {
                        Log.Debug("card: user: {0} is not the card owner. Cannot switch transponder", user.Name);
                        result = TvResult.NotTheOwner;
                        return(false);
                    }
                }
                else // same transponder, free previous subchannel before tuning..
                {
                    _cardHandler.Card.FreeSubChannel(user.SubChannel);
                }
            }

            if (OnBeforeTuneEvent != null)
            {
                OnBeforeTuneEvent(_cardHandler);
            }

            TvCardBase card = _cardHandler.Card as TvCardBase;

            if (card != null)
            {
                card.AfterTuneEvent -= new TvCardBase.OnAfterTuneDelegate(Card_OnAfterTuneEvent);
                card.AfterTuneEvent += new TvCardBase.OnAfterTuneDelegate(Card_OnAfterTuneEvent);
            }
            else
            {
                HybridCard hybridCard = _cardHandler.Card as HybridCard;
                if (hybridCard != null)
                {
                    hybridCard.AfterTuneEvent = new TvCardBase.OnAfterTuneDelegate(Card_OnAfterTuneEvent);
                }
            }

            result = TvResult.Succeeded;
            return(true);
        }
        /// <summary>
        /// Removes the user from this card
        /// </summary>
        /// <param name="user">The user.</param>
        public void RemoveUser(IUser user)
        {
            if (_cardHandler.IsLocal == false)
            {
                try
                {
                    RemoteControl.HostName = _cardHandler.DataBaseCard.ReferencedServer().HostName;
                    RemoteControl.Instance.RemoveUserFromOtherCards(_cardHandler.DataBaseCard.IdCard, user);
                    return;
                }
                catch (Exception)
                {
                    Log.Error("card: unable to connect to slave controller at:{0}",
                              _cardHandler.DataBaseCard.ReferencedServer().HostName);
                    return;
                }
            }
            ITvCardContext context = _cardHandler.Card.Context as ITvCardContext;

            if (context == null)
            {
                return;
            }
            if (!context.DoesExists(user))
            {
                return;
            }
            context.GetUser(ref user, _cardHandler.DataBaseCard.IdCard);

            Log.Debug("usermanagement.RemoveUser: {0}, subch: {1} of {2}, card: {3}", user.Name, user.SubChannel, _cardHandler.Card.SubChannels.Length, _cardHandler.DataBaseCard.IdCard);
            context.Remove(user);
            if (!context.ContainsUsersForSubchannel(user.SubChannel))
            {
                //only remove subchannel if it exists.
                if (_cardHandler.Card.GetSubChannel(user.SubChannel) != null)
                {
                    int usedSubChannel = user.SubChannel;
                    // Before we remove the subchannel we have to stop it
                    ITvSubChannel subChannel = _cardHandler.Card.GetSubChannel(user.SubChannel);
                    if (subChannel.IsTimeShifting)
                    {
                        subChannel.StopTimeShifting();
                    }
                    else if (subChannel.IsRecording)
                    {
                        subChannel.StopRecording();
                    }
                    _cardHandler.Card.FreeSubChannel(user.SubChannel);
                    CleanTimeshiftFilesThread cleanTimeshiftFilesThread =
                        new CleanTimeshiftFilesThread(_cardHandler.DataBaseCard.TimeShiftFolder,
                                                      String.Format("live{0}-{1}.ts", _cardHandler.DataBaseCard.IdCard,
                                                                    usedSubChannel));
                    Thread cleanupThread = new Thread(cleanTimeshiftFilesThread.CleanTimeshiftFiles);
                    cleanupThread.IsBackground = true;
                    cleanupThread.Name         = "TS_File_Cleanup";
                    cleanupThread.Priority     = ThreadPriority.Lowest;
                    cleanupThread.Start();
                }
            }
            if (_cardHandler.IsIdle)
            {
                if (_cardHandler.Card.SupportsPauseGraph)
                {
                    _cardHandler.Card.PauseGraph();
                }
                else
                {
                    _cardHandler.Card.StopGraph();
                }
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Stops the time shifting.
        /// </summary>
        /// <returns></returns>
        public bool Stop(ref IUser user)
        {
            try
            {
                if (_cardHandler.DataBaseCard.Enabled == false)
                {
                    return(true);
                }

                ITvSubChannel subchannel = _cardHandler.Card.GetSubChannel(user.SubChannel);
                if (subchannel is BaseSubChannel)
                {
                    ((BaseSubChannel)subchannel).AudioVideoEvent -= AudioVideoEventHandler;
                }

                Log.Write("card {2}: StopTimeShifting user:{0} sub:{1}", user.Name, user.SubChannel,
                          _cardHandler.Card.Name);

                lock (this)
                {
                    try
                    {
                        RemoteControl.HostName = _cardHandler.DataBaseCard.ReferencedServer().HostName;
                        if (!RemoteControl.Instance.CardPresent(_cardHandler.DataBaseCard.IdCard))
                        {
                            return(true);
                        }

                        Log.Write("card: StopTimeShifting user:{0} sub:{1}", user.Name, user.SubChannel);

                        if (_cardHandler.IsLocal == false)
                        {
                            return(RemoteControl.Instance.StopTimeShifting(ref user));
                        }
                    }
                    catch (Exception)
                    {
                        Log.Error("card: unable to connect to slave controller at:{0}",
                                  _cardHandler.DataBaseCard.ReferencedServer().HostName);
                        return(false);
                    }

                    ITvCardContext context = _cardHandler.Card.Context as ITvCardContext;
                    if (context == null)
                    {
                        return(true);
                    }
                    if (_linkageScannerEnabled)
                    {
                        _cardHandler.Card.ResetLinkageScanner();
                    }

                    if (_cardHandler.IsIdle)
                    {
                        _cardHandler.PauseCard(user);
                    }
                    else
                    {
                        Log.Debug("card not IDLE - removing user: {0}", user.Name);
                        _cardHandler.Users.RemoveUser(user);
                    }

                    context.Remove(user);
                    return(true);
                }
            }
            catch (Exception ex)
            {
                Log.Write(ex);
            }
            return(false);
        }