コード例 #1
0
        /// <summary>
        /// Generate TUI Reports
        /// </summary>
        /// <param name="serialNumber">Serial Number</param>
        /// <param name="flightName">flightName</param>
        /// <param name="period">Period</param>
        /// <returns>Task result </returns>
        private Task GenerateTuiReport(string serialNumber, string flightName, string period)
        {
            var pdfDirectory    = this._configuration["SSRSInfo:PDFDirectory"] ?? throw new ArgumentNullException($"_configuration[\"SSRSInfo:PDFDirectory\"]");
            var reportServerUrl = this._configuration["SSRSInfo:ServerUrl"] ?? throw new ArgumentNullException($"_configuration[\"SSRSInfo:ServerUrl\"]");
            var userSsrs        = this._configuration["SSRSInfo:SSRSUser"] ?? throw new ArgumentNullException($"_configuration[\"SSRSInfo:SSRSUser\"]");
            var pwdSsrs         = this._configuration["SSRSInfo:SSRSPwd"] ?? throw new ArgumentNullException($"_configuration[\"SSRSInfo:SSRSPwd\"]");
            var domainSsrs      = this._configuration["SSRSInfo:SSRSDomain"] ?? throw new ArgumentNullException($"_configuration[\"SSRSInfo:SSRSDomain\"]");
            var reportPath      = this._configuration["SSRSInfo:ReportPath"] ?? throw new ArgumentNullException($"_configuration[\"SSRSInfo:ReportPath\"]");

            using (var rs = new ReportExecutionService())
            {
                try
                {
                    rs.Timeout     = Timeout.Infinite;
                    rs.Credentials = new NetworkCredential(userSsrs, pwdSsrs, domainSsrs);
                    rs.Url         = $"{reportServerUrl}/ReportExecution2005.asmx";

                    ParameterValue[] parameters = new ParameterValue[3];
                    parameters[0] = new ParameterValue
                    {
                        Name  = "SerialNumber",
                        Value = serialNumber
                    };
                    parameters[1] = new ParameterValue
                    {
                        Name  = "FlightName",
                        Value = flightName
                    };
                    parameters[2] = new ParameterValue
                    {
                        Name  = "Period",
                        Value = period
                    };

                    rs.LoadReport(reportPath, null);
                    rs.SetExecutionParameters(parameters, CultureInfo.CurrentCulture.ToString());

                    string devInfo = "<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>";
                    var    result  = rs.Render("pdf", devInfo, Extension: out _, MimeType: out _, Encoding: out _, Warnings: out _, StreamIds: out _);

                    rs.GetExecutionInfo();

                    File.WriteAllBytes(
                        $"{pdfDirectory}\\{serialNumber}_{period}_{DateTime.Now.ToString("ddMMyyyyHHmmss", CultureInfo.InvariantCulture)}.pdf",
                        result);
                    this._logger?.LogDebug(
                        $"GenerateTUIReport {Thread.CurrentThread.ManagedThreadId} :  GeneratedPdf {serialNumber}_{period}");

                    rs.Dispose();
                }
                catch (SoapException se)
                {
                    this._logger?.LogError(se, "ReportExecutionTask se: ");
                    this._logger?.LogError(se, "SerialNumber is: " + serialNumber);
                }
                catch (WebException we)
                {
                    Debug.WriteLine(we);
                    this._logger?.LogError(we, "ReportExecutionTask we: ");
                    throw;
                }
                catch (UnauthorizedAccessException e)
                {
                    this._logger?.LogError(e, "ReportExecutionTask e : ");
                    throw;
                }
            }

            return(Task.FromResult(0));
        }
コード例 #2
0
 public void Dispose()
 {
     m_res.Dispose();
 }