Esempio n. 1
0
        public void PushAsync_100_messages_for_random_or_invalid_jobId()
        {
            //arrange
            INotificationManager <JobId> notificationMgr = null;
            var handlerInfoOnly = GetMockHandler();
            var id = Helper.GetJobId();

            notificationMgr = new NotificationManager();

            //act
            var msgInfo  = new MessageHook("hook message", "info-unit-testing", MessageType.Info);
            var msgError = new MessageHook("hook message", "error-unit-testing", MessageType.Error);

            notificationMgr.RegisterHook(id, MessageType.Info, handlerInfoOnly.Object);
            notificationMgr.PushAsync(id, msgInfo);

            for (int i = 0; i < 100; i++)
            {
                notificationMgr.PushAsync(Helper.GetJobId(), msgError); //random sender key
            }

            Thread.Sleep(2500);

            //assert

            handlerInfoOnly.Verify(h => h.DoHandle(It.Is <JobId>(p => p.Equals(id)), It.IsAny <MessageHook>()), Times.Once());
            handlerInfoOnly.Verify(h => h.DoHandle(It.Is <JobId>(p => p.Equals(id)), It.Is <MessageHook>(mh => mh.Equals(msgInfo))), Times.Once());
        }
Esempio n. 2
0
        public void PushAsync_with_few_valid_hooks()
        {
            //arrange
            INotificationManager <JobId> notificationMgr = null;
            var handlerInfoOnly  = GetMockHandler();
            var handlerErrorOnly = GetMockHandler();
            var id = Helper.GetJobId();

            notificationMgr = new NotificationManager();

            //act
            var msgInfo  = new MessageHook("hook message", "info-unit-testing", MessageType.Info);
            var msgError = new MessageHook("hook message", "error-unit-testing", MessageType.Error);

            notificationMgr.RegisterHook(id, MessageType.Info, handlerInfoOnly.Object);
            notificationMgr.RegisterHook(id, MessageType.Error, handlerErrorOnly.Object);
            notificationMgr.PushAsync(id, msgInfo);
            notificationMgr.PushAsync(id, msgError);

            //assert

            handlerInfoOnly.Verify(h => h.DoHandle(It.Is <JobId>(p => p.Equals(id)), It.IsAny <MessageHook>()), Times.Once());
            handlerErrorOnly.Verify(h => h.DoHandle(It.Is <JobId>(p => p.Equals(id)), It.IsAny <MessageHook>()), Times.Once());

            handlerInfoOnly.Verify(h => h.DoHandle(It.Is <JobId>(p => p.Equals(id)), It.Is <MessageHook>(mh => mh.Equals(msgInfo))), Times.Once());
            handlerErrorOnly.Verify(h => h.DoHandle(It.Is <JobId>(p => p.Equals(id)), It.Is <MessageHook>(mh => mh.Equals(msgError))), Times.Once());
        }
Esempio n. 3
0
 public void DoHandle(JobId sender, MessageHook message)
 {
     lock (_messages)
     {
         _messages.Add(new Tuple <JobId, MessageHook>(sender, message));
     }
 }
Esempio n. 4
0
 public CheckEnum()
 {
     InitializeComponent();
     if (Hook == null) {
         Hook = new MessageHook();
         Application.AddMessageFilter(Hook);
     }
     Hook.MouseDown += new MessageHook.LeftButtonDown(Hook_MouseDown);
     Hook.KeyUp += new MessageHook.KeyPressUp(Hook_KeyUp);
 }
Esempio n. 5
0
 public CheckEnum()
 {
     InitializeComponent();
     if (Hook == null)
     {
         Hook = new MessageHook();
         Application.AddMessageFilter(Hook);
     }
     Hook.MouseDown += new MessageHook.LeftButtonDown(Hook_MouseDown);
     Hook.KeyUp     += new MessageHook.KeyPressUp(Hook_KeyUp);
 }
