Пример #1
0
        public ScheduledReportProxy GetScheduledReport(int id)
        {
            ScheduledReportProxy proxy = new ScheduledReportProxy();

            try
            {
                ScheduledReport scheduledReport = ScheduledReports.GetScheduledReport(TSAuthentication.GetLoginUser(), id);
                proxy = scheduledReport.GetProxy();
            }
            catch (Exception ex)
            {
                ExceptionLogs.LogException(TSAuthentication.GetLoginUser(), ex, "ReportService.GetScheduledReport");
            }

            return(proxy);
        }
Пример #2
0
        public bool DeleteData(ScheduledReports SRObject)
        {
            bool Delete;

            try
            {
                string SqlQuery = "DELETE FROM [ScheduledReports] WHERE ID=" + SRObject.ID + "";
                Delete = objAdaptor.ExecuteNonQuery(SqlQuery);
            }
            catch
            {
                Delete = false;
            }
            finally
            {
            }
            return(Delete);
        }
Пример #3
0
        public bool InsertData(ScheduledReports SRObject)
        {
            bool Insert = false;

            try
            {
                string SqlQuery = "INSERT INTO [ScheduledReports] (ReportID,Frequency,Days,SpecificDay,SendTo,CopyTo,BlindCopyTo,Title,Body,FileFormat) " +
                                  "VALUES(" + SRObject.ReportID + ",'" + SRObject.Frequency + "','" + SRObject.Days + "'," + SRObject.SpecificDay + "," +
                                  "'" + SRObject.SendTo + "','" + SRObject.CopyTo + "','" + SRObject.BlindCopyTo + "','" + SRObject.Title +
                                  "','" + SRObject.Body + "','" + SRObject.FileFormat + "')";
                Insert = objAdaptor.ExecuteNonQuery(SqlQuery);
            }
            catch
            {
                Insert = false;
            }
            return(Insert);
        }
Пример #4
0
        public int[] DeleteScheduledReports(string reportIDs)
        {
            List <int> result = new List <int>();

            int[] ids = JsonConvert.DeserializeObject <int[]>(reportIDs);
            for (int i = 0; i < ids.Length; i++)
            {
                int             reportID        = ids[i];
                ScheduledReport scheduledReport = ScheduledReports.GetScheduledReport(TSAuthentication.GetLoginUser(), reportID);
                if (scheduledReport != null && scheduledReport.OrganizationId == TSAuthentication.OrganizationID && (TSAuthentication.UserID == scheduledReport.CreatorId || TSAuthentication.IsSystemAdmin))
                {
                    scheduledReport.Delete();
                    scheduledReport.Collection.Save();
                    result.Add(reportID);
                }
            }

            return(result.ToArray());
        }
Пример #5
0
        public bool UpdateData(ScheduledReports SRObject)
        {
            bool Update;

            try
            {
                string SqlQuery = "UPDATE [ScheduledReports] SET ReportID=" + SRObject.ReportID + ",Frequency='" + SRObject.Frequency +
                                  "',Days='" + SRObject.Days + "',SpecificDay=" + SRObject.SpecificDay + ",SendTo='" + SRObject.SendTo +
                                  "',CopyTo='" + SRObject.CopyTo + "',BlindCopyTo='" + SRObject.BlindCopyTo + "',Title='" + SRObject.Title +
                                  "',Body='" + SRObject.Body + "',FileFormat='" + SRObject.FileFormat + "' WHERE ID=" + SRObject.ID + "";
                Update = objAdaptor.ExecuteNonQuery(SqlQuery);
            }
            catch
            {
                Update = false;
            }
            finally
            {
            }
            return(Update);
        }
Пример #6
0
        public string GetScheduledReports()
        {
            List <ScheduledReportItem> result  = new List <ScheduledReportItem>();
            ScheduledReports           reports = new ScheduledReports(TSAuthentication.GetLoginUser());

            try
            {
                reports.LoadAll(TSAuthentication.OrganizationID);

                foreach (ScheduledReport report in reports)
                {
                    result.Add(new ScheduledReportItem(report));
                }
            }
            catch (Exception ex)
            {
                ExceptionLogs.LogException(TSAuthentication.GetLoginUser(), ex, "ReportService.GetScheduledReports");
            }

            return(JsonConvert.SerializeObject(result));
        }
Пример #7
0
        public bool SetScheduledReportIsActive(int scheduledReportId, bool isActive)
        {
            bool isSuccessful = false;

            try
            {
                LoginUser        loginUser        = TSAuthentication.GetLoginUser();
                ScheduledReports scheduledReports = new ScheduledReports(loginUser);
                scheduledReports.LoadById(scheduledReportId);

                if (scheduledReports != null && scheduledReports.Any())
                {
                    scheduledReports[0].IsActive = isActive;

                    if (!isActive)
                    {
                        scheduledReports[0].NextRun = null;
                    }
                    else
                    {
                        scheduledReports[0].SetNextRun();
                    }

                    scheduledReports[0].ModifierId = loginUser.UserID;
                    scheduledReports.Save();
                    isSuccessful = true;
                }
            }
            catch (Exception ex)
            {
                isSuccessful = false;
                ExceptionLogs.LogException(TSAuthentication.GetLoginUser(), ex, "ReportService.SetScheduledReportIsActive");
            }

            return(isSuccessful);
        }
