Esempio n. 1
0
        public MediaSearchViewmodel(IPreview preview, IEngine engine, TMediaType mediaType, VideoLayer layer,
                                    bool closeAfterAdd, VideoFormatDescription videoFormatDescription)
        {
            _engine = engine;
            Layer   = layer;
            if (mediaType == TMediaType.Movie)
            {
                _videoFormatDescription = engine.FormatDescription;
                if (preview != null)
                {
                    PreviewViewmodel = new PreviewViewmodel(engine, preview)
                    {
                        IsSegmentsVisible = true
                    }
                }
                ;
            }
            else
            {
                _videoFormatDescription = videoFormatDescription;
            }
            _mediaType = mediaType;
            if (PreviewViewmodel != null)
            {
                PreviewViewmodel.PropertyChanged += _onPreviewViewModelPropertyChanged;
            }
            IMediaDirectory pri = mediaType == TMediaType.Animation
                ? (IMediaDirectory)engine.MediaManager.AnimationDirectoryPRI
                : engine.MediaManager.MediaDirectoryPRI;
            IMediaDirectory sec = mediaType == TMediaType.Animation
                ? (IMediaDirectory)engine.MediaManager.AnimationDirectorySEC
                : engine.MediaManager.MediaDirectorySEC;

            _searchDirectory = pri != null && pri.DirectoryExists()
                ? pri
                : sec != null && sec.DirectoryExists()
                    ? sec
                    : null;
            if (_searchDirectory != null)
            {
                _searchDirectory.MediaAdded    += _searchDirectory_MediaAdded;
                _searchDirectory.MediaRemoved  += _searchDirectory_MediaRemoved;
                _searchDirectory.MediaVerified += _searchDirectory_MediaVerified;
            }
            _mediaCategory    = MediaCategories.FirstOrDefault();
            NewEventStartType = TStartType.After;
            if (!closeAfterAdd)
            {
                OkButtonText = resources._button_Add;
            }
            _createCommands();
            Items = new ObservableCollection <MediaViewViewmodel>(_searchDirectory.GetFiles()
                                                                  .Where(m => _canAddMediaToCollection(m, mediaType))
                                                                  .Select(m => new MediaViewViewmodel(m)));
            _itemsView = CollectionViewSource.GetDefaultView(Items);
            _itemsView.SortDescriptions.Add(mediaType == TMediaType.Movie
                ? new SortDescription(nameof(MediaViewViewmodel.LastUpdated), ListSortDirection.Descending)
                : new SortDescription(nameof(MediaViewViewmodel.MediaName), ListSortDirection.Ascending));
            _itemsView.Filter += _itemsFilter;
        }
        public MediaSearchViewmodel(IPreview preview, IMediaManager manager, TMediaType mediaType, VideoLayer layer, bool closeAfterAdd, VideoFormatDescription videoFormatDescription)
        {
            _manager = manager;
            _engine  = manager.Engine;
            Layer    = layer;
            if (mediaType == TMediaType.Movie)
            {
                _videoFormatDescription = manager.FormatDescription;
                _frameRate = _videoFormatDescription.FrameRate;
                if (preview != null)
                {
                    _previewViewmodel = new PreviewViewmodel(preview)
                    {
                        IsSegmentsVisible = true
                    }
                }
                ;
                WindowWidth = _previewViewmodel != null ? 950 : 650;
            }
            else
            {
                _videoFormatDescription = videoFormatDescription;
                _frameRate  = videoFormatDescription?.FrameRate;
                WindowWidth = 750;
            }
            _mediaType = mediaType;
            if (_previewViewmodel != null)
            {
                _previewViewmodel.PropertyChanged += _onPreviewViewModelPropertyChanged;
            }
            IMediaDirectory pri = mediaType == TMediaType.Animation ? (IMediaDirectory)_manager.AnimationDirectoryPRI : _manager.MediaDirectoryPRI;
            IMediaDirectory sec = mediaType == TMediaType.Animation ? (IMediaDirectory)_manager.AnimationDirectorySEC : _manager.MediaDirectorySEC;

            _searchDirectory                = pri != null && pri.DirectoryExists() ? pri : sec != null && sec.DirectoryExists() ? sec : null;
            _searchDirectory.MediaAdded    += _searchDirectory_MediaAdded;
            _searchDirectory.MediaRemoved  += _searchDirectory_MediaRemoved;
            _searchDirectory.MediaVerified += _searchDirectory_MediaVerified;

            _closeAfterAdd    = closeAfterAdd;
            _mediaCategory    = MediaCategories.FirstOrDefault();
            NewEventStartType = TStartType.After;
            if (!closeAfterAdd)
            {
                OkButtonText = resources._button_Add;
            }
            _createCommands();
            _items = new ObservableCollection <MediaViewViewmodel>(_searchDirectory.GetFiles()
                                                                   .Where(m => _canAddMediaToCollection(m, mediaType))
                                                                   .Select(m => new MediaViewViewmodel(m)));
            _itemsView = CollectionViewSource.GetDefaultView(_items);
            _itemsView.SortDescriptions.Add(new SortDescription(nameof(MediaViewViewmodel.MediaName), ListSortDirection.Ascending));
            _itemsView.Filter += _itemsFilter;
            _view              = new MediaSearchView()
            {
                DataContext = this
            };
            _view.Closed += _windowClosed;
            _view.Show();
        }