Пример #1
0
        private static ExecuteReportRequest[] ExtractReportRequests(IEnumerable<RequestHelper> requestHelper)
        {
            var allReportRequests = new List<ExecuteReportRequest>();

            foreach (var requestInfo in requestHelper)
            {
                var parameters = ExtractParameters(requestInfo);

                FormatType formatType;
                if (!Enum.TryParse(requestInfo.OutputFormatType, out formatType))
                {
                    Assert.Fail("OutputFormatType not recognized");
                }

                var executeReportRequest = new ExecuteReportRequest
                {
                    reportName = requestInfo.ReportName,
                    outputFilename = requestInfo.OutputFilename,
                    outputFormatType = formatType,
                    parameters = parameters
                };

                allReportRequests.Add(executeReportRequest);
            }

            return allReportRequests.ToArray();
        }
        public void GivenAnExecuteReportRequest_WhenReportNameIsNotNabOrBqlAllItemReport_ThenBankCodeShouldBeEmpty()
        {
            ExecuteReportRequest request = new ExecuteReportRequest()
            {
                reportName = "Some_Other_Report"
            };

            var bankCode = request.GetBankCode();

            Assert.AreEqual(string.Empty, bankCode);
        }
        public void GivenAnExecuteReportRequest_WhenReportNameIsDailyVifReport_ThenReturnFalse()
        {
            ExecuteReportRequest request = new ExecuteReportRequest()
            {
                reportName = "NAB_Daily_VIF_Transmission_Report"
            };

            bool isAllItemReport = request.IsAllItemsReport();

            Assert.IsFalse(isAllItemReport);
        }
        public void GivenAnExecuteReportRequest_WhenReportNameIsBqlAllItemReport_ThenBankCodeShouldBeBql()
        {
            ExecuteReportRequest request = new ExecuteReportRequest()
            {
                reportName = "BQL_All_Items_Report"
            };

            var bankCode = request.GetBankCode();

            Assert.AreEqual("BQL", bankCode);
        }
        public void GivenAnExecuteReportRequest_WhenReportNameIsBqlAllItemReport_ThenReturnTrue()
        {
            ExecuteReportRequest request = new ExecuteReportRequest()
            {
                reportName = "BQL_All_Items_Report"
            };

            bool isAllItemReport = request.IsAllItemsReport();

            Assert.IsTrue(isAllItemReport);
        }
 public void Initialize()
 {
     fileSystem = new Mock<IFileSystem>();
     reportHelper = new Mock<AllItemsReportHelper>(fileSystem.Object);
     repository = new Mock<ReportingRepository>(null);
     reportRequest = new ExecuteReportRequest()
     {
         outputFilename = "outputFilename",
         parameters = new[] { 
             new Parameter { name = "processdate", value = "2018-05-07" }, 
             new Parameter { name = "processingState", value = "VIC" } }
     };
 }
        public ValidatedResponse<string> RenderReport(ExecuteReportRequest reportRequest, string outputFolderPath)
        {
            if (string.IsNullOrEmpty(reportRequest.outputFilename))
            {
                Log.Debug("RenderReport : Report outputFilename must not be null or empty");
                return ValidatedResponseHelper.Failure<string>("Report OutputFilename must not be null or empty");
            }

            var reportExecutionWatch = Stopwatch.StartNew();

            Log.Debug("{@ReportRequest}", reportRequest);

            var fileNameAndPath = Path.Combine(outputFolderPath, reportRequest.outputFilename);
            try
            {
                var processDateParam = reportRequest.parameters.GetValue("businessdate");
                var lockedBoxParam = reportRequest.parameters.GetValue("lockedbox");

                var lockedBoxConfig = this.lockedBoxConfigs.Single(c => c.CustomerId.Equals(lockedBoxParam.value, StringComparison.OrdinalIgnoreCase));

                DateTime processDate;
                if (!DateTime.TryParse(processDateParam.value, out processDate))
                {
                    Log.Debug("RenderReport : Invalid DateTime format '{0}'", processDateParam.value);
                    return ValidatedResponseHelper.Failure<string>("Invalid DateTime format '{0}'", processDateParam.value);
                }

                var items = this.repository.GetLockedBoxCreditCardItems(processDate, lockedBoxParam.value, lockedBoxConfig.IsCreditCard);

                DateTime runDate = DateTime.Now;

                using (var streamWriter = this.fileSystem.File.CreateText(fileNameAndPath))
                {
                    Log.Information("Found {0} items for processing.", items.Count);

                    if (items.Any())
                    {
                        string previousBatchNumber = items.First().BatchNumber;
                        int pageNumber = 1;

                        int debitCount = 0;
                        int creditCount = 0;
                        int debitRejectCount = 0;
                        int creditRejectCount = 0;
                        decimal batchHeaderAmount = 0m;
                        decimal debitAmount = 0m;
                        decimal creditAmount = 0m;

                        for (int i = 0; i < items.Count; i++)
                        {
                            string currentBatchNumber = items[i].BatchNumber;

                            if (this.reportHelper.IsNewBatchNumberGroup(previousBatchNumber, currentBatchNumber) ||
                                (i == 0))
                            {
                                if (i != 0)
                                {
                                    this.reportHelper.PrintPageFooter(streamWriter, previousBatchNumber, debitCount, creditCount, batchHeaderAmount, debitAmount, creditAmount, debitRejectCount, creditRejectCount);
                                }

                                previousBatchNumber = currentBatchNumber;
                                debitCount = 0;
                                creditCount = 0;
                                batchHeaderAmount = 0m;
                                debitAmount = 0m;
                                creditAmount = 0m;

                                Log.Debug("Starting new page: {0}.", pageNumber);

                                this.reportHelper.PrintPageHeader(streamWriter, processDate, runDate, currentBatchNumber, lockedBoxConfig.WorkSourceCode, lockedBoxConfig.WorkSourceName, items[i].PaymentType, lockedBoxConfig.DpNumber, pageNumber, lockedBoxConfig.IsCreditCard);

                                pageNumber++;
                            }

                            this.reportHelper.PrintReportRow(streamWriter, items[i], lockedBoxConfig.IsCreditCard);

                            this.reportHelper.CalculateReportSummary(items[i], ref debitCount, ref creditCount, ref batchHeaderAmount, ref debitAmount, ref creditAmount);

                            if (i == (items.Count - 1))
                            {
                                // print footer for last item
                                this.reportHelper.PrintPageFooter(streamWriter, previousBatchNumber, debitCount, creditCount, batchHeaderAmount, debitAmount, creditAmount, debitRejectCount, creditRejectCount);
                            }
                        }

                        this.reportHelper.PrintReportFooter(streamWriter);
                    }
                }

                Log.Information("RenderReport : Created report at {0}", fileNameAndPath);
            }
            catch (Exception ex)
            {
                Log.Error("RenderReport: Something went wrong {@stackTrace}", ex.ToString());
                return ValidatedResponseHelper.Failure<string>("Error {0}", ex);
            }
            finally
            {
                reportExecutionWatch.Stop();

                Log.Information("RenderReport : [{@outputFilename}] Finish generating report in {@time} seconds", reportRequest.outputFilename, reportExecutionWatch.ElapsedMilliseconds / 1000.0);
            }

            return ValidatedResponse<string>.Success(fileNameAndPath);
        }
