Esempio n. 1
0
        public ImageMaster()
        {
            List<DiscRecorder> recorders = new List<DiscRecorder>();
            _media = PhysicalMedia.Unknown;
            _nodes = new List<IMediaNode>();
            _mediaStates = new ReadOnlyCollection<MediaState>(new List<MediaState> { MediaState.Unknown });

            MsftDiscMaster2 discMaster = null;
            try
            {
                discMaster = new MsftDiscMaster2();

                if (!discMaster.IsSupportedEnvironment)
                    throw new NotSupportedException(
                        "Either the environment does not contain one or more optical devices or the " +
                        "execution context has no permission to access the devices.");

                foreach (string uniqueRecorderId in discMaster)
                {
                    recorders.Add(new DiscRecorder(uniqueRecorderId));
                }
                _recorders = new ReadOnlySelectableCollection<DiscRecorder>(recorders);
            }
            catch (COMException ex)
            {
                throw new NotSupportedException("IMAP2 not found on this system. It will need to be installed (ErrorCode = " + ex.ErrorCode + ").", ex);
            }
            finally
            {
                if (discMaster != null) Marshal.ReleaseComObject(discMaster);
            }
        }
Esempio n. 2
0
        public async Task <IActionResult> AddMovie(AddMovieViewModel addMedia)
        {
            Media        media    = _context.Medias.SingleOrDefault(m => m.TmdbId == addMedia.TmdbId);
            List <Genre> dbGenres = _context.Genres.ToList();

            if (media == null)
            {
                MediaType mediaType = _context.MediaTypes.SingleOrDefault(m => m.Name == SpinningFilmHelper.MovieType);

                string responseBody = await _apiService.GetWithCreditsAsync(addMedia.TmdbId, SpinningFilmHelper.MovieType);

                TmdbMovieResult movieResult = JsonConvert.DeserializeObject <TmdbMovieResult>(responseBody);

                responseBody = await _apiService.GetOmdbResult(movieResult.ImdbId);

                RatingResult ratingResult = JsonConvert.DeserializeObject <RatingResult>(responseBody);

                media = new Media(movieResult, mediaType, ratingResult, movieResult.ImdbId);
                _context.Add(media);

                Movie movie = new Movie(movieResult, media.MediaId);
                _context.Add(movie);

                foreach (var item in movieResult.Genres)
                {
                    var        genre      = dbGenres.SingleOrDefault(g => g.GenreId == item.GenreId) ?? _context.Genres.Add(item).Entity;
                    MediaGenre mediaGenre = new MediaGenre(media.MediaId, genre);
                    _context.Add(mediaGenre);
                }

                movieResult.Credits.Cast.ForEach(c => c.MediaId = media.MediaId);
                _context.Casts.AddRange(movieResult.Credits.Cast);

                movieResult.Credits.Crew.ForEach(c => c.MediaId = media.MediaId);
                _context.Crews.AddRange(movieResult.Credits.Crew);

                _context.SaveChanges();
            }

            Guid userId = User.Identity.GetNameIdGuid();

            if (!_context.PhysicalMedias.Any(m => m.AppUserId == userId && m.MediaId == media.MediaId))
            {
                PhysicalMedia physicalMedia = new PhysicalMedia(media.MediaId, userId, (bool)addMedia.DigitalCopy, addMedia.DiscType);
                _context.PhysicalMedias.Add(physicalMedia);

                foreach (var genreId in addMedia.ExtraGenreIds)
                {
                    var        genre      = dbGenres.SingleOrDefault(g => g.GenreId == genreId);
                    ExtraGenre extraGenre = new ExtraGenre(physicalMedia.PhysicalMediaId, genre);
                    _context.Add(extraGenre);
                }

                _context.SaveChanges();

                return(View("AddMedia", media));
            }

            return(RedirectToAction("Index", "Home"));
        }
