public void ShouldLoadMediaBin() { var context = new RoughCutEditorEntities(); using (TransactionScope transactionScope = new TransactionScope()) { var libraryId = CreateId(typeof(Services.Contracts.Container).Name); var dataProvider = new DataProvider(this.loggerService, null, libraryId); Project project = Project.CreateProject(1, "creator", DateTime.Now); Item item = SqlHelper.CreateSqlVideoItem(); item.Id = 1; item.Resources.First().Id = 1; item.Resources.First().VideoFormat.Id = 1; Item childItem = SqlHelper.CreateSqlVideoItem(); childItem.Id = 2; childItem.Resources.First().Id = 2; childItem.Resources.First().VideoFormat.Id = 2; context.AddToItem(item); context.AddToItem(childItem); context.SaveChanges(); Container mediaBin = Container.CreateContainer(1); mediaBin.Items.Add(item); Container childContainer = Container.CreateContainer(2); childContainer.Items.Add(childItem); mediaBin.Containers.Add(childContainer); context.AddToContainer(mediaBin); context.SaveChanges(); var mediaBinContainer = dataProvider.LoadMediaBin(new Uri(string.Format(IdUrlTemplate, mediaBin.Id))); Assert.AreEqual(1, mediaBinContainer.Items.Count); Assert.AreEqual(1, mediaBinContainer.Containers.Count); Assert.AreEqual(0, mediaBinContainer.Containers[0].Items.Count); Assert.AreEqual(string.Format(IdUrlTemplate, item.Id), mediaBinContainer.Items[0].Id.ToString()); Assert.AreEqual(item.Title, mediaBinContainer.Items[0].Title); Assert.AreEqual(item.Description, mediaBinContainer.Items[0].Description); Assert.IsInstanceOfType(mediaBinContainer.Items[0], typeof(VideoItem)); Assert.AreEqual(1, mediaBinContainer.Items[0].Resources.Count); Assert.AreEqual(string.Format(IdUrlTemplate, item.Resources.First().Id), mediaBinContainer.Items[0].Resources[0].Id.ToString()); Assert.AreEqual(item.Resources.First().Ref, mediaBinContainer.Items[0].Resources[0].Ref); Assert.AreEqual(item.Resources.First().VideoFormat.Duration, ((VideoItem)mediaBinContainer.Items[0]).Duration); Assert.AreEqual(item.Resources.First().VideoFormat.FrameRate, ((VideoItem)mediaBinContainer.Items[0]).FrameRate.ToString()); Assert.AreEqual(item.Resources.First().VideoFormat.ResolutionX, ((VideoItem)mediaBinContainer.Items[0]).Width); Assert.AreEqual(item.Resources.First().VideoFormat.ResolutionY, ((VideoItem)mediaBinContainer.Items[0]).Height); } }
public void ShouldFilterResultsWhenLoadingLibraryWithFilter() { var context = new RoughCutEditorEntities(); using (TransactionScope transactionScope = new TransactionScope()) { var libraryId = CreateId(typeof(Services.Contracts.Container).Name); var dataProvider = new DataProvider(this.loggerService, libraryId); Container container = Container.CreateContainer(libraryId.ToString()); container.Title = "Test"; Item item1 = SqlHelper.CreateSqlVideoItem(); item1.Title = "FilterItem"; Item item2 = SqlHelper.CreateSqlAudioItem(); item2.Title = "Test"; Item item3 = SqlHelper.CreateSqlImageItem(); item3.Title = "Test2"; container.Items.Add(item1); container.Items.Add(item2); container.Items.Add(item3); context.AddToContainer(container); context.SaveChanges(); var filter = "Filter"; var library = dataProvider.LoadLibrary(filter, 0); Assert.AreEqual(1, library.Items.Count); } }
public void ShouldLoadLibrary() { var context = new RoughCutEditorEntities(); using (TransactionScope transactionScope = new TransactionScope()) { var libraryId = CreateId(typeof(Services.Contracts.Container).Name); var dataProvider = new DataProvider(this.loggerService, null, libraryId); Container container = Container.CreateContainer(1); container.Title = "Test"; Container childContainer = Container.CreateContainer(2); childContainer.Title = "ChildContainer"; Item item = SqlHelper.CreateSqlVideoItem(); item.Id = 1; item.Resources.First().Id = 1; item.Resources.First().VideoFormat.Id = 1; Item childItem = SqlHelper.CreateSqlVideoItem(); childItem.Id = 2; childItem.Resources.First().Id = 2; childItem.Resources.First().VideoFormat.Id = 2; container.Items.Add(item); childContainer.Items.Add(childItem); container.Containers.Add(childContainer); context.AddToContainer(container); context.SaveChanges(); var library = dataProvider.LoadLibrary(1000); Assert.AreEqual(container.Title, library.Title); Assert.AreEqual(1, library.Items.Count); Assert.AreEqual(1, library.Containers.Count); Assert.AreEqual(childContainer.Title, library.Containers[0].Title); Assert.AreEqual(0, library.Containers[0].Items.Count); Assert.AreEqual(string.Format(IdUrlTemplate, item.Id), library.Items[0].Id.ToString()); Assert.AreEqual(item.Title, library.Items[0].Title); Assert.AreEqual(item.Description, library.Items[0].Description); Assert.IsInstanceOfType(library.Items[0], typeof(VideoItem)); Assert.AreEqual(1, library.Items[0].Resources.Count); Assert.AreEqual(string.Format(IdUrlTemplate, item.Resources.First().Id), library.Items[0].Resources[0].Id.ToString()); Assert.AreEqual(item.Resources.First().Ref, library.Items[0].Resources[0].Ref); Assert.AreEqual(item.Resources.First().ResourceType, library.Items[0].Resources[0].ResourceType); Assert.AreEqual(item.Resources.First().VideoFormat.Duration, ((VideoItem)library.Items[0]).Duration); Assert.AreEqual(item.Resources.First().VideoFormat.FrameRate, ((VideoItem)library.Items[0]).FrameRate.ToString()); Assert.AreEqual(item.Resources.First().VideoFormat.ResolutionX, ((VideoItem)library.Items[0]).Width); Assert.AreEqual(item.Resources.First().VideoFormat.ResolutionY, ((VideoItem)library.Items[0]).Height); } }
public void ShouldRetrieveProjectsByUser() { var context = new RoughCutEditorEntities(); using (TransactionScope transactionScope = new TransactionScope()) { var libraryId = CreateId(typeof(Services.Contracts.Container).Name); var dataProvider = new DataProvider(this.loggerService, null, libraryId); Project project1 = Project.CreateProject(1, "creator", DateTime.Now); project1.Duration = 100; project1.Resolution = "HD"; project1.AutoSaveInterval = 100; project1.StartTimeCode = 3600; project1.SmpteFrameRate = "Smpte2997NonDrop"; project1.RippleMode = true; Container mediaBin1 = Container.CreateContainer(1); project1.MediaBin = mediaBin1; Project project2 = Project.CreateProject(2, "notthesamecreator", DateTime.Now); project2.Duration = 100; project2.Resolution = "HD"; project2.AutoSaveInterval = 100; project2.StartTimeCode = 3600; project2.SmpteFrameRate = "Smpte2997NonDrop"; project2.RippleMode = true; Container mediaBin2 = Container.CreateContainer(2); project2.MediaBin = mediaBin2; context.AddToProject(project1); context.AddToProject(project2); context.SaveChanges(); var projects = dataProvider.GetProjectsByUser("creator"); Assert.AreEqual(1, projects.Count()); Assert.AreEqual(project1.Duration, projects[0].Duration); Assert.AreEqual(project1.Resolution, projects[0].Resolution); Assert.AreEqual(project1.AutoSaveInterval, projects[0].AutoSaveInterval); Assert.AreEqual(project1.StartTimeCode, projects[0].StartTimeCode); Assert.AreEqual(project1.SmpteFrameRate, projects[0].SmpteFrameRate); Assert.AreEqual(project1.RippleMode, projects[0].RippleMode); Assert.AreEqual(project1.Creator, projects[0].Creator); } }
/// <summary> /// Deletes the project. /// </summary> /// <param name="site">The <see cref="Uri"/> of the project site.</param> /// <returns>True if project have been deleted else false. </returns> public bool DeleteProject(Uri site) { if (site != null) { try { using (RoughCutEditorEntities context = new RoughCutEditorEntities()) { context.CommandTimeout = DefaultCommandTimeout; var projectId = ExtractIdFromUri(site); Project sqlProject = LoadFullProject(projectId, context); if (sqlProject != null) { sqlProject.Titles.ToList().ForEach(context.DeleteObject); sqlProject.Comments.ToList().ForEach(context.DeleteObject); sqlProject.MediaBin.Containers.ToList().ForEach(context.DeleteObject); sqlProject.Comments.ToList().ForEach(context.DeleteObject); sqlProject.Tracks.ToList().ForEach( x => { x.Shots.ToList().ForEach(context.DeleteObject); context.DeleteObject(x); }); sqlProject.Titles.ToList().ForEach(context.DeleteObject); context.DeleteObject(sqlProject); context.SaveChanges(SaveOptions.AcceptAllChangesAfterSave); } return(true); } } catch (Exception ex) { this.Log(ex); return(false); } } return(false); }
public void ShouldLoadTitleTemplates() { var context = new RoughCutEditorEntities(); using (TransactionScope transactionScope = new TransactionScope()) { var libraryId = CreateId(typeof(Services.Contracts.Container).Name); var dataProvider = new DataProvider(this.loggerService, null, libraryId); TitleTemplate titleTemplate = SqlHelper.CreateSqlTitleTemplate(); context.AddToTitleTemplate(titleTemplate); context.SaveChanges(); var titleTemplates = dataProvider.LoadTitleTemplates(); Assert.AreEqual(1, titleTemplates.Count); Assert.AreEqual(string.Format(IdUrlTemplate, titleTemplate.Id), titleTemplates[0].Id.ToString()); Assert.AreEqual(titleTemplate.TemplateName, titleTemplates[0].TemplateName); } }
public void ShouldLimitResultsWhenLoadingLibraryWithMaxNumberOfItems() { var context = new RoughCutEditorEntities(); using (TransactionScope transactionScope = new TransactionScope()) { var libraryId = CreateId(typeof(Services.Contracts.Container).Name); var dataProvider = new DataProvider(this.loggerService, null, libraryId); Container container = Container.CreateContainer(1); container.Title = "Test"; Item item1 = SqlHelper.CreateSqlVideoItem(); item1.Id = 1; item1.Resources.First().Id = 1; item1.Resources.First().VideoFormat.Id = 1; Item item2 = SqlHelper.CreateSqlAudioItem(); item2.Id = 2; item2.Resources.First().Id = 2; item2.Resources.First().AudioFormat.Id = 2; Item item3 = SqlHelper.CreateSqlImageItem(); item3.Id = 3; item3.Resources.First().Id = 3; item3.Resources.First().ImageFormat.Id = 3; container.Items.Add(item1); container.Items.Add(item2); container.Items.Add(item3); context.AddToContainer(container); context.SaveChanges(); var maxNumberOfItems = 2; var library = dataProvider.LoadLibrary(maxNumberOfItems); Assert.AreEqual(maxNumberOfItems, library.Items.Count); } }
/// <summary> /// Deletes the project. /// </summary> /// <param name="site">The <see cref="Uri"/> of the project site.</param> /// <returns>True if project have been deleted else false. </returns> public bool DeleteProject(Uri site) { try { using (RoughCutEditorEntities context = new RoughCutEditorEntities { CommandTimeout = DefaultCommandTimeout }) { string uriString = site.ToString(); Project sqlProject = LoadFullProject(uriString, context); if (sqlProject != null) { sqlProject.Titles.ToList().ForEach(context.DeleteObject); sqlProject.Comments.ToList().ForEach(context.DeleteObject); sqlProject.MediaBin.Containers.ToList().ForEach(context.DeleteObject); sqlProject.Comments.ToList().ForEach(context.DeleteObject); sqlProject.Tracks.ToList().ForEach(x => { x.Shots.ToList().ForEach(context.DeleteObject); context.DeleteObject(x); }); sqlProject.Titles.ToList().ForEach(context.DeleteObject); context.DeleteObject(sqlProject); context.SaveChanges(true); } return(true); } } catch (Exception ex) { this.Log(ex); return(false); } }
public void ShouldDeleteProject() { var context = new RoughCutEditorEntities(); using (TransactionScope transactionScope = new TransactionScope()) { var libraryId = CreateId(typeof(Services.Contracts.Container).Name); var dataProvider = new DataProvider(this.loggerService, null, libraryId); Item item = Item.CreateItem(1, "title", "Video"); item.Description = "description"; item.Resources = new EntityCollection <Resource>(); Resource resource = Resource.CreateResource(1, "\test\test.wmv", "Master"); resource.VideoFormat = VideoFormat.CreateVideoFormat(1); resource.VideoFormat.Duration = 10; resource.VideoFormat.FrameRate = "Smpte25"; resource.VideoFormat.ResolutionX = 200; resource.VideoFormat.ResolutionY = 500; item.Resources.Add(resource); context.AddToItem(item); TitleTemplate titleTemplate = TitleTemplate.CreateTitleTemplate(1, "TemplateName"); context.AddToTitleTemplate(titleTemplate); context.SaveChanges(); Project project = Project.CreateProject(1, "creator", DateTime.Now); project.Duration = 100; project.Resolution = "HD"; project.AutoSaveInterval = 100; project.StartTimeCode = 3600; project.SmpteFrameRate = "Smpte2997NonDrop"; project.RippleMode = true; Container mediaBin = Container.CreateContainer(1); mediaBin.Items.Add(item); Container container = Container.CreateContainer(2); mediaBin.Containers.Add(container); project.MediaBin = mediaBin; Comment comment = Comment.CreateComment(1, "Text", "Timeline", "user", DateTime.Today); comment.MarkIn = 1200; comment.MarkOut = 1500; Comment shotComment = Comment.CreateComment(2, "Text", "Shot", "user", DateTime.Today); shotComment.MarkIn = 170; shotComment.MarkOut = 180; project.Comments.Add(comment); project.Comments.Add(shotComment); Track track = Track.CreateTrack(1, "Video"); Shot shot = Shot.CreateShot(1); shot.Item = item; shot.ItemMarkIn = 150; shot.ItemMarkOut = 200; shot.TrackMarkIn = 500; shot.TrackMarkOut = 0; shot.Volume = 5; shot.Comments.Add(shotComment); track.Shots = new EntityCollection <Shot>(); track.Shots.Add(shot); project.Tracks.Add(track); Title title = Title.CreateTitle(1, 600, 100, "Main", "Sub"); title.TitleTemplate = titleTemplate; project.Titles.Add(title); context.AddToProject(project); context.SaveChanges(); var retrievedProject = dataProvider.LoadProject(new Uri(string.Format("http://temp/{0}", project.Id))); bool result = dataProvider.DeleteProject(new Uri(string.Format("http://temp/{0}", project.Id))); var retrievedDeletedProject = dataProvider.LoadProject(new Uri(string.Format("http://temp/{0}", project.Id))); Assert.IsTrue(result); Assert.IsNull(retrievedDeletedProject.Id); } }
public void ShouldSaveProject() { var context = new RoughCutEditorEntities(); using (TransactionScope transactionScope = new TransactionScope()) { var libraryId = CreateId(typeof(Services.Contracts.Container).Name); var dataProvider = new DataProvider(this.loggerService, null, libraryId); Item item = Item.CreateItem(1, "title", "Video"); item.Description = "description"; item.Resources = new EntityCollection <Resource>(); Resource resource = Resource.CreateResource(1, "\test\test.wmv", "Master"); resource.VideoFormat = VideoFormat.CreateVideoFormat(1); resource.VideoFormat.Duration = 10; resource.VideoFormat.FrameRate = "Smpte25"; resource.VideoFormat.ResolutionX = 200; resource.VideoFormat.ResolutionY = 500; item.Resources.Add(resource); context.AddToItem(item); TitleTemplate titleTemplate = TitleTemplate.CreateTitleTemplate(1, "TestTemplateName"); context.AddToTitleTemplate(titleTemplate); context.SaveChanges(); Services.Contracts.VideoItem videoItem = new Services.Contracts.VideoItem(); videoItem.Id = new Uri(string.Format(IdUrlTemplate, 1)); videoItem.Title = "title"; videoItem.Description = "description"; Services.Contracts.Resource videoResource = new Services.Contracts.Resource(); videoResource.Id = new Uri(string.Format(IdUrlTemplate, 1)); videoResource.Ref = "\test\test.wmv"; videoItem.Resources.Add(videoResource); Services.Contracts.Project project = new Services.Contracts.Project(); project.Id = new Uri(string.Format(IdUrlTemplate, 1)); project.Duration = 100; project.Resolution = "HD"; project.AutoSaveInterval = 100; project.StartTimeCode = 3600; project.SmpteFrameRate = "Smpte2997NonDrop"; project.RippleMode = true; project.Creator = "creator"; project.Created = DateTime.Now; Services.Contracts.MediaBin mediaBin = new Services.Contracts.MediaBin(); mediaBin.Id = new Uri(string.Format(IdUrlTemplate, 1)); mediaBin.Items.Add(videoItem); Services.Contracts.Container container = new Services.Contracts.Container(); container.Id = new Uri(string.Format(IdUrlTemplate, 2)); container.Title = "Test"; mediaBin.Containers.Add(container); project.MediaBin = mediaBin; Services.Contracts.Track track = new Services.Contracts.Track(); track.Id = new Uri(string.Format(IdUrlTemplate, 1)); track.TrackType = "Video"; Services.Contracts.Comment shotComment = new Services.Contracts.Comment(); shotComment.Id = new Uri(string.Format(IdUrlTemplate, 1)); shotComment.Creator = "user"; shotComment.Created = DateTime.Today; shotComment.Type = "Shot"; shotComment.Text = "Text"; shotComment.MarkIn = 170; shotComment.MarkOut = 180; Services.Contracts.Shot shot = new Services.Contracts.Shot(); shot.Id = new Uri(string.Format(IdUrlTemplate, 1)); shot.Source = videoItem; shot.SourceAnchor = new Anchor { MarkIn = 150, MarkOut = 200 }; shot.TrackAnchor = new Anchor { MarkIn = 500, MarkOut = 0 }; shot.Volume = 50; shot.Comments.Add(shotComment); track.Shots.Add(shot); Services.Contracts.Sequence sequence = new Services.Contracts.Sequence(); sequence.Id = new Guid(); project.Sequences.Add(sequence); project.Sequences[0].Tracks.Add(track); Services.Contracts.Comment comment = new Services.Contracts.Comment(); comment.Id = new Uri(string.Format(IdUrlTemplate, 2)); comment.Creator = "user"; comment.Created = DateTime.Today; comment.Type = "Timeline"; comment.Text = "Text"; comment.MarkIn = 1200; comment.MarkOut = 1500; project.Comments.Add(comment); project.Comments.Add(shotComment); Services.Contracts.Title title = new Services.Contracts.Title(); title.Id = new Uri(string.Format(IdUrlTemplate, 1)); title.TrackAnchor = new Anchor { MarkIn = 600, MarkOut = 100 }; title.TextBlockCollection.Add(new TextBlock { Text = "Main" }); title.TextBlockCollection.Add(new TextBlock { Text = "Sub" }); title.TitleTemplate = new Services.Contracts.TitleTemplate { Id = new Uri(string.Format(IdUrlTemplate, titleTemplate.Id)), TemplateName = titleTemplate.TemplateName }; project.Titles.Add(title); var result = dataProvider.SaveProject(project); Assert.IsTrue(result); Project retrievedProject = context.Project.Include("Tracks") .Include("Tracks.Shots") .Include("Tracks.Shots.Comments") .Include("Tracks.Shots.Item") .Include("Tracks.Shots.Item.Resources") .Include("Tracks.Shots.Item.Resources.VideoFormat") .Include("Tracks.Shots.Item.Resources.AudioFormat") .Include("Tracks.Shots.Item.Resources.ImageFormat") .Include("Comments") .Include("MediaBin") .Include("MediaBin.Containers") .Include("Titles") .Include("Titles.TitleTemplate") .Where(x => x.Id == 1).FirstOrDefault(); Assert.IsNotNull(retrievedProject); Assert.AreEqual(project.Duration, retrievedProject.Duration); Assert.AreEqual(project.Resolution, retrievedProject.Resolution); Assert.AreEqual(project.Resolution, retrievedProject.Resolution); Assert.AreEqual(project.AutoSaveInterval, retrievedProject.AutoSaveInterval); Assert.AreEqual(project.StartTimeCode, retrievedProject.StartTimeCode); Assert.AreEqual(project.SmpteFrameRate, retrievedProject.SmpteFrameRate); Assert.AreEqual(project.RippleMode, retrievedProject.RippleMode); Assert.AreEqual(project.Creator, retrievedProject.Creator); Assert.IsNotNull(retrievedProject.MediaBin); Assert.AreEqual(mediaBin.Id.ToString(), string.Format(IdUrlTemplate, retrievedProject.MediaBin.Id)); Assert.AreEqual(0, retrievedProject.MediaBin.Items.Count); Assert.AreEqual(1, retrievedProject.MediaBin.Containers.Count); Assert.AreEqual(1, retrievedProject.Tracks.Count); Assert.AreEqual(track.Id.ToString(), string.Format(IdUrlTemplate, retrievedProject.Tracks.First().Id)); Assert.AreEqual(track.TrackType, retrievedProject.Tracks.First().TrackType); Assert.AreEqual(track.Shots.Count, retrievedProject.Tracks.First().Shots.Count); Assert.AreEqual(shot.Id.ToString(), string.Format(IdUrlTemplate, retrievedProject.Tracks.First().Shots.First().Id)); Assert.AreEqual(shot.TrackAnchor.MarkIn, retrievedProject.Tracks.First().Shots.First().TrackMarkIn); Assert.AreEqual(shot.TrackAnchor.MarkOut, retrievedProject.Tracks.First().Shots.First().TrackMarkOut); Assert.AreEqual(shot.SourceAnchor.MarkIn, retrievedProject.Tracks.First().Shots.First().ItemMarkIn); Assert.AreEqual(shot.Volume, retrievedProject.Tracks.First().Shots.First().Volume); Assert.AreEqual(1, retrievedProject.Tracks.First().Shots.First().Comments.Count); Assert.AreEqual(shotComment.Id.ToString(), string.Format(IdUrlTemplate, retrievedProject.Tracks.First().Shots.First().Comments.First().Id)); Assert.AreEqual(shotComment.Text, retrievedProject.Tracks.First().Shots.First().Comments.First().Text); Assert.AreEqual(shotComment.Creator, retrievedProject.Tracks.First().Shots.First().Comments.First().Creator); Assert.AreEqual(shotComment.Created, retrievedProject.Tracks.First().Shots.First().Comments.First().Created); Assert.AreEqual(shotComment.Type, retrievedProject.Tracks.First().Shots.First().Comments.First().CommentType); Assert.AreEqual(shotComment.MarkIn, retrievedProject.Tracks.First().Shots.First().Comments.First().MarkIn); Assert.AreEqual(shotComment.MarkOut, retrievedProject.Tracks.First().Shots.First().Comments.First().MarkOut); Assert.AreEqual(videoItem.Id.ToString(), string.Format(IdUrlTemplate, retrievedProject.Tracks.First().Shots.First().Item.Id)); Assert.AreEqual(videoItem.Title, retrievedProject.Tracks.First().Shots.First().Item.Title); Assert.AreEqual(videoItem.Description, retrievedProject.Tracks.First().Shots.First().Item.Description); Assert.AreEqual("video", retrievedProject.Tracks.First().Shots.First().Item.ItemType.ToLowerInvariant()); Assert.AreEqual(videoItem.Resources[0].Id.ToString(), string.Format(IdUrlTemplate, retrievedProject.Tracks.First().Shots.First().Item.Resources.First().Id)); Assert.AreEqual(videoItem.Resources[0].Ref, retrievedProject.Tracks.First().Shots.First().Item.Resources.First().Ref); Assert.AreEqual(item, retrievedProject.Tracks.First().Shots.First().Item); Assert.AreEqual(2, retrievedProject.Comments.Count); Assert.AreEqual(comment.Id.ToString(), string.Format(IdUrlTemplate, retrievedProject.Comments.ElementAt(1).Id)); Assert.AreEqual(comment.Text, retrievedProject.Comments.ElementAt(1).Text); Assert.AreEqual(comment.Creator, retrievedProject.Comments.ElementAt(1).Creator); Assert.AreEqual(comment.Created, retrievedProject.Comments.ElementAt(1).Created); Assert.AreEqual(comment.Type, retrievedProject.Comments.ElementAt(1).CommentType); Assert.AreEqual(comment.MarkIn, retrievedProject.Comments.ElementAt(1).MarkIn); Assert.AreEqual(comment.MarkOut, retrievedProject.Comments.ElementAt(1).MarkOut); Assert.AreEqual(shotComment.Id.ToString(), string.Format(IdUrlTemplate, retrievedProject.Comments.ElementAt(0).Id)); Assert.AreEqual(shotComment.Text, retrievedProject.Comments.ElementAt(0).Text); Assert.AreEqual(shotComment.Creator, retrievedProject.Comments.ElementAt(0).Creator); Assert.AreEqual(shotComment.Created, retrievedProject.Comments.ElementAt(0).Created); Assert.AreEqual(shotComment.Type, retrievedProject.Comments.ElementAt(0).CommentType); Assert.AreEqual(shotComment.MarkIn, retrievedProject.Comments.ElementAt(0).MarkIn); Assert.AreEqual(shotComment.MarkOut, retrievedProject.Comments.ElementAt(0).MarkOut); Assert.AreEqual(1, retrievedProject.Titles.Count); Assert.AreEqual(title.Id.ToString(), string.Format(IdUrlTemplate, retrievedProject.Titles.ElementAt(0).Id)); Assert.AreEqual(title.TextBlockCollection[0].Text, retrievedProject.Titles.ElementAt(0).MainText); Assert.AreEqual(title.TextBlockCollection[1].Text, retrievedProject.Titles.ElementAt(0).SubText); Assert.AreEqual(title.TrackAnchor.MarkIn, retrievedProject.Titles.ElementAt(0).TrackMarkIn); Assert.AreEqual(title.TrackAnchor.MarkOut, retrievedProject.Titles.ElementAt(0).TrackMarkOut); Assert.AreEqual(title.TitleTemplate.Id.ToString(), string.Format(IdUrlTemplate, retrievedProject.Titles.ElementAt(0).TitleTemplate.Id)); Assert.AreEqual(title.TitleTemplate.TemplateName, retrievedProject.Titles.ElementAt(0).TitleTemplate.TemplateName); } }
public void ShouldLoadProject() { var context = new RoughCutEditorEntities(); using (TransactionScope transactionScope = new TransactionScope()) { var libraryId = CreateId(typeof(Services.Contracts.Container).Name); var dataProvider = new DataProvider(this.loggerService, null, libraryId); Item item = Item.CreateItem(1, "title", "Video"); item.Description = "description"; item.Resources = new EntityCollection <Resource>(); Resource resource = Resource.CreateResource(1, "\test\test.wmv", "Master"); resource.VideoFormat = VideoFormat.CreateVideoFormat(1); resource.VideoFormat.Duration = 10; resource.VideoFormat.FrameRate = "Smpte25"; resource.VideoFormat.ResolutionX = 200; resource.VideoFormat.ResolutionY = 500; item.Resources.Add(resource); context.AddToItem(item); TitleTemplate titleTemplate = TitleTemplate.CreateTitleTemplate(1, "TemplateName"); context.AddToTitleTemplate(titleTemplate); context.SaveChanges(); Project project = Project.CreateProject(1, "creator", DateTime.Now); project.Duration = 100; project.Resolution = "HD"; project.AutoSaveInterval = 100; project.StartTimeCode = 3600; project.SmpteFrameRate = "Smpte2997NonDrop"; project.RippleMode = true; Container mediaBin = Container.CreateContainer(1); mediaBin.Items.Add(item); Container container = Container.CreateContainer(2); container.Items.Add(item); mediaBin.Containers.Add(container); project.MediaBin = mediaBin; Comment comment = Comment.CreateComment(3, "Text", "Timeline", "user", DateTime.Today); comment.MarkIn = 1200; comment.MarkOut = 1500; Comment shotComment = Comment.CreateComment(4, "Text", "Shot", "user", DateTime.Today); shotComment.MarkIn = 170; shotComment.MarkOut = 180; project.Comments.Add(comment); project.Comments.Add(shotComment); Track track = Track.CreateTrack(1, "Video"); Shot shot = Shot.CreateShot(1); shot.Item = item; shot.ItemMarkIn = 150; shot.ItemMarkOut = 200; shot.TrackMarkIn = 500; shot.TrackMarkOut = 0; shot.Volume = 5; shot.Comments.Add(shotComment); track.Shots = new EntityCollection <Shot>(); track.Shots.Add(shot); project.Tracks.Add(track); Title title = Title.CreateTitle(1, 600, 100, "Main", "Sub"); title.TitleTemplate = titleTemplate; project.Titles.Add(title); context.AddToProject(project); context.SaveChanges(); var retrievedProject = dataProvider.LoadProject(new Uri(string.Format(IdUrlTemplate, project.Id))); Assert.AreEqual(project.Duration, retrievedProject.Duration); Assert.AreEqual(project.Resolution, retrievedProject.Resolution); Assert.AreEqual(project.AutoSaveInterval, retrievedProject.AutoSaveInterval); Assert.AreEqual(project.StartTimeCode, retrievedProject.StartTimeCode); Assert.AreEqual(project.SmpteFrameRate, retrievedProject.SmpteFrameRate); Assert.AreEqual(project.RippleMode, retrievedProject.RippleMode); Assert.AreEqual(project.Creator, retrievedProject.Creator); Assert.IsNotNull(retrievedProject.MediaBin); Assert.AreEqual(string.Format(IdUrlTemplate, mediaBin.Id), retrievedProject.MediaBin.Id.ToString()); Assert.AreEqual(1, retrievedProject.MediaBin.Items.Count); Assert.AreEqual(1, retrievedProject.MediaBin.Containers.Count); Assert.AreEqual(0, retrievedProject.MediaBin.Containers[0].Items.Count); Assert.AreEqual(1, retrievedProject.Sequences[0].Tracks.Count); Assert.AreEqual(string.Format(IdUrlTemplate, track.Id), retrievedProject.Sequences[0].Tracks[0].Id.ToString()); Assert.AreEqual(track.TrackType, retrievedProject.Sequences[0].Tracks[0].TrackType); Assert.AreEqual(track.Shots.Count, retrievedProject.Sequences[0].Tracks[0].Shots.Count); Assert.AreEqual(string.Format(IdUrlTemplate, shot.Id), retrievedProject.Sequences[0].Tracks[0].Shots[0].Id.ToString()); Assert.AreEqual(shot.TrackMarkIn, retrievedProject.Sequences[0].Tracks[0].Shots[0].TrackAnchor.MarkIn); Assert.AreEqual(shot.TrackMarkOut, retrievedProject.Sequences[0].Tracks[0].Shots[0].TrackAnchor.MarkOut); Assert.AreEqual(shot.ItemMarkIn, retrievedProject.Sequences[0].Tracks[0].Shots[0].SourceAnchor.MarkIn); Assert.AreEqual(shot.ItemMarkOut, retrievedProject.Sequences[0].Tracks[0].Shots[0].SourceAnchor.MarkOut); Assert.AreEqual(shot.Volume, retrievedProject.Sequences[0].Tracks[0].Shots[0].Volume); Assert.AreEqual(1, retrievedProject.Sequences[0].Tracks[0].Shots[0].Comments.Count); Assert.AreEqual(string.Format(IdUrlTemplate, shotComment.Id), retrievedProject.Sequences[0].Tracks[0].Shots[0].Comments[0].Id.ToString()); Assert.AreEqual(shotComment.Creator, retrievedProject.Sequences[0].Tracks[0].Shots[0].Comments[0].Creator); Assert.AreEqual(shotComment.Created, retrievedProject.Sequences[0].Tracks[0].Shots[0].Comments[0].Created); Assert.AreEqual(shotComment.Text, retrievedProject.Sequences[0].Tracks[0].Shots[0].Comments[0].Text); Assert.AreEqual(shotComment.CommentType, retrievedProject.Sequences[0].Tracks[0].Shots[0].Comments[0].Type); Assert.AreEqual(shotComment.MarkIn, retrievedProject.Sequences[0].Tracks[0].Shots[0].Comments[0].MarkIn); Assert.AreEqual(shotComment.MarkOut, retrievedProject.Sequences[0].Tracks[0].Shots[0].Comments[0].MarkOut); Assert.AreEqual(2, retrievedProject.Comments.Count); Assert.AreEqual(string.Format(IdUrlTemplate, comment.Id), retrievedProject.Comments[1].Id.ToString()); Assert.AreEqual(comment.Created, retrievedProject.Comments[1].Created); Assert.AreEqual(comment.Creator, retrievedProject.Comments[1].Creator); Assert.AreEqual(comment.Text, retrievedProject.Comments[1].Text); Assert.AreEqual(comment.CommentType, retrievedProject.Comments[1].Type); Assert.AreEqual(comment.MarkIn, retrievedProject.Comments[1].MarkIn); Assert.AreEqual(comment.MarkOut, retrievedProject.Comments[1].MarkOut); Assert.AreEqual(string.Format(IdUrlTemplate, shotComment.Id), retrievedProject.Comments[0].Id.ToString()); Assert.AreEqual(shotComment.Created, retrievedProject.Comments[0].Created); Assert.AreEqual(shotComment.Creator, retrievedProject.Comments[0].Creator); Assert.AreEqual(shotComment.Text, retrievedProject.Comments[0].Text); Assert.AreEqual(shotComment.CommentType, retrievedProject.Comments[0].Type); Assert.AreEqual(shotComment.MarkIn, retrievedProject.Comments[0].MarkIn); Assert.AreEqual(shotComment.MarkOut, retrievedProject.Comments[0].MarkOut); Assert.AreEqual(string.Format(IdUrlTemplate, item.Id), retrievedProject.Sequences[0].Tracks[0].Shots[0].Source.Id.ToString()); Assert.AreEqual(item.Title, retrievedProject.Sequences[0].Tracks[0].Shots[0].Source.Title); Assert.AreEqual(item.Description, retrievedProject.Sequences[0].Tracks[0].Shots[0].Source.Description); Assert.IsInstanceOfType(retrievedProject.Sequences[0].Tracks[0].Shots[0].Source, typeof(VideoItem)); Assert.AreEqual(string.Format(IdUrlTemplate, item.Resources.First().Id), retrievedProject.Sequences[0].Tracks[0].Shots[0].Source.Resources[0].Id.ToString()); Assert.AreEqual(item.Resources.First().Ref, retrievedProject.Sequences[0].Tracks[0].Shots[0].Source.Resources[0].Ref); Assert.AreEqual(item.Resources.First().VideoFormat.Duration, ((VideoItem)retrievedProject.Sequences[0].Tracks[0].Shots[0].Source).Duration); Assert.AreEqual(item.Resources.First().VideoFormat.FrameRate, ((VideoItem)retrievedProject.Sequences[0].Tracks[0].Shots[0].Source).FrameRate.ToString()); Assert.AreEqual(item.Resources.First().VideoFormat.ResolutionX, ((VideoItem)retrievedProject.Sequences[0].Tracks[0].Shots[0].Source).Width); Assert.AreEqual(item.Resources.First().VideoFormat.ResolutionY, ((VideoItem)retrievedProject.Sequences[0].Tracks[0].Shots[0].Source).Height); Assert.AreEqual(1, retrievedProject.Titles.Count); Assert.AreEqual(string.Format(IdUrlTemplate, title.Id), retrievedProject.Titles[0].Id.ToString()); Assert.AreEqual(title.MainText, retrievedProject.Titles[0].TextBlockCollection[0].Text); Assert.AreEqual(title.SubText, retrievedProject.Titles[0].TextBlockCollection[1].Text); Assert.AreEqual(title.TrackMarkIn, retrievedProject.Titles[0].TrackAnchor.MarkIn); Assert.AreEqual(title.TrackMarkOut, retrievedProject.Titles[0].TrackAnchor.MarkOut); Assert.AreEqual(string.Format(IdUrlTemplate, title.TitleTemplate.Id), retrievedProject.Titles[0].TitleTemplate.Id.ToString()); Assert.AreEqual(title.TitleTemplate.TemplateName, retrievedProject.Titles[0].TitleTemplate.TemplateName); } }
/// <summary> /// Saves a project into the repository. /// </summary> /// <param name="project">The project to be saved.</param> /// <returns>true, indicates that the project was saved. false, that the save failed.</returns> public bool SaveProject(Services.Contracts.Project project) { // TODO // This method must also start the Sub-Clipping Job. Use the same code that is in the // RCE.Services.OutputService.GenerateCompositeStreamManifest method. You can ignore all // the additional method parameters (pbpDataStreamName, adsDataStreamName, compressManifest, // gapUriString, gapCmsId, gapAzureId) since they are not being used. RoughCutEditorEntities context = null; try { context = new RoughCutEditorEntities(); context.CommandTimeout = 1000; IList <Item> items = new List <Item>(); RetrieveItems(items, project.MediaBin.Items, context); RetrieveItems(items, project.MediaBin.Containers, context); var id = ExtractIdFromUri(project.Id); Project sqlProject = LoadFullProject(id, context); if (sqlProject == null) { sqlProject = new Project { Id = id }; context.AddToProject(sqlProject); } SqlDataProviderTranslator.ConvertToSqlProject(project, sqlProject); id = ExtractIdFromUri(project.MediaBin.Id); Container sqlMediaBin = context.Container.Where(m => m.Id == id).FirstOrDefault(); if (sqlMediaBin == null) { sqlMediaBin = new Container { Id = id, Title = project.MediaBin.Title }; } sqlMediaBin.Items.Clear(); sqlProject.MediaBin = SqlDataProviderTranslator.ConvertToSqlMediaBin( project.MediaBin, sqlMediaBin, items); foreach (RCE.Services.Contracts.Container container in project.MediaBin.Containers) { id = ExtractIdFromUri(container.Id); Container sqlContainer = context.Container.Where(m => m.Id == id).FirstOrDefault(); if (sqlContainer == null) { sqlContainer = new Container { Id = id, Title = container.Title }; sqlMediaBin.Containers.Add(sqlContainer); } sqlContainer.Items.Clear(); SqlDataProviderTranslator.ConvertToSqlMediaBin(container, sqlContainer, items); } sqlMediaBin.Containers.Where(x => x.EntityState == EntityState.Unchanged).ToList().ForEach( x => { x.Items.Where(i => i.EntityState == EntityState.Unchanged).ToList().ForEach( i => { x.Items.Remove(i); }); sqlMediaBin.Containers.Remove(x); context.DeleteObject(x); }); foreach (Services.Contracts.Comment comment in project.Comments) { id = ExtractIdFromUri(comment.Id); Comment sqlComment = sqlProject.Comments.Where(m => m.Id == id).FirstOrDefault(); if (sqlComment == null) { sqlComment = new Comment { Id = id }; sqlProject.Comments.Add(sqlComment); } SqlDataProviderTranslator.ConvertToSqlComment(comment, sqlComment); } sqlProject.Comments.Where(x => x.EntityState == EntityState.Unchanged).ToList().ForEach( x => { sqlProject.Comments.Remove(x); context.DeleteObject(x); }); foreach (Services.Contracts.Track track in project.Sequences[0].Tracks) { id = ExtractIdFromUri(track.Id); Track sqlTrack = sqlProject.Tracks.Where(m => m.Id == id).FirstOrDefault(); if (sqlTrack == null) { sqlTrack = new Track { Id = id }; sqlProject.Tracks.Add(sqlTrack); } SqlDataProviderTranslator.ConvertToSqlTrack(track, sqlTrack); foreach (Services.Contracts.Shot shot in track.Shots) { id = ExtractIdFromUri(shot.Id); Shot sqlShot = sqlTrack.Shots.Where(m => m.Id == id).FirstOrDefault(); if (sqlShot == null) { sqlShot = new Shot { Id = id }; sqlTrack.Shots.Add(sqlShot); } SqlDataProviderTranslator.ConvertToSqlShot(shot, sqlShot, items); foreach (Services.Contracts.Comment comment in shot.Comments) { id = ExtractIdFromUri(comment.Id); Comment sqlComment = sqlProject.Comments.Where(m => m.Id == id).FirstOrDefault(); if (sqlComment == null) { sqlComment = new Comment { Id = id }; sqlShot.Comments.Add(sqlComment); } else if (sqlComment.EntityState == EntityState.Added) { sqlShot.Comments.Add(sqlComment); } SqlDataProviderTranslator.ConvertToSqlComment(comment, sqlComment); } sqlShot.Comments.Where(x => x.EntityState == EntityState.Unchanged).ToList().ForEach( x => { sqlProject.Comments.Remove(x); context.DeleteObject(x); }); } sqlTrack.Shots.Where(x => x.EntityState == EntityState.Unchanged).ToList().ForEach( x => { sqlTrack.Shots.Remove(x); context.DeleteObject(x); }); } sqlProject.Tracks.Where(x => x.EntityState == EntityState.Unchanged).ToList().ForEach( x => { sqlProject.Tracks.Remove(x); context.DeleteObject(x); }); foreach (Services.Contracts.Title title in project.Titles) { id = ExtractIdFromUri(title.Id); Title sqlTitle = sqlProject.Titles.Where(m => m.Id == id).FirstOrDefault(); if (sqlTitle == null) { sqlTitle = new Title { Id = id }; var tempId = ExtractIdFromUri(title.TitleTemplate.Id); sqlTitle.TitleTemplate = context.TitleTemplate.Where(m => m.Id == tempId).FirstOrDefault(); sqlProject.Titles.Add(sqlTitle); } SqlDataProviderTranslator.ConvertToSqlTitle(title, sqlTitle); } sqlProject.Titles.Where(x => x.EntityState == EntityState.Unchanged).ToList().ForEach( x => { sqlProject.Titles.Remove(x); context.DeleteObject(x); }); context.SaveChanges(); return(true); } catch (Exception ex) { this.Log(ex); return(false); } finally { if (context != null) { context.Dispose(); } } }
/// <summary> /// Saves a project into the repository. /// </summary> /// <param name="project">The project to be saved.</param> /// <returns>true, indicates that the project was saved. false, that the save failed.</returns> public bool SaveProject(Services.Contracts.Project project) { RoughCutEditorEntities context = new RoughCutEditorEntities { CommandTimeout = 1000 }; try { IList <Item> items = new List <Item>(); RetrieveItems(items, project.MediaBin.Items, context); RetrieveItems(items, project.MediaBin.Containers, context); string uriString = project.Id.ToString(); Project sqlProject = LoadFullProject(uriString, context); if (sqlProject == null) { sqlProject = new Project { Id = uriString }; context.AddToProject(sqlProject); } SqlDataProviderTranslator.ConvertToSqlProject(project, sqlProject); uriString = project.MediaBin.Id.ToString(); Container sqlMediaBin = context.Container.Where(m => m.Id == uriString).FirstOrDefault(); if (sqlMediaBin == null) { sqlMediaBin = new Container { Id = uriString, Title = project.MediaBin.Title }; } sqlMediaBin.Items.Clear(); sqlProject.MediaBin = SqlDataProviderTranslator.ConvertToSqlMediaBin(project.MediaBin, sqlMediaBin, items); foreach (RCE.Services.Contracts.Container container in project.MediaBin.Containers) { uriString = container.Id.ToString(); Container sqlContainer = context.Container.Where(m => m.Id == uriString).FirstOrDefault(); if (sqlContainer == null) { sqlContainer = new Container { Id = uriString, Title = container.Title }; sqlMediaBin.Containers.Add(sqlContainer); } sqlContainer.Items.Clear(); SqlDataProviderTranslator.ConvertToSqlMediaBin(container, sqlContainer, items); } sqlMediaBin.Containers.Where(x => x.EntityState == EntityState.Unchanged) .ToList() .ForEach(x => { x.Items.Where(i => i.EntityState == EntityState.Unchanged) .ToList() .ForEach(i => { x.Items.Remove(i); }); sqlMediaBin.Containers.Remove(x); context.DeleteObject(x); }); foreach (Services.Contracts.Comment comment in project.Comments) { uriString = comment.Id.ToString(); Comment sqlComment = sqlProject.Comments.Where(m => m.Id == uriString).FirstOrDefault(); if (sqlComment == null) { sqlComment = new Comment { Id = uriString }; sqlProject.Comments.Add(sqlComment); } SqlDataProviderTranslator.ConvertToSqlComment(comment, sqlComment); } sqlProject.Comments.Where(x => x.EntityState == EntityState.Unchanged) .ToList() .ForEach(x => { sqlProject.Comments.Remove(x); context.DeleteObject(x); }); foreach (Services.Contracts.Track track in project.Timeline) { uriString = track.Id.ToString(); Track sqlTrack = sqlProject.Tracks.Where(m => m.Id == uriString).FirstOrDefault(); if (sqlTrack == null) { sqlTrack = new Track { Id = uriString }; sqlProject.Tracks.Add(sqlTrack); } SqlDataProviderTranslator.ConvertToSqlTrack(track, sqlTrack); foreach (Services.Contracts.Shot shot in track.Shots) { uriString = shot.Id.ToString(); Shot sqlShot = sqlTrack.Shots.Where(m => m.Id == uriString).FirstOrDefault(); if (sqlShot == null) { sqlShot = new Shot { Id = uriString }; sqlTrack.Shots.Add(sqlShot); } SqlDataProviderTranslator.ConvertToSqlShot(shot, sqlShot, items); foreach (Services.Contracts.Comment comment in shot.Comments) { uriString = comment.Id.ToString(); Comment sqlComment = sqlProject.Comments.Where(m => m.Id == uriString).FirstOrDefault(); if (sqlComment == null) { sqlComment = new Comment { Id = uriString }; sqlShot.Comments.Add(sqlComment); } else if (sqlComment.EntityState == EntityState.Added) { sqlShot.Comments.Add(sqlComment); } SqlDataProviderTranslator.ConvertToSqlComment(comment, sqlComment); } sqlShot.Comments.Where(x => x.EntityState == EntityState.Unchanged) .ToList() .ForEach(x => { sqlProject.Comments.Remove(x); context.DeleteObject(x); }); } sqlTrack.Shots.Where(x => x.EntityState == EntityState.Unchanged) .ToList() .ForEach(x => { sqlTrack.Shots.Remove(x); context.DeleteObject(x); }); } sqlProject.Tracks.Where(x => x.EntityState == EntityState.Unchanged) .ToList() .ForEach(x => { sqlProject.Tracks.Remove(x); context.DeleteObject(x); }); foreach (Services.Contracts.Title title in project.Titles) { uriString = title.Id.ToString(); Title sqlTitle = sqlProject.Titles.Where(m => m.Id == uriString).FirstOrDefault(); if (sqlTitle == null) { sqlTitle = new Title { Id = uriString }; string tempId = title.TitleTemplate.Id.ToString(); sqlTitle.TitleTemplate = context.TitleTemplate.Where(m => m.Id == tempId).FirstOrDefault(); sqlProject.Titles.Add(sqlTitle); } SqlDataProviderTranslator.ConvertToSqlTitle(title, sqlTitle); } sqlProject.Titles.Where(x => x.EntityState == EntityState.Unchanged) .ToList() .ForEach(x => { sqlProject.Titles.Remove(x); context.DeleteObject(x); }); context.SaveChanges(); return(true); } catch (Exception ex) { this.Log(ex); return(false); } }