Beispiel #1
0
        /// <summary>
        /// Loads a project from the repository returning back the details.
        /// </summary>
        /// <param name="site">The <see cref="Uri"/> of the project site.</param>
        /// <returns>The <see cref="Services.Contracts.Project"/> that exists at the specified <see cref="Uri"/>.</returns>
        public Services.Contracts.Project LoadProject(Uri site)
        {
            RoughCutEditorEntities context = null;
            Project project = null;

            try
            {
                context = new RoughCutEditorEntities();
                context.CommandTimeout = DefaultCommandTimeout;

                var projectId = ExtractIdFromUri(site);
                project = LoadProject(projectId, context);

                if (project == null)
                {
                    return(new Services.Contracts.Project());
                }
            }
            finally
            {
                if (context != null)
                {
                    context.Dispose();
                }
            }

            return(SqlDataProviderTranslator.ConvertToProject(project, this.metadataLocator));
        }
Beispiel #2
0
        /// <summary>
        /// Loads the MediaBin <see cref="Container" /> with a <see cref="ItemCollection" /> that contains the items in the media bin.
        /// </summary>
        /// <param name="mediaBinUri">The <see cref="Uri"/> of the media bin to load.</param>
        /// <returns>A <see cref="Container"/> with the media elements for the project.</returns>
        public Services.Contracts.MediaBin LoadMediaBin(Uri mediaBinUri)
        {
            Container mediaBin             = null;
            RoughCutEditorEntities context = null;

            try
            {
                context = new RoughCutEditorEntities();
                context.CommandTimeout = 180;

                var id = ExtractIdFromUri(mediaBinUri);

                mediaBin =
                    context.Container.Include("Items")
                    .Include("Items.Resources")
                    .Include("Items.Resources.VideoFormat")
                    .Include("Items.Resources.AudioFormat")
                    .Include("Items.Resources.ImageFormat")
                    .Include("Containers")
                    .Where(x => x.Id == id)
                    .FirstOrDefault();
            }
            finally
            {
                if (context != null)
                {
                    context.Dispose();
                }
            }

            return(SqlDataProviderTranslator.ConvertToMediaBin(mediaBin, this.metadataLocator));
        }
Beispiel #3
0
        /// <summary>
        /// Get the projects collection of the given user.
        /// </summary>
        /// <param name="userName">The name of the user.</param>
        /// <returns>A <see cref="ProjectCollection"/> with all the projects of the user.</returns>
        public ProjectCollection GetProjectsByUser(string userName)
        {
            RoughCutEditorEntities context  = default(RoughCutEditorEntities);
            List <Project>         projects = default(List <Project>);

            try
            {
                context = new RoughCutEditorEntities();

                projects = context.Project.Include("MediaBin").Where(x => x.Creator == userName).ToList();
            }
            finally
            {
                if (context != null)
                {
                    context.Dispose();
                }
            }

            return(SqlDataProviderTranslator.ConvertToProjects(projects, this.metadataLocator));
        }
Beispiel #4
0
        /// <summary>
        /// Loads a <see cref="TitleTemplate"/> from the repository.
        /// </summary>
        /// <returns>The <see cref="TitleTemplateCollection"/> of the titles template that were loaded.</returns>
        public TitleTemplateCollection LoadTitleTemplates()
        {
            RoughCutEditorEntities context        = null;
            List <TitleTemplate>   titleTemplates = null;

            try
            {
                context = new RoughCutEditorEntities();
                context.CommandTimeout = DefaultCommandTimeout;
                titleTemplates         = context.TitleTemplate.ToList();
            }
            finally
            {
                if (context != null)
                {
                    context.Dispose();
                }
            }

            return(SqlDataProviderTranslator.ConvertToTitleTemplates(titleTemplates));
        }
Beispiel #5
0
        private RCE.Services.Contracts.Container LoadLibrary(Uri libraryId, string filter, int maxNumberOfItems)
        {
            RCE.Services.Contracts.Container library = null;
            RoughCutEditorEntities           context = null;

            try
            {
                context = new RoughCutEditorEntities();
                context.CommandTimeout = DefaultCommandTimeout;

                var id = ExtractIdFromUri(libraryId);

                ObjectQuery <Container> sqlContainerQuery = context.Container.Include("Containers");

                if (!string.IsNullOrEmpty(filter))
                {
                    sqlContainerQuery = sqlContainerQuery.Include("Containers.Items");
                }

                Container sqlContainer = sqlContainerQuery.FirstOrDefault(x => x.Id == id);

                ObjectQuery <Item> query = context.Item;

                if (maxNumberOfItems > 0)
                {
                    query.Top(maxNumberOfItems.ToString(CultureInfo.InvariantCulture));
                }

                IQueryable <Item> items = query.Where(x => x.Container.FirstOrDefault().Id == sqlContainer.Id);

                if (sqlContainer != null)
                {
                    foreach (Item item in items)
                    {
                        if (!item.Resources.IsLoaded)
                        {
                            item.Resources.Load();

                            foreach (Resource resource in item.Resources)
                            {
                                if (!resource.VideoFormatReference.IsLoaded)
                                {
                                    resource.VideoFormatReference.Load();
                                }

                                if (!resource.AudioFormatReference.IsLoaded)
                                {
                                    resource.AudioFormatReference.Load();
                                }

                                if (!resource.ImageFormatReference.IsLoaded)
                                {
                                    resource.ImageFormatReference.Load();
                                }
                            }
                        }
                    }

                    sqlContainer.Items.Attach(items);
                    library = SqlDataProviderTranslator.ConvertToContainer(
                        sqlContainer, filter, maxNumberOfItems, this.metadataLocator);
                }
            }
            finally
            {
                if (context != null)
                {
                    context.Dispose();
                }
            }

            return(library);
        }
Beispiel #6
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();
                }
            }
        }