예제 #1
0
        public static string GetFileNameWithoutExtension(string fileName, TMediaType mediaType)
        {
            if (fileName == null)
            {
                return(string.Empty);
            }
            string fileExt = Path.GetExtension(fileName).ToLowerInvariant();

            switch (mediaType)
            {
            case TMediaType.Movie:
            case TMediaType.Unknown:
                return(VideoFileTypes.Contains(fileExt) ? Path.GetFileNameWithoutExtension(fileName) : Path.GetFileName(fileName));

            case TMediaType.Still:
                return(StillFileTypes.Contains(fileExt) ? Path.GetFileNameWithoutExtension(fileName) : Path.GetFileName(fileName));

            case TMediaType.Audio:
                return(AudioFileTypes.Contains(fileExt) ? Path.GetFileNameWithoutExtension(fileName) : Path.GetFileName(fileName));

            case TMediaType.Animation:
                return(AnimationFileTypes.Contains(fileExt) ? Path.GetFileNameWithoutExtension(fileName) : Path.GetFileName(fileName));

            default:
                throw new NotImplementedException($"FileUtils::ExtractFilenameWithoutExtension {mediaType}");
            }
        }
 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)
         {
             _preview = new PreviewViewmodel(preview, false, false)
             {
                 IsSegmentsVisible = true
             }
         }
         ;
     }
     else
     {
         _videoFormatDescription = videoFormatDescription;
     }
     _mediaType = mediaType;
     if (_preview != null)
     {
         _preview.PropertyChanged += _onPreviewViewModelPropertyChanged;
     }
     CommandAdd        = new UiCommand(_add, _allowAdd);
     _mediaCategory    = MediaCategories.FirstOrDefault();
     NewEventStartType = TStartType.After;
     SetupSearchDirectory(closeAfterAdd, mediaType);
 }
예제 #3
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();
        }
 bool _canAddMediaToCollection(IMedia media, TMediaType requiredMediaType)
 {
     return
         (media != null &&
          media.MediaType == requiredMediaType
          &&
          ((requiredMediaType == TMediaType.Still && media.FormatDescription().IsWideScreen == _videoFormatDescription?.IsWideScreen) ||
           (media.MediaType == TMediaType.Movie && media.FrameRate().Equals(_frameRate)) ||
           media.MediaType == TMediaType.Animation));
 }
예제 #6
0
 private void _chooseMedia(TMediaType mediaType, IEvent baseEvent, TStartType startType, VideoFormatDescription videoFormatDescription = null)
 {
     if (_mediaSearchViewModel == null)
     {
         _mediaSearchViewModel                     = new MediaSearchViewmodel(_engineViewModel.Engine, _event.Engine.MediaManager, mediaType, VideoLayer.Program, true, videoFormatDescription);
         _mediaSearchViewModel.BaseEvent           = baseEvent;
         _mediaSearchViewModel.NewEventStartType   = startType;
         _mediaSearchViewModel.MediaChoosen       += _mediaSearchViewModelMediaChoosen;
         _mediaSearchViewModel.SearchWindowClosed += _searchWindowClosed;
     }
 }
        private async void SetupSearchDirectory(bool closeAfterAdd, TMediaType mediaType)
        {
            var pri = _mediaType == TMediaType.Animation
                ? (IWatcherDirectory)Engine.MediaManager.AnimationDirectoryPRI
                : Engine.MediaManager.MediaDirectoryPRI;
            var sec = _mediaType == TMediaType.Animation
                ? (IWatcherDirectory)Engine.MediaManager.AnimationDirectorySEC
                : Engine.MediaManager.MediaDirectorySEC;

            _searchDirectory = pri != null && await Task.Run(() => pri.DirectoryExists)
                ? pri
                : sec != null && await Task.Run(() => sec.DirectoryExists)
                    ? sec
                    : null;

            if (_searchDirectory == null)
            {
                return;
            }

            _searchDirectory.MediaAdded    += _searchDirectory_MediaAdded;
            _searchDirectory.MediaRemoved  += _searchDirectory_MediaRemoved;
            _searchDirectory.MediaVerified += _searchDirectory_MediaVerified;

            if (!closeAfterAdd)
            {
                OkButtonText = resources._button_Add;
            }
            Items = new ObservableCollection <MediaViewViewmodel>(
                _searchDirectory.GetAllFiles()
                .Where(m => _canAddMediaToCollection(m, mediaType))
                .Select(m => new MediaViewViewmodel(m)));
            _itemsView         = CollectionViewSource.GetDefaultView(Items);
            _itemsView.Filter += _itemsFilter;

            IsRecursive = _searchDirectory is IServerDirectory sd && sd.IsRecursive;

            if (mediaType == TMediaType.Movie || mediaType == TMediaType.Audio)
            {
                SortByIngestDate();
            }
            else
            {
                SortByName();
            }
        }
