Beispiel #1
0
        public ConvertOperationViewModel(IConvertOperation operation, IPreview preview, IMediaManager mediaManager)
            : base(operation)
        {
            _convertOperation     = operation;
            _mediaManager         = mediaManager;
            _destMediaName        = operation.DestMediaProperties.MediaName;
            _destFileName         = operation.DestMediaProperties.FileName;
            _destCategory         = operation.DestMediaProperties.MediaCategory;
            _destMediaEmphasis    = operation.DestMediaProperties is IPersistentMediaProperties ? ((IPersistentMediaProperties)operation.DestMediaProperties).MediaEmphasis : TMediaEmphasis.None;
            _destParental         = operation.DestMediaProperties.Parental;
            _destMediaVideoFormat = operation.DestMediaProperties.VideoFormat;

            _audioChannelMappingConversion = operation.AudioChannelMappingConversion;
            _aspectConversion = operation.AspectConversion;
            _audioVolume      = operation.AudioVolume;
            _sourceFieldOrderEnforceConversion = operation.SourceFieldOrderEnforceConversion;
            _duration      = operation.Duration;
            _startTC       = operation.StartTC;
            _trim          = operation.Trim;
            _loudnessCheck = operation.LoudnessCheck;
            operation.SourceMedia.PropertyChanged += OnSourceMediaPropertyChanged;
            Array.Copy(_aspectConversions, _aspectConversionsEnforce, 3);
            if (preview != null)
            {
                _previewVm = new PreviewViewmodel(preview)
                {
                    Media = operation.SourceMedia
                };
                _previewVm.PropertyChanged += _previewVm_PropertyChanged;
            }
        }
Beispiel #2
0
        public IngestOperationViewModel(IIngestOperation operation, IPreview preview, IEngine engine)
            : base(operation)
        {
            _ingestOperation = operation;
            _engine          = engine;
            string destFileName = $"{Path.GetFileNameWithoutExtension(operation.Source.FileName)}.{operation.MovieContainerFormat}";

            _destMediaProperties = new PersistentMediaProxy
            {
                FileName      = operation.DestDirectory.GetUniqueFileName(destFileName),
                MediaName     = FileUtils.GetFileNameWithoutExtension(destFileName, operation.Source.MediaType),
                MediaType     = operation.Source.MediaType == TMediaType.Unknown ? TMediaType.Movie : operation.Source.MediaType,
                Duration      = operation.Source.Duration,
                TcStart       = operation.StartTC,
                MediaGuid     = operation.Source.MediaGuid,
                MediaCategory = operation.Source.MediaCategory
            };

            _audioChannelMappingConversion = operation.AudioChannelMappingConversion;
            _aspectConversion = operation.AspectConversion;
            _audioVolume      = operation.AudioVolume;
            _sourceFieldOrderEnforceConversion = operation.SourceFieldOrderEnforceConversion;
            _loudnessCheck = operation.LoudnessCheck;
            operation.Source.PropertyChanged += OnSourceMediaPropertyChanged;
            AspectConversionsEnforce          = new TAspectConversion[3];
            Array.Copy(AspectConversions, AspectConversionsEnforce, 3);
            if (preview != null)
            {
                PreviewViewmodel = new PreviewViewmodel(engine, preview)
                {
                    SelectedIngestOperation = operation
                }
            }
            ;
        }
 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);
 }
Beispiel #4
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;
        }
