public async Task <IEnumerable <GeneralRating> > GetMappedMovies(IEnumerable <UserImdbRating> ratingList) { try { List <GeneralRating> mappedRatings = new List <GeneralRating>(); foreach (UserImdbRating imdbRating in ratingList) { MovieMap movie = await _context.Movies .Find(movie => movie.Title.ToLower().Contains(imdbRating.MovieTitle.ToLower())) .FirstOrDefaultAsync(); if (movie != null) { GeneralRating mappedRating = new GeneralRating { MovieId = movie.MovieId, RatingValue = imdbRating.RatingValue / 2 }; mappedRatings.Add(mappedRating); } } return(mappedRatings); } catch (Exception ex) { throw ex; } }
// Click on Listbox Element private async void MenuItem_Click(object sender, RoutedEventArgs e) { // Get menu item name string menuItemName = ((MenuItem)sender).Name; int selectedMovieViewModelId = Convert.ToInt32(((MenuItem)sender).Tag); MovieViewModel selectedMovieViewModel = MovieMap.MapToMovieViewModel(await movieService.GetMovieByIdAsync(selectedMovieViewModelId)); switch (menuItemName) { case "menuItemPlayMovie": ((ModernWindow)Application.Current.MainWindow).Hide(); new PlayerWindow(selectedMovieViewModel).Show(); break; case "menuItemMovieProfile": this.Dispatcher.Invoke(() => { IInputElement target = NavigationHelper.FindFrame("_top", this); NavigationCommands.GoToPage.Execute("/Views/Content/MovieProfile.xaml#" + selectedMovieViewModelId, target); }); break; default: break; } }
private async void setViewModel() { // We use just one Setting (Get and Update this Setting) await settingService.GetSettingByIdAsync(1).ContinueWith(async settingResult => settingViewModel = SettingMap.MapToSettingViewModel(await settingResult) ); // Set MovieViewModels await movieService.GetMoviesAsync().ContinueWith(async moviesResult => movieViewModels = MovieMap.MapToMovieViewModelList(await moviesResult) ); BindingContext = settingViewModel; }
public async Task NavigateFromMenu(int id) { if (!MenuPages.ContainsKey(id)) { // Set MovieViewModels await movieService.GetMoviesAsync().ContinueWith(async moviesResult => movieViewModels = MovieMap.MapToMovieViewModelList(await moviesResult) ); switch (id) { case (int)MenuItemType.Connection: MenuPages.Add(id, new NavigationPage(new ConnectionPage())); break; case (int)MenuItemType.MoviesList: MenuPages.Add(id, new NavigationPage(new MoviesListPage(movieViewModels))); break; case (int)MenuItemType.Command: MenuPages.Add(id, new NavigationPage(new CommandPage())); break; case (int)MenuItemType.Log: MenuPages.Add(id, new NavigationPage(new LogPage())); break; } } var newPage = MenuPages[id]; if (newPage != null && Detail != newPage) { Detail = newPage; if (Device.RuntimePlatform == Device.Android) { await Task.Delay(100); } IsPresented = false; } }
// Save movie model changes and filter changes private async void buttonSave_Click(object sender, RoutedEventArgs e) { await showLoading(); await Task.Factory.StartNew(async() => { var movies = MovieMap.MapToMovieList(movieViewModels); await movieService.UpdateAllMovieAsync(movies).ContinueWith(moviesResult => { socketServer.CloseClientConnection("Kapcsolat bezárása..."); // Start Socket Server after new movies socketServer.StartServer(settingViewModel); }); var filter = FilterMap.MapFilterViewModelToFilter(filterViewModel); await filterService.UpdateFilterAsync(filter); await hideLoading(); }); }
private async void OnItemSelected(object sender, SelectedItemChangedEventArgs args) { var item = args.SelectedItem as MovieViewModel; if (item == null) { return; } if (Connection.Instance.ClientSocket != null && Connection.Instance.ClientSocket.ClientSocket != null && Connection.Instance.ClientSocket.ClientSocket.Connected && Connection.Instance.ClientSocket.IsPlayMovie) { SocketClientService.Instance.SendMovie(MovieMap.MapToMovie(item)); } else { await DisplayAlert("Nincs kapcsolat", "Film küldése sikertelen...\nNincs kapcsolat a szerverrel", "Ok"); } // Manually deselect item. listViewMovies.SelectedItem = null; }
private static void Map() { MovieMap.Configure(); }
// Receive data private void ReceiveCallback(IAsyncResult ar) { Socket socket = ar.AsyncState as Socket; if (socket.Connected) { int received; try { received = socket.EndReceive(ar); } catch (Exception ex) { // Close connection CloseClientConnection("Probléma az adatok fogadása közben..." + Environment.NewLine + ex.Message, socket.RemoteEndPoint); return; } // Get received movie object or movie command if (received != 0) { byte[] dataBuf = new byte[received]; Array.Copy(buffer, dataBuf, received); // Client sent a movie if (received != 194) { MovieViewModel movieViewModel = MovieMap.MapToMovieViewModel(BinaryConverter.BinaryToMovieObject(dataBuf)); LoggerService.Instance.Loggers.Add(new Logger { Id = LoggerService.Instance.LastId + 1, Message = "Kliens kiválasztott egy filmet ---\n\t" + movieViewModel.Title, Sender = Sender.SocketServer, LogDate = DateTime.Now }); connection.ClientSockets.FirstOrDefault(c => c.ClientSocket == socket).IsPlayMovie = true; // Start playing movie Application.Current.Dispatcher.Invoke(() => { ((ModernWindow)Application.Current.MainWindow).Hide(); new PlayerWindow(movieViewModel).Show(); }); // Listen again (Receive data) socket.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, new AsyncCallback(ReceiveCallback), socket); } // Client sent a movie command else { MovieCommand commandEnum = BinaryConverter.BinaryToCommandEnum(dataBuf); if (commandEnum != MovieCommand.CloseClient) { // Process movie command Application.Current.Dispatcher.Invoke(() => { PlayerWindow playerWindow = Application.Current.Windows.OfType <PlayerWindow>().FirstOrDefault(); switch (commandEnum) { case MovieCommand.StartPauseMovie: playerWindow.PlayPause(); break; case MovieCommand.StopMovie: playerWindow.Stop(); break; case MovieCommand.RewindMovie: playerWindow.Rewind(); break; case MovieCommand.ForwardMovie: playerWindow.Forward(); break; case MovieCommand.SoundPlus: playerWindow.SoundPlus(); break; case MovieCommand.SoundMinus: playerWindow.SoundMinus(); break; case MovieCommand.Mute: playerWindow.MuteOnOff(); break; case MovieCommand.FullScreen: playerWindow.SetFullScreen(); break; case MovieCommand.ShutdownPc: playerWindow.SetPcOption(PCOption.Shutdown); break; case MovieCommand.Restart: playerWindow.SetPcOption(PCOption.Restart); break; case MovieCommand.Hibernate: playerWindow.SetPcOption(PCOption.Hibernate); break; case MovieCommand.LogOff: playerWindow.SetPcOption(PCOption.LogOff); break; case MovieCommand.Sleep: playerWindow.SetPcOption(PCOption.Sleep); break; case MovieCommand.Lock: playerWindow.SetPcOption(PCOption.Lock); break; case MovieCommand.CloseMovie: playerWindow.CloseWindow(); break; } }); // Listen again (Receive data) socket.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, new AsyncCallback(ReceiveCallback), socket); } else { CloseClientConnection("A kliens bezárta a kapcsolatot", socket.RemoteEndPoint); } } } else { CloseClientConnection("Nem érhető el a kliens", socket.RemoteEndPoint); } } else { CloseClientConnection("Nem érhető el a kliens", socket.RemoteEndPoint); } }
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)); }