public void Process(Item[] items, Sitecore.Tasks.CommandItem commandItem, ScheduleItem schedule) { CheckboxField active = commandItem.InnerItem.Fields["active"]; if (active.Checked) { //prepare email message string from = commandItem["from"]; string to = commandItem["to"]; string subject = commandItem["subject"]; MailMessage message = new MailMessage(from, to) { Subject = subject, }; //attach reports in excel format MultilistField reportReferences = commandItem.InnerItem.Fields["reports"]; foreach (Item item in reportReferences.GetItems()) { ReportItem reportItem = null; Report report = null; try { reportItem = new ReportItem(item); report = new Report(); foreach (var sItem in reportItem.Scanners) { report.AddScanner(sItem); } foreach (var vItem in reportItem.Viewers) { report.AddViewer(vItem); } foreach (var fItem in reportItem.Filters) { report.AddFilter(fItem); } report.Run(); //attach to mail message string tempPath = new ASR.Export.HtmlExport(report, reportItem).SaveFile("Automated report " + reportItem.Name, "xls"); Attachment newAttachment = new Attachment(tempPath); message.Attachments.Add(newAttachment); } catch (Exception ex) { message.Body += String.Format("An error occured while running '{0}'\n{1}\n\n", reportItem.Name, ex.ToString()); } } MainUtil.SendMail(message); } }
public void Start(ClientPipelineArgs args) { if (!args.IsPostBack) { Util.ShowItemBrowser( "Select the report", "Select the report", "Database/32x32/view_h.png", "Select", Current.Context.Settings.ReportsFolder, Current.Context.ReportItem == null ? Current.Context.Settings.ReportsFolder : Current.Context.ReportItem.Path, Current.Context.Settings.ConfigurationDatabase); args.WaitForPostBack(); } else { if (!Sitecore.Data.ID.IsID(args.Result)) { return; } Database database = Sitecore.Configuration.Factory.GetDatabase(Current.Context.Settings.ConfigurationDatabase); Sitecore.Diagnostics.Assert.IsNotNull(database,"no configuration databsae"); Item item = database.GetItem(args.Result); Sitecore.Diagnostics.Assert.IsNotNull(item, "report item cannot be loaded"); switch(item.Template.Key) { case "report": ReportItem rItem = new ReportItem(item); if (rItem != null) { Current.Context.ReportItem = rItem; Current.Context.Report = null; Sitecore.Context.ClientPage.SendMessage(this, "ASR.MainForm:update"); } break; case "saved report": Message m = Message.Parse(this, "ASR.MainForm:openlink"); System.Collections.Specialized.NameValueCollection nvc = Sitecore.StringUtil.ParseNameValueCollection(item["parameters"], '&', '='); m.Arguments.Add(nvc); Sitecore.Context.ClientPage.SendMessage(m); break; } } }
public HtmlExport(Report report, ReportItem reportItem) { this.report = report; this.reportItem = reportItem; }
public static ReportItem CreateFromParameters(NameValueCollection nvc) { Assert.IsNotNull(nvc, "Incorrect Parameters Format"); var id = nvc["id"]; if (id == null) return null; var database = Sitecore.Configuration.Factory.GetDatabase(Settings.Instance.ConfigurationDatabase); var reportItem = new ReportItem(database.GetItem(id)); if (reportItem == null) throw new Exception("Report has been deleted"); foreach (string key in nvc.Keys) { if (key.Contains("^")) { var item_parameter = key.Split('^'); var guid = new ID(item_parameter[0]); var ri = reportItem.FindItem(guid); if (ri != null) { ri.SetAttributeValue(item_parameter[1], nvc[key]); } } } return reportItem; }