Пример #8
0
        public ValidatedResponse<string> RenderReport(ExecuteReportRequest reportRequest, string outputFolderPath)
        {
            if (string.IsNullOrEmpty(reportRequest.outputFilename))
            {
                Log.Debug("RenderReport : Report outputFilename must not be null or empty");
                return ValidatedResponseHelper.Failure<string>("Report OutputFilename must not be null or empty");
            }

            var reportExecutionWatch = Stopwatch.StartNew();

            Log.Debug("{@ReportRequest}", reportRequest);

            var fileNameAndPath = Path.Combine(outputFolderPath, reportRequest.outputFilename);
            try
            {
                string bankCode = reportRequest.GetBankCode();
                bool isBql = reportRequest.IsBql();

                var processDateParam = reportRequest.parameters.GetValue("processdate");
                var processStateParam = reportRequest.parameters.GetValue("processingstate", !isBql);

                DateTime processDate;
                if (!DateTime.TryParse(processDateParam.value, out processDate))
                {
                    Log.Debug("RenderReport : Invalid DateTime format '{0}'", processDateParam.value);
                    return ValidatedResponseHelper.Failure<string>("Invalid DateTime format '{0}'", processDateParam.value);
                }

                if (isBql)
                {
                    processStateParam.value = "QLD";
                }

                var allItems = this.repository.GetAllItems(processDate, processStateParam.value, bankCode);

                DateTime runDate = DateTime.Now;

                using (var streamWriter = this.fileSystem.File.CreateText(fileNameAndPath))
                {
                    if (allItems.Any())
                    {
                        Log.Information("Found {0} all items for processing.", allItems.Count);

                        string previousBatchNumber = allItems.First().BatchNumber;
                        string previousTransactionNumber = allItems.First().TransactionNumber;
                        int pageRowCount = 0;
                        int pageNumber = 1;

                        for (int i = 0; i < allItems.Count; i++)
                        {
                            string currentBatchNumber = allItems[i].BatchNumber;
                            string currentTransactionNumber = allItems[i].TransactionNumber;

                            if (this.reportHelper.IsNewBatchNumberGroup(previousBatchNumber, currentBatchNumber) ||
                                this.reportHelper.IsNewTransactionGroup(previousTransactionNumber, currentTransactionNumber))
                            {
                                previousBatchNumber = currentBatchNumber;
                                previousTransactionNumber = currentTransactionNumber;

                                if (!this.reportHelper.IsStartNewPage(pageRowCount))
                                {
                                    streamWriter.WriteLine();
                                    pageRowCount++;
                                }
                            }

                            if (this.reportHelper.IsStartNewPage(pageRowCount))
                            {
                                Log.Debug("Starting new page: {0}.", pageNumber);

                                this.reportHelper.PrintPageHeader(streamWriter, processDate, runDate, bankCode, processStateParam.value, pageNumber);

                                pageNumber++;
                                pageRowCount = 0;
                            }

                            this.reportHelper.PrintReportRow(streamWriter, allItems[i]);

                            pageRowCount++;
                        }

                        this.reportHelper.PrintReportFooter(streamWriter, allItems);
                    }
                    else
                    {
                        Log.Information("Found 0 all items for processing.", allItems.Count);

                        this.reportHelper.PrintEmptyReport(streamWriter, processDate, bankCode);
                    }
                }

                Log.Information("RenderReport : Created report at {0}", fileNameAndPath);
            }
            catch (Exception ex)
            {
                Log.Error("RenderReport: Something went wrong {@stackTrace}", ex.ToString());
                return ValidatedResponseHelper.Failure<string>("Error {0}", ex);
            }
            finally
            {
                reportExecutionWatch.Stop();

                Log.Information("RenderReport : [{@outputFilename}] Finish generating report in {@time} seconds", reportRequest.outputFilename, reportExecutionWatch.ElapsedMilliseconds / 1000.0);
            }

            return ValidatedResponse<string>.Success(fileNameAndPath);
        }