Esempio n. 3
0
        public async Task <IActionResult> EditMedia(EditMediaViewModel editMedia)
        {
            PhysicalMedia physicalMedia = await _physicalMediaService.Get(editMedia.PhysicalMediaId);

            var authorizationResult = await _authorizationService.AuthorizeAsync(User, physicalMedia, new SameUserRequirement());

            if (!authorizationResult.Succeeded)
            {
                return(new ForbidResult());
            }

            //PhysicalMedia physicalMedia = _context.PhysicalMedias.SingleOrDefault(p => p.MediaId == editMedia.PhysicalMediaId && p.AppUserId == User.Identity.GetNameIdGuid());
            physicalMedia.DiscTypeId  = editMedia.DiscTypeId;
            physicalMedia.DigitalCopy = editMedia.DigitalCopy;
            await _physicalMediaService.Update(physicalMedia);

            List <Genre>      genres      = _context.Genres.Where(g => g.Extra).ToList();
            List <MediaGenre> mediaGenres = _context.MediaGenres.Where(m => m.MediaId == editMedia.PhysicalMediaId && genres.Select(g => g.GenreId).Contains(m.GenreId)).ToList();

            if (mediaGenres != null)
            {
                _context.RemoveRange(mediaGenres);
            }

            foreach (var extraGenreId in editMedia.ExtraGenreIds)
            {
                var genre = genres.SingleOrDefault(g => g.GenreId == extraGenreId);
                _context.Add(new ExtraGenre(physicalMedia.PhysicalMediaId, genre));
            }

            _context.SaveChanges();

            return(RedirectToAction("Index", new { type = SpinningFilmHelper.MovieType }));
        }
Esempio n. 4
0
        public async Task <EditMediaViewModel> CreateViewModel(PhysicalMedia physicalMedia)
        {
            Media media = await _mediaRepository.GetByIdAsync(physicalMedia.MediaId);

            var discTypes = await _discTypeRepository.ListAllAsync();

            var extraGenres = await _extraGenreRepository.ListAsync(new ExtraGenreSpecification(physicalMedia.PhysicalMediaId));

            var genres = await _genreRepository.ListAsync(new GenreSpecification(true));//_context.Genres.Where(g => !g.Default).ToList();

            EditMediaViewModel editMedia = new EditMediaViewModel(media, physicalMedia, discTypes, genres, extraGenres);

            return(editMedia);
        }
Esempio n. 5
0
        public async Task <IActionResult> EditModal(Guid physicalMediaId)
        {
            PhysicalMedia physicalMedia = await _physicalMediaService.Get(physicalMediaId);

            var authorizationResult = await _authorizationService.AuthorizeAsync(User, physicalMedia, new SameUserRequirement());

            if (!authorizationResult.Succeeded)
            {
                return(new ForbidResult());
            }

            EditMediaViewModel editMedia = await _editMediaViewModelService.CreateViewModel(physicalMedia);

            return(View(editMedia));
        }
Esempio n. 6
0
        public async Task <IActionResult> InfoModal(Guid physicalMediaId)
        {
            PhysicalMedia physicalMedia = await _physicalMediaService.Get(physicalMediaId);

            var authorizationResult = await _authorizationService.AuthorizeAsync(User, physicalMedia, new SameUserRequirement());

            if (!authorizationResult.Succeeded)
            {
                return(new ForbidResult());
            }

            MediaInformationViewModel mediaVM = await _mediaInformationViewModelService.CreateViewModelFromPhysicalMedia(physicalMedia);

            return(View(mediaVM));
        }
Esempio n. 7
0
        public async Task <IActionResult> WatchedAdd(WatchedViewModel watched)
        {
            PhysicalMedia physicalMedia = await _physicalMediaService.Get(watched.PhysicalMediaId);

            var authorizationResult = await _authorizationService.AuthorizeAsync(User, physicalMedia, new SameUserRequirement());

            if (!authorizationResult.Succeeded)
            {
                return(new ForbidResult());
            }

            var result = await _watchedViewModelService.AddWatched(physicalMedia, watched.Date);

            return(Json(result));
        }
Esempio n. 8
0
        public async Task <IActionResult> MediaDelete(Guid physicalMediaId)
        {
            PhysicalMedia physicalMedia = await _physicalMediaService.Get(physicalMediaId);

            var authorizationResult = await _authorizationService.AuthorizeAsync(User, physicalMedia, new SameUserRequirement());

            if (!authorizationResult.Succeeded)
            {
                return(new ForbidResult());
            }

            await _physicalMediaService.Delete(physicalMedia);

            return(RedirectToAction("Index", new { type = SpinningFilmHelper.MovieType }));
        }
