Exemplo n.º 1
0
        private void LoadReportFromSession(decimal Id)
        {
            try
            {
                _report = (FI.BusinessObjects.OlapReport)Session["Report"];
            }
            catch (InvalidCastException exc)
            {
                if (Id == -1)
                {
                    throw new Exception("Cannot load report from session");
                }

                LoadReportFromId(Id);
            }

            if (_report.ID != Id || _report.State == Report.StateEnum.Closed)
            {
                if (_report.State == Report.StateEnum.Executing)
                {
                    _report.CancelExecute();                     // if report was executing , and not current, cancel it
                }
                LoadReportFromId(Id);
            }
        }
Exemplo n.º 2
0
        public Report GetReport(decimal ID, System.Type ReportType, bool Open)
        {
            Report report = null;

            if (ReportType == typeof(OlapReport))
            {
                report = new OlapReport(ID, this._owner);
            }
            else if (ReportType == typeof(StorecheckReport))
            {
                report = new StorecheckReport(ID, this._owner);
            }
            else if (ReportType == typeof(CustomSqlReport))
            {
                report = new CustomSqlReport(ID, this._owner);
            }
            else if (ReportType == typeof(CustomMdxReport))
            {
                report = new CustomMdxReport(ID, this._owner);
            }
            else
            {
                throw new Exception("ReportType " + ReportType.ToString() + " is not supported");
            }

            if (Open)
            {
                report.Open();
            }

            report.StartExecuteEvent += new EventHandler(report_StartExecuteEvent);
            report.EndExecuteEvent   += new EventHandler(report_EndExecuteEvent);
            return(report);
        }
Exemplo n.º 3
0
        public Controller(FI.BusinessObjects.OlapReport Report , System.Web.UI.Page Page)
        {
            if(Report==null)
                throw new NullReferenceException();

            _report=Report;
            _page=Page;
        }
        protected void BackButton_Click(object sender, System.EventArgs e)
        {
            _report.Close(false);
            string reportId=_user.ReportSystem.GetReportTypeCode(_report.GetType()).ToString();

            _report=null;
            Response.Redirect(Request.ApplicationPath + "/ReportList.aspx?content=List&rpttype=" + reportId);
        }
Exemplo n.º 5
0
        private void BackButton_Click(object sender, System.EventArgs e)
        {
            _report.Close(false);
            string reportId = _user.ReportSystem.GetReportTypeCode(_report.GetType()).ToString();

            _report = null;
            Response.Redirect(Request.ApplicationPath + "/ReportList.aspx?content=List&rpttype=" + reportId);
        }