Beispiel #5
0
 public IngestOperationViewModel(IIngestOperation operation, IEngine engine)
     : base(operation, engine.MediaManager)
 {
     _operation                         = operation;
     _engine                            = engine;
     _destMediaVideoFormat              = operation.Source.VideoFormat;
     DestMediaName                      = FileUtils.GetFileNameWithoutExtension(operation.Source.MediaName, operation.Source.MediaType);
     _duration                          = operation.Source.Duration;
     _startTc                           = operation.Source.TcStart;
     _destCategory                      = ((IIngestDirectory)operation.Source.Directory).MediaCategory;
     IsMovie                            = operation.Source.MediaType == TMediaType.Unknown || operation.Source.MediaType == TMediaType.Movie;
     IsStill                            = operation.Source.MediaType == TMediaType.Still;
     _audioChannelMappingConversion     = operation.AudioChannelMappingConversion;
     _aspectConversion                  = operation.AspectConversion;
     _audioVolume                       = operation.AudioVolume;
     _sourceFieldOrderEnforceConversion = operation.SourceFieldOrderEnforceConversion;
     _loudnessCheck                     = operation.LoudnessCheck;
     operation.Source.PropertyChanged  += OnSourceMediaPropertyChanged;
     AspectConversionsEnforce           = new TAspectConversion[3];
     Array.Copy(AspectConversions, AspectConversionsEnforce, 3);
     if (engine.Preview != null)
     {
         _preview = new PreviewViewmodel(engine.Preview, true, false)
         {
             SelectedIngestOperation = operation
         }
     }
     ;
     CommandRemove = new UiCommand(o => Removed?.Invoke(this, EventArgs.Empty));
 }
        private void AppMainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            foreach (Engine engine in App.EngineController.Engines)
            {
                TabItem newtab = new TabItem();
                newtab.Header = engine.EngineName;
                PreviewViewmodel newPreviewViewmodel = new PreviewViewmodel(engine);
                Debug.WriteLine(engine, "Creating viewmodel for");
                var evm = new EngineViewmodel(engine);
                Debug.WriteLine(engine, "Creating commands for");
                evm.PreviewViewmodel = newPreviewViewmodel;
                newtab.Content = evm.View;
                tcChannels.Items.Add(newtab);

                Debug.WriteLine(engine.MediaManager, "Creating tab for");
                TabItem tabIngest = new TabItem();
                tabIngest.Header = engine.EngineName + " - Media";
                MediaManagerView newMediaManagerView = new MediaManagerView();
                MediaManagerViewmodel newMediaManagerViewmodel = new MediaManagerViewmodel(engine.MediaManager, newPreviewViewmodel);
                newMediaManagerView.DataContext = newMediaManagerViewmodel;
                tabIngest.Content = newMediaManagerView;
                tcChannels.Items.Add(tabIngest);

                //Debug.WriteLine(engine.Templates, "Creating tab for");
                //TabItem tabTemplates = new TabItem();
                //tabTemplates.Header = engine.EngineName + " - Animacje";
                //TemplatesView newTemplatesView = new TemplatesView();
                //TemplatesViewmodel newTemplatesViewmodel = new TemplatesViewmodel(engine);
                //newTemplatesView.DataContext = newTemplatesViewmodel;
                //tabTemplates.Content = newTemplatesView;
                //tcChannels.Items.Add(tabTemplates);
            }
            tcChannels.SelectedIndex = 0;
        }
        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();
        }
