Exemple #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CreateMediaItem"/> class.
        /// </summary>
        /// <param name="dataParsingService">The data parsing service.</param>
        /// <param name="mapper">The mapper.</param>
        public CreateMediaItem(IYoutubeUrlParseService dataParsingService, IMediaItemMapper mapper) : base()
        {
            _dataParsingService = dataParsingService;
            _mapper             = mapper;

            InitializeCommands();
        }
Exemple #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PlaylistMapper"/> class.
        /// </summary>
        /// <param name="dialogViewModel">The dialog view model.</param>
        public PlaylistMapper(ViewModelServiceContainer container, IMediaItemMapper mediaItemMapper, IDialogViewModel dialogViewModel, IValidator <Playlist> validator)
            : base(container, validator)
        {
            _dialogViewModel = dialogViewModel ?? throw new ArgumentNullException(nameof(dialogViewModel), $"{nameof(dialogViewModel)} {Resources.IsRequired}");
            _mediaItemMapper = mediaItemMapper ?? throw new ArgumentNullException(nameof(mediaItemMapper), $"{nameof(mediaItemMapper)} {Resources.IsRequired}");

            InitializeMapper();
        }
        public CreateMediaItem(IYoutubeUrlParser dataParsingService, IMediaItemMapper mapper, IMessenger messenger)
            : base(messenger)
        {
            _dataParsingService = dataParsingService ?? throw new ArgumentNullException(nameof(dataParsingService), $"{nameof(mapper)} {Resources.IsRequired}");
            _mapper             = mapper ?? throw new ArgumentNullException(nameof(mapper), $"{nameof(mapper)} {Resources.IsRequired}");

            InitializeCommands();
        }
Exemple #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PlaylistMapper"/> class.
        /// </summary>
        /// <param name="dialogViewModel">The dialog view model.</param>
        public PlaylistMapper(IMediaItemMapper mediaItemMapper, DialogViewModel dialogViewModel, ILocalizationService translator, ISequenceProvider sequenceProvider, IMapleLog log, IValidator <Playlist> validator)
            : base(translator, sequenceProvider, log, validator)
        {
            _dialogViewModel = dialogViewModel ?? throw new ArgumentNullException(nameof(dialogViewModel));
            _mediaItemMapper = mediaItemMapper ?? throw new ArgumentNullException(nameof(mediaItemMapper));

            InitializeMapper();
        }
Exemple #5
0
 public static IEnumerable <MediaItem> GetMany(this IMediaItemMapper mapper, IEnumerable <Data.MediaItem> items, int playlistId)
 {
     return(items.ForEach(p =>
     {
         var item = mapper.Get(p);
         item.PlaylistId = playlistId;
         return item;
     }));
 }
Exemple #6
0
        public MediaRepository(IPlaylistMapper playlistMapper, IMediaItemMapper mediaItemMapper, IMediaPlayerMapper mediaPlayerMapper, IPlaylistContext context)
        {
            _context = context ?? throw new ArgumentNullException(nameof(context));

            _mediaItemMapper   = mediaItemMapper ?? throw new ArgumentNullException(nameof(mediaItemMapper));
            _playlistMapper    = playlistMapper ?? throw new ArgumentNullException(nameof(playlistMapper));
            _mediaPlayerMapper = mediaPlayerMapper ?? throw new ArgumentNullException(nameof(mediaPlayerMapper));

            _busyStack            = new BusyStack();
            _busyStack.OnChanged += (hasItems) => { IsBusy = hasItems; };
        }
Exemple #7
0
        public Playlist(ViewModelServiceContainer container, IValidator <Playlist> validator, IDialogViewModel dialogViewModel, IMediaItemMapper mediaItemMapper, PlaylistModel model)
            : base(model, validator, container?.Messenger)
        {
            if (container == null)
            {
                throw new ArgumentNullException(nameof(container), $"{nameof(container)} {Resources.IsRequired}");
            }

            SkipChangeTracking = true;
            using (BusyStack.GetToken())
            {
                _itemsLock = new object();

                _mediaItemMapper  = mediaItemMapper ?? throw new ArgumentNullException(nameof(mediaItemMapper), $"{nameof(mediaItemMapper)} {Resources.IsRequired}");
                _dialogViewModel  = dialogViewModel ?? throw new ArgumentNullException(nameof(dialogViewModel), $"{nameof(dialogViewModel)} {Resources.IsRequired}");
                _sequenceProvider = container.SequenceService;

                _translator   = container.LocalizationService;
                _title        = model.Title;
                _description  = model.Description;
                _repeatMode   = (RepeatMode)model.RepeatMode;
                _isShuffeling = model.IsShuffeling;
                _sequence     = model.Sequence;

                RepeatModes = new RangeObservableCollection <RepeatMode>(Enum.GetValues(typeof(RepeatMode)).Cast <RepeatMode>().ToList());
                _history    = new Stack <int>();

                Items = new RangeObservableCollection <MediaItem>();
                _items.CollectionChanged += (o, e) => OnPropertyChanged(nameof(Count));

                BindingOperations.EnableCollectionSynchronization(Items, _itemsLock);
                View = CollectionViewSource.GetDefaultView(Items); // TODO add sorting by sequence
                OnPropertyChanged(nameof(Count));

                LoadFromFileCommand   = AsyncCommand.Create(LoadFromFile, () => CanLoadFromFile());
                LoadFromFolderCommand = AsyncCommand.Create(LoadFromFolder, () => CanLoadFromFolder());
                LoadFromUrlCommand    = AsyncCommand.Create(LoadFromUrl, () => CanLoadFromUrl());

                RemoveCommand      = new RelayCommand <object>(Remove, CanRemove);
                RemoveRangeCommand = new RelayCommand <IList>(RemoveRange, CanRemoveRange);
                ClearCommand       = new RelayCommand(() => Clear(), CanClear);

                AddRange(_mediaItemMapper.GetMany(model.MediaItems));

                MessageTokens.Add(Messenger.Subscribe <PlayingMediaItemMessage>(OnPlaybackItemChanged, m => m.PlaylistId == Id && _items.Contains(m.Content)));

                Validate();
            }
            SkipChangeTracking = false;
        }
