Exemplo n.º 1
0
        /// <summary>
        /// Publishes all scheduled items for time period
        /// </summary>
        /// <param name="fromDate">Start of the period</param>
        /// <param name="toDate">End of the period</param>
        private void PublishSchedules(DateTime fromDate, DateTime toDate)
        {
            IEnumerable <PublishSchedule> duePublishSchedules = _scheduledPublishRepo.GetUnpublishedSchedules(fromDate, toDate);

            if (duePublishSchedules == null)
            {
                Log.Info(string.Format("Scheduled Publish: No publish schedules from {0} to {1}",
                                       fromDate.ToString(Context.Culture),
                                       toDate.ToString(Context.Culture)), this);
                return;
            }

            foreach (var schedule in duePublishSchedules)
            {
                Handle handle = ScheduledPublishManager.Publish(schedule);
                ScheduledPublishReport report = ScheduledPublishManager.GetScheduledPublishReport(handle);
                if (report.IsSuccessful)
                {
                    MarkAsPublished(schedule);
                }

                if (ScheduledPublishSettings.IsSendEmailChecked)
                {
                    try
                    {
                        MailManager.SendEmail(report.Message, schedule.ItemToPublish, schedule.SchedulerUsername);
                    }
                    catch (Exception ex)
                    {
                        Log.Error(string.Format("{0} {1}", "Scheduled Publish: Sending publish email confirmation failed.", ex), schedule);
                    }
                }
            }
        }
        /// <summary>
        /// Gets a report on the handle.
        /// </summary>
        /// <param name="handle">Handle.</param>
        /// <returns>A <see cref="T:ScheduledPublish.Models.ScheduledPublishReport"/> report on the handle result.</returns>
        public static ScheduledPublishReport GetScheduledPublishReport(Handle handle)
        {
            bool          isSuccessful = false;
            StringBuilder sbMessage    = new StringBuilder();

            if (handle == null)
            {
                sbMessage.Append("Final Status: Fail.<br/>");
                sbMessage.Append("Please, check log files for more information.<br/>");
            }
            else
            {
                PublishStatus status = PublishManager.GetStatus(handle);

                if (status == null)
                {
                    sbMessage.Append("The scheduled publishing process was unexpectedly interrupted.<br/>");
                    sbMessage.Append("Please, check log files for more information.<br/>");
                }
                else
                {
                    if (status.Failed)
                    {
                        sbMessage.Append("Final Status: Fail.<br/>");
                        sbMessage.Append("Please, check log files for more information.<br/>");
                    }
                    else if (status.IsDone)
                    {
                        sbMessage.Append("Final Status: Success.<br/>");
                        isSuccessful = true;
                    }

                    sbMessage.AppendFormat("Items processed: {0}.<br/><br/>", status.Processed);

                    if (status.Messages != null)
                    {
                        sbMessage.Append("Detailed Information:<br/>");

                        foreach (var message in status.Messages)
                        {
                            sbMessage.Append(message);
                            sbMessage.Append("<br/>");
                        }
                    }
                }
            }

            ScheduledPublishReport report = new ScheduledPublishReport
            {
                IsSuccessful = isSuccessful,
                Message      = sbMessage.ToString()
            };

            return(report);
        }