Exemple #1
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);
        }
        /// <summary>
        /// Returns back all of the items that are contained in the library filtering them using the filter provided.
        /// </summary>
        /// <param name="libraryId">The <see cref="Uri"/> of the container to load from the library.</param>
        /// <param name="filter">The filter used to get the items.</param>
        /// <param name="maxNumberOfItems">Maximum no. of records in the result.</param>
        /// <returns>A <see cref="Container"/> with the items.</returns>
        private static RCE.Services.Contracts.Container LoadLibrary(Uri libraryId, string filter, int maxNumberOfItems)
        {
            RoughCutEditorEntities context = new RoughCutEditorEntities {
                CommandTimeout = DefaultCommandTimeout
            };

            string uriString = libraryId.ToString();

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

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

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

            ObjectQuery <Item> query = context.Item;

            // .Include("Resources")
            // .Include("Resources.VideoFormat")
            // .Include("Resources.AudioFormat")
            // .Include("Resources.ImageFormat")
            if (maxNumberOfItems > 0)
            {
                query.Top(maxNumberOfItems.ToString(CultureInfo.InvariantCulture));
            }

            IQueryable <Item> items = query.Where(x => x.Container.FirstOrDefault().Id == sqlContainer.Id)
                                      .SelectMany(x => x.Resources.Where(r => r.ResourceType != "LiveSmoothStream"))
                                      .Select(x => x.Item);

            RCE.Services.Contracts.Container library = null;

            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);
            }

            return(library);
        }