Esempio n. 9
0
 public MediaInformationViewModel(Media media,
                                  Movie movie,
                                  PhysicalMedia physicalMedia,
                                  IReadOnlyList <MediaExtraGenre> mediaExtraGenres,
                                  IReadOnlyList <Watched> watched,
                                  IReadOnlyList <Cast> cast,
                                  IReadOnlyList <Crew> crew)
 {
     Media            = media;
     Movie            = movie;
     PhysicalMedia    = physicalMedia;
     MediaExtraGenres = mediaExtraGenres;
     Watched          = watched;
     Cast             = cast;
     Crew             = crew;
 }
Esempio n. 10
0
 public MediaInformationViewModel(Media media,
                                  Movie movie,
                                  PhysicalMedia physicalMedia,
                                  List <Genre> genres,
                                  List <Watched> watched,
                                  List <Cast> cast,
                                  List <Crew> crew)
 {
     Media         = media;
     Movie         = movie;
     PhysicalMedia = physicalMedia;
     Genres        = genres;
     Watched       = watched;
     Cast          = cast;
     Crew          = crew;
 }
Esempio n. 11
0
        public async Task Delete(PhysicalMedia physicalMedia)
        {
            await _physicalMediaRepository.DeleteAsync(physicalMedia);

            var extraGenres = await _extraGenresRepository.ListAsync(new ExtraGenreSpecification(physicalMedia.PhysicalMediaId));

            await _extraGenresRepository.DeleteRangeAsync(extraGenres);

            var watched = await _watchedRepository.ListAsync(new WatchedSpecification(physicalMedia.PhysicalMediaId));

            await _watchedRepository.DeleteRangeAsync(watched);

            var physicalSeason = await _physicalSeasonRepository.ListAsync(new PhysicalSeasonSpecification(physicalMedia.PhysicalMediaId));

            await _physicalSeasonRepository.DeleteRangeAsync(physicalSeason);
        }
Esempio n. 12
0
        public async Task <WatchedViewModel> AddWatched(PhysicalMedia physicalMedia, DateTime dateWatched)
        {
            physicalMedia.Watched = true;
            await _physicalMediaRepository.UpdateAsync(physicalMedia);

            Watched watched = new Watched
            {
                WatchedId       = Guid.NewGuid(),
                PhysicalMediaId = physicalMedia.PhysicalMediaId,
                Date            = dateWatched
            };

            await _watchedRepository.AddAsync(watched);

            var watchedList = await _watchedRepository.ListAsync(new WatchedSpecification(physicalMedia.PhysicalMediaId));

            return(new WatchedViewModel {
                Count = watchedList.Count, LastWatched = watchedList.Max(w => w.Date).ToString("MM/dd/yyyy")
            });
        }
Esempio n. 13
0
        public ImageMaster()
        {
            List <DiscRecorder> recorders = new List <DiscRecorder>();

            _media       = PhysicalMedia.Unknown;
            _nodes       = new List <IMediaNode>();
            _mediaStates = new ReadOnlyCollection <MediaState>(new List <MediaState> {
                MediaState.Unknown
            });

            MsftDiscMaster2 discMaster = null;

            try
            {
                discMaster = new MsftDiscMaster2();

                if (!discMaster.IsSupportedEnvironment)
                {
                    throw new NotSupportedException(
                              "Either the environment does not contain one or more optical devices or the " +
                              "execution context has no permission to access the devices.");
                }

                foreach (string uniqueRecorderId in discMaster)
                {
                    recorders.Add(new DiscRecorder(uniqueRecorderId));
                }
                _recorders = new ReadOnlySelectableCollection <DiscRecorder>(recorders);
            }
            catch (COMException ex)
            {
                throw new NotSupportedException("IMAP2 not found on this system. It will need to be installed (ErrorCode = " + ex.ErrorCode + ").", ex);
            }
            finally
            {
                if (discMaster != null)
                {
                    Marshal.ReleaseComObject(discMaster);
                }
            }
        }