Esempio n. 6
0
            // Запуск потока прослушки/получения сообщений
            private void RunMessagePump()
            {
                // Создаем виртуальное окно
                MessageHook messageHandler = new MessageHook(this);

                messageHandler.MessageReceived += new EventHandler <MessageEventArgs>(messageHandler_MessageReceived);

                // Инициальзируем объект-монетоприемник дескриптором этого окна
                _coin.Handler = messageHandler.Handle;

                // запускаем цикл сообщений и даем знать другим потокам, что мы закончили
                _messagePumpRunning.Set();
                Application.Run();
            }
Esempio n. 7
0
        public void PushAsync_with_invalid_senderkey_and_message()
        {
            //arrange
            INotificationManager <JobId> notificationMgr = null;

            notificationMgr = new NotificationManager();
            var msg = new MessageHook("hook message", "info-unit-testing", MessageType.Info);
            var id  = Helper.GetJobId();

            //act
            //assert

            Assert.Throws <ArgumentNullException>(() => notificationMgr.PushAsync(null, null));
            Assert.Throws <ArgumentNullException>(() => notificationMgr.PushAsync(null, msg));
            Assert.Throws <ArgumentNullException>(() => notificationMgr.PushAsync(id, null));
        }
Esempio n. 8
0
        public PlayerForm(IAimpPlayer player, MessageHook coreMessage)
        {
            _playLists  = new List <IAimpPlaylist>();
            _aimpPlayer = player;
            InitializeComponent();

            _loggerForm = new LoggerForm();

            coreMessage.OnCoreMessage += (message, param1, param2) =>
            {
                if (message == AimpCoreMessageType.EventPlayableFileInfo)
                {
                    var cover = _aimpPlayer.CurrentFileInfo.AlbumArt;
                    if (cover != null)
                    {
                        pictureBox1.Image = cover;
                    }
                }
                else if (message == AimpCoreMessageType.EventPlayerState)
                {
                    Logger.Instance.AddInfoMessage($"[Event] AimpPlayer.StateChanged: {param1}");

                    switch ((AimpPlayerState)param1)
                    {
                    case AimpPlayerState.Stopped:
                        Text = "State: stopped";
                        break;

                    case AimpPlayerState.Pause:
                        Text = "State: pause";
                        break;

                    case AimpPlayerState.Playing:
                        Text = "State: playing";
                        break;
                    }
                }

                return(ActionResultType.OK);
            };

            Load += OnActivated;

            //_aimpPlayer.PlaylistManager.PlaylistActivated += (name, id) =>
            //{
            //    Logger.Instance.AddInfoMessage($"[Event] PlayListManager.PlaylistActivated: {name} {id}");

            //    foreach (var tabPage in tabPlayLists.TabPages)
            //    {
            //        var tp = tabPage as TabPage;
            //        if (tp != null && tp.Tag.Equals(id))
            //        {
            //            tabPlayLists.SelectTab(tp);
            //            break;
            //        }
            //    }
            //};

            //_aimpPlayer.PlaylistManager.PlaylistAdded += (name, id) =>
            //{
            //    Logger.Instance.AddInfoMessage($"[Event] PlayListManager.PlaylistAdded: {name} {id}");

            //    IAimpPlaylist pl;
            //    if (_aimpPlayer.PlaylistManager.GetLoadedPlaylistById(id, out pl) == ActionResultType.OK)
            //    {
            //        AddPlayListTab(id, name, pl);
            //    }
            //};

            //_aimpPlayer.PlaylistManager.PlaylistRemoved += (name, id) =>
            //{
            //    Logger.Instance.AddInfoMessage($"[Event] PlayListManager.PlaylistRemoved: {name} {id}");

            //    foreach (var tabPage in tabPlayLists.TabPages)
            //    {
            //        var tp = tabPage as TabPage;
            //        if (tp != null && tp.Tag.Equals(id))
            //        {
            //            tabPlayLists.TabPages.Remove(tp);
            //            break;
            //        }
            //    }
            //};

            _aimpPlayer.ServicePlaylistManager.PlaylistQueue.ContentChanged += (sender) =>
            {
                Logger.Instance.AddInfoMessage($"[Event] PlaylistQueue.ContentChanged");
            };

            _aimpPlayer.ServicePlaylistManager.PlaylistQueue.StateChanged += (sender) =>
            {
                Logger.Instance.AddInfoMessage($"[Event] PlaylistQueue.StateChanged");
            };
        }