Beispiel #1
0
        public DevicesView()
        {
            this.InitializeComponent();

            this._serviceConnector = ServiceConnector.GetInstance();
            this._viewModel = (DevicesViewModel)this.DataContext;

            this.SetupUpdate();
        }
        private void SendMessageToUser()
        {
            if (string.IsNullOrEmpty(this._viewModel.SendText))
            {
                return;
            }

            ServiceConnector.GetInstance().SendMessage(this._viewModel.UserItem.ID, this._viewModel.SendText);
            this._viewModel.SendText = string.Empty;
        }
Beispiel #3
0
        public void ServiceConnectorSendMessageTest()
        {
            // arrange
            IServiceConnector serviceConnector = ServiceConnector.GetInstance();

            serviceConnector.SetAddress("http://localhost:5000/");
            serviceConnector.TrySetUsername("testUser", out var testUser);

            // act
            var result = serviceConnector.SendMessage(_adminUserId, "Hallo test");

            // assert
            Assert.IsNotNull(result);
        }
Beispiel #4
0
        public void ServiceConnectorDeviceGetValueTest()
        {
            // arrange
            IServiceConnector serviceConnector = ServiceConnector.GetInstance();

            serviceConnector.SetAddress("http://localhost:5000/");
            // it must a non exist device
            const long id = 12345678L;
            // act
            var result = serviceConnector.DeviceGetValue(id);

            // assert
            Assert.AreEqual(0, result);
        }
Beispiel #5
0
        public void ServiceConnectorGetAllUsersTest()
        {
            // arrange
            IServiceConnector serviceConnector = ServiceConnector.GetInstance();

            serviceConnector.SetAddress("http://localhost:5000/");

            // act
            var result = serviceConnector.GetAllUsers();

            // assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Any());
        }
Beispiel #6
0
        public void ServiceConnectorGetMessagesTest()
        {
            // arrange
            IServiceConnector serviceConnector = ServiceConnector.GetInstance();

            serviceConnector.SetAddress("http://localhost:5000/");
            serviceConnector.TrySetUsername("testUser", out var testUser);

            // act
            var result = serviceConnector.GetMessages(_adminUserId);

            // assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Any());
            Assert.AreEqual("Hallo ich bin der Admin Benutzer", result.First().Text);
        }
Beispiel #7
0
        public void ServiceConnectorSetUserAndGetAllUsersTest()
        {
            // arrange
            IServiceConnector serviceConnector = ServiceConnector.GetInstance();

            serviceConnector.SetAddress("http://localhost:5000/");
            serviceConnector.TrySetUsername("testUser", out var testUser);

            // act
            var result = serviceConnector.GetAllUsers();

            // assert
            Assert.IsNotNull(result);
            // only admin, well it show only other not self user
            Assert.AreEqual(1, result.Length);
        }
Beispiel #8
0
        public void ServiceConnectorTrySetUsernameTest()
        {
            // arrange
            IServiceConnector serviceConnector = ServiceConnector.GetInstance();

            serviceConnector.SetAddress("http://localhost:5000/");
            const string username = "******";

            // act
            var success = serviceConnector.TrySetUsername(username, out var result);

            // assert
            Assert.IsTrue(success);
            Assert.IsNotNull(result);
            Assert.AreEqual(username, result.Username);
            Assert.AreNotEqual(0, result.ID);
        }
Beispiel #9
0
        public void ServiceConnectorDeviceSendComandTextTest()
        {
            // arrange
            IServiceConnector serviceConnector = ServiceConnector.GetInstance();

            serviceConnector.SetAddress("http://localhost:5000/");
            serviceConnector.DeviceGetText(1L);
            string sendText = "Hello";

            // act
            var result     = serviceConnector.DeviceSendCommand(1L, sendText);
            var resultText = serviceConnector.DeviceGetText(1L);

            // assert
            Assert.IsTrue(result);
            Assert.AreEqual(sendText, resultText);
        }
Beispiel #10
0
        public void ServiceConnectorDeviceSendComandValueTest()
        {
            // arrange
            IServiceConnector serviceConnector = ServiceConnector.GetInstance();

            serviceConnector.SetAddress("http://localhost:5000/");
            serviceConnector.DeviceGetValue(1L);
            const long value = 234L;

            // act
            var result      = serviceConnector.DeviceSendCommand(1L, 234);
            var resultValue = serviceConnector.DeviceGetValue(1L);

            // assert
            Assert.IsTrue(result);
            Assert.AreEqual(value, resultValue);
        }
Beispiel #11
0
        public void ServiceConnectorSendMessageAndGetMessageTest()
        {
            // arrange
            IServiceConnector serviceConnector = ServiceConnector.GetInstance();

            serviceConnector.SetAddress("http://localhost:5000/");
            serviceConnector.TrySetUsername("testUser", out _);

            // act
            serviceConnector.SendMessage(_adminUserId, "Hallo test");
            var result = serviceConnector.GetMessages(_adminUserId);

            // assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Any());
            Assert.AreEqual("Hallo test", result.Last().Text);
        }
        private void _dispatcherTimer_Tick()
        {
            var messages = ServiceConnector.GetInstance().GetMessages(this._viewModel.UserItem.ID);

            foreach (var item in messages)
            {
                if (this._viewModel.Messages.Contains(item))
                {
                    continue;
                }

                this._viewModel.Messages.Add(item);
            }

            // TODO: sieht nicht gut aus.
            this._viewModel.LastIndex = this._viewModel.Messages.Count - 1;
            this.listbox.ScrollIntoView(this.listbox.SelectedItem);
        }
        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}");
        }
Beispiel #14
0
        public void ServiceConnectorDeviceSendComandGetResponseTest()
        {
            // arrange
            IServiceConnector serviceConnector = ServiceConnector.GetInstance();

            serviceConnector.SetAddress("http://localhost:5000/");
            serviceConnector.DeviceGet(1L);
            const long id       = 1L;
            const long value    = 456L;
            string     sendText = "Hello";

            // act
            var result         = serviceConnector.DeviceSendCommand(id, value, sendText);
            var resultResponse = serviceConnector.DeviceGet(id);

            // assert
            Assert.IsTrue(result);
            Assert.AreEqual(sendText, resultResponse.Text);
            Assert.AreEqual(value, resultResponse.Value);
        }