コード例 #1
0
 public MovieItemViewModel(string movieId) : this()
 {
     MovieId = movieId;
     using (var repos = new RepositoryService())
     {
         var movie = repos.FindMovie(movieId);
         Rank      = movie.Rank;
         PlayCount = movie.PlayCount;
         Path      = movie.Path;
     }
     UpdateTags();
 }
コード例 #2
0
        public async Task UnregisterMovie(string movieId, ObservableCollection <MovieItemViewModel> movieCollection)
        {
            var moviePath = "";
            await dispatcher.InvokeAsync(() =>
            {
                List <string> thumbnailPaths;
                using (var repos = new RepositoryService())
                {
                    var movie = repos.FindMovie(movieId);
                    if (movie == null)
                    {
                        logger.Information($"動画はすでに登録解除されています。{movieId}");
                        return;
                    }
                    moviePath      = movie.Path;
                    thumbnailPaths = repos.FindMovieThumbnails(movieId).Select(t => t.Path).ToList();
                    repos.RemoveMovie(movie);
                }

                var model = movieCollection.Where(m => m.MovieId == movieId).FirstOrDefault();
                if (model != null)
                {
                    App.Current.Dispatcher.Invoke(() =>
                    {
                        movieCollection.Remove(model);
                    });

                    foreach (var path in thumbnailPaths)
                    {
                        try
                        {
                            if (File.Exists(path))
                            {
                                File.Delete(path);
                            }
                        }
                        catch (Exception)
                        {
                            logger.Warning($"サムネイル{path}が削除できませんでした。");
                        }
                    }
                }
                logger.Information($"削除された動画の登録を解除しました。{moviePath}");
            });
        }