Ejemplo n.º 1
0
        public override void Process(ServiceProcess process, object arguments)
        {
            PagePublisherParameters parameters = (PagePublisherParameters)arguments;

            process.SetCompletePercentage(0);
            process.SetStatus("Initializing");

            using (var coreService = Client.GetCoreService())
            {
                _pagePublisherData = new PagePublisherData();
                // get a list of the items from the core service
                ItemsFilterData filter  = GetFilter(parameters);
                XElement        listXml = coreService.GetListXml(parameters.LocationId, filter);

                // Get the page id's that will be published
                string[] pageIds      = GetPageIds(listXml);
                int      batchSize    = 5;
                int      currentBatch = 0;

                // Publish pages
                try
                {
                    double ratio      = pageIds.Count() / batchSize;
                    double percentage = 100 / ratio;
                    double currperc   = 0;
                    while (currentBatch * batchSize < pageIds.Count())
                    {
                        string[] nextBatch = pageIds.Skip(currentBatch * batchSize)
                                             .Take(batchSize).ToArray();
                        coreService.Publish(nextBatch, GetPublishInstructionData(parameters), parameters.TargetUri, parameters.Priority, new ReadOptions());
                        currentBatch++;
                        currperc += percentage;
                        if (currperc >= 1)
                        {
                            process.IncrementCompletePercentage();
                            currperc = 0;
                        }
                    }
                    _pagePublisherData.SuccessMessage = string.Format("{0} Pages published successfully", pageIds.Length.ToString());
                }
                catch (Exception ex)
                {
                    //process.Complete(string.Format("Failed to publish, reason: {0}", ex.Message));
                    _pagePublisherData.FailedMessage = string.Format("Page publishing failed, reason {0}", ex.Message);
                }

                process.Complete("done");
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// GetFilter - Creates a ItemFilter which is used to obtain a list of publishable items.
        /// </summary>
        /// <param name="parameters">PagePublisherParameters</param>
        /// <returns>ItemsFilterData object</returns>
        private ItemsFilterData GetFilter(PagePublisherParameters parameters)
        {
            ItemsFilterData filter = null;

            if (parameters.LocationId.EndsWith("-1")) // is Publication
            {
                filter = new RepositoryItemsFilterData();
            }
            else // is Folder or Structure Group
            {
                filter = new OrganizationalItemItemsFilterData();
            }

            filter.Recursive = parameters.Recursive;
            List <ItemType> itemTypesList = new List <ItemType>();

            itemTypesList.Add(ItemType.Page);
            filter.ItemTypes = itemTypesList.ToArray();
            return(filter);
        }
Ejemplo n.º 3
0
        public ItemCountResult GetCount(GetCountParameters parameters)
        {
            try
            {
                if (parameters == null || parameters.OrganizationalItemId == null)
                {
                    throw new ArgumentNullException("parameters");
                }

                DateTime        start   = DateTime.Now;
                ItemsFilterData filter  = GetFilter(parameters);
                XElement        listXml = Client.GetListXml(parameters.OrganizationalItemId, filter);

                return(ProcessCounts(listXml, start));
            }
            catch (Exception ex)
            {
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message));
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Contains actual processing logic: instantiates a CoreService client, queries for item list,
        /// then sets the actual response counts data object, while updating the progress all along.
        /// </summary>
        /// <param name="process">the current ServiceProcess</param>
        /// <param name="arguments">CountItemsParameters arguments</param>
        public override void Process(ServiceProcess process, object arguments)
        {
            CountItemsParameters parameters = (CountItemsParameters)arguments;

            process.SetCompletePercentage(25);
            process.SetStatus("Initializing");

            using (var coreService = Client.GetCoreService())
            {
                ItemsFilterData filter = GetFilter(parameters);
                process.SetCompletePercentage(50);
                process.SetStatus("Retrieving count data");

                XElement listXml = coreService.GetListXml(parameters.OrgItemUri, filter);
                process.SetCompletePercentage(75);
                process.SetStatus("Extracting item counts");

                ProcessCounts(listXml);
                process.Complete("Done");
            }
        }