Пример #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>
        /// 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();
                }
            }
        }