コード例 #1
0
    public void AddUserOwnerTest()
    {
      ITvCardContext ctx = new TvCardContext();

      IUser u1 = new User("u1", false, 1);
      ctx.Add(u1);

      Assert.IsTrue(ctx.IsOwner(u1), "user is not owner");
    }
コード例 #2
0
    public void AddNewUserTest()
    {
      ITvCardContext ctx = new TvCardContext();

      IUser u1 = new User("u1", false, 1);
      ctx.Add(u1);

      Assert.IsTrue(UserExists(ctx, u1), "user is not found");
    }
コード例 #3
0
    public void RemoveUserTest()
    {
      ITvCardContext ctx = new TvCardContext();

      IUser u1 = new User("u1", false, 1);
      ctx.Add(u1);      
      ctx.Remove(u1);
      Assert.AreEqual(0, ctx.Users.Length, "user count wrong");
      Assert.IsFalse(UserExists(ctx, u1), "user is found");

      Assert.IsTrue(((TvCardContext)ctx).UsersOld.Contains(u1), "user not found in history");      
    }
コード例 #4
0
    public void AddAlreadyExistingUserTest()
    {
      ITvCardContext ctx = new TvCardContext();

      IUser u1 = new User("u1", false, 1);
      ctx.Add(u1);

      User u2 = new User("u1", false, 2);
      ctx.Add(u2);

      Assert.AreEqual(1, ctx.Users.Length, "user count wrong");
      Assert.IsTrue(UserExists(ctx, u2), "user is not found");
    }
コード例 #5
0
    public void AddAnotherUserNotOwnerTest()
    {
      ITvCardContext ctx = new TvCardContext();

      IUser u1 = new User("u1", false, 1);
      ctx.Add(u1);

      User u2 = new User("u2", false, 2);
      ctx.Add(u2);

      Assert.IsTrue(ctx.IsOwner(u1), "user is owner");
      Assert.IsFalse(ctx.IsOwner(u2), "user is not owner");
    }
コード例 #6
0
        /// <summary>
        /// Returns the current filename used for recording
        /// </summary>
        /// <param name="user">User</param>
        /// <returns>filename or null when not recording</returns>
        public string FileName(ref IUser user)
        {
            try
            {
                if (_cardHandler.DataBaseCard.Enabled == false)
                {
                    return("");
                }

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

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

                TvCardContext context = _cardHandler.Card.Context as TvCardContext;
                if (context == null)
                {
                    return(null);
                }
                context.GetUser(ref user);
                ITvSubChannel subchannel = _cardHandler.Card.GetSubChannel(user.SubChannel);
                if (subchannel == null)
                {
                    return(null);
                }
                return(subchannel.RecordingFileName);
            }
            catch (Exception ex)
            {
                Log.Write(ex);
                return("");
            }
        }
コード例 #7
0
        private bool StopRecording(ref IUser user, TvCardContext context)
        {
            bool stop = false;

            context.GetUser(ref user);
            ITvSubChannel subchannel = GetSubChannel(user.SubChannel);

            if (subchannel != null)
            {
                subchannel.StopRecording();
                _cardHandler.Card.FreeSubChannel(user.SubChannel);
                if (subchannel.IsTimeShifting == false || context.Users.Length <= 1)
                {
                    _cardHandler.Users.RemoveUser(user);
                }
                stop = true;
            }
            else
            {
                Log.Write("card: StopRecording subchannel null, skipping");
            }
            return(stop);
        }
コード例 #8
0
    public void ExistingUserGetUserTest()
    {
      ITvCardContext ctx = new TvCardContext();

      IUser u1 = new User("u1", false, 1);
      u1.SubChannel = 2;
      ctx.Add(u1);

      IUser getUser;
      ctx.GetUser(2, out getUser);

      Assert.NotNull(getUser, "user is null");
      Assert.AreEqual("u1", getUser.Name);
      Assert.AreEqual(2, getUser.SubChannel);
      Assert.AreEqual(1, getUser.CardId);
    }
コード例 #9
0
    public void NonExistingUserDoesExistsTest()
    {
      ITvCardContext ctx = new TvCardContext();

      IUser u1 = new User("u1", false, 1);
      ctx.Add(u1);

      IUser getUser = new User("u2", false, 2);

      Assert.IsFalse(ctx.DoesExists(getUser), "user exists");
    }