Exemple #8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Playlist" /> class.
        /// </summary>
        /// <param name="translator">The translator.</param>
        /// <param name="mediaItemMapper">The media item mapper.</param>
        /// <param name="dialogViewModel">The dialog view model.</param>
        /// <param name="model">The model.</param>
        /// <exception cref="System.ArgumentNullException">dialogViewModel</exception>
        /// <exception cref="System.ArgumentException"></exception>
        public Playlist(ILocalizationService translator, IMediaItemMapper mediaItemMapper, ISequenceProvider sequenceProvider, IValidator <Playlist> validator, DialogViewModel dialogViewModel, Data.Playlist model)
            : base(model, validator)
        {
            using (_busyStack.GetToken())
            {
                _itemsLock        = new object();
                _sequenceProvider = sequenceProvider ?? throw new ArgumentNullException(nameof(sequenceProvider));
                _dialogViewModel  = dialogViewModel ?? throw new ArgumentNullException(nameof(dialogViewModel));
                _translator       = translator ?? throw new ArgumentNullException(nameof(translator));
                _mediaItemMapper  = mediaItemMapper ?? throw new ArgumentNullException(nameof(mediaItemMapper));

                Items       = new RangeObservableCollection <MediaItem>();
                RepeatModes = new ObservableCollection <RepeatMode>(Enum.GetValues(typeof(RepeatMode)).Cast <RepeatMode>().ToList());
                History     = new Stack <int>();

                BindingOperations.EnableCollectionSynchronization(Items, _itemsLock);

                _title        = model.Title;
                _description  = model.Description;
                _id           = model.Id;
                _repeatMode   = (RepeatMode)model.RepeatMode;
                _isShuffeling = model.IsShuffeling;
                _sequence     = model.Sequence;
                _createdBy    = model.CreatedBy;
                _createdOn    = model.CreatedOn;
                _updatedBy    = model.UpdatedBy;
                _updatedOn    = model.UpdatedOn;

                if (model.MediaItems == null)
                {
                    throw new ArgumentException($"{model.MediaItems} cannot be null");
                }

                Items.AddRange(_mediaItemMapper.GetMany(model.MediaItems));

                Items.CollectionChanged += (o, e) =>
                {
                    OnPropertyChanged(nameof(Count));
                };

                View = CollectionViewSource.GetDefaultView(Items);
                OnPropertyChanged(nameof(Count));

                InitializeCommands();
                IntializeValidation();

                Validate();
            }
        }
Exemple #9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DialogViewModel"/> class.
        /// </summary>
        /// <param name="service">The service.</param>
        /// <param name="mediaItemMapper">The media item mapper.</param>
        public DialogViewModel(ILocalizationService translator, IYoutubeUrlParseService service, IMediaItemMapper mediaItemMapper, FileSystemViewModel fileSystemViewModel)
        {
            _translator          = translator ?? throw new ArgumentNullException(nameof(translator));
            _service             = service ?? throw new ArgumentNullException(nameof(service));
            _mediaItemMapper     = mediaItemMapper ?? throw new ArgumentNullException(nameof(mediaItemMapper));
            _fileSystemViewModel = fileSystemViewModel ?? throw new ArgumentNullException(nameof(fileSystemViewModel));

            CloseDialogCommand  = new RelayCommand(Close, () => CanClose());
            CancelDialogCommand = new RelayCommand(Cancel, () => CanCancel());
            AcceptDialogCommand = new RelayCommand(Accept, () => CanAccept());

            ExceptionDialogViewModel = new ExceptionDialogViewModel();
            MessageDialogViewModel   = new MessageDialogViewModel();
            ProgressDialogViewModel  = new ProgressDialogViewModel();
        }