Exemplo n.º 6
0
        public Controller(FI.BusinessObjects.OlapReport Report, System.Web.UI.Page Page)
        {
            if (Report == null)
            {
                throw new NullReferenceException();
            }

            _report = Report;
            _page   = Page;
        }
        protected override void LoadSession()
        {
            base.LoadSession();

            //debug
            //LoadReport();
            //return;

            if(Session["Report"]==null)
                throw new Exception("Session failure : report");

            _report=(FI.BusinessObjects.OlapReport)Session["Report"];
        }
        public void SendDistribution(decimal distributionId, DateTime getCacheFrom, Guid olapTaskGuid, out bool isFromCache)
        {
            try
            {
                isFromCache = false;

                FI.DataAccess.Distributions dacObj = DataAccessFactory.Instance.GetDistributionsDA();
                decimal userId = dacObj.GetDistributionOwnerId(distributionId);
                if (userId <= 0)
                {
                    return;
                }

                User         user   = new User(userId, true);
                Distribution distr  = user.DistributionSystem.GetDistribution(distributionId, true);
                Report       report = distr.Report;

                if (report.IsProxy)
                {
                    report.Open();
                }

                if (report.State == Report.StateEnum.Open)
                {
                    OlapReport olapRpt = report as OlapReport;
                    if (olapRpt != null)
                    {
                        olapRpt.Execute(olapTaskGuid);
                    }
                    else
                    {
                        report.Execute();
                    }
                }

                Contact contact = distr.Contact;
                if (contact.IsProxy)
                {
                    contact.Fetch();
                }


                SendReport(report, new Contact[] { contact }, distr.Format, getCacheFrom, out isFromCache);
            }
            catch (Exception exc)
            {
                Common.LogWriter.Instance.WriteEventLogEntry(exc);
                throw exc;
            }
        }
        public void RefreshCachedReports(string CompanyNameShort)
        {
            Common.LogWriter.Instance.WriteEventLogEntry("Start RefreshCachedReports: " + CompanyNameShort);

            lock (this)
            {
                // check if already being handled
                if (_refreshCachedRequests.Contains(CompanyNameShort))
                {
                    return;
                }
                _refreshCachedRequests.Add(CompanyNameShort);
            }

            int count = 0;

            try
            {
                FI.Common.DataAccess.IUsersDA       userDao = DataAccessFactory.Instance.GetUsersDA();
                FI.Common.DataAccess.IOlapReportsDA rptDao  = DataAccessFactory.Instance.GetOlapReportsDA();

                decimal companyId = userDao.GetCompanyIdByShortName(CompanyNameShort);
                if (companyId <= 0)
                {
                    return;
                }

                Common.Data.FIDataTable tbl = rptDao.GetCashedReportsToRefresh(companyId);
                if (tbl != null)
                {
                    foreach (DataRow row in tbl.Rows)
                    {
                        User       usr = new User((decimal)row["user_id"], false);
                        OlapReport rpt = usr.ReportSystem.GetReport((decimal)row["rpt_id"], typeof(OlapReport), true) as OlapReport;
                        rpt.Execute();
                        count++;
                    }
                }
            }
            catch (Exception exc)
            {
                Common.LogWriter.Instance.WriteEventLogEntry(exc);
                throw exc;
            }
            finally
            {
                _refreshCachedRequests.Remove(CompanyNameShort);
                Common.LogWriter.Instance.WriteEventLogEntry(string.Format("End RefreshCachedReports: Company={0}, Count={1}", CompanyNameShort, count));
            }
        }
        protected override void LoadSession()
        {
            base.LoadSession();

            //debug
            //LoadReport();
            //return;



            if (Session["Report"] == null)
            {
                throw new Exception("Session failure : report");
            }

            _report = (FI.BusinessObjects.OlapReport)Session["Report"];
        }
        protected void btnImport_Click(object sender, System.EventArgs e)
        {
            try
            {
                ArrayList ids = _gr.SelectedPrimaryKeys;
                if (ids != null && ids.Count > 0)
                {
                    string [] key = (string[])ids[0];

                    // import mdx
                    FI.BusinessObjects.OlapReport olapReport = (FI.BusinessObjects.OlapReport)_user.ReportSystem.GetReport(decimal.Parse(key[0]), typeof(FI.BusinessObjects.OlapReport), true);
                    _report.Mdx = olapReport.BuildMdx();
                }

                Server.Transfer("Design.aspx?content=Design", false);
            }
            catch (Exception exc)
            {
                this.ShowException(exc);
            }
        }