Пример #9
0
        public ValidatedResponse<string> RenderReport(ExecuteReportRequest reportRequest, string outputFolderPath)
        {
            if (string.IsNullOrEmpty(reportRequest.outputFilename))
            {
                Log.Debug("RenderReport : Report outputFilename must not be null or empty");
                return ValidatedResponseHelper.Failure<string>("Report OutputFilename must not be null or empty");
            }

            Log.Information("RenderReport : [{@outputFilename}] Requesting report object {@reportName}", reportRequest.outputFilename, reportRequest.reportName);

            var reportExecutionWatch = Stopwatch.StartNew();

            var parameters = this.GetParameters(reportRequest);
            var reportObject = this.GetReportObjectFromSSRS(reportRequest.reportName);

            if (!reportObject.IsSuccessful)
            {
                Log.Error("RenderReport : [{@outputFilename}] Error retrieve report {@reportName}", reportRequest.outputFilename, reportRequest.reportName);
                return ValidatedResponseHelper.Failure<string>("Error retrieve report {0} : {1}", reportRequest.reportName, reportObject.ValidationResults.AsString());
            }

            var fileNameAndPath = string.Empty;
            try
            {
                var renderFormat = RenderFormat.FromValue(reportRequest.outputFormatType.ToString()); // also throws ArgumentException if can't be parsed
                
                // Set parameters into SoapClient object.
                var rsExec = new ReportExecutionServiceSoapClient();
                rsExec.Endpoint.Address = this.reportExecution2005Reference;
                rsExec.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
                rsExec.ClientCredentials.Windows.ClientCredential = null;

                Log.Debug("RenderReport : [{@outputFilename}] Loading report {@report}", reportRequest.outputFilename, reportObject.Result.Path);

                rsExec.LoadReport(this.trusteduserHeader, reportObject.Result.Path, null, out this.serviceInfo, out this.execInfo);

                Log.Debug("RenderReport : [{@outputFilename}] Report loaded {@report} with Execution ID {@executionID}", reportRequest.outputFilename, reportObject.Result.Path, this.execInfo.ExecutionID);

                this.execHeader.ExecutionID = this.execInfo.ExecutionID;

                // Set the parameters.
                rsExec.SetExecutionParameters(this.execHeader, this.trusteduserHeader, parameters, "EN-US", out this.execInfo);

                Log.Debug("RenderReport : [{@outputFilename}] Parameters {@param} was set.", reportRequest.outputFilename, parameters);

                byte[] result;
                string extension;
                string encoding;
                string mimeType;
                RE2005.Warning[] warnings;
                string[] streamIDs;

                Log.Debug("RenderReport : [{@outputFilename}] Rendering report...", reportRequest.outputFilename);

                // Render the report.
                rsExec.Render(this.execHeader, null, renderFormat.SSRSValue, null, out result, out extension, out mimeType, out encoding, out warnings, out streamIDs);

                Log.Debug("RenderReport : [{@outputFilename}] Saving report to file...", reportRequest.outputFilename);

                fileNameAndPath = this.fileWriter.WriteToFile(outputFolderPath, reportRequest.outputFilename, result);

                Log.Information("RenderReport : [{@outputFilename}] Report saved in {@filenameandPath}", reportRequest.outputFilename, fileNameAndPath);
            }
            catch (Exception ex)
            {
                Log.Error(ex, "RenderReport: Something went wrong {@stackTrace}", ex.ToString());
                return ValidatedResponseHelper.Failure<string>("Error {0}", ex.ToString());
            }
            finally
            {
                reportExecutionWatch.Stop();

                Log.Information("RenderReport : [{@outputFilename}] Finish generating report in {@time} seconds", reportRequest.outputFilename, reportExecutionWatch.ElapsedMilliseconds / 1000.0);
            }

            return ValidatedResponse<string>.Success(fileNameAndPath);
        }
Пример #10
0
        private ParameterValue[] GetParameters(ExecuteReportRequest reportRequest)
        {
            var parameters = new List<ParameterValue>();
            foreach (var requestParam in reportRequest.parameters)
            {
                parameters.Add(new ParameterValue
                {
                    Name = requestParam.name,
                    Value = requestParam.value
                });
            }

            return parameters.ToArray();
        }