Beispiel #8
0
 public EventEditViewmodel(EngineViewmodel engineViewModel, PreviewViewmodel previewViewModel)
 {
     _engineViewModel  = engineViewModel;
     _previewViewModel = previewViewModel;
     if (previewViewModel != null)
     {
         previewViewModel.PropertyChanged += PreviewViewModel_PropertyChanged;
     }
     _engine = engineViewModel.Engine;
     _fields.CollectionChanged += _fields_or_commands_CollectionChanged;
     CommandSaveEdit            = new UICommand()
     {
         ExecuteDelegate = _save, CanExecuteDelegate = _canSave
     };
     CommandUndoEdit = new UICommand()
     {
         ExecuteDelegate = _load, CanExecuteDelegate = o => IsModified
     };
     CommandChangeMovie = new UICommand()
     {
         ExecuteDelegate = _changeMovie, CanExecuteDelegate = _canChangeMovie
     };
     CommandEditMovie = new UICommand()
     {
         ExecuteDelegate = _editMovie, CanExecuteDelegate = _canEditMovie
     };
     CommandCheckVolume = new UICommand()
     {
         ExecuteDelegate = _checkVolume, CanExecuteDelegate = _canCheckVolume
     };
     CommandEditField = new UICommand {
         ExecuteDelegate = _editField
     };
     CommandTriggerStartType = new UICommand {
         ExecuteDelegate = _triggerStartType, CanExecuteDelegate = _canTriggerStartType
     };
     CommandMoveUp = new UICommand()
     {
         ExecuteDelegate = o => _event?.MoveUp(), CanExecuteDelegate = _canMoveUp
     };
     CommandMoveDown = new UICommand()
     {
         ExecuteDelegate = o => _event?.MoveDown(), CanExecuteDelegate = _canMoveDown
     };
     CommandDelete = new UICommand
     {
         ExecuteDelegate = o =>
         {
             if (_event != null && MessageBox.Show(resources._query_DeleteItem, resources._caption_Confirmation, MessageBoxButton.OKCancel) == MessageBoxResult.OK)
             {
                 EventClipboard.SaveUndo(new IEvent[] { _event }, _event.StartType == TStartType.After ? _event.Prior : _event.Parent);
                 _event.Delete();
             }
         },
         CanExecuteDelegate = o => _event?.AllowDelete() == true
     };
 }
 public MediaManagerViewmodel(MediaManager MediaManager, PreviewViewmodel PreviewVm)
 {
     _mediaManager = MediaManager;
     _previewViewModel = PreviewVm;
     _createCommands();
     _mediaCategory = _mediaCategories.FirstOrDefault();
     MediaDirectory = MediaManager.MediaDirectoryPGM;
     EditMedia = new MediaEditViewmodel(PreviewVm);
 }
 public MediaEditViewmodel(IMedia media, IMediaManager mediaManager, PreviewViewmodel previewVm, bool showButtons) : base(media, new MediaEditView())
 {
     CommandSaveEdit = new UICommand()
     {
         ExecuteDelegate = ModelUpdate, CanExecuteDelegate = o => CanSave()
     };
     CommandCancelEdit = new UICommand()
     {
         ExecuteDelegate = ModelLoad, CanExecuteDelegate = o => IsModified
     };
     CommandRefreshStatus = new UICommand()
     {
         ExecuteDelegate = _refreshStatus
     };
     CommandCheckVolume = new UICommand()
     {
         ExecuteDelegate = _checkVolume, CanExecuteDelegate = (o) => !_isVolumeChecking
     };
     _previewVm    = previewVm;
     _mediaManager = mediaManager;
     _showButtons  = showButtons;
     if (previewVm != null)
     {
         previewVm.PropertyChanged += _onPreviewPropertyChanged;
     }
     Model.PropertyChanged += OnMediaPropertyChanged;
     if (Model is IAnimatedMedia)
     {
         _fields.CollectionChanged += _fields_CollectionChanged;
         CommandAddField            = new UICommand {
             ExecuteDelegate = _addField, CanExecuteDelegate = _canAddField
         };
         CommandDeleteField = new UICommand {
             ExecuteDelegate = _deleteField, CanExecuteDelegate = _canDeleteField
         };
         CommandEditField = new UICommand {
             ExecuteDelegate = _editField, CanExecuteDelegate = _canDeleteField
         };
     }
 }
