Exemple #1
0
        /// <summary>
        /// Permet d'initialiser le manager en démarrant le serveur socket
        /// </summary>
        public async Task Init()
        {
            _socketServerService.OnClientConnected     += OnSocketClientConnected;
            _socketServerService.OnClientsDisconnected += OnSocketClientDisconnected;
            _socketServerService.OnMessageReceived     += OnSocketMessageReceived;
            _socketServerService.InitServer();

            await _socketServerService.StartServer();
        }
Exemple #2
0
        private async void setViewModel()
        {
            // Upload SQLite database through FTP
            await FTPServer.UploadDB();

            // We use just one Setting (Get and Update this Setting)
            settingViewModel = SettingMap.MapToSettingViewModel(await settingService.GetSettingByIdAsync(1));

            // Get movies and Start Socket Server if movies count more than 0 and not null
            await movieService.GetMoviesAsync().ContinueWith(async moviesResult =>
            {
                movies = await moviesResult;

                if (movies != null && movies.Count > 0)
                {
                    SocketServerService socketServer = new SocketServerService();
                    // Start Socket Server listen
                    socketServer.StartServer(settingViewModel);
                }
            });
        }
Exemple #3
0
        private async Task <ObservableCollection <MovieViewModel> > setViewModel()
        {
            // We just update Setting and Filter models, no delete - no insert
            var setting = await settingService.GetSettingByIdAsync(1);

            var filter = await filterService.GetFilterByIdAsync(1);

            // FileSizes - FileTypes
            var fileSizes = await fileSizeService.GetFileSizesAsync();

            var fileTypes = await fileTypeService.GetFileTypesAsync();

            // Get viewmodels
            this.Dispatcher.Invoke(() =>
            {
                settingViewModel = SettingMap.MapToSettingViewModel(setting);
                filterViewModel  = FilterMap.MapToFilterViewModel(filter);
                filterViewModel.FileTypeViewModels = FileTypeMap.MapToFileTypeViewModelList(fileTypes);
                filterViewModel.FileSizeViewModels = FileSizeMap.MapToFileSizeViewModelList(fileSizes);

                dockPanelFilter.DataContext = filterViewModel;
            }
                                   );

            // Show message if MoviesPath is not set
            if (!Directory.Exists(settingViewModel.MoviesPath))
            {
                this.Dispatcher.Invoke(() =>
                {
                    MessageBoxResult result = ModernDialog.ShowMessage("A(z) '" + settingViewModel.MoviesPath + "' mappa nem létezik, így nem lehet filmeket keresni! Szeretnéd megváltoztatni most?", "'Filmek' mappa nem létezik", MessageBoxButton.YesNo);
                    if (result == MessageBoxResult.Yes)
                    {
                        IInputElement target = NavigationHelper.FindFrame("_top", this);
                        NavigationCommands.GoToPage.Execute("/Views/Content/SettingServer.xaml", target);
                    }
                    else
                    {
                        IInputElement target = NavigationHelper.FindFrame("_top", this);
                        LinkCommands.NavigateLink.Execute("/Views/Pages/Introduction.xaml", target);
                    }
                });
            }
            // Get movies and set viewmodel
            else
            {
                // Get movies from database
                moviesFromDb = await movieService.GetMoviesAsync();

                movieViewModels = MovieMap.MapToMovieViewModelList(moviesFromDb);

                await Task.Factory.StartNew(async() =>
                {
                    moviesFromFileServer = await MovieServer.GetMovieTitles(settingViewModel.MoviesPath, FileTypeMap.MapToFileTypeList(settingViewModel.FileTypeViewModels));
                });

                // We have no movies in database
                if (movieViewModels.Count <= 0)
                {
                    await movieService.InsertAllMovieAsync(moviesFromFileServer).ContinueWith(async moviesResult =>
                    {
                        movieViewModels = MovieMap.MapToMovieViewModelList(await moviesResult);
                        // Start Socket Server after new movies
                        socketServer.StartServer(settingViewModel);
                    }
                                                                                              );

                    //movieViewModels = MovieMap.MapToMovieViewModelList(insertedMovies);
                }
                else
                {
                    // Delete and insert changes
                    var deleted  = moviesFromDb.Where(m => !moviesFromFileServer.Select(c => c.Title).Contains(m.Title)).ToList();
                    var inserted = moviesFromFileServer.Where(c => !moviesFromDb.Select(m2 => m2.Title).Contains(c.Title)).ToList();

                    if (deleted != null && deleted.Count > 0)
                    {
                        // Delete my movies
                        await movieService.DeleteMoviesByListIdAsync(deleted.Select(d => d.Id).ToList());
                    }
                    if (inserted != null && inserted.Count > 0)
                    {
                        // Insert my movies
                        await movieService.InsertAllMovieAsync(inserted).ContinueWith(moviesResult =>
                                                                                      // Start Socket Server after new movies
                                                                                      socketServer.StartServer(settingViewModel)
                                                                                      );
                    }

                    // Correct current movies what can search with TMDB
                    moviesFromDb = await movieService.GetMoviesAsync();

                    movieViewModels = MovieMap.MapToMovieViewModelList(moviesFromDb);
                }
            };


            return(await Task.FromResult(movieViewModels));
        }