Пример #8
0
        public override void Run()
        {
            ScheduledReports.UnlockThread(LoginUser, (int)_threadPosition);

            while (!IsStopped)
            {
                Logs.WriteHeader("Starting Run");

                try
                {
                    int      waitBeforeLoggingWithoutScheduledReportsDue = 30;
                    DateTime noScheduledReportsDue = DateTime.UtcNow;

                    while (true)
                    {
                        try
                        {
                            if (ServiceStopped)
                            {
                                Logs.WriteHeader("ServiceThread.ServiceStopped");
                                break;
                            }

                            if (IsStopped)
                            {
                                Logs.WriteHeader("IsStopped");
                                break;
                            }

                            ScheduledReport scheduledReport = GetNextScheduledReport(LoginUser.ConnectionString, (int)_threadPosition, Logs);

                            if (scheduledReport != null)
                            {
                                string publicLogPath = TeamSupport.Data.Quarantine.ServiceQ.GetAttachmentPath16(LoginUser, scheduledReport.OrganizationId, scheduledReport.FilePathID);
                                _publicLog = new ReportSenderPublicLog(publicLogPath, scheduledReport.Id, scheduledReport.OrganizationId);
                                Log(string.Format("Date and times used for this log entries are in TimeZone {0}", _publicLog.OrganizationTimeZoneInfo.DisplayName), LogType.Public);
                                QueueEmail(scheduledReport);
                                noScheduledReportsDue = DateTime.UtcNow;
                            }
                            else
                            {
                                if (DateTime.UtcNow.Subtract(noScheduledReportsDue).Minutes >= waitBeforeLoggingWithoutScheduledReportsDue)
                                {
                                    Log(string.Format("No scheduled reports due found in the last {0} minutes", waitBeforeLoggingWithoutScheduledReportsDue));
                                    noScheduledReportsDue = DateTime.UtcNow;
                                }

                                Thread.Sleep(10000);
                                continue;
                            }
                        }
                        catch (Exception ex)
                        {
                            Log("Error sending report email - Ending Thread");
                            Logs.WriteException(ex);
                            ExceptionLogs.LogException(LoginUser, ex, "ReportSender", "Error sending report email");
                        }
                        finally
                        {
                            UpdateHealth();
                        }
                    }
                }
                catch (Exception ex)
                {
                    Logs.WriteException(ex);
                }
                finally
                {
                    Logs.WriteHeader("Exiting.");
                }
            }
        }
Пример #9
0
 public override void ReleaseAllLocks()
 {
     ScheduledReports.UnlockAll(LoginUser);
 }