Esempio n. 14
0
        public async Task <MediaInformationViewModel> CreateViewModel(Guid mediaId, Guid appUserId)
        {
            Media media = await _mediaRepository.GetByIdAsync(mediaId);

            Movie movie = await _movieRepository.SingleOrDefaultAsync(new MovieSpecification(mediaId));

            PhysicalMedia physicalMedia = await _physicalMediaRepository.SingleOrDefaultAsync(new PhysicalMediaSpecification(appUserId, mediaId));//_context.PhysicalMedias.SingleOrDefault(p => p.MediaId == mediaId && p.AppUserId == User.Identity.GetNameIdGuid());

            var mediaExtraGenres = await _mediaExtraGenreRepository.ListAsync(new MediaExtraGenreSpecification(mediaId, physicalMedia.PhysicalMediaId));

            //List<MediaGenre> mediaGenres = _context.MediaGenres.Where(g => g.MediaId == mediaId).ToList();
            //List<ExtraGenre> extraGenres = _context.ExtraGenres.Where(g => g.PhysicalMediaId == physicalMedia.PhysicalMediaId).ToList();
            //List<Genre> genres = _context.Genres.Where(g => mediaGenres.Select(m => m.GenreId).Contains(g.GenreId) || extraGenres.Select(m => m.GenreId).Contains(g.GenreId)).ToList();
            var watched = await _watchedRepository.ListAsync(new WatchedSpecification(physicalMedia.PhysicalMediaId));   //_context.Watched.Where(w => w.PhysicalMediaId == physicalMedia.PhysicalMediaId).ToList();

            var cast = await _castRepository.ListAsync(new CastSpecification(mediaId, SpinningFilmHelper.MaxCastOrder)); //_context.Casts.Where(c => c.MediaId == mediaId && c.Order < 3).OrderBy(c => c.Order).ToList();

            var crew = await _crewRepository.ListAsync(new CrewSpecification(mediaId, SpinningFilmHelper.Director));     //_context.Crews.Where(c => c.MediaId == mediaId && c.Job == "Director").ToList();

            return(new MediaInformationViewModel(media, movie, physicalMedia, mediaExtraGenres, watched, cast, crew));
        }
Esempio n. 15
0
        public void LoadMedia()
        {
            long mediaStateFlags;
            var mediaStates = new List<MediaState>();

            if (!_recorderLoaded)
                throw new InvalidOperationException("LoadRecorder must be called first.");
            if (_recorders.SelectedIndex == -1)
                throw new InvalidOperationException("No DiscRecorder selected on the DiscRecorders list.");

            MsftDiscRecorder2 recorder = null;
            MsftFileSystemImage image = null;
            MsftDiscFormat2Data format = null;

            try
            {
                recorder = new MsftDiscRecorder2();
                recorder.InitializeDiscRecorder(_recorders.SelectedItem.InternalUniqueId);
                format = new MsftDiscFormat2Data();
                if (!format.IsCurrentMediaSupported(recorder))
                    throw new MediaNotSupportedException("There is no media in the device.");

                //
                // Get the media type in the recorder
                //
                format.Recorder = recorder;
                _media = (PhysicalMedia)format.CurrentPhysicalMediaType;

                mediaStateFlags = (long)format.CurrentMediaStatus;
                foreach (MediaState state in Enum.GetValues(typeof(MediaState)))
                {
                    if (((long)mediaStateFlags & (long)state) > 0)
                        mediaStates.Add(state);
                }
                if (mediaStates.Count == 0) mediaStates.Add(MediaState.Unknown);
                _mediaStates = new ReadOnlyCollection<MediaState>(mediaStates);

                if ((mediaStateFlags & (long)IMAPI_FORMAT2_DATA_MEDIA_STATE.IMAPI_FORMAT2_DATA_MEDIA_STATE_WRITE_PROTECTED) > 0)
                    throw new MediaNotSupportedException("The media in the device is write protected.");
                //
                // Create a file system and select the media type
                //
                image = new MsftFileSystemImage();
                image.ChooseImageDefaultsForMediaType((IMAPI_MEDIA_PHYSICAL_TYPE)_media);

                //
                // See if there are other recorded sessions on the disc
                //
                if (!format.MediaHeuristicallyBlank)
                {
                    image.MultisessionInterfaces = format.MultisessionInterfaces;
                    image.ImportFileSystem();
                }

                _mediaCapacity = 2048 * image.FreeMediaBlocks;
                _mediaLoaded = true;
            }
            finally
            {
                if (image != null) Marshal.ReleaseComObject(image);
                if (format != null) Marshal.ReleaseComObject(format);
                if (recorder != null) Marshal.ReleaseComObject(recorder);
            }
        }