Exemple #10
0
        public MediaRepository(IPlaylistMapper playlistMapper,
                               IMediaItemMapper mediaItemMapper,
                               IMediaPlayerMapper mediaPlayerMapper,
                               IMediaItemRepository mediaItemRepository,
                               IMediaPlayerRepository mediaPlayerRepository,
                               IPlaylistRepository playlistRepository)
        {
            _mediaItemMapper   = mediaItemMapper ?? throw new ArgumentNullException(nameof(mediaItemMapper), $"{nameof(mediaItemMapper)} {Resources.IsRequired}");
            _playlistMapper    = playlistMapper ?? throw new ArgumentNullException(nameof(playlistMapper), $"{nameof(playlistMapper)} {Resources.IsRequired}");
            _mediaPlayerMapper = mediaPlayerMapper ?? throw new ArgumentNullException(nameof(mediaPlayerMapper), $"{nameof(mediaPlayerMapper)} {Resources.IsRequired}");

            _mediaItemRepository   = mediaItemRepository ?? throw new ArgumentNullException(nameof(mediaItemRepository), $"{nameof(mediaItemRepository)} {Resources.IsRequired}");
            _mediaPlayerRepository = mediaPlayerRepository ?? throw new ArgumentNullException(nameof(mediaPlayerRepository), $"{nameof(mediaPlayerRepository)} {Resources.IsRequired}");
            _playlistRepository    = playlistRepository ?? throw new ArgumentNullException(nameof(playlistRepository), $"{nameof(playlistRepository)} {Resources.IsRequired}");

            _busyStack            = new BusyStack();
            _busyStack.OnChanged += (hasItems) => { IsBusy = hasItems; };
        }
Exemple #11
0
        public DialogViewModel(ILocalizationService translator, IYoutubeUrlParser service, IMediaItemMapper mediaItemMapper, IMessenger messenger, FileSystemViewModel fileSystemViewModel, Func <CreateMediaItem> createMediaItemFactory)
        {
            _translator             = translator ?? throw new ArgumentNullException(nameof(translator), $"{nameof(translator)} {Resources.IsRequired}");
            _service                = service ?? throw new ArgumentNullException(nameof(service), $"{nameof(service)} {Resources.IsRequired}");
            _mediaItemMapper        = mediaItemMapper ?? throw new ArgumentNullException(nameof(mediaItemMapper), $"{nameof(mediaItemMapper)} {Resources.IsRequired}");
            _fileSystemViewModel    = fileSystemViewModel ?? throw new ArgumentNullException(nameof(fileSystemViewModel), $"{nameof(fileSystemViewModel)} {Resources.IsRequired}");
            _messenger              = messenger ?? throw new ArgumentNullException(nameof(messenger), $"{nameof(messenger)} {Resources.IsRequired}");
            _createMediaItemFactory = createMediaItemFactory ?? throw new ArgumentNullException(nameof(createMediaItemFactory), $"{nameof(createMediaItemFactory)} {Resources.IsRequired}");


            CloseDialogCommand  = new RelayCommand(Close, () => CanClose());
            CancelDialogCommand = new RelayCommand(Cancel, () => CanCancel());
            AcceptDialogCommand = new RelayCommand(Accept, () => CanAccept());

            ExceptionDialogViewModel = new ExceptionDialogViewModel();
            MessageDialogViewModel   = new MessageDialogViewModel();
            ProgressDialogViewModel  = new ProgressDialogViewModel();
        }
Exemple #12
0
 public MediaItems(ViewModelServiceContainer container, IMediaItemMapper mediaItemMapper, Func <IMediaRepository> repositoryFactory)
     : base(container)
 {
     _repositoryFactory = repositoryFactory ?? throw new ArgumentNullException(nameof(repositoryFactory), $"{nameof(repositoryFactory)} {Resources.IsRequired}");
     _mediaItemMapper   = mediaItemMapper ?? throw new ArgumentNullException(nameof(mediaItemMapper), $"{nameof(mediaItemMapper)} {Resources.IsRequired}");
 }
Exemple #13
0
 public static IList <MediaItem> GetManyAsList(this IMediaItemMapper mapper, IEnumerable <Data.MediaItem> items)
 {
     return(items.ForEach(mapper.Get).ToList());
 }
Exemple #14
0
 public static IEnumerable <MediaItem> GetMany(this IMediaItemMapper mapper, IEnumerable <Data.MediaItem> items)
 {
     return(items.ForEach(mapper.Get));
 }
Exemple #15
0
 public MediaItems(IMapleLog log, ILocalizationService translationService, ISequenceProvider sequenceProvider, IMediaItemMapper mediaItemMapper, Func <IMediaRepository> repo)
     : base(log, translationService, sequenceProvider)
 {
     _repositoryFactory = repo ?? throw new ArgumentNullException(nameof(repo));
     _mediaItemMapper   = mediaItemMapper ?? throw new ArgumentNullException(nameof(mediaItemMapper));
 }