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