Beispiel #1
0
        /// <summary>
        /// To Get Reports Data.
        /// </summary>
        /// <param name="id">ReportId or SummaryId.</param>
        /// <param name="relatedToType">Related To Type.</param>
        /// <param name="moduleType">Module Type.</param>
        /// <returns>Report Data.</returns>
        public static IReportsData GenerateReportsData(Guid id, RelatedToType relatedToType, ModuleType moduleType)
        {
            var reportService = GetDependency <IReportService>();

            Assert.IsInstanceOfType(reportService, typeof(IReportService));
            var reportData = reportService.GenerateReportsData(id, relatedToType, moduleType);

            Assert.IsNotNull(reportData);
            return(reportData);
        }
Beispiel #2
0
 public IReportsData GenerateReportsData(Guid id, RelatedToType reportType, ModuleType moduleType)
 {
     if (reportType == RelatedToType.Summary)
     {
         FindSummaryForReport(id, moduleType);
     }
     else
     {
         FindReportForReport(id, moduleType);
     }
     return(_reportDetails);
 }
Beispiel #3
0
        public string GetReportsData(Guid id, ModuleType moduleType, RelatedToType type)
        {
            Identity.InjectIdentity();
            using (var iocService = DependencyContainer.Resolve <IReportService>())
            {
                //get template detail
                _reportService = iocService.Instance;
            }
            var reportsData = _reportService.GenerateReportsData(id, type, moduleType);

            var reportsDocument = new XmlDocument();
            var nav             = reportsDocument.CreateNavigator();

            using (var writer = nav.AppendChild())
            {
                var ser = new XmlSerializer(reportsData.GetType());
                ser.Serialize(writer, reportsData);
            }

            var detailDocument       = new XmlDocument();
            var detailElementQuery   = detailDocument.CreateElement("Query");
            var detailElementXmlData = detailDocument.CreateElement("XmlData");

            detailElementQuery.AppendChild(detailElementXmlData);

            detailDocument.AppendChild(detailElementQuery);

            if (reportsDocument.DocumentElement != null)
            {
                detailElementXmlData.AppendChild(
                    detailDocument.ImportNode(
                        reportsDocument.DocumentElement, true));
            }

            return(detailDocument.InnerXml);
        }
        public string GetReportsData(Guid id, ModuleType moduleType, RelatedToType type)
        {
            string reportData;

            // Get the sign-in key from the URL. This is a hash which uniquely identifies a user's
            // authentication context and can be used for impersonation.
            var tokenString = HttpContext.Current.Request.QueryString["wsSignInKey"];

            if (string.IsNullOrWhiteSpace(tokenString))
            {
                _log.Error("SSRS Report Data: SSRS Service Request made without security key.");
                throw new Exception("SSRS Service Request made without security key.");
            }
            try
            {
                // Use the given token string to authenticate the current user.
                Thread.CurrentPrincipal =
                    new JwtTokenValidator(TokenManagerFactory.GetTokenManager()).GetClaimsPrincipalFromToken(tokenString);
            }
            catch (Exception ex)
            {
                _log.Error("SSRS Report Data: Could not authenticate user : {0}", ex);
                throw;
            }

            // Check to make sure the user is authenticated.
            if (Thread.CurrentPrincipal == null ||
                Thread.CurrentPrincipal.Identity == null ||
                !Thread.CurrentPrincipal.Identity.IsAuthenticated)
            {
                _log.Error("SSRS Report Data: User is not authenticated.");
                throw new Exception("User is not authenticated.");
            }
            try
            {
                // Resolve the Report service. Note: We can't use constructor injection here since
                // the user may not be authenticated until this method executes. If the service is
                // instantiated before authentication, the system will throw an exception.
                using (var iocService = DependencyContainer.Resolve <IReportService>())
                {
                    var reportService = iocService.Instance;

                    // Retrieve report data.
                    var reportsData = reportService.GenerateReportsData(id, type, moduleType);

                    var reportsDocument = new XmlDocument();
                    var nav             = reportsDocument.CreateNavigator();
                    using (var writer = nav.AppendChild())
                    {
                        var ser = new XmlSerializer(reportsData.GetType());
                        ser.Serialize(writer, reportsData);
                    }

                    var detailDocument       = new XmlDocument();
                    var detailElementQuery   = detailDocument.CreateElement("Query");
                    var detailElementXmlData = detailDocument.CreateElement("XmlData");
                    detailElementQuery.AppendChild(detailElementXmlData);

                    detailDocument.AppendChild(detailElementQuery);

                    if (reportsDocument.DocumentElement != null)
                    {
                        detailElementXmlData.AppendChild(
                            detailDocument.ImportNode(
                                reportsDocument.DocumentElement, true));
                    }

                    reportData = detailDocument.InnerXml;
                }
            }
            catch (Exception ex)
            {
                _log.Error("SSRS Service Request Failure: {0}", ex);
                throw;
            }
            return(reportData);
        }
        private void RenderReportViewer(Guid id, RelatedToType relatedType, ModuleType moduleType)
        {
            _log.Debug("Rendering [{0}] [{1}] Viewer...", relatedType.GetDescription(), moduleType.GetDescription());
            try
            {
                var  isDraft = false;
                var  reportNumber = string.Empty;
                var  templateQueryService = DependencyContainer.Resolve <ITemplateQueryService>();
                Guid agencyId, templateId;

                if (relatedType != RelatedToType.Summary)
                {
                    using (var iocService = DependencyContainer.Resolve <IReportQueryService>())
                    {
                        //get workflow status detail
                        _reportQueryService = iocService.Instance;
                        var reportsInfo = _reportQueryService.GetReportInfo(id);
                        isDraft    = reportsInfo.State != ReportState.Complete;
                        agencyId   = reportsInfo.Agency.AgencyId;
                        templateId = reportsInfo.TemplateId;
                        if (!reportsInfo.WorkflowRights.CanView && !UserHasAccessRights(reportsInfo.Agency.AgencyId, moduleType))
                        {
                            ReportViewer1.Visible  = false;
                            AccessDisabled.Visible = true;
                            Response.Redirect("~/#/error");
                            return;
                        }
                        reportNumber = reportsInfo.Number;
                    }
                }
                else
                {
                    //get reportnumber for selected summary record
                    using (var iocSummaryService = DependencyContainer.Resolve <ISummaryQueryService>())
                    {
                        //get workflow status detail
                        _summaryQueryService = iocSummaryService.Instance;
                        var summaryInfo = _summaryQueryService.GetSummaryInfo(id);
                        agencyId   = summaryInfo.Agency.AgencyId;
                        templateId = templateQueryService.Instance.GetDefaultTemplate(summaryInfo.Agency.AgencyId, moduleType).Id;

                        if (!UserHasAccessRights(summaryInfo.Agency.AgencyId, moduleType))
                        {
                            ReportViewer1.Visible  = false;
                            AccessDisabled.Visible = true;
                            Response.Redirect("~/#/error");
                            return;
                        }
                        reportNumber = summaryInfo.Number;
                    }
                }

                AccessDisabled.Visible = false;

                var reportServerUri = String.Format("http://{0}/ReportServer",
                                                    ConfigurationManager.AppSettings["ReportServer"]);
                var reportPath = String.Format("/{0}",
                                               ConfigurationManager.AppSettings["ReportRootPath"]);
                ReportViewer1.ServerReport.ReportPath      = reportPath;
                ReportViewer1.ServerReport.ReportServerUrl = new Uri(reportServerUri);
                ReportViewer1.ShowParameterPrompts         = false;
                ReportViewer1.ShowFindControls             = false;
                ReportViewer1.ShowExportControls           = true;
                ReportViewer1.ShowToolBar = true;

                int validity;
                var result = Int32.TryParse(ConfigurationManager.AppSettings["SSRSTokenTimeout"], out validity);
                if (!result)
                {
                    validity = 5;
                }

                var headerText = templateQueryService.Instance.GetTemplateHeaderText(moduleType, reportNumber, agencyId, templateId);

                var svcQuery = String.Format("{0}",
                                             ConfigurationManager.AppSettings["SSRSServiceHost"]) +
                               "api/ssrsreports/getreportsdata/"
                               + id.ToString()
                               + "/" + moduleType.ToString()
                               + "/" + relatedType.ToString() + "?wsSignInKey=" + new JwtTokenGenerator(TokenManagerFactory.GetTokenManager()).GenerateJwtToken(System.Web.HttpContext.Current.User.Identity as ClaimsIdentity, validity);
                var reportParameters = new List <ReportParameter>
                {
                    new ReportParameter("svcQuery", svcQuery),
                    new ReportParameter("isDraft", isDraft.ToString()),
                    new ReportParameter("imageDataSource", ConfigurationManager.ConnectionStrings["InformRMSMediaSSRS"].ConnectionString),
                    new ReportParameter("headerText", headerText)
                };

                _log.Debug("SSRS URI: {0}", reportServerUri);
                reportParameters.ForEach(p =>
                {
                    foreach (var value in p.Values)
                    {
                        _log.Debug("SSRS Parameter {0} = {1}", p.Name, value);
                    }
                });

                ReportViewer1.ServerReport.SetParameters(reportParameters);
                ReportViewer1.ServerReport.Refresh();
            }
            catch (Exception ex)
            {
                _log.Error("Failure to render SSRS Report {0}", ex);
            }
        }