/// <summary>
        /// Execute the report
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Init(object sender, EventArgs e)
        {
            var reportName = Request.QueryString["reportName"].ToString();
            var sessionId  = Request.QueryString["session"];

            var token = Request.Form["hiddenToken"];

            if (token == null)
            {
                token = Guid.NewGuid().ToString();
            }

            hiddenToken.Value = token;

            string reportDocumentKey = "ReportDocument_" + token;

            if (string.IsNullOrEmpty(reportName))
            {
                errorLabel.Text = CommonResx.ReportGenFailedMessage;
                return;
            }

            var report = new Sage.CA.SBS.ERP.Sage300.Common.Models.Reports.Report();

            report.Context = JsonSerializer.Deserialize <Sage.CA.SBS.ERP.Sage300.Common.Models.Context>(Session["Context"].ToString());
            CommonUtil.SetCulture(report.Context.Language);

            report.Context.Container = ConfigurationHelper.Container;

            var  reportDocument = InMemoryCacheProvider.Instance.Get <SageWebReportDocument>(reportDocumentKey);
            bool isNew;

            if (reportDocument == null)
            {
                using (var session = BusinessPoolManager.GetSession(report.Context, DBLinkType.Company, out isNew))
                {
                    var repository = report.Context.Container.Resolve <ILandlordRepository>();
                    var reportPath = repository.GetSharedDirectory(report.Context.TenantId);
                    CommonUtil.ValidatePathName(reportPath);
                    CommonUtil.ValidateFileName(reportName);
                    var reportFullName = Path.Combine(reportPath, "Reports", reportName);
                    var accpacReport   = session.SelectReport(reportFullName, "", null);

                    var userId = session.GetSession().UserID;
                    EvictUserWatcher.AddUserIdToPauseEviction(userId);
                    var doc = accpacReport.GetReportDocument();
                    reportDocument = new SageWebReportDocument(doc, session, accpacReport);

                    EvictUserWatcher.RemoveUserIdFromPauseEviction(userId);
                }
                InMemoryCacheProvider.Instance.Set(reportDocumentKey, reportDocument, ConfigurationHelper.ReportCacheExpirationInMinutes);
            }

            if (reportDocument != null)
            {
                CrystalReportViewerSage300.ReportSource = reportDocument.CrystalReportDocument;
                CrystalReportViewerSage300.DataBind();
            }
        }