コード例 #10
0
        /// <summary>
        /// Starts recording.
        /// </summary>
        /// <param name="user">User</param>
        /// <param name="fileName">Name of the recording file.</param>
        /// <param name="contentRecording">if true then create a content recording else a reference recording</param>
        /// <param name="startTime">not used</param>
        /// <returns></returns>
        public TvResult Start(ref IUser user, ref string fileName, bool contentRecording, long startTime)
        {
            bool useErrorDetection = false;

            try
            {
                if (_cardHandler.DataBaseCard.Enabled == false)
                {
                    return(TvResult.CardIsDisabled);
                }

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

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

                    TvCardContext context = _cardHandler.Card.Context as TvCardContext;
                    if (context == null)
                    {
                        return(TvResult.UnknownChannel);
                    }

                    context.GetUser(ref user);
                    ITvSubChannel subchannel = _cardHandler.Card.GetSubChannel(user.SubChannel);
                    if (subchannel == null)
                    {
                        return(TvResult.UnknownChannel);
                    }

                    _subchannel = subchannel;

                    //gibman
                    // RecordingFormat 0 = ts
                    // RecordingFormat 1 = mpeg
                    fileName = fileName.Replace("\r\n", " ");
                    fileName = System.IO.Path.ChangeExtension(fileName, ".ts");

                    useErrorDetection = true;

                    if (useErrorDetection)
                    {
                        // fix mantis 0002807: A/V detection for recordings is not working correctly
                        // reset the events ONLY before attaching the observer, at a later position it can already miss the a/v callback.
                        _eventVideo.Reset();
                        _eventAudio.Reset();
                        Log.Debug("Recorder.start add audioVideoEventHandler");
                        ((BaseSubChannel)subchannel).AudioVideoEvent += AudioVideoEventHandler;
                    }

                    Log.Write("card: StartRecording {0} {1}", _cardHandler.DataBaseCard.IdCard, fileName);
                    bool result = subchannel.StartRecording(fileName);
                    bool isScrambled;
                    if (result)
                    {
                        fileName      = subchannel.RecordingFileName;
                        context.Owner = user;
                        if (useErrorDetection)
                        {
                            if (!WaitForRecordingFile(ref user, out isScrambled))
                            {
                                Log.Write("card: Recording failed! {0} {1}", _cardHandler.DataBaseCard.IdCard, fileName);

                                string cardRecordingFolderName = _cardHandler.DataBaseCard.RecordingFolder;
                                Stop(ref user);
                                _cardHandler.Users.RemoveUser(user);

                                string recordingfolderName = System.IO.Path.GetDirectoryName(fileName);
                                if (recordingfolderName == cardRecordingFolderName)
                                {
                                    Utils.FileDelete(fileName);
                                }
                                else
                                {
                                    // delete 0-byte file in case of error
                                    Utils.DeleteFileAndEmptyDirectory(fileName);
                                }
                                ((BaseSubChannel)subchannel).AudioVideoEvent -= AudioVideoEventHandler;
                                if (isScrambled)
                                {
                                    return(TvResult.ChannelIsScrambled);
                                }
                                return(TvResult.NoVideoAudioDetected);
                            }
                            ((BaseSubChannel)subchannel).AudioVideoEvent -= AudioVideoEventHandler;
                        }
                    }
                    if (_timeshiftingEpgGrabberEnabled)
                    {
                        Channel channel = Channel.Retrieve(user.IdChannel);
                        if (channel.GrabEpg)
                        {
                            _cardHandler.Card.GrabEpg();
                        }
                        else
                        {
                            Log.Info("TimeshiftingEPG: channel {0} is not configured for grabbing epg", channel.DisplayName);
                        }
                    }

                    return(TvResult.Succeeded);
                }
            }
            catch (Exception ex)
            {
                Log.Write(ex);
            }
            return(TvResult.UnknownError);
        }
コード例 #11
0
    public void RemoveUserChangeOwnerShipToSchedulerTest()
    {
      ITvCardContext ctx = new TvCardContext();

      IUser u1 = new User("u1", false, 1);
      IUser u2 = new User("u2", false, 1);
      IUser scheduler = new User("scheduler", true, 1);
      ctx.Add(u1);
      ctx.Add(u2);
      ctx.Add(scheduler);
      ctx.Lock(scheduler); //set ownership

      ctx.Remove(u2);

      Assert.IsTrue(ctx.IsOwner(scheduler), "scheduler user is not owner");      
    }
コード例 #12
0
    public void NonExistingUserSetTimeshiftStoppedReasonTest()
    {
      ITvCardContext ctx = new TvCardContext();

      IUser u1 = new User("u1", false, 1);
      u1.SubChannel = 2;
      ctx.Add(u1);      

      User u2 = new User("u2", false, 2);
      ctx.SetTimeshiftStoppedReason(u2, TvStoppedReason.KickedByAdmin);
      ctx.Remove(u1);
      Assert.AreEqual(TvStoppedReason.UnknownReason, ctx.GetTimeshiftStoppedReason(u1), "tvstoppedreason the same");            
    }
