public override void Process(ServiceProcess process, object arguments)
        {
            while (process.PercentComplete < 100)
            {
                process.IncrementCompletePercentage();
                process.SetStatus("Loading...");

                Random rnd = new Random(DateTime.Now.GetHashCode());
                Thread.Sleep(((int)(rnd.NextDouble() * 4) + 10) * 10);
            }
            process.Complete();
        }
        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");
            }
        }
        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();
			    string[] pageIds;

			    if (parameters.LocationId.EndsWith("-1") || parameters.LocationId.EndsWith("-4")) // Publication or Structure Group
			    {
                    // 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
                     pageIds = GetPageIds(listXml);
			    }
			    else // Component
			    {
                    var readOptions = new ReadOptions();

                    // Get the current component
                    var componentData = (ComponentData)coreService.Read(parameters.LocationId, readOptions);

                    // Get the initial set of using items
                    var filter = new UsingItemsFilterData
                    {
                        BaseColumns = ListBaseColumns.Default,
                        IncludedVersions = VersionCondition.OnlyLatestAndCheckedOutVersions,
                        IncludeLocalCopies = true,
                        ItemTypes = new[] { ItemType.Component, ItemType.Page }
                    };

                    var usingItemsXml = coreService.GetListXml(parameters.LocationId, filter);
                    var pageIdsList = GetPageIds(usingItemsXml).ToList();

                    var level = 1;
                    // We set the depth limit to 10, just so that we will never get an infinite loop in case
                    // component 1 is included within a component 2 that is included within component 1.
                    int depthLimit = 10;

                    var componentIdsList = GetComponentIds(usingItemsXml).ToList();

                    var targets = componentIdsList.Distinct(StringComparer.InvariantCultureIgnoreCase);

                    while (level <= depthLimit && targets.Count() > 0)
                    {
                        var nextTargets = new HashSet<string>();

                        foreach (var targetId in targets)
                        {
                            usingItemsXml = coreService.GetListXml(targetId, filter);
                            pageIdsList.AddRange(GetPageIds(usingItemsXml));
                            foreach (var e in usingItemsXml.Elements())
                            {
                                nextTargets.Add(e.Attribute("ID").Value);
                            }
                        }

                        targets = nextTargets.ToList();
                        level++;
                    }

			        pageIds = pageIdsList.ToArray();
			    }


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