Exemple #2
0
        /// <summary>
        /// Execute the report
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Init(object sender, EventArgs e)
        {
            var reportName = Request.QueryString["reportName"].ToString();
            var sessionId  = Request.QueryString["session"];

            if (string.IsNullOrEmpty(reportName))
            {
                errorLabel.Text = CommonResx.ReportGenFailedMessage;
                return;
            }

            var report = new Sage.CA.SBS.ERP.Sage300.Common.Models.Reports.Report();

            report.Context = JsonSerializer.Deserialize <Sage.CA.SBS.ERP.Sage300.Common.Models.Context>(Session["Context"].ToString());
            CommonUtil.SetCulture(report.Context.Language);

            report.Context.Container = ConfigurationHelper.Container;

            ReportDocument reportDocument;
            bool           isNew;

            using (var session = BusinessPoolManager.GetSession(report.Context, DBLinkType.Company, out isNew))
            {
                var repository = report.Context.Container.Resolve <ILandlordRepository>();
                var reportPath = repository.GetSharedDirectory(report.Context.TenantId);
                CommonUtil.ValidatePathName(reportPath);
                CommonUtil.ValidateFileName(reportName);
                var reportFullName = Path.Combine(reportPath, "Reports", reportName);
                var accpacReport   = session.SelectReport(reportFullName, "", null);

                var userId = session.GetSession().UserID;
                EvictUserWatcher.AddUserIdToPauseEviction(userId);
                reportDocument = accpacReport.GetReportDocument();
                EvictUserWatcher.RemoveUserIdFromPauseEviction(userId);
            }

            if (reportDocument != null)
            {
                CrystalReportViewerSage300.ReportSource = reportDocument;
                CrystalReportViewerSage300.DataBind();
            }
        }
        /// <summary>
        /// Execute the report
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Init(object sender, EventArgs e)
        {
            var    token             = Request.QueryString["token"];
            var    sessionId         = Request.QueryString["session"];
            string reportDocumentKey = "ReportDocument_" + token;

            // set the page hidden variable.
            hiddenToken.Value     = token;
            hiddenSessionId.Value = sessionId;

            var report = GetReport(token, sessionId);

            if (report == null)
            {
                errorLabel.Text = CommonResx.ReportGenFailedMessage;
                return;
            }

            CommonUtil.SetCulture(report.Context.Language);

            // Check whether this report belongs to the same user.If not don't do anything.
            if (report.Context.SessionId != sessionId)
            {
                errorLabel.Text = CommonResx.NotAuthorizedMesage;
                return;
            }

            report.Context.Container = ConfigurationHelper.Container;

            bool isNew;

            var reportDocument = InMemoryCacheProvider.Instance.Get <SageWebReportDocument>(reportDocumentKey);

            if (reportDocument == null)
            {
                using (var watcher = new WADLogWatcher("ReportWatcher"))
                {
                    var session = BusinessPoolManager.GetSession(report.Context, DBLinkType.Company, out isNew);

                    watcher.Print("Session Created.");

                    // Throw an exception if the Crystal Reports template file is not found
                    var output       = GetReportTemplatePath(report.Name, session.UserLanguage);
                    var reportPath   = output.Item1;
                    var filenameOnly = output.Item2;
                    if (!File.Exists(reportPath))
                    {
                        //
                        // Security Consideration:
                        //    Do not use the full path in the message. Use only the filename
                        //
                        var msg = string.Format(CommonResx.Template_ReportCouldNotBeLocated, filenameOnly);
                        throw new MissingFileException(msg);
                    }

                    ACCPAC.Advantage.Report accpacReport = session.SelectReport(report.Name, report.ProgramId, report.MenuId);
                    foreach (var parameter in report.Parameters)
                    {
                        var value = GetValue(parameter);
                        accpacReport.SetParam(parameter.Id, value);
                    }

                    var userId = session.GetSession().UserID;
                    EvictUserWatcher.AddUserIdToPauseEviction(userId);

                    try
                    {
                        // Use lock to fix CRM multiple users concurrency printing issues.
                        lock (Lock)
                        {
                            var doc = accpacReport.GetReportDocument();
                            reportDocument = new SageWebReportDocument(doc, session, accpacReport);
                        }
                    }
                    finally
                    {
                        // Make sure we remove that from EvictUserWatcher no matter what happen
                        EvictUserWatcher.RemoveUserIdFromPauseEviction(userId);
                    }

                    watcher.Print("Report Document Created.");

                    // store the report object in the memory
                    InMemoryCacheProvider.Instance.Set(reportDocumentKey,
                                                       reportDocument,
                                                       ConfigurationHelper.ReportCacheExpirationInMinutes);
                }
            }

            if (reportDocument != null)
            {
                CrystalReportViewerSage300.ReportSource = reportDocument.CrystalReportDocument;
                CrystalReportViewerSage300.DataBind();
                SetLogoPath(reportDocument, report);
            }

            if (!IsPostBack && report.ReportProcessType.HasFlag(ReportProcessType.OnLoad))
            {
                Process(report);
            }
        }
