コード例 #1
0
 private void Login()
 {
     if (LoginTB.Text.Length >= 5)
     {
         string email    = LoginTB.Text;
         string password = PasswordTB.Password;
         //httpPost validation
         if (SessionHelper.SetActiveUserSession(new ApplicationUser {
             UserName = email, Password = password
         }))
         {
             ConnectToRoom connectToRoomForm = new ConnectToRoom();
             connectToRoomForm.Show();
             this.Close();
         }
         else
         {
             MessageBox.Show("Invalid login or password", "Sync Player");
         }
     }
     else
     {
         LoginTB.Focus();
     }
 }
コード例 #2
0
        private async void DisconnectBTN_Click(object sender, RoutedEventArgs e)
        {
            await _connection.StopAsync();

            if (_connectToRoom == null)
            {
                _connectToRoom = new ConnectToRoom();
                _connectToRoom.Show();
                this.Close();
            }
        }
コード例 #3
0
        public void UserActor_should_connect_to_room_properly()
        {
            //arrange
            var connectToRoom = new ConnectToRoom("testUser", "testRoom");

            //act
            var connectToRoomResponse = userDispatcher.Ask <ConnectedToRoom>(connectToRoom).Result;

            //assert
            connectToRoomResponse.Room.Should().NotBeNull();
            connectToRoomResponse.Room.Name.Should().Be("testRoom");
        }
コード例 #4
0
 private void RegisterBTN_Click(object sender, RoutedEventArgs e)
 {
     if (AgreementCB.IsChecked == true)
     {
         if (EmailTB.Text.Length >= 5 &&
             LoginTB.Text.Length >= 5 &&
             PasswordTB.Password.Length >= 5 &&
             RepeatPasswordTB.Password.Length >= 5)
         {
             if (PasswordTB.Password == RepeatPasswordTB.Password)
             {
                 string email    = EmailTB.Text;
                 string password = PasswordTB.Password;
                 string username = LoginTB.Text;
                 var    user     = new ApplicationUser()
                 {
                     Email = email, UserName = username, Password = password
                 };
                 if (new HttpHelper().Request(user, new AppSettingsReader().GetValue("ServerHost", typeof(string)) + "api/Auth/Register"))
                 {
                     SessionHelper.SetActiveUserSession(user);
                     ConnectToRoom connectToRoomForm = new ConnectToRoom();
                     connectToRoomForm.Show();
                     this.Close();
                 }
                 else
                 {
                     MessageBox.Show("User with this login or email already exist", "Sync Player");
                 }
             }
             else
             {
                 RepeatPasswordTB.Password = string.Empty;
                 RepeatPasswordTB.Focus();
             }
         }
         else
         {
             EmailTB.Focus();
         }
     }
     else
     {
         var converter = new BrushConverter();
         var brush     = (Brush)converter.ConvertFromString("#FF0000");
         AgreementCB.BorderBrush = brush;
         AgreementCB.Background  = brush;
     }
 }
コード例 #5
0
        private void HandleConnectToRoom(ConnectToRoom cmd)
        {
            Subscribe(cmd.RoomName, cmd.UserName);

            Sender.Tell(new ConnectedToRoom(userState.LastRoom), Self);
        }
コード例 #6
0
        private void RegisterListeners()
        {
            _connection.On <string>("UserDisconect", (username) =>
            {
                this.Dispatcher.Invoke(() =>
                {
                    UpdateUserList();
                });
            });
            _connection.On <string>("UserConnected", (username) =>
            {
                this.Dispatcher.Invoke(() =>
                {
                    _readyToPLay = false;
                    mePlayer.Pause();
                    btnPlay.IsEnabled = false;
                    UpdateUserList();
                });
            });
            _connection.On("RoomClosed", async() =>
            {
                await this.Dispatcher.Invoke(async() =>
                {
                    await _connection.StopAsync();
                    if (_connectToRoom == null)
                    {
                        _connectToRoom = new ConnectToRoom();
                        _connectToRoom.Show();
                        this.Close();
                    }
                });
            });
            _connection.On <string, IEnumerable <string> >("DownloadMedia", async(fileName, chunks) =>
            {
                var folderName = await _mediaLoadService.DownloadFileAsync(fileName, chunks, _room.UniqName);
                _mediaLoadService.MergeFile(folderName, _room.PlaylistPath, fileName);
                _playlist.Add(new MediaService().GetMedia($"{_room.PlaylistPath}\\{fileName}"));
                _room.Medias = new List <Media>(_playlist);
                UpdatePlaylist();
                await _connection.SendAsync("MediaDownloaded");
            });
            _connection.On <Media>("NextMedia", model =>
            {
                this.Dispatcher.Invoke(() =>
                {
                    var media = GetMedia(model);
                    mePlayer.Stop();
                    mePlayer.Source = new Uri(media.FileName);
                });
            });
            _connection.On <string, string>("Receive", AddTextToChat);
            _connection.On <TimeSpan>("Play", (currentTrackTime) =>
            {
                this.Dispatcher.Invoke(() =>
                {
                    if (_readyToPLay)
                    {
                        mePlayer.Play();
                    }
                });
            });
            _connection.On("Pause", () => this.Dispatcher.Invoke(() => mePlayer.Pause()));
            _connection.On("Stop", () => this.Dispatcher.Invoke(() => mePlayer.Stop()));
            _connection.On("ReadyToPlay", () =>
            {
                _readyToPLay = true;
                this.Dispatcher.Invoke(async() =>
                {
                    var track = _playlist.FirstOrDefault();
                    await _connection.SendAsync("SetNextMedia", track);
                    btnPlay.IsEnabled = true;
                });
            });
            _connection.On("RequireCheckMedia", async() =>
            {
                await _connection.SendAsync("CheckMedia", _room.Medias);
            });

            if (_isHost)
            {
                btnPause.Visibility         = Visibility.Visible;
                btnPlay.Visibility          = Visibility.Visible;
                btnStop.Visibility          = Visibility.Visible;
                NextMedia.Visibility        = Visibility.Visible;
                ResetPlaylistBTN.Visibility = Visibility.Visible;
                btnPlay.IsEnabled           = false;

                _connection.On <IEnumerable <Media>, string>("RequireMedia", async(models, id) =>
                {
                    await this.Dispatcher.Invoke(async() =>
                    {
                        var path = mePlayer.Source.LocalPath;
                        foreach (var media in models)
                        {
                            GC.SuppressFinalize(mePlayer.Source);
                            mePlayer.Source = null;
                            var uploadMedia = GetMedia(media);
                            var result      = _mediaLoadService.UploadFile(uploadMedia.FileName, _room.UniqName);
                            await _connection.SendAsync("UploadMedia", id, uploadMedia.Name, result);
                        }
                        mePlayer.Source = new Uri(path);
                    });
                });
                _connection.On("RequireNextMedia", () =>
                {
                    this.Dispatcher.Invoke(async() => {
                        string currentFilePath = mePlayer.Source.LocalPath;
                        mePlayer.Source        = null;
                        _playlist.Remove(_playlist.FirstOrDefault(media => media.FileName == currentFilePath));
                        var nextMedia = _playlist.FirstOrDefault();
                        await _connection.SendAsync("SetNextMedia", nextMedia);
                    });
                });
            }
        }