public void ConstructorShouldSetDatabaseName()
        {
            // Arrange
            var    entities = new UMoviesEntities();
            string dbName;

            // Act
            dbName = entities.Database.Connection.Database;

            // Assert
            Assert.AreEqual("UMovies", dbName);
        }
Exemple #2
0
        private async Task InitializeSignalR(string url)
        {
            _hubConnection?.Stop();

            _hubConnection = new HubConnection(url);
            _soulstoneHub  = _hubConnection.CreateHubProxy("umoviesHub");

            _soulstoneHub.On <string>("Welcome", (message) =>
            {
                try
                {
                    ConsoleLog(message);
                }
                catch (Exception ex)
                {
                    ConsoleLog("An error has occurred: " + ex.Message);
                }
            });

            _soulstoneHub.On <string, string>("PlayMovie", (folderName, fileName) =>
            {
                try
                {
                    KillProcess();
                    InvokeConsoleLog(fileName);
                    var movieFilePath = Path.Combine(_videoRootFolder, Path.Combine(folderName, fileName));
                    var arguments     = $@"""{movieFilePath}"" /fullscreen";
                    InvokeConsoleLog(arguments);
                    var processStart = new ProcessStartInfo(_videoPlayerPath, arguments);
                    _process         = Process.Start(processStart);
                }
                catch (Exception ex)
                {
                    ConsoleLog("An error has occurred: " + ex.Message);
                }
            });

            _soulstoneHub.On <int>("PlayAllMovieFiles", (movieId) =>
            {
                try
                {
                    KillProcess();
                    var entities = new UMoviesEntities();
                    var movie    = entities.Movies.FirstOrDefault(m => m.Id == movieId);
                    if (movie != null)
                    {
                        var movieFilePath = string.Empty;
                        foreach (var movieFile in movie.MovieFiles)
                        {
                            movieFilePath += $@"""{Path.Combine(_videoRootFolder, Path.Combine(movie.MovieFolder, movieFile.FileName))}"" ";
                        }

                        var arguments = $@"/add /play {movieFilePath} /fullscreen";
                        InvokeConsoleLog(arguments);
                        var processStart = new ProcessStartInfo(_videoPlayerPath, arguments);
                        _process         = Process.Start(processStart);
                    }
                    else
                    {
                        ConsoleLog($"Movie with id:{movieId} not found");
                    }
                }
                catch (Exception ex)
                {
                    ConsoleLog("An error has occurred: " + ex.Message);
                }
            });

            _soulstoneHub.On("PlayPause", () =>
            {
                try
                {
                    ConsoleLog("Play/Pause");
                    var input = new InputSimulator();
                    input.Keyboard.KeyDown(VirtualKeyCode.CONTROL);
                    input.Keyboard.KeyPress(VirtualKeyCode.VK_P);
                    input.Keyboard.KeyUp(VirtualKeyCode.CONTROL);
                }
                catch (Exception ex)
                {
                    ConsoleLog("An error has occurred: " + ex.Message);
                }
            });

            _soulstoneHub.On("SkipBack", () =>
            {
                try
                {
                    ConsoleLog("Skip Back");
                    var input = new InputSimulator();
                    input.Keyboard.KeyDown(VirtualKeyCode.CONTROL);
                    input.Keyboard.KeyPress(VirtualKeyCode.VK_L);
                    input.Keyboard.KeyUp(VirtualKeyCode.CONTROL);
                }
                catch (Exception ex)
                {
                    ConsoleLog("An error has occurred: " + ex.Message);
                }
            });

            _soulstoneHub.On("SkipForward", () =>
            {
                try
                {
                    ConsoleLog("Skip Forward");
                    var input = new InputSimulator();
                    input.Keyboard.KeyDown(VirtualKeyCode.CONTROL);
                    input.Keyboard.KeyPress(VirtualKeyCode.VK_R);
                    input.Keyboard.KeyUp(VirtualKeyCode.CONTROL);
                }
                catch (Exception ex)
                {
                    ConsoleLog("An error has occurred: " + ex.Message);
                }
            });

            _soulstoneHub.On("PlayFromBeginning", () =>
            {
                try
                {
                    ConsoleLog("Play from the beginning");
                    var input = new InputSimulator();
                    input.Keyboard.KeyDown(VirtualKeyCode.CONTROL);
                    input.Keyboard.KeyPress(VirtualKeyCode.VK_B);
                    input.Keyboard.KeyUp(VirtualKeyCode.CONTROL);
                }
                catch (Exception ex)
                {
                    ConsoleLog("An error has occurred: " + ex.Message);
                }
            });

            _soulstoneHub.On("ClosePlayer", () =>
            {
                try
                {
                    ConsoleLog("Closing Player");
                    KillProcess();
                }
                catch (Exception ex)
                {
                    ConsoleLog("An error has occurred: " + ex.Message);
                }
            });

            try
            {
                await _hubConnection.Start();
            }
            catch
            {
                InvokeConsoleLog("SignalR connection could not be established");
            }

            if (_hubConnection.State == ConnectionState.Connected)
            {
                InvokeConsoleLog("SignalR connection established");
            }

            _timer.Start();
        }