Beispiel #1
0
        private void ButtonOpenMain_Click(object sender, RoutedEventArgs e)
        {
            var ofd = new OpenFileDialog();

            if (ofd.ShowDialog() != null)
            {
                if (string.IsNullOrEmpty(ofd.FileName))
                {
                    return;
                }

                var img = System.Drawing.Image.FromFile(ofd.FileName);
                var bit = ResizeImage(img, 320, 240);

                string path = $"{Environment.CurrentDirectory}\\temp";
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }

                bit.Save($"{path}\\temp.tmp");

                EventbusManager.GetEventbus().OpenView <MainView>(new MainMessage($"{path}\\temp.tmp"));
            }
        }
        public MenuView()
        {
            this.InitializeComponent();

            this._viewModel = (MenuViewModel)this.DataContext;

            EventbusManager.Register <MenuView, UpdateCommandMessage>(this.UpdateCommandMessageReceived);
        }
        public void CleanUpEventbus()
        {
            var eventbus = EventbusManager.GetEventbus();

            eventbus.Deregister <MockView>();
            eventbus.Deregister <Mock2View>();

            Assert.AreEqual(0, eventbus.RegisteredCount);
        }
        public MainView()
        {
            this.InitializeComponent();

            this._viewModel = (MainViewModel)this.DataContext;

            EventbusManager.GetEventbus().Register <MainView, MainMessage>(this.EventBusReceivedMessage);

            this.FinishConvertEvent += this.MainView_FinishConvertEvent;
        }
        private void ButtonShowDevices_Click(object sender, RoutedEventArgs e)
        {
            if (EventbusManager.IsViewOpen(typeof(DevicesView), 2))
            {
                EventbusManager.CloseView <DevicesView>(2);
                return;
            }

            EventbusManager.OpenView <DevicesView>(2);
        }
        private void ButtonOpenUserList_Click(object sender, RoutedEventArgs e)
        {
            if (EventbusManager.IsViewOpen(typeof(UserlistView), 0))
            {
                return;
            }

            this._viewModel.ViewOpened = ViewOpen.Userlist;
            EventbusManager.OpenView <UserlistView>(0);
        }
        private void ButtonOpenMain_Click(object sender, RoutedEventArgs e)
        {
            if (EventbusManager.IsViewOpen(typeof(MainView), 0))
            {
                return;
            }

            this._viewModel.ViewOpened = ViewOpen.Main;
            EventbusManager.OpenView <MainView>(0);
        }
        public void EventbusManagerSimpleTest()
        {
            // arrange
            var eventbus = EventbusManager.GetEventbus();

            // act
            eventbus.Register <MockView, MockMessage>((message) => true);

            // asssert

            Assert.AreEqual(1, eventbus.RegisteredCount);
        }
        public void EventbusManagerRegisterTwoEventsForTwoViewsGetCountFromTargetViewTest()
        {
            // arrange
            var eventbus = EventbusManager.GetEventbus();
            Func <IMessageContainer, bool> message1 = (message) => true;
            Func <IMessageContainer, bool> message2 = (message) => true;

            // act
            eventbus.Register <MockView, MockMessage>(message1);
            eventbus.Register <Mock2View, MockMessage>(message2);

            // asssert
            Assert.AreEqual(2, eventbus.RegisteredCount);
        }
        public void EventbusManagerSendOneMessageErrorNotReceiverTest()
        {
            // arrange
            var eventbus = EventbusManager.GetEventbus();
            Func <IMessageContainer, bool> message1 = (message) => true;

            eventbus.Register <MockView, MockMessage>(message1);

            // act
            var result = Assert.ThrowsException <EventbusException>(() => eventbus.Send <MockView, MockMessage2>(new MockMessage2("my message")));

            // asssert
            Assert.AreEqual("Not found or registered. View: MockView, MockMessage2", result.Message);
        }
        public MainView()
        {
            this.InitializeComponent();

            this._viewModel = (MainViewModel)this.DataContext;

            EventbusManager.Register <MainView, MainMessage>(this.EventBusReceivedMessage);
            var settings = UserSettingsLoader.GetInstance().Settings;

            this._viewModel.Username         = settings.Username;
            this._viewModel.Interval         = settings.Interval;
            this._viewModel.HostAddressItems = settings.ServerAddressItems;
            this._viewModel.HostAddress      = settings.ServerAddress;
        }