Exemple #4
0
        /// <summary>
        /// Execute the report
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Init(object sender, EventArgs e)
        {
            var token = Request.QueryString["token"];
            string reportDocumentKey = "ReportDocument_" + token;

            // set the page hidden variable.
            hiddenToken.Value = token;

            var report = GetReport(token);

            if (report == null)
            {
                errorLabel.Text = CommonResx.ReportGenFailedMessage;
                return;
            }

            CommonUtil.SetCulture(report.Context.Language);

            //Check whether this report belongs to the same user.If not don't do anything.
            if (report.Context.SessionId != Session.SessionID)
            {
                errorLabel.Text = CommonResx.NotAuthorizedMesage;
                return;
            }
            
            report.Context.Container = ConfigurationHelper.Container;

            bool isNew;

            var reportDocument = InMemoryCacheProvider.Instance.Get<ReportDocument>(reportDocumentKey);

            if (reportDocument == null)
            {
                using (var watcher = new WADLogWatcher("ReportWatcher"))
                {
                    using (var session = BusinessPoolManager.GetSession(report.Context, DBLinkType.Company, out isNew))
                    {
                        watcher.Print("Session Created.");
                        var accpacReport = session.SelectReport(report.Name, report.ProgramId, report.MenuId);
                        foreach (var parameter in report.Parameters)
                        {
                            var value = GetValue(parameter);
                            accpacReport.SetParam(parameter.Id, value);
                        }

                        reportDocument = accpacReport.GetReportDocument();
                        watcher.Print("Report Document Created.");

                        // store the report object in the memory
                        InMemoryCacheProvider.Instance.Set(reportDocumentKey, reportDocument);
                    }
                }
            }

            if (reportDocument != null)
            {
                CrystalReportViewerSage300.ReportSource = reportDocument;
                CrystalReportViewerSage300.DataBind();
                SetLogoPath(reportDocument, report);
            }

            if (!IsPostBack && report.ReportProcessType.HasFlag(ReportProcessType.OnLoad))
            {
                Process(report);
            }
        }
        /// <summary>
        /// Execute the report
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Init(object sender, EventArgs e)
        {
            var    token             = Request.QueryString["token"];
            var    sessionId         = Request.QueryString["session"];
            string reportDocumentKey = "ReportDocument_" + token;

            // set the page hidden variable.
            hiddenToken.Value     = token;
            hiddenSessionId.Value = sessionId;

            var report = GetReport(token, sessionId);

            if (report == null)
            {
                errorLabel.Text = CommonResx.ReportGenFailedMessage;
                return;
            }

            CommonUtil.SetCulture(report.Context.Language);

            //Check whether this report belongs to the same user.If not don't do anything.
            if (report.Context.SessionId != sessionId)
            {
                errorLabel.Text = CommonResx.NotAuthorizedMesage;
                return;
            }

            report.Context.Container = ConfigurationHelper.Container;

            bool isNew;

            var reportDocument = InMemoryCacheProvider.Instance.Get <SageWebReportDocument>(reportDocumentKey);

            if (reportDocument == null)
            {
                using (var watcher = new WADLogWatcher("ReportWatcher"))
                {
                    using (var session = BusinessPoolManager.GetSession(report.Context, DBLinkType.Company, out isNew))
                    {
                        watcher.Print("Session Created.");
                        var accpacReport = session.SelectReport(report.Name, report.ProgramId, report.MenuId);
                        foreach (var parameter in report.Parameters)
                        {
                            var value = GetValue(parameter);
                            accpacReport.SetParam(parameter.Id, value);
                        }

                        var userId = session.GetSession().UserID;
                        EvictUserWatcher.AddUserIdToPauseEviction(userId);

                        try
                        {
                            //Use lock to fix CRM multiple users concurrency printing issues.
                            lock (Lock)
                            {
                                reportDocument = new SageWebReportDocument(accpacReport.GetReportDocument());
                            }
                        }
                        finally
                        {
                            // make sure we remove that from EvictUserWatcher no matter what happen
                            EvictUserWatcher.RemoveUserIdFromPauseEviction(userId);
                        }

                        watcher.Print("Report Document Created.");

                        // store the report object in the memory
                        InMemoryCacheProvider.Instance.Set(reportDocumentKey, reportDocument);
                    }
                }
            }

            if (reportDocument != null)
            {
                CrystalReportViewerSage300.ReportSource = reportDocument.CrystalReportDocument;
                CrystalReportViewerSage300.DataBind();
                SetLogoPath(reportDocument, report);
            }

            if (!IsPostBack && report.ReportProcessType.HasFlag(ReportProcessType.OnLoad))
            {
                Process(report);
            }
        }