Beispiel #11
0
        public MediaManagerViewmodel(IEngine engine, IPreview preview)
        {
            _mediaManager = engine.MediaManager;
            Engine        = engine;
            _preview      = preview;
            if (preview != null)
            {
                PreviewViewmodel = new PreviewViewmodel(engine, preview);
            }

            MediaDirectories = new List <MediaDirectoryViewmodel>();
            MediaDirectories.AddRange(_mediaManager.IngestDirectories.Where(d => d.ContainsImport()).Select(d => new MediaDirectoryViewmodel(d, d.DirectoryName, true)));
            var archiveDirectory = _mediaManager.ArchiveDirectory;

            if (archiveDirectory != null)
            {
                MediaDirectories.Insert(0, new MediaDirectoryViewmodel(archiveDirectory, resources._archive));
            }
            var animationDirectorySec = _mediaManager.AnimationDirectorySEC;
            var animationDirectoryPri = _mediaManager.AnimationDirectoryPRI;

            if (animationDirectorySec != null && animationDirectorySec != animationDirectoryPri)
            {
                MediaDirectories.Insert(0, new MediaDirectoryViewmodel(animationDirectorySec, resources._animations_Secondary));
            }
            if (animationDirectoryPri != null)
            {
                MediaDirectories.Insert(0, new MediaDirectoryViewmodel(animationDirectoryPri, resources._animations_Primary));
            }
            var serverDirectoryPri = _mediaManager.MediaDirectoryPRI;
            var serverDirectorySec = _mediaManager.MediaDirectorySEC;

            if (serverDirectorySec != null && serverDirectorySec != serverDirectoryPri)
            {
                MediaDirectories.Insert(0, new MediaDirectoryViewmodel(serverDirectorySec, resources._secondary));
            }
            if (serverDirectoryPri != null)
            {
                MediaDirectories.Insert(0, new MediaDirectoryViewmodel(serverDirectoryPri, resources._primary));
            }

            _mediaCategory    = MediaCategories.FirstOrDefault();
            SelectedDirectory = MediaDirectories.FirstOrDefault();
            if (_mediaManager.FileManager != null)
            {
                FileManagerViewmodel = new FileManagerViewmodel(_mediaManager.FileManager);
            }
            RecordersViewmodel = new RecordersViewmodel(Engine, _mediaManager.Recorders);
            RecordersViewmodel.PropertyChanged += _recordersViewmodel_PropertyChanged;
            VideoPreview = UiPluginManager.ComposePart <IVideoPreview>(this);
            VideoPreview?.SetSource(RecordersViewmodel.Channel?.PreviewUrl);

            CommandSearch                 = new UiCommand(_search, _canSearch);
            CommandClearFilters           = new UiCommand(_clearFilters, _canClearFilters);
            CommandDeleteSelected         = new UiCommand(_deleteSelected, o => _isSomethingSelected() && engine.HaveRight(EngineRight.MediaDelete));
            CommandIngestSelectedToServer = new UiCommand(_ingestSelectedToServer, _canIngestSelectedToServer);
            CommandMoveSelectedToArchive  = new UiCommand(_moveSelectedToArchive, o => _selectedDirectory != null && _selectedDirectory.IsServerDirectory && _isSomethingSelected() && engine.HaveRight(EngineRight.MediaArchive) && engine.HaveRight(EngineRight.MediaDelete));
            CommandCopySelectedToArchive  = new UiCommand(_copySelectedToArchive, o => _selectedDirectory != null && _selectedDirectory.IsServerDirectory && _isSomethingSelected() && engine.HaveRight(EngineRight.MediaArchive));
            CommandSweepStaleMedia        = new UiCommand(_sweepStaleMedia, o => CurrentUser.IsAdmin);
            CommandGetLoudness            = new UiCommand(_getLoudness, o => _isSomethingSelected() && engine.HaveRight(EngineRight.MediaEdit));
            CommandExport                 = new UiCommand(_export, _canExport);
            CommandRefresh                = new UiCommand(async ob => await _reloadFiles(), _canRefresh);
            CommandSyncPriToSec           = new UiCommand(_syncSecToPri, o => _selectedDirectory.IsServerDirectory && CurrentUser.IsAdmin);
            CommandCloneAnimation         = new UiCommand(_cloneAnimation, _canCloneAnimation);
            CommandTogglePropertiesPanel  = new UiCommand(o => IsPropertiesPanelVisible = !IsPropertiesPanelVisible);
            CommandVerifyAllMedia         = new UiCommand(_verifyAllMedia, o => _selectedDirectory.IsServerDirectory && CurrentUser.IsAdmin);
        }