コード例 #13
0
    public void NonExistingUserGetUserTest()
    {
      ITvCardContext ctx = new TvCardContext();

      IUser u1 = new User("u1", false, 1);
      u1.SubChannel = 2;
      ctx.Add(u1);

      IUser getUser;
      ctx.GetUser(1, out getUser);

      Assert.IsNull(getUser, "user is not null");      
    }
コード例 #14
0
    public void RemoveOneOfManyUserNotOwnerTest()
    {
      ITvCardContext ctx = new TvCardContext();

      IUser u1 = new User("u1", false, 1);
      ctx.Add(u1);

      User u2 = new User("u2", false, 2);
      ctx.Add(u2);

      ctx.Remove(u1);
      Assert.IsTrue(ctx.IsOwner(u2), "user is not owner");
    }
コード例 #15
0
    public void RemoveOneOnlyUserNoOwnerTest()
    {
      ITvCardContext ctx = new TvCardContext();

      IUser u1 = new User("u1", false, 1);
      ctx.Add(u1);
      ctx.Remove(u1);
      Assert.IsTrue(ctx.IsOwner(u1), "user is owner");
    }
コード例 #16
0
    public void RemoveNonExistingUserTest()
    {
      ITvCardContext ctx = new TvCardContext();

      IUser u1 = new User("u1", false, 1);
      User u2 = new User("u2", false, 2);
      ctx.Add(u1);
      ctx.Remove(u2);

      Assert.IsFalse(((TvCardContext)ctx).UsersOld.Contains(u1), "user found in history");
      Assert.IsFalse(((TvCardContext)ctx).UsersOld.Contains(u2), "user found in history");
    }
コード例 #17
0
    public void RemoveAdminUserNotInHistoryTest()
    {
      ITvCardContext ctx = new TvCardContext();

      IUser u1 = new User("u1", true, 1);
      ctx.Add(u1);
      ctx.Remove(u1);

      Assert.IsFalse(((TvCardContext)ctx).UsersOld.Contains(u1), "user found in history");      
    }
コード例 #18
0
    public void RemoveUserChangeOwnerShipToUserTest()
    {
      ITvCardContext ctx = new TvCardContext();

      IUser u1 = new User("u1", false, 1);
      IUser u2 = new User("u2", false, 1);
      IUser u3 = new User("u3", false, 1);      
      ctx.Add(u1);
      ctx.Add(u2);
      ctx.Add(u3);

      ctx.Lock(u3); //set ownership      
      ctx.Remove(u3);

      Assert.IsTrue(ctx.IsOwner(u1), "user1 user is not owner");
    }
コード例 #19
0
    public void ExistingUserSetTimeshiftStoppedReasonTest()
    {
      ITvCardContext ctx = new TvCardContext();

      IUser u1 = new User("u1", false, 1);      
      ctx.Add(u1);      

      User u2 = new User("u1", false, 1);
      ctx.SetTimeshiftStoppedReason(u2,TvStoppedReason.KickedByAdmin);
      ctx.Remove(u1);
      Assert.AreEqual(TvStoppedReason.KickedByAdmin, ctx.GetTimeshiftStoppedReason(u2), "tvstoppedreason not the same");            
    }
コード例 #20
0
    public void HeartBeatUserTest()
    {
      ITvCardContext ctx = new TvCardContext();

      IUser u1 = new User("u1", false, 1);
      DateTime oldHB = u1.HeartBeat;
      ctx.Add(u1);      

      ctx.HeartBeatUser(u1);

      Assert.AreNotEqual(u1.HeartBeat, oldHB, "heartbeat hasnt changed");
    }
コード例 #21
0
    public void NonExistingUserContainsUsersForSubchannelTest()
    {
      ITvCardContext ctx = new TvCardContext();

      IUser u1 = new User("u1", false, 1);
      u1.SubChannel = 2;
      ctx.Add(u1);

      Assert.IsFalse(ctx.ContainsUsersForSubchannel(1), "user with subchannel found");
    }
コード例 #22
0
    public void GetExistingUserTest()
    {
      ITvCardContext ctx = new TvCardContext();

      IUser u1 = new User("u1", false, 1);      
      ctx.Add(u1);

      IUser getUser = new User("u1", false, 1);
      ctx.GetUser(ref getUser);

      Assert.AreEqual(u1.Name, getUser.Name, "user name not equal");
      Assert.AreEqual(u1.CardId, getUser.CardId, "user cardid not equal");
    }
コード例 #23
0
    public void ClearTest()
    {
      ITvCardContext ctx = new TvCardContext();

      for (int i = 0; i < 10; i++)
      {
        IUser u1 = new User("u" + i, false, 1);
        ctx.Add(u1);
      }
      ctx.Clear();
      Assert.AreEqual(10, ((TvCardContext)ctx).UsersOld.Count, "oldusers count wrong");
      Assert.AreEqual(0, ctx.Users.Length, "users count wrong");
    }       
