Пример #1
0
        /// <summary>
        /// Constructor for the class. Sets the credentials and declares the report server information
        /// </summary>
        public ReportGeneratorUtilHelper()
        {
            //XmlConfigurator.Configure();
            executionInfo = new OrderClassesII.ReportExecution2005.ExecutionInfo();
            res           = new OrderClassesII.ReportExecution2005.ReportExecutionService();
            rs            = new ReportingService2010();

            res.Credentials = System.Net.CredentialCache.DefaultCredentials;
            rs.Credentials  = System.Net.CredentialCache.DefaultCredentials;
        }
Пример #2
0
        /// <summary>
        /// This is what will generate the reports. It takes in a list of ReportDetails and will parse the parameters out of the information for the report.
        /// It then iterates over the reports and delivers them according to the distribution type that was set. The centrralPrintDistributionLists is used to
        /// track the CentralPrint distribution types specified so that it can batch the files created that are targeted and then finally after all the logic
        /// is done output the information into an xml file.
        /// </summary>
        /// <param name="reports">This is a list of Reports passed in.</param>
        public byte[] GenerateAndExecuteDelivery(List <ReportDetail> reports)
        {
            //Dictionary<string, List<string>> centralPrintDistributionLists = new Dictionary<string, List<string>>();
            //WriteLogInfo("Request & Report configuration - validation completed, Generating SSRS reports started.", outputFileName);
            byte[] renderResult = null;
            foreach (ReportDetail report in reports)
            {
                string fullReportPath = report.ReportPath + report.ReportName;
                //ThreadContext.Properties["StackTrace"] = string.Empty;
                DateTime startTime = DateTime.Now;
                try
                {
                    if (string.IsNullOrEmpty(report.ReportDetailIdentifier) || string.IsNullOrEmpty(report.ReportName))
                    {
                        return(null);
                    }
                    var reportTimeout = Convert.ToInt32(Config.Setting("ReportServiceTimeOut"));
                    res.Timeout = reportTimeout;

                    executionInfo = res.LoadReport(fullReportPath, null);

                    //creates the list of parameters to be used
                    OrderClassesII.ReportExecution2005.ParameterValue[] parameters = new OrderClassesII.ReportExecution2005.ParameterValue[report.Parameters.Count];
                    int parametersTracker = 0;
                    foreach (OrderClassesII.ReportParameter parameter in report.Parameters)
                    {
                        parameters[parametersTracker]      = new OrderClassesII.ReportExecution2005.ParameterValue();
                        parameters[parametersTracker].Name = parameter.Name;
                        if (parameter.Type.Equals("DateTime"))
                        {
                            parameters[parametersTracker].Value = Convert.ToDateTime(parameter.Value).ToString();
                        }
                        else if (parameter.Type.Equals("String"))
                        {
                            parameters[parametersTracker].Value = parameter.Value;
                        }
                        parameters[parametersTracker].Value = parameter.Value;
                        parametersTracker++;
                    }
                    res.SetExecutionParameters(parameters, null);

                    foreach (DistributionDetail distributionDetail in report.Distributions)
                    {
                        string format = distributionDetail.OutputFileType.ToLower();
                        if (distributionDetail.OutputFileType.Trim().ToLower().Equals("png"))
                        {
                            format = "image";
                        }
                        string deviceInfo = null;
                        string extension  = distributionDetail.OutputFileType.ToLower();
                        string mimeType   = "";
                        string encoding   = "";
                        OrderClassesII.ReportExecution2005.Warning[] warnings = null;
                        string[] streamIDs = null;

                        mimeType = GetMimeType(distributionDetail.OutputFileType);

                        renderResult = res.Render(format, deviceInfo, out extension, out mimeType, out encoding, out warnings, out streamIDs);

                        if (warnings != null)
                        {
                            StringBuilder errorMessage = new StringBuilder();
                            foreach (var warning in warnings)
                            {
                                errorMessage.Append(warning.Message);
                            }
                            throw new Exception(errorMessage.ToString());
                        }

                        string fileName = distributionDetail.FileName;
                        fileName += GetFileExtension(distributionDetail.OutputFileType);

                        return(renderResult);
                    }

                    string timeDifference = DateTime.Now.Subtract(startTime).ToString();
                }
                catch (Exception ex)
                {
                    string timeDifference = DateTime.Now.Subtract(startTime).ToString();
                    string errorMessage   = string.Format("The report {0}, failed to generate files. Error Message: {1}", report.ReportName, ex.Message);
                }
            }
            return(renderResult);
        }