void InitPeriods() { var gamePeriods = projectVM.Dashboard.GamePeriods; MediaFileSetVM fileSet = projectVM.FileSet; var start = new Time(0); var file = fileSet.FirstOrDefault(); var duration = file.Duration; var pDuration = new Time(duration.MSeconds / gamePeriods.Count); if (projectVM.Periods == null || projectVM.Periods.ViewModels.Count == 0) { // If no periods are provided create the default ones // defined in the dashboard cameraSynchronizationVM.InitialPeriods = new ObservableCollection <Period> (); foreach (string s in gamePeriods) { Period period = new Period { Name = s }; period.Start(start); period.Stop(start + pDuration); cameraSynchronizationVM.InitialPeriods.Add(period); start += pDuration; } projectVM.Periods.Model.Reset(cameraSynchronizationVM.InitialPeriods); } else { // Create a copy of the project periods and keep the // project ones to resynchronize the events in SaveChanges() cameraSynchronizationVM.InitialPeriods = projectVM.Periods.Model.Clone(); } }
public async Task Replace_FileNotContained_Added() { dialogMock.Setup(d => d.OpenMediaFile(It.IsAny <object> ())).Returns(new MediaFile { FilePath = "new" }); MediaFileSet fileSet = new MediaFileSet(); MediaFileSetVM fileSetVM = new MediaFileSetVM { Model = fileSet }; fileSet.Add(new MediaFile { FilePath = "old" }); MediaFileVM newFileVM = await App.Current.EventsBroker.PublishWithReturn <ReplaceMediaFileEvent, MediaFileVM> (new ReplaceMediaFileEvent { OldFileSet = fileSetVM, OldFile = new MediaFileVM { Model = new MediaFile { FilePath = "not contained" } }, }); Assert.IsNotNull(newFileVM); Assert.IsNotNull(newFileVM.Model); Assert.AreEqual("new", newFileVM.FilePath); Assert.AreEqual("new", newFileVM.Model.FilePath); Assert.AreEqual(2, fileSetVM.Count()); }
protected override async Task <bool> LoadProject() { ProjectVM project = ViewModel.Project; if (project.Model.IsFakeCapture) { /* If it's a fake live project prompt for a video file and * create a new PreviewMediaFile for this project and recreate the thumbnails */ Log.Debug("Importing fake live project"); await App.Current.StateController.MoveTo(NewProjectState.NAME, project); return(false); } // Check if the file associated to the project exists if (!project.FileSet.Model.CheckFiles()) { if (!App.Current.GUIToolkit.SelectMediaFiles(project.FileSet.Model)) { return(false); } } if (project.FileSet.Duration == null) { Log.Warning("The selected project is empty. Rediscovering files"); for (int i = 0; i < project.Model.FileSet.Count; i++) { project.Model.FileSet [i] = App.Current.MultimediaToolkit.DiscoverFile(project.Model.FileSet [i].FilePath); } } project.Model.CleanupTimers(); project.Model.UpdateEventTypesAndTimers(); try { if (ViewModel.VideoPlayer.SupportsMultipleCameras) { ViewModel.VideoPlayer.OpenFileSet(project.FileSet); } else { MediaFileSetVM limitedSet = new MediaFileSetVM(); var fileset = project.FileSet.Model.Clone(); fileset.Clear(); fileset.Add(project.FileSet.Model.First()); limitedSet.Model = fileset; ViewModel.VideoPlayer.OpenFileSet(limitedSet); } } catch (Exception ex) { Log.Exception(ex); App.Current.Dialogs.ErrorMessage(Catalog.GetString("An error occurred opening this project:") + "\n" + ex.Message); return(false); } return(true); }
public void TestDurationWithNullModel() { // Arrange MediaFileSetVM newVM = new MediaFileSetVM(); // Action Time duration = newVM.Duration; // Assert Assert.IsNull(duration); }
public void Setup() { model = new MediaFileSet { IsStretched = false, }; model.Add(new MediaFile { FilePath = "/videos/test.mp4", Duration = new Time(20000), }); viewModel = new MediaFileSetVM { Model = model, }; }
// Copied and migrated from MediaFileSet.cs bool Replace(MediaFileSetVM fileSet, MediaFileVM oldFile, MediaFileVM newFile) { bool found = false; if (fileSet.Contains(oldFile)) { if (newFile != null && oldFile != null) { newFile.Name = oldFile.Name; newFile.Offset = oldFile.Offset; } fileSet.ViewModels [fileSet.ViewModels.IndexOf(oldFile)] = newFile; found = true; } else { fileSet.ViewModels.Add(newFile); } return(found); }
public async Task Replace_FileNotSelected_NothingChanged() { dialogMock.Setup(d => d.OpenMediaFile(It.IsAny <object> ())).Returns <MediaFile> (null); MediaFileSet fileSet = new MediaFileSet(); MediaFileSetVM fileSetVM = new MediaFileSetVM { Model = fileSet }; fileSet.Add(new MediaFile { FilePath = "old" }); MediaFileVM newFileVM = await App.Current.EventsBroker.PublishWithReturn <ReplaceMediaFileEvent, MediaFileVM> (new ReplaceMediaFileEvent { OldFileSet = fileSetVM, OldFile = fileSetVM.ViewModels.First(), }); Assert.IsNotNull(newFileVM); Assert.IsNotNull(newFileVM.Model); Assert.AreSame(fileSetVM.ViewModels.First(), newFileVM); Assert.AreEqual(fileSetVM.ViewModels.First().Model, newFileVM.Model); Assert.AreEqual(1, fileSetVM.Count()); }