public void RunReport() { try { QueuedReport rpt = ReportQueue.Instance.GetReport(ReportQueueID, null, false); if (rpt != null) { string errors = rpt.RunReport(); if (string.IsNullOrWhiteSpace(errors)) { EventQueue.Instance.UpdateEventStatus(this.EventQueueID, (int)EventStatusEnum.Complete, DateTime.Now, EventStatusEnum.Complete.ToString(), null); } else { EventQueue.Instance.UpdateEventStatus(this.EventQueueID, (int)EventStatusEnum.Error, DateTime.Now, EventStatusEnum.Error.ToString(), errors); } } else { LogUtility.LogError("Unable to load queued report (" + ReportQueueID + "). Report may have been deleted prior to the event executing."); EventQueue.Instance.UpdateEventStatus(this.EventQueueID, (int)EventStatusEnum.Error, DateTime.Now, EventStatusEnum.Error.ToString(), "Unable to load queued report (" + ReportQueueID + "). Report may have been deleted prior to the event executing."); } } catch (Exception ex) { LogUtility.LogException(ex); EventQueue.Instance.UpdateEventStatus(this.EventQueueID, (int)EventStatusEnum.Error, DateTime.Now, EventStatusEnum.Error.ToString(), ex.Message + " " + ex.StackTrace); } }
public void DownloadReport(long reportQueueID) { QueuedReport rpt = null; string errors = null; // make sure user can view this report before downloading it if (validateID(reportQueueID, false, false, true, out rpt, out errors)) { Response.Clear(); if (rpt.OutFile != null) { Response.AppendHeader("content-disposition", "attachment; filename=\"" + rpt.OutFileName ?? rpt.ReportType + "\""); Response.ContentType = "application/octet-stream"; Response.BinaryWrite(rpt.OutFile); } else { Response.Write("Report has no data (" + reportQueueID + ")."); } } else { Response.Write("User cannot view this report (" + (rpt != null ? rpt.ReportName : "") + ")."); } SetDownloadFinished(ReportKey); Response.Flush(); Response.End(); }
public static Dictionary <string, string> QueueReport( int REPORT_TYPEID, Dictionary <string, string> reportParameters, string scheduledDate) { Dictionary <string, string> result = new Dictionary <string, string>() { { "success", "false" }, { "guid", "" }, { "error", "" } }; DateTime sd = DateTime.MinValue; DateTime.TryParse(scheduledDate, out sd); try { var loggedInMembershipUser = Membership.GetUser(); var loggedInMembershipUserId = loggedInMembershipUser.ProviderUserKey.ToString(); var loggedInUser = new WTS_User(); loggedInUser.Load(loggedInMembershipUserId); QueuedReport rpt = ReportQueue.Instance.QueueReport(Guid.NewGuid().ToString(), loggedInUser.ID, REPORT_TYPEID, sd, reportParameters, reportParameters != null && reportParameters.ContainsKey("Title") ? reportParameters["Title"] : null); IEvent evt = null; if (rpt != null && rpt.ReportQueueID > 0) { evt = EventQueue.Instance.QueueRunReportEvent(rpt.ReportQueueID, DateTime.MinValue); } if (rpt != null && evt != null) { result["success"] = "true"; result["id"] = rpt.ReportQueueID.ToString(); result["guid"] = rpt.Guid; } else { LogUtility.Log("Unable to create report." + (rpt == null || rpt.ReportQueueID == 0 ? " Queued Report cannot be saved." : "") + (evt == null ? " Event could not be created." : "")); } } catch (Exception ex) { result["error"] = ex.Message + " " + ex.StackTrace; LogUtility.LogException(ex); } return(result); }
public static string SaveReports(string changes) { Dictionary <string, string> result = new Dictionary <string, string>() { { "Success", "true" }, { "Error", "" } }; if (!string.IsNullOrWhiteSpace(changes)) { string[] chgArr = changes.Split(';'); foreach (var chg in chgArr) { string[] nv = chg.Split('='); if (nv.Length == 2) { string id = nv[0]; string newValue = nv[1]; QueuedReport rpt = null; string errorMsg = null; if (validateID(Convert.ToInt64(id), false, true, false, out rpt, out errorMsg)) { ReportQueue.Instance.UpdateReportStatus(Convert.ToInt64(id), rpt.REPORT_STATUSID, rpt.ExecutionStartDate, rpt.CompletedDate, rpt.Result, rpt.Error, rpt.OutFileName, null, rpt.OutFileSize, newValue == "1", false); } else { result["Error"] = "Unable to modify report (" + id + "). " + errorMsg; result["Success"] = "false"; break; } } else { result["Error"] = "Invalid tokens in change array."; result["Success"] = "false"; break; } } } return(JsonConvert.SerializeObject(result, Formatting.None)); }
public static string DeleteReport(long reportQueueID) { Dictionary <string, string> result = new Dictionary <string, string>() { { "Exists", "" } , { "Deleted", "" } , { "Archived", "" } , { "Error", "" } }; bool exists = false, deleted = false, archived = false; string errorMsg = string.Empty; QueuedReport rpt = null; if (!validateID(reportQueueID, true, false, false, out rpt, out errorMsg)) { exists = false; deleted = false; archived = false; } else { try { exists = true; deleted = ReportQueue.Instance.DeleteReport(reportQueueID); } catch (Exception ex) { LogUtility.LogException(ex); exists = false; deleted = false; archived = false; errorMsg = ex.Message; } } result["Exists"] = exists.ToString(); result["Deleted"] = deleted.ToString(); result["Archived"] = archived.ToString(); result["Error"] = errorMsg; return(JsonConvert.SerializeObject(result, Formatting.None)); }
private static void SubmitNextReport() { if (QueuedReports.Count < 1) { return; } QueuedReport queuedReport = QueuedReports[0]; submittingReports = true; Webrequests.Enqueue(Url, queuedReport.Body, (code, response) => { if (code == 200) { QueuedReports.RemoveAt(0); submittingReports = false; SubmitNextReport(); } else { Timers.Once(5f, SubmitNextReport); } }, null, RequestMethod.POST, queuedReport.Headers); }
private static bool validateID(long reportQueueID, bool validateDelete, bool validateArchive, bool loadData, out QueuedReport rpt, out string errorMsg) { errorMsg = string.Empty; rpt = null; var loggedInMembershipUser = Membership.GetUser(); var loggedInUser = new WTS_User(); loggedInUser.Load(loggedInMembershipUser.ProviderUserKey.ToString()); if (reportQueueID == 0) { errorMsg = "ReportQueueID missing or invalid."; return(false); } else { rpt = ReportQueue.Instance.GetReport(reportQueueID, null, loadData); if (rpt == null) { errorMsg = "Report (" + reportQueueID + ") is invalid."; return(false); } if (validateDelete && rpt.WTS_RESOURCEID != loggedInUser.ID && !UserCanDeleteReports()) { errorMsg = "User cannot delete this report."; return(false); } if (validateArchive && rpt.WTS_RESOURCEID != loggedInUser.ID && !UserCanArchiveReports()) { errorMsg = "User cannot archive this report."; return(false); } } return(true); }
public static string EmailReport(int reportQueueID, string userIDs, string names, string emails) { Dictionary <string, string> result = new Dictionary <string, string>() { { "Success", "false" }, { "Error", "" } }; QueuedReport rpt = null; string errors = null; try { // first validate that user can see this report; if they can, then we allow them to email it if (validateID(reportQueueID, false, false, true, out rpt, out errors)) { if (rpt.OutFile != null) { string[] emailArr = emails.Split(','); string[] nameArr = names.Split(','); Dictionary <string, string> toAddresses = new Dictionary <string, string>(); for (int i = 0; i < emailArr.Length; i++) { if (!toAddresses.ContainsKey(emailArr[i])) { toAddresses.Add(emailArr[i], nameArr[i]); } } string subject = rpt.ReportName; WTS_User loggedInUser = GetLoggedInUser(); string body = "You have been sent the following report from " + loggedInUser.First_Name + " " + loggedInUser.Last_Name + ": " + rpt.ReportName + " (" + rpt.OutFileName + ")"; string from = WTSConfiguration.EmailFrom; string fromName = WTSConfiguration.EmailFromName; Dictionary <string, byte[]> attachments = new Dictionary <string, byte[]>(); attachments.Add(rpt.OutFileName, rpt.OutFile); WTS.Events.EventQueue.Instance.QueueEmailEvent(toAddresses, null, null, subject, body, from, fromName, false, System.Net.Mail.MailPriority.Normal, attachments, false); result["Success"] = "true"; } else { result["Error"] = "Report (" + reportQueueID + ") contains no data."; } } else { result["Error"] = "User cannot view this report (" + (rpt != null ? rpt.ReportName : "") + ")."; } } catch (Exception ex) { LogUtility.LogException(ex); result["Error"] = ex.Message; } return(JsonConvert.SerializeObject(result, Formatting.None)); }