Exemplo n.º 12
0
        public void ExecuteAllOlapReports(string CompanyNameShort, int millisecondsTimeout, string logPath)
        {
            if (!System.IO.Path.IsPathRooted(logPath))
            {
                logPath = FI.Common.AppConfig.TempDir + "\\" + logPath;
            }

            FI.Common.DataAccess.IUsersDA dacObj = DataAccessFactory.Instance.GetUsersDA();
            FI.Common.Data.FIDataTable    table  = dacObj.ReadUsers();
            if (table.Rows.Count == 0)
            {
                return;
            }
            table.DefaultView.Sort = "Id asc";

            int errorCount = 0;
            int rptCount   = 1;

            foreach (System.Data.DataRowView userRow in table.DefaultView)
            {
                if (((string)userRow["CompanyNameShort"]).ToUpper() == CompanyNameShort.ToUpper())
                {
                    User user = new User((decimal)userRow["Id"], false);
                    FI.Common.Data.FIDataTable t = user.ReportSystem.GetReportHeaders(typeof(OlapReport));
                    t.DefaultView.Sort = "id asc";

                    string userLog            = string.Format("***************** User id={0}, login='******', password='******'", user.ID, user.Logon, user.Password);
                    System.IO.StreamWriter sw = System.IO.File.AppendText(logPath);
                    sw.WriteLine(userLog);
                    sw.Close();

                    foreach (DataRowView rptRow in t.DefaultView)
                    {
                        if ((byte)rptRow["sharing_status"] == (byte)Report.SharingEnum.InheriteSubscriber ||
                            (byte)rptRow["sharing_status"] == (byte)Report.SharingEnum.SnapshotSubscriber)
                        {
                            continue;
                        }

                        string log = string.Format("{0}\t#{1}\t", DateTime.Now.ToShortTimeString(), rptCount);
                        try
                        {
                            OlapReport rpt = (OlapReport)user.ReportSystem.GetReport((decimal)rptRow["id"], typeof(OlapReport), true);
                            log += string.Format("OlapReport id={0}, name='{1}', description='{2}'", rpt.ID, rpt.Name, rpt.Description);

                            rpt.BeginExecute();
                            int milisecondCount = 0;
                            while (milisecondCount < millisecondsTimeout && rpt.State == Report.StateEnum.Executing)
                            {
                                System.Threading.Thread.Sleep(500);
                                milisecondCount += 500;
                            }

                            if (rpt.State == Report.StateEnum.Executing)
                            {
                                rpt.CancelExecute();
                                log += "\r\n\tcanceled on timeout";
                            }
                            else
                            {
                                rpt.EndExecute();
                                log += "\r\n\tcompleted, cells=" + rpt.Cellset.Axis0PosCount * rpt.Cellset.Axis1PosCount;
                            }
                        }
                        catch (Exception exc)
                        {
                            log += string.Format("exception \r\n\t\t{0}", exc.Message);
                            errorCount++;
                        }
                        rptCount++;

                        sw = System.IO.File.AppendText(logPath);
                        sw.WriteLine(log);
                        sw.Close();
                    }
                }
            }
        }
        private void LoadReportFromSession(decimal Id)
        {
            try
            {
                _report=(FI.BusinessObjects.OlapReport)Session["Report"];
            }
            catch(InvalidCastException exc)
            {
                if(Id==-1)
                    throw new Exception("Cannot load report from session");

                LoadReportFromId(Id);
            }

            if(_report.ID!=Id || _report.State==Report.StateEnum.Closed)
            {
                if(_report.State==Report.StateEnum.Executing)
                    _report.CancelExecute(); // if report was executing , and not current, cancel it

                LoadReportFromId(Id);
            }
        }
 private void LoadReportFromId(decimal Id)
 {
     _report=(FI.BusinessObjects.OlapReport)_user.ReportSystem.GetReport(Id , typeof(FI.BusinessObjects.OlapReport) , true);
     Session["Report"]=_report;
 }