Beispiel #12
0
        private void SetupUpdate()
        {
            MessengerManager.GetInstance().Add(() =>
            {
                if (!EventbusManager.IsViewOpen(typeof(DevicesView), this._channel))
                {
                    return;
                }


                EventbusManager.Send<DevicesView, DeviceUpdateCommand>(new DeviceUpdateCommand(CommandMessage.Update), this._channel);
            });
            EventbusManager.Register<DevicesView, DeviceUpdateCommand>(this.ReceiveUpdateCommand);
        }
        private void SetupUpdate()
        {
            MessengerManager.GetInstance().Add(() =>
            {
                if (!EventbusManager.IsViewOpen(typeof(UserlistView), 0))
                {
                    return;
                }


                EventbusManager.Send <UserlistView, UpdateCommandMessage>(new UpdateCommandMessage(CommandMessage.Update), 0);
            });
            EventbusManager.Register <UserlistView, UpdateCommandMessage>(this.ReceiveUpdateCommand);
        }
        public void EventbusManagerRegisterTwoEventsInOneViewErrorTest()
        {
            // arrange
            var eventbus = EventbusManager.GetEventbus();
            Func <IMessageContainer, bool> message1 = (message) => true;
            Func <IMessageContainer, bool> message2 = (message) => true;

            eventbus.Register <MockView, MockMessage>(message1);

            // act
            var result = Assert.ThrowsException <EventbusException>(() => eventbus.Register <MockView, MockMessage>(message2));

            // asssert
            Assert.AreEqual("can not register one moretime to the viewType MockView about message type: MockMessage", result.Message);
        }
        public ChatView()
        {
            this.InitializeComponent();

            this._viewModel = (ChatViewModel)this.DataContext;

            MessengerManager.GetInstance().Add(() =>
            {
                if (!EventbusManager.IsViewOpen(typeof(ChatView), 0))
                {
                    return;
                }

                this._dispatcherTimer_Tick();
            });
            EventbusManager.Register <ChatView, LoadCommandMessage>(this.LoadCommandReceived);
        }
        public void EventbusManagerSendOneMessageTest()
        {
            // arrange
            var    eventbus = EventbusManager.GetEventbus();
            string result   = string.Empty;
            Func <IMessageContainer, bool> message1 = (message) => { result = message.Content.ToString(); return(true); };
            Func <IMessageContainer, bool> message2 = (message) => true;

            eventbus.Register <MockView, MockMessage>(message1);
            eventbus.Register <MockView, MockMessage2>(message2);

            // act
            eventbus.Send <MockView, MockMessage>(new MockMessage("my message"));

            // asssert
            Assert.AreEqual("my message", result);
        }
        private void ButtonAccept_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(this._viewModel.Username))
            {
                MessageBox.Show("username must be set.");
                return;
            }

            if (string.IsNullOrEmpty(this._viewModel.HostAddress))
            {
                MessageBox.Show("host address must be set.");
                return;
            }

            var service = ServiceConnector.GetInstance();

            service.SetAddress(this._viewModel.HostAddress);

            if (service.TrySetUsername(this._viewModel.Username, out var userItem))
            {
                EventbusManager.OpenView <UserlistView>(0);
                EventbusManager.Send <MainWindow, UpdateCommandMessage>(new UpdateCommandMessage(userItem), 0);
                EventbusManager.Send <MenuView, UpdateCommandMessage>(new UpdateCommandMessage(ViewOpen.Userlist), 0);

                if (!this._viewModel.HostAddressItems.Any(a => a.Equals(this._viewModel.HostAddress)))
                {
                    this._viewModel.HostAddressItems = this._viewModel.HostAddressItems.Append(this._viewModel.HostAddress);
                }

                var settings = new SettingsFile
                {
                    Username           = this._viewModel.Username,
                    Interval           = this._viewModel.Interval,
                    ServerAddress      = this._viewModel.HostAddress,
                    ServerAddressItems = this._viewModel.HostAddressItems
                };
                UserSettingsLoader.GetInstance().Save(settings);

                MessengerManager.GetInstance().Start(this._viewModel.Interval);
                return;
            }

            MessageBox.Show($"Can not use username: {this._viewModel.Username}");
        }
 public void Dispose() => EventbusManager.Deregister <ChatView>();
 public void Dispose()
 {
     EventbusManager.GetEventbus().Deregister <MainView>();
     this.FinishConvertEvent -= this.MainView_FinishConvertEvent;
 }
Beispiel #20
0
 private void Window_Loaded(object sender, RoutedEventArgs e)
 {
     EventbusManager.OpenView <MainView>(0);
     EventbusManager.Send <MenuView, UpdateCommandMessage>(new UpdateCommandMessage(ViewOpen.Main), 0);
     EventbusManager.Register <MainWindow, UpdateCommandMessage>(this.UpdateCommandMessageReceived);
 }
Beispiel #21
0
 public void Dispose() => EventbusManager.Deregister<DevicesView>();
 private void ListBox_MouseDoubleClick(object sender, MouseButtonEventArgs e)
 {
     EventbusManager.Send <MenuView, UpdateCommandMessage>(new UpdateCommandMessage(ViewOpen.Chat), 0);
     EventbusManager.Send <ChatView, LoadCommandMessage>(new LoadCommandMessage(this._viewModel.SelectedUser), 0, true);
 }
 public void Dispose()
 {
     EventbusManager.Deregister <MainView>();
 }