Exemple #1
0
        /// <summary>
        /// Builds the whole index by indexing all the items in the specified
        /// repository.
        /// </summary>
        /// <param name="repository">The repository.</param>
        /// <param name="filter">The optional item filter; paging information
        /// will be overwritten.</param>
        /// <param name="cancel">The cancellation token.</param>
        /// <param name="progress">The optional progress reporter.</param>
        public void Build(
            ICadmusRepository repository,
            ItemFilter filter,
            CancellationToken cancel,
            IProgress <ProgressReport> progress = null)
        {
            if (filter == null)
            {
                filter = new ItemFilter();
            }
            filter.PageNumber = 1;
            filter.PageSize   = 100;

            // first page
            DataPage <ItemInfo> page = repository.GetItems(filter);

            if (page.Total == 0)
            {
                return;
            }

            ProgressReport report = progress != null
                ? new ProgressReport()
                : null;

            do
            {
                // index all the items in page
                foreach (ItemInfo info in page.Items)
                {
                    IItem item = repository.GetItem(info.Id);
                    if (item == null)
                    {
                        continue;
                    }
                    _writer.Write(item);
                }

                // handle cancel and progress
                if (cancel.IsCancellationRequested)
                {
                    break;
                }

                if (progress != null)
                {
                    report.Count  += page.Items.Count;
                    report.Percent = report.Count * 100 / page.Total;
                    progress.Report(report);
                }

                // next page
                if (++filter.PageNumber > page.PageCount)
                {
                    break;
                }
                page = repository.GetItems(filter);
            } while (page.Items.Count != 0);
        }
        public ActionResult <IItem> GetItem(
            [FromRoute] string database,
            [FromRoute] string id,
            [FromQuery] bool parts)
        {
            ICadmusRepository repository =
                _repositoryProvider.CreateRepository(database);
            IItem item = repository.GetItem(id, parts);

            if (item == null)
            {
                return(new NotFoundResult());
            }
            return(Ok(item));
        }
        public ActionResult <PartDefinition> GetFacetFromItemId(
            string database,
            [FromRoute] string id)
        {
            ICadmusRepository repository =
                _repositoryProvider.CreateRepository(database);

            IItem item = repository.GetItem(id, false);

            if (item?.FacetId == null)
            {
                return(NotFound());
            }

            FacetDefinition facet = repository.GetFacetDefinition(item.FacetId);

            if (facet == null)
            {
                return(NotFound());
            }
            return(Ok(facet));
        }
        public ActionResult <PartDefinition[]> GetFacetPartsFromItem(
            string database,
            [FromRoute] string id,
            [FromQuery] bool noRoles = false)
        {
            ICadmusRepository repository =
                _repositoryProvider.CreateRepository(database);

            IItem item = repository.GetItem(id, false);

            PartDefinition[] result;

            if (item?.FacetId != null)
            {
                FacetDefinition facet = repository.GetFacetDefinition(item.FacetId);
                result = CollectFacetParts(facet, noRoles);
            }
            else
            {
                result = Array.Empty <PartDefinition>();
            }

            return(Ok(result));
        }