Esempio n. 16
0
 public async Task Update(PhysicalMedia physicalMedia)
 {
     await _physicalMediaRepository.UpdateAsync(physicalMedia);
 }
Esempio n. 17
0
        public void LoadMedia()
        {
            long mediaStateFlags;
            var  mediaStates = new List <MediaState>();

            if (!_recorderLoaded)
            {
                throw new InvalidOperationException("LoadRecorder must be called first.");
            }
            if (_recorders.SelectedIndex == -1)
            {
                throw new InvalidOperationException("No DiscRecorder selected on the DiscRecorders list.");
            }

            MsftDiscRecorder2   recorder = null;
            MsftFileSystemImage image    = null;
            MsftDiscFormat2Data format   = null;

            try
            {
                recorder = new MsftDiscRecorder2();
                recorder.InitializeDiscRecorder(_recorders.SelectedItem.InternalUniqueId);
                format = new MsftDiscFormat2Data();
                if (!format.IsCurrentMediaSupported(recorder))
                {
                    throw new MediaNotSupportedException("There is no media in the device.");
                }

                //
                // Get the media type in the recorder
                //
                format.Recorder = recorder;
                _media          = (PhysicalMedia)format.CurrentPhysicalMediaType;

                mediaStateFlags = (long)format.CurrentMediaStatus;
                foreach (MediaState state in Enum.GetValues(typeof(MediaState)))
                {
                    if (((long)mediaStateFlags & (long)state) > 0)
                    {
                        mediaStates.Add(state);
                    }
                }
                if (mediaStates.Count == 0)
                {
                    mediaStates.Add(MediaState.Unknown);
                }
                _mediaStates = new ReadOnlyCollection <MediaState>(mediaStates);

                if ((mediaStateFlags & (long)IMAPI_FORMAT2_DATA_MEDIA_STATE.IMAPI_FORMAT2_DATA_MEDIA_STATE_WRITE_PROTECTED) > 0)
                {
                    throw new MediaNotSupportedException("The media in the device is write protected.");
                }
                //
                // Create a file system and select the media type
                //
                image = new MsftFileSystemImage();
                image.ChooseImageDefaultsForMediaType((IMAPI_MEDIA_PHYSICAL_TYPE)_media);

                //
                // See if there are other recorded sessions on the disc
                //
                if (!format.MediaHeuristicallyBlank)
                {
                    image.MultisessionInterfaces = format.MultisessionInterfaces;
                    image.ImportFileSystem();
                }
                _mediaCapacity = 2048 * (long)image.FreeMediaBlocks;
                _mediaLoaded   = true;
            }
            finally
            {
                if (image != null)
                {
                    Marshal.ReleaseComObject(image);
                }
                if (format != null)
                {
                    Marshal.ReleaseComObject(format);
                }
                if (recorder != null)
                {
                    Marshal.ReleaseComObject(recorder);
                }
            }
        }
Esempio n. 18
0
        public async Task <MediaInformationViewModel> CreateViewModelFromPhysicalMedia(PhysicalMedia physicalMedia)
        {
            Media media = await _mediaRepository.GetByIdAsync(physicalMedia.MediaId);

            Movie movie = await _movieRepository.SingleOrDefaultAsync(new MovieSpecification(physicalMedia.MediaId));

            var mediaExtraGenres = await _mediaExtraGenreRepository.ListAsync(new MediaExtraGenreSpecification(physicalMedia.MediaId, physicalMedia.PhysicalMediaId));

            var watched = await _watchedRepository.ListAsync(new WatchedSpecification(physicalMedia.PhysicalMediaId));

            var cast = await _castRepository.ListAsync(new CastSpecification(physicalMedia.MediaId, SpinningFilmHelper.MaxCastOrder));

            var crew = await _crewRepository.ListAsync(new CrewSpecification(physicalMedia.MediaId, SpinningFilmHelper.Director));

            return(new MediaInformationViewModel(media, movie, physicalMedia, mediaExtraGenres, watched, cast, crew));
        }