Пример #10
0
        public int SaveScheduledReport(int scheduledReportId,
                                       int reportId,
                                       string emailSubject,
                                       string emailBody,
                                       string emailAddresses,
                                       Object startOn,
                                       ScheduledReportFrequency frequency,
                                       int every,
                                       int weekday,
                                       int dayOfMonth,
                                       bool isActive)
        {
            try
            {
                LoginUser        loginUser        = TSAuthentication.GetLoginUser();
                ScheduledReports scheduledReports = new ScheduledReports(loginUser);

                if (scheduledReportId == 0)
                {
                    ScheduledReport scheduledReport = scheduledReports.AddNewScheduledReport();
                    scheduledReport.ReportId        = reportId;
                    scheduledReport.EmailSubject    = emailSubject;
                    scheduledReport.EmailBody       = emailBody;
                    scheduledReport.EmailRecipients = emailAddresses;
                    scheduledReport.OrganizationId  = TSAuthentication.OrganizationID;
                    scheduledReport.IsActive        = true;
                    scheduledReport.StartDate       = (DateTime)startOn;
                    scheduledReport.RecurrencyId    = (byte)frequency;
                    scheduledReport.Every           = (byte)every;
                    scheduledReport.Weekday         = (byte)weekday;
                    scheduledReport.Monthday        = (byte)dayOfMonth;
                    scheduledReport.IsActive        = isActive;
                    scheduledReport.FilePathID      = 3;

                    //This needs to be set before SetNextRun because that one needs it to get the timezone to use.
                    scheduledReport.CreatorId = loginUser.UserID;

                    if (isActive)
                    {
                        scheduledReport.SetNextRun();
                    }
                    else
                    {
                        scheduledReport.NextRun = null;
                    }

                    scheduledReport.Collection.Save();

                    scheduledReportId = scheduledReport.Id;
                }
                else
                {
                    scheduledReports.LoadById(scheduledReportId);

                    if (scheduledReports != null && scheduledReports.Any())
                    {
                        scheduledReports[0].EmailSubject    = emailSubject;
                        scheduledReports[0].EmailBody       = emailBody;
                        scheduledReports[0].EmailRecipients = emailAddresses;
                        scheduledReports[0].IsActive        = true;
                        try
                        { scheduledReports[0].StartDate = (DateTime)startOn; }
                        catch (Exception ex) { }
                        scheduledReports[0].RecurrencyId = (byte)frequency;
                        scheduledReports[0].Every        = (byte)every;
                        scheduledReports[0].Weekday      = (byte)weekday;
                        scheduledReports[0].Monthday     = (byte)dayOfMonth;
                        scheduledReports[0].IsActive     = isActive;

                        if (isActive)
                        {
                            scheduledReports[0].SetNextRun();
                        }
                        else
                        {
                            scheduledReports[0].NextRun = null;
                        }

                        scheduledReports[0].ModifierId = loginUser.UserID;
                        scheduledReports.Save();
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionLogs.LogException(TSAuthentication.GetLoginUser(), ex, "ReportService.SaveScheduledReport");
            }

            return(scheduledReportId);
        }
Пример #11
0
        protected void RptApplyButton_Click(object sender, EventArgs e)
        {
            string    doNotProceed = "";
            string    days         = "";
            int       specificday  = 0;
            DataTable dt           = new DataTable();
            int       rID          = -1;
            int       reportID     = 0;

            if (Request.QueryString["ID"] != "" && Request.QueryString["ID"] != null)
            {
                rID = int.Parse(Request.QueryString["ID"]);
            }
            dt = VSWebBL.ConfiguratorBL.ReportsBL.Ins.GetReports(rID);
            try
            {
                if (RptListComboBox.SelectedItem.Text != "")
                {
                    reportID = Convert.ToInt32(RptListComboBox.SelectedItem.Value);
                }
                if (RptFrequencyRadioButtonList.SelectedItem.Value.ToString() == "1")
                {
                    for (int i = 0; i < 7; i++)
                    {
                        if (RptFrequencyCheckBoxList.Items[i].Selected)
                        {
                            if (RptFrequencyCheckBoxList.SelectedItems.Count == 1)
                            {
                                days += RptFrequencyCheckBoxList.SelectedItem.Text;
                            }
                            else
                            {
                                days += RptFrequencyCheckBoxList.Items[i].Text + ",";
                            }
                        }
                    }
                }
                else if (RptFrequencyRadioButtonList.SelectedItem.Value.ToString() == "2")
                {
                    specificday = Convert.ToInt32(RptDayTextBox.Text);
                }
                if (RptFrequencyCheckBoxList.SelectedItems.Count > 1)
                {
                    if (days != "")
                    {
                        days = days.Remove(days.Length - 1);
                    }
                }
                if (RptFrequencyRadioButtonList.SelectedItem.Value.ToString() == "1" && days == "")
                {
                    doNotProceed = "you must select at least one day when Weekly frequency is set.";
                }
                if (doNotProceed == "")
                {
                    if (dt.Rows.Count > 0)
                    {
                        //Update
                        ScheduledReports sr = new ScheduledReports(int.Parse(dt.Rows[0]["ID"].ToString()), reportID,
                                                                   RptFrequencyRadioButtonList.SelectedItem.Text, days, specificday, RptSendToTextBox.Text,
                                                                   RptCopyToTextBox.Text, RptBlindCopyToTextBox.Text, RptSubjectTextBox.Text, RptBodyMemo.Text,
                                                                   RptFileFormatComboBox.SelectedItem.Text);
                        bool updated = VSWebBL.ConfiguratorBL.ReportsBL.Ins.UpdateData(sr);
                    }
                    else
                    {
                        //Insert
                        ScheduledReports sr = new ScheduledReports(0, reportID,
                                                                   RptFrequencyRadioButtonList.SelectedItem.Text, days, specificday, RptSendToTextBox.Text,
                                                                   RptCopyToTextBox.Text, RptBlindCopyToTextBox.Text, RptSubjectTextBox.Text, RptBodyMemo.Text,
                                                                   RptFileFormatComboBox.SelectedItem.Text);
                        bool inserted = VSWebBL.ConfiguratorBL.ReportsBL.Ins.InsertData(sr);
                    }
                    errorDiv.Style.Value            = "display: none";
                    Session["SchedRptUpdateStatus"] = RptListComboBox.SelectedItem.Text;
                    Response.Redirect("Reports.aspx", false);
                    Context.ApplicationInstance.CompleteRequest();
                }
                else
                {
                    errorDiv.Style.Value = "display: block";
                    errorDiv.InnerHtml   = RptListComboBox.SelectedItem.Text.ToString() + " scheduling has failed: " + doNotProceed +
                                           "<button type=\"button\" class=\"close\" data-dismiss=\"alert\"><span aria-hidden=\"true\">&times;</span><span class=\"sr-only\">Close</span></button>";
                }
            }
            catch (Exception ex)
            {
                errorDiv.Style.Value = "display: block";
                errorDiv.InnerHtml   = RptListComboBox.SelectedItem.Text.ToString() + " report scheduling has failed: " + ex.Message +
                                       "<button type=\"button\" class=\"close\" data-dismiss=\"alert\"><span aria-hidden=\"true\">&times;</span><span class=\"sr-only\">Close</span></button>";
                Log.Entry.Ins.WriteHistoryEntry(DateTime.Now.ToString() + " Exception - " + ex);
            }
        }