Beispiel #12
0
        public MediaManagerViewmodel(IEngine engine, IPreview preview)
        {
            _mediaManager = engine.MediaManager;
            _engine       = engine;
            _preview      = preview;
            if (preview != null)
            {
                PreviewViewmodel = new PreviewViewmodel(engine, preview);
            }

            MediaDirectories = new List <MediaDirectoryViewmodel>();
            MediaDirectories.AddRange(_mediaManager.IngestDirectories.Where(d => d.ContainsImport()).Select(d => new MediaDirectoryViewmodel(d, true)));
            IArchiveDirectory archiveDirectory = _mediaManager.ArchiveDirectory;

            if (archiveDirectory != null)
            {
                MediaDirectories.Insert(0, new MediaDirectoryViewmodel(archiveDirectory));
            }
            IAnimationDirectory animationDirectoryPri = _mediaManager.AnimationDirectoryPRI;

            if (animationDirectoryPri != null)
            {
                MediaDirectories.Insert(0, new MediaDirectoryViewmodel(animationDirectoryPri));
            }
            IAnimationDirectory animationDirectorySec = _mediaManager.AnimationDirectorySEC;

            if (animationDirectorySec != null)
            {
                MediaDirectories.Insert(0, new MediaDirectoryViewmodel(animationDirectorySec));
            }
            IServerDirectory serverDirectoryPri = _mediaManager.MediaDirectoryPRI;

            if (serverDirectoryPri != null)
            {
                MediaDirectories.Insert(0, new MediaDirectoryViewmodel(serverDirectoryPri));
            }
            IServerDirectory serverDirectorySec = _mediaManager.MediaDirectorySEC;

            if (serverDirectorySec != null && serverDirectorySec != serverDirectoryPri)
            {
                MediaDirectories.Insert(1, new MediaDirectoryViewmodel(serverDirectorySec));
            }

            _mediaCategory    = MediaCategories.FirstOrDefault();
            SelectedDirectory = MediaDirectories.FirstOrDefault();
            if (_mediaManager.FileManager != null)
            {
                FileManagerViewmodel = new FileManagerViewmodel(_mediaManager.FileManager);
            }
            RecordersViewmodel = new RecordersViewmodel(_engine, _mediaManager.Recorders);
            RecordersViewmodel.PropertyChanged += _recordersViewmodel_PropertyChanged;
            ComposePlugins();
            VideoPreview?.SetSource(RecordersViewmodel.Channel?.PreviewUrl);

            CommandSearch = new UICommand {
                ExecuteDelegate = _search, CanExecuteDelegate = _canSearch
            };
            CommandClearFilters = new UICommand {
                ExecuteDelegate = _clearFilters, CanExecuteDelegate = _canClearFilters
            };
            CommandDeleteSelected = new UICommand {
                ExecuteDelegate = _deleteSelected, CanExecuteDelegate = o => _isSomethingSelected() && engine.HaveRight(EngineRight.MediaDelete)
            };
            CommandIngestSelectedToServer = new UICommand {
                ExecuteDelegate = _ingestSelectedToServer, CanExecuteDelegate = _canIngestSelectedToServer
            };
            CommandMoveSelectedToArchive = new UICommand {
                ExecuteDelegate = _moveSelectedToArchive, CanExecuteDelegate = o => _selectedDirectory != null && _selectedDirectory.IsServerDirectory && _isSomethingSelected() && engine.HaveRight(EngineRight.MediaArchive) && engine.HaveRight(EngineRight.MediaDelete)
            };
            CommandCopySelectedToArchive = new UICommand {
                ExecuteDelegate = _copySelectedToArchive, CanExecuteDelegate = o => _selectedDirectory != null && _selectedDirectory.IsServerDirectory && _isSomethingSelected() && engine.HaveRight(EngineRight.MediaArchive)
            };
            CommandSweepStaleMedia = new UICommand {
                ExecuteDelegate = _sweepStaleMedia, CanExecuteDelegate = o => CurrentUser.IsAdmin
            };
            CommandGetLoudness = new UICommand {
                ExecuteDelegate = _getLoudness, CanExecuteDelegate = o => _isSomethingSelected() && engine.HaveRight(EngineRight.MediaEdit)
            };
            CommandExport = new UICommand {
                ExecuteDelegate = _export, CanExecuteDelegate = _canExport
            };
            CommandRefresh = new UICommand {
                ExecuteDelegate = ob => _refreshMediaDirectory(_selectedDirectory?.Directory), CanExecuteDelegate = _canRefresh
            };
            CommandSyncPriToSec = new UICommand {
                ExecuteDelegate = _syncSecToPri, CanExecuteDelegate = o => _selectedDirectory.IsServerDirectory && CurrentUser.IsAdmin
            };
            CommandCloneAnimation = new UICommand {
                ExecuteDelegate = _cloneAnimation, CanExecuteDelegate = _canCloneAnimation
            };
            CommandTogglePropertiesPanel = new UICommand {
                ExecuteDelegate = o => IsPropertiesPanelVisible = !IsPropertiesPanelVisible
            };
        }
        public MediaManagerViewmodel(IMediaManager mediaManager, IPreview preview)
        {
            _mediaManager = mediaManager;
            _preview      = preview;
            if (preview != null)
            {
                PreviewViewmodel = new PreviewViewmodel(preview);
            }

            MediaDirectories = new List <MediaDirectoryViewmodel>();
            MediaDirectories.AddRange(mediaManager.IngestDirectories.Where(d => d.ContainsImport()).Select(d => new MediaDirectoryViewmodel(d, true)));
            IArchiveDirectory archiveDirectory = mediaManager.ArchiveDirectory;

            if (archiveDirectory != null)
            {
                MediaDirectories.Insert(0, new MediaDirectoryViewmodel(archiveDirectory));
            }

            IAnimationDirectory animationDirectoryPRI = mediaManager.AnimationDirectoryPRI;

            if (animationDirectoryPRI != null)
            {
                MediaDirectories.Insert(0, new MediaDirectoryViewmodel(animationDirectoryPRI));
            }
            IAnimationDirectory animationDirectorySEC = mediaManager.AnimationDirectorySEC;

            if (animationDirectorySEC != null)
            {
                MediaDirectories.Insert(0, new MediaDirectoryViewmodel(animationDirectorySEC));
            }

            IServerDirectory        serverDirectoryPRI   = mediaManager.MediaDirectoryPRI;
            MediaDirectoryViewmodel serverDirectoryPRIVm = new MediaDirectoryViewmodel(serverDirectoryPRI);

            if (serverDirectoryPRI != null)
            {
                MediaDirectories.Insert(0, serverDirectoryPRIVm);
            }
            IServerDirectory serverDirectorySEC = mediaManager.MediaDirectorySEC;

            if (serverDirectorySEC != null && serverDirectorySEC != serverDirectoryPRI)
            {
                MediaDirectories.Insert(1, new MediaDirectoryViewmodel(serverDirectorySEC));
            }

            _mediaCategory    = MediaCategories.FirstOrDefault();
            SelectedDirectory = serverDirectoryPRIVm;
            if (mediaManager.FileManager != null)
            {
                FileManagerViewmodel = new FileManagerViewmodel(mediaManager.FileManager);
            }
            RecordersViewmodel = new RecordersViewmodel(mediaManager.Recorders);
            RecordersViewmodel.PropertyChanged += _recordersViewmodel_PropertyChanged;
            _previewDisplay = true;
            ComposePlugins();
            VideoPreview?.SetSource(RecordersViewmodel.Channel?.PreviewUrl);

            CommandSearch = new UICommand {
                ExecuteDelegate = _search, CanExecuteDelegate = _canSearch
            };
            CommandClearFilters = new UICommand {
                ExecuteDelegate = _clearFilters, CanExecuteDelegate = _canClearFilters
            };
            CommandDeleteSelected = new UICommand {
                ExecuteDelegate = _deleteSelected, CanExecuteDelegate = _isSomethingSelected
            };
            CommandIngestSelectedToServer = new UICommand {
                ExecuteDelegate = _ingestSelectedToServer, CanExecuteDelegate = _canIngestSelectedToServer
            };
            CommandMoveSelectedToArchive = new UICommand {
                ExecuteDelegate = _moveSelectedToArchive, CanExecuteDelegate = o => _selectedDirectory != null && _selectedDirectory.IsServerDirectory && _isSomethingSelected(o)
            };
            CommandCopySelectedToArchive = new UICommand {
                ExecuteDelegate = _copySelectedToArchive, CanExecuteDelegate = o => _selectedDirectory != null && _selectedDirectory.IsServerDirectory && _isSomethingSelected(o)
            };
            CommandSweepStaleMedia = new UICommand {
                ExecuteDelegate = _sweepStaleMedia
            };
            CommandGetLoudness = new UICommand {
                ExecuteDelegate = _getLoudness, CanExecuteDelegate = _isSomethingSelected
            };
            CommandExport = new UICommand {
                ExecuteDelegate = _export, CanExecuteDelegate = _canExport
            };
            CommandRefresh = new UICommand {
                ExecuteDelegate = ob => _refreshMediaDirectory(_selectedDirectory?.Directory), CanExecuteDelegate = o => _selectedDirectory?.IsIngestDirectory == true
            };
            CommandSyncPriToSec = new UICommand {
                ExecuteDelegate = _syncSecToPri, CanExecuteDelegate = o => _selectedDirectory.IsServerDirectory
            };
            CommandCloneAnimation = new UICommand {
                ExecuteDelegate = _cloneAnimation, CanExecuteDelegate = _canCloneAnimation
            };
        }
        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;
        }