예제 #1
0
        protected virtual void JobRefresh()
        {
            IEnumerable <Job> jobs = GetJobs();

            var handles = _jobEntities.Keys.ToList();

            foreach (var job in jobs)
            {
                var jobDetail = new JobEntity();

                var handleStr      = job.Handle.ToString();
                var containsHandle = handles.Contains(handleStr);
                if (containsHandle)
                {
                    jobDetail = _jobEntities[handleStr];
                    handles.Remove(handleStr);
                }

                MapJobEntity(job, jobDetail);

                if (!containsHandle)
                {
                    PublishingStats.NumberOfPublishes++;

                    _jobEntities.TryAdd(handleStr, jobDetail);
                }
            }

            foreach (var handle in handles)
            {
                JobEntity expiredJob;
                _jobEntities.TryGetValue(handle, out expiredJob);

                if (expiredJob.EndTime == null)
                {
                    expiredJob.EndTime = DateTime.UtcNow;
                }
            }


            var removeJobs = _jobEntities.Where(x => x.Value.EndTime.HasValue);

            //remove any remaining handle
            foreach (var job in removeJobs)
            {
                JobEntity finishedEntity;

                if (job.Value.EndTime < DateTime.UtcNow.AddMinutes(-2))
                {
                    _jobEntities.TryRemove(job.Key, out finishedEntity);
                }
                else
                {
                    _jobEntities.TryGetValue(job.Key, out finishedEntity);
                }

                if (finishedEntity != null && finishedEntity.StatsProcessed == false)
                {
                    finishedEntity.StatsProcessed = true;
                    UpdateStats(finishedEntity);
                }
            }


            PublishingStats.NumberOfQueuedPublishes = _jobEntities.Count(x => x.Value.Status == JobState.Queued);
        }
예제 #2
0
        protected JobEntity MapJobEntity(Job job, JobEntity jobDetail)
        {
            PublishOptions[] publishOptions = (Sitecore.Publishing.PublishOptions[])(job.Options.Parameters[0]);
            PublishStatus    publishStatus  = ((Sitecore.Publishing.PublishStatus)(job.Options.Parameters[1]));

            jobDetail.Handle      = job.Handle;
            jobDetail.JobName     = job.Name;
            jobDetail.JobCategory = job.Category;
            jobDetail.QueueTime   = job.QueueTime;

            jobDetail.Mode         = publishOptions[0].Mode.ToString();
            jobDetail.IsSingleItem = jobDetail.Mode.ToLower().Equals(SingleItem);

            var currentStatus = publishStatus.State;

            if (currentStatus != JobState.Queued && jobDetail.StartTime == null)
            {
                jobDetail.StartTime = DateTime.UtcNow;
            }
            if (currentStatus == JobState.Finished && jobDetail.EndTime == null)
            {
                jobDetail.EndTime = DateTime.UtcNow;
            }
            if (currentStatus == JobState.Running)
            {
                jobDetail.EndTime = null;
            }

            jobDetail.Status = currentStatus;

            if (!String.IsNullOrEmpty(job.Options.ContextUser.Name))
            {
                jobDetail.Owner = job.Options.ContextUser.Name.ToString();
            }

            if (publishStatus.CurrentLanguage != null)
            {
                jobDetail.CurrentLanguage = publishStatus.CurrentLanguage.CultureInfo.DisplayName.ToString();
            }

            if (publishStatus.CurrentTarget != null)
            {
                jobDetail.CurrentTargetDatabase = publishStatus.CurrentTarget.Name.ToString();
            }

            jobDetail.Processed = publishStatus.Processed;

            if (jobDetail.IsSingleItem)
            {
                jobDetail.ItemName = publishOptions[0].RootItem.Paths.Path;

                jobDetail.Processed = publishStatus.Processed;
            }
            else
            {
                jobDetail.ItemName = "Full Site";
            }

            jobDetail.SourceDatabase = publishOptions[0].SourceDatabase.Name.ToString();

            List <string> targetDbs       = new List <string>();
            List <string> targetLanguages = new List <string>();

            foreach (PublishOptions publishoptions in publishOptions)
            {
                if (!targetDbs.Contains(publishoptions.TargetDatabase.Name))
                {
                    targetDbs.Add(publishoptions.TargetDatabase.Name);
                }

                if (!targetLanguages.Contains(publishoptions.Language.CultureInfo.Name))
                {
                    targetLanguages.Add(publishoptions.Language.CultureInfo.Name);
                }

                var messages = publishStatus.Messages;

                if (messages.Count > 0)
                {
                    if (jobDetail.Message.Count < messages.Count)
                    {
                        for (int i = jobDetail.Message.Count; i < messages.Count; i++)
                        {
                            var message = messages[i];
                            jobDetail.Message.Add(message);
                        }
                    }
                }
            }


            jobDetail.TargetDatabase = targetDbs.ToArray();

            jobDetail.Languages = targetLanguages;

            return(jobDetail);
        }