예제 #8
0
        public static string DefaultFileExtension(TMediaType type)
        {
            switch (type)
            {
            case TMediaType.Movie:
            case TMediaType.Unknown:
                return(VideoFileTypes[0]);

            case TMediaType.Still:
                return(StillFileTypes[0]);

            case TMediaType.Audio:
                return(AudioFileTypes[0]);

            case TMediaType.Animation:
                return(AnimationFileTypes[0]);

            default:
                throw new NotImplementedException($"FileUtils::DefaultFileExtension {type}");
            }
        }
예제 #9
0
 public static string DefaultFileExtension(TMediaType type)
 {
     if (type == TMediaType.Movie || type == TMediaType.Unknown)
         return VideoFileTypes[0];
     if (type == TMediaType.Still)
         return StillFileTypes[0];
     throw new NotImplementedException(string.Format("MediaDirectory:DefaultFileExtension {0}", type));
 }
        public MediaSearchViewmodel(EngineViewmodel engineVM, TMediaType mediaType, bool closeAfterAdd, TVideoFormat? videoFormat)
        {
            _manager = engineVM.Engine.MediaManager;
            _previewViewmodel = engineVM.PreviewViewmodel;
            if (_previewViewmodel != null)
                _previewViewmodel.PropertyChanged += OnPreviewPropertyChanged;
            _mediaType = mediaType;
            if (mediaType == TMediaType.AnimationFlash)
                _searchDirectory = _manager.AnimationDirectoryPGM;
            else
                _searchDirectory = _manager.MediaDirectoryPGM;
            _searchDirectory.MediaAdded += new EventHandler<MediaEventArgs>(_searchDirectory_MediaAdded);
            _searchDirectory.MediaRemoved += new EventHandler<MediaEventArgs>(_searchDirectory_MediaRemoved);
            _searchDirectory.MediaVerified += new EventHandler<MediaEventArgs>(_searchDirectory_MediaVerified);

            _videoFormat = videoFormat;
            _closeAfterAdd = closeAfterAdd;
            _mediaCategory = MediaCategories.FirstOrDefault();
            NewEventStartType = TStartType.After;
            if (!closeAfterAdd)
                OkButtonText = Properties.Resources._button_Add;
            _createCommands();
            _items = new ObservableCollection<MediaViewViewmodel>(_searchDirectory.Files
                .Where(m=> m.MediaType == mediaType && (videoFormat == null || m.VideoFormat == videoFormat))
                .Select(m => new MediaViewViewmodel(m)));
            _itemsView = CollectionViewSource.GetDefaultView(_items);
            _itemsView.SortDescriptions.Add(new SortDescription("MediaName", ListSortDirection.Ascending));
            _itemsView.Filter += _itemsFilter;

            _window = new MediaSearchView();
            _window.Owner = App.Current.MainWindow;
            _window.DataContext = this;
            _window.Closed += _windowClosed;
            _window.Show();
            //_window.Topmost = true;
        }