コード例 #24
0
    public void GetNonExistingUserWithCardIDTest()
    {
      ITvCardContext ctx = new TvCardContext();

      IUser u1 = new User("u1", false, 1);
      ctx.Add(u1);

      IUser getUser = new User("u2", false, 1);
      ctx.GetUser(ref getUser, 2);

      Assert.AreNotEqual(u1.Name, getUser.Name, "user name equal");
      Assert.AreNotEqual(2, getUser.CardId, "user cardid equal");
    }
コード例 #25
0
    public void GetNonExistingUserExistsTest()
    {
      ITvCardContext ctx = new TvCardContext();

      IUser u1 = new User("u1", false, 1);
      ctx.Add(u1);

      IUser getUser = new User("u2", false, 2);      
      bool exists = false;
      ctx.GetUser(ref getUser, out exists);

      Assert.IsFalse(exists, "user exists");
    }
コード例 #26
0
    public void ExistingUserDoesExistsTest()
    {
      ITvCardContext ctx = new TvCardContext();

      IUser u1 = new User("u1", false, 1);
      ctx.Add(u1);            

      Assert.IsTrue(ctx.DoesExists(u1), "user does not exists");
    }
コード例 #27
0
ファイル: Recorder.cs プロジェクト: arangas/MediaPortal-1
 private bool StopRecording(ref IUser user, TvCardContext context)
 {
   bool stop = false;
   context.GetUser(ref user);
   ITvSubChannel subchannel = GetSubChannel(user.SubChannel);
   if (subchannel != null)
   {
     subchannel.StopRecording();
     _cardHandler.Card.FreeSubChannel(user.SubChannel);
     if (subchannel.IsTimeShifting == false || context.Users.Length <= 1)
     {
       _cardHandler.Users.RemoveUser(user);
     }
     stop = true;
   }
   else
   {
     Log.Write("card: StopRecording subchannel null, skipping");        
   }
   return stop;
 }
コード例 #28
0
        /// <summary>
        /// Stops recording.
        /// </summary>
        /// <param name="user">User</param>
        /// <returns></returns>
        public bool Stop(ref IUser user)
        {
            try
            {
                if (_cardHandler.DataBaseCard.Enabled == false)
                {
                    return(false);
                }
                Log.Write("card: StopRecording card={0}, user={1}", _cardHandler.DataBaseCard.IdCard, user.Name);
                lock (this)
                {
                    try
                    {
                        RemoteControl.HostName = _cardHandler.DataBaseCard.ReferencedServer().HostName;
                        if (!RemoteControl.Instance.CardPresent(_cardHandler.DataBaseCard.IdCard))
                        {
                            return(false);
                        }

                        if (_cardHandler.IsLocal == false)
                        {
                            return(RemoteControl.Instance.StopRecording(ref user));
                        }
                    }
                    catch (Exception)
                    {
                        Log.Error("card: unable to connect to slave controller at:{0}",
                                  _cardHandler.DataBaseCard.ReferencedServer().HostName);
                        return(false);
                    }
                    Log.Write("card: StopRecording for card:{0}", _cardHandler.DataBaseCard.IdCard);
                    TvCardContext context = _cardHandler.Card.Context as TvCardContext;
                    if (context == null)
                    {
                        Log.Write("card: StopRecording context null");
                        return(false);
                    }
                    if (user.IsAdmin)
                    {
                        context.GetUser(ref user);
                        ITvSubChannel subchannel = _cardHandler.Card.GetSubChannel(user.SubChannel);
                        if (subchannel == null)
                        {
                            Log.Write("card: StopRecording subchannel null, skipping");
                            return(false);
                        }
                        subchannel.StopRecording();
                        _cardHandler.Card.FreeSubChannel(user.SubChannel);
                        if (subchannel.IsTimeShifting == false || context.Users.Length <= 1)
                        {
                            _cardHandler.Users.RemoveUser(user);
                        }
                    }

                    IUser[] users = context.Users;
                    for (int i = 0; i < users.Length; ++i)
                    {
                        ITvSubChannel subchannel = _cardHandler.Card.GetSubChannel(users[i].SubChannel);
                        if (subchannel != null)
                        {
                            if (subchannel.IsRecording)
                            {
                                Log.Write("card: StopRecording setting new context owner on user '{0}'", users[i].Name);
                                context.Owner = users[i];
                                break;
                            }
                        }
                    }
                    return(true);
                }
            }
            catch (Exception ex)
            {
                Log.Write(ex);
            }
            return(false);
        }