public void ShouldConvertTrackToSqlTrack()
        {
            var track    = SqlHelper.CreateTrack();
            var sqlTrack = new SqlTrack();

            SqlDataProviderTranslator.ConvertToSqlTrack(track, sqlTrack);

            SqlHelper.AssertTrack(track, sqlTrack);
        }
Ejemplo n.º 2
0
        /// <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();
                }
            }
        }
Ejemplo n.º 3
0
        /// <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);
            }
        }