Exemplo n.º 15
0
 private void LoadReportFromId(decimal Id)
 {
     _report           = (FI.BusinessObjects.OlapReport)_user.ReportSystem.GetReport(Id, typeof(FI.BusinessObjects.OlapReport), true);
     Session["Report"] = _report;
 }
        public void SendReport(Report report, Guid olapTaskGuid, Contact[] contacts, Report.ExportFormat Format, DateTime minCacheTimestamp, DateTime currentTimestamp, out bool isFromCache)
        {
            isFromCache = false;

            if (contacts.Length == 0)
            {
                return;
            }

            if (report.IsProxy)
            {
                report.Open();
            }

            string fileNamePattern     = report.GetType().Name + "_" + report.ID.ToString() + "_";
            string newFileName         = fileNamePattern + currentTimestamp.ToString("yyyyMMddHHmmssfff") + "." + Format.ToString();
            string cacheLookupFileName = fileNamePattern + minCacheTimestamp.ToString("yyyyMMddHHmmssfff") + "." + Format.ToString();
            string filePath            = null;
            string reportString        = null;

            // lookup cached report
            if (minCacheTimestamp != DateTime.MinValue && minCacheTimestamp != DateTime.MaxValue)
            {
                string[] lookupPaths = Directory.GetFiles(FI.Common.AppConfig.TempDir, fileNamePattern + "*." + Format.ToString());
                if (lookupPaths != null)
                {
                    foreach (string path in lookupPaths)
                    {
                        string file = Path.GetFileName(path);
                        if (file.Length == cacheLookupFileName.Length && file.CompareTo(cacheLookupFileName) > 0)
                        {
                            filePath    = FI.Common.AppConfig.TempDir + @"\" + file;
                            isFromCache = true;
                            break;
                        }
                    }
                }
            }

            // no cache, execute
            if (filePath == null)
            {
                if (report.State == Report.StateEnum.Open)
                {
                    OlapReport olapRpt = report as OlapReport;
                    if (olapRpt != null)
                    {
                        olapRpt.Execute(olapTaskGuid);
                    }
                    else
                    {
                        report.Execute();
                    }
                }

                filePath = FI.Common.AppConfig.TempDir + @"\" + newFileName;
                report.Export(filePath, Format);
            }


            // send to contacts
            foreach (Contact cnt in contacts)
            {
                if (Format == Report.ExportFormat.HTML && reportString == null)
                {
                    if (cnt.DistributionFormat == Contact.DistributionFormatEnum.MessageBody || cnt.DistributionFormat == Contact.DistributionFormatEnum.Body_And_Attachment)
                    {
                        StreamReader sr = new StreamReader(filePath, System.Text.Encoding.Unicode, true);
                        if (sr != null)
                        {
                            reportString = sr.ReadToEnd();
                            sr.Close();
                        }
                    }
                }

                //send via email
                try
                {
                    if (cnt.IsProxy)
                    {
                        cnt.Fetch();
                    }

                    // message object
                    System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
                    msg.From = new System.Net.Mail.MailAddress(FI.Common.AppConfig.SmtpSender);
                    msg.To.Add(cnt.EMail);
                    msg.Subject = report.Name + " (" + report.Description + ")";
                    //OpenSmtp.Mail.MailMessage msg=new OpenSmtp.Mail.MailMessage();
                    //msg.From=new OpenSmtp.Mail.EmailAddress(FI.Common.AppConfig.SmtpSender);
                    //msg.To.Add(new OpenSmtp.Mail.EmailAddress(cnt.EMail));
                    //msg.Subject=report.Name + " (" + report.Description + ")";

                    // attachment if ordered or report is not html
                    if (cnt.DistributionFormat == Contact.DistributionFormatEnum.Attachment ||
                        cnt.DistributionFormat == Contact.DistributionFormatEnum.Body_And_Attachment ||
                        Format != Report.ExportFormat.HTML)
                    {
                        //OpenSmtp.Mail.Attachment att=new OpenSmtp.Mail.Attachment(filePath);
                        //att.Encoding=System.Web.Mail.MailEncoding.UUEncode;
                        System.Net.Mail.Attachment att = new System.Net.Mail.Attachment(filePath);
                        msg.Attachments.Add(att);
                    }

                    // message body (if retport is html)
                    if (Format == Report.ExportFormat.HTML &&
                        (cnt.DistributionFormat == Contact.DistributionFormatEnum.MessageBody ||
                         cnt.DistributionFormat == Contact.DistributionFormatEnum.Body_And_Attachment))
                    {
                        //msg.HtmlBody=reportString;
                        msg.Body       = reportString;
                        msg.IsBodyHtml = true;
                    }

//					msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "0"); //This is crucial. put 0 there
//					msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout", 90);

                    //OpenSmtp.Mail.SmtpConfig.LogToText=false;

                    System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient();
                    smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
                    smtp.Host           = FI.Common.AppConfig.SmtpServer;
                    smtp.Timeout        = 600000; // 10 minutes
                    if (FI.Common.AppConfig.SmtpPort > 0)
                    {
                        smtp.Port = FI.Common.AppConfig.SmtpPort;
                    }

                    //OpenSmtp.Mail.Smtp smtp=new OpenSmtp.Mail.Smtp();
                    //smtp.SendTimeout=600;
                    //smtp.Host=FI.Common.AppConfig.SmtpServer;
                    if (FI.Common.AppConfig.SmtpUserName != null && FI.Common.AppConfig.SmtpUserName != "")
                    {
                        smtp.Credentials = new System.Net.NetworkCredential(FI.Common.AppConfig.SmtpUserName, FI.Common.AppConfig.SmtpPassword);
                        //smtp.Username=FI.Common.AppConfig.SmtpUserName;
                        //smtp.Password=FI.Common.AppConfig.SmtpPassword;
                    }
                    smtp.Send(msg);
                    //smtp.SendMail(msg);
//					System.Web.Mail.SmtpMail.SmtpServer=FI.Common.AppConfig.SmtpServer;
//					System.Web.Mail.SmtpMail.Send(msg);
                }
                catch (Exception exc)
                {
                    // because real exception is inside:
                    while (exc.InnerException != null)
                    {
                        exc = exc.InnerException;
                    }

                    Common.LogWriter.Instance.WriteEventLogEntry(exc);
                    throw exc;
                }
            }
        }