private IEpsReportConfig CreateReportConfig(EpsOutput output, IMacroProcessor macroProcessor, EpsOutputParam report, EpsOutputParam[] reportParams, ISession session) { var res = new EpsReportConfig(); // добавляем параметры этого отчета res.Parameters = reportParams .Where(p => !EpsTaskParameterTypes.IsKnownParameter(p.OutputParamCode)) .ToDictionary(i => i.OutputParamCode, i => macroProcessor.Process(i.OutputParamValue)); // добавляем в отчет обязательный параметр UserCode res.Parameters.Add(EpsReportParameterTypes.UserCode, output.Login_r); // определяем имя файла отчета (оно же subvalue для параметров) res.ReportName = macroProcessor.Process(report.OutputParamValue); if (string.IsNullOrEmpty(res.ReportName)) { throw new Exception(string.Format("Empty report file name in output {0}. Check the settings.", output.OutputID)); } //TODO: Нужно бы переделать алгоритм определения кода отчета. Фиг знает почему так. res.ReportCode = Path.GetFileNameWithoutExtension(res.ReportName); macroProcessor.AddOrReplace("SQL", macroString => ProcessSqlMacro(macroString, session, reportParams)); //определяем имя выгрузки отчета (итоговое имя) var resultReportFile = GetParamValue(reportParams, macroProcessor, EpsTaskParameterTypes.ResultReportFile, res.ReportName); // если ничего не задано - то берем имя файла отчета // иначе вычисляем результируещее имя с учетом макросов res.ReportResultFileName = IsNullOrEmptyAfterTrim(resultReportFile) ? res.ReportName : resultReportFile; // : ProcessReportFileName(session, resultReportFile, reportParams); //получаем параметр типа EpsTaskParams.ChangeODBC. 0 - строку переопределять (переопределяет все подключения в отчете), 1 - строку не переопределять. var changeOdbcStr = GetParamValue(reportParams, macroProcessor, EpsTaskParameterTypes.ChangeODBC, res.ReportName); res.ConnectionString = changeOdbcStr == "1" ? null : EpsConfig.OdbcConnectionString; //получим пользовательский параметр ReportUseODAC //var wmsReport = session.Get<WmsReport>(res.ReportCode); //var reportUseOdac = wmsReport.CPV_List.FirstOrDefault(i => i.CustomParam.CustomParamCode == WmsReportCPV.ReportUseODACParameter); //TODO: исправить на вариант выше (когда Виталик починит метаданные) var reportUseOdac = session .Query <WmsReportCPV>() .Any( i => i.CustomParam.CustomParamCode == WmsReportCPV.ReportUseODACParameter && i.REPORT.Report == res.ReportCode && i.CPVValue == "1"); //параметр ReportUseODAC в приоритете if (reportUseOdac) { res.ConnectionString = EpsConfig.OdacConnectionString; } //вычисляем полное имя к файлу отчета res.ReportFullFileName = (output.ReportFileSubFolder_r != null) ? Path.Combine(EpsConfig.ReportPath, output.ReportFileSubFolder_r, res.ReportName) : Path.Combine(EpsConfig.ReportPath, res.ReportName); return(res); }
public void When_parameters_is_pased_than_its_recognized() { var epsConfig = GetEpsConfiguration(); var configurator = new EpsJobConfigurator(epsConfig, new MacroProcessor()); var output = new EpsOutput { OutputID = -100, OutputStatus = OutputStatuses.OS_ON_TRANSFER, EpsHandler = 100, Login_r = "test_user_login", ReportFileSubFolder_r = "TST" }; output.Output_EpsOutputParam_List.Add(new EpsOutputParam { OutputParamType = EpsParamTypes.EPS, OutputParamCode = EpsTaskParameterTypes.Zip, OutputParamValue = "1" }); output.Output_EpsOutputParam_List.Add(new EpsOutputParam { OutputParamType = EpsParamTypes.EPS, OutputParamCode = EpsTaskParameterTypes.ReserveCopy, OutputParamValue = "1" }); var emailTask = new EpsOutputTask { OutputTaskID = -101, OutputTaskCode = EpsOutputTaskCodes.OTC_MAIL, OutputTaskOrder = 1, OutputTaskStatus = OutputStatuses.OS_NEW, }; output.Output_EpsOutputTask_List.Add(emailTask); emailTask.OutputTask_EpsOutputParam_List.Add(new EpsOutputParam { OutputParamType = EpsParamTypes.TSK, OutputParamCode = EpsTaskParameterTypes.FileFormat, OutputParamValue = "wmsMLC.EPS.wmsEPS.ExportTypes.FRExcel2007" }); emailTask.OutputTask_EpsOutputParam_List.Add(new EpsOutputParam { OutputParamType = EpsParamTypes.TSK, OutputParamCode = EpsTaskParameterTypes.Conversion, OutputParamValue = "UTF-32" }); emailTask.OutputTask_EpsOutputParam_List.Add(new EpsOutputParam { OutputParamType = EpsParamTypes.TSK, OutputParamCode = EpsTaskParameterTypes.Spacelife, OutputParamValue = "1" }); var reportParam = new EpsOutputParam { OutputParamType = EpsParamTypes.REP, OutputParamCode = EpsTaskParameterTypes.EpsReport, OutputParamValue = "Test001.frx" }; output.Output_EpsOutputParam_List.Add(new EpsOutputParam { OutputParamType = EpsParamTypes.REP, OutputParamCode = "Parameter1", OutputParamValue = "value1", OutputParamSubValue = "Test001.frx" }); output.Output_EpsOutputParam_List.Add(new EpsOutputParam { OutputParamType = EpsParamTypes.REP, OutputParamCode = "Parameter2", OutputParamValue = "value2", OutputParamSubValue = "Test001.frx" }); output.Output_EpsOutputParam_List.Add(new EpsOutputParam { OutputParamType = EpsParamTypes.REP, OutputParamCode = EpsTaskParameterTypes.ResultReportFile, OutputParamValue = "${SQL=select REPORT_${SYSMACHINENAME}_${UserCode}_${DATE:yyyyMMdd}_${Parameter1}_${Parameter2}.txt from dual}", OutputParamSubValue = "Test001.frx" }); output.Output_EpsOutputParam_List.Add(new EpsOutputParam { OutputParamType = EpsParamTypes.REP, OutputParamCode = EpsTaskParameterTypes.ChangeODBC, OutputParamValue = "1" }); output.Output_EpsOutputParam_List.Add(reportParam); var resultReportName = string.Format("REPORT_{0}_{1}_{2:yyyyMMdd}_value1_value2.txt", Environment.MachineName, output.Login_r, DateTime.Now); var sqlQuery = new Mock <ISQLQuery>(); sqlQuery.Setup(i => i.UniqueResult <string>()).Returns(resultReportName); var session = new Mock <ISession>(); session.Setup(i => i.CreateSQLQuery(It.IsAny <string>())).Returns(sqlQuery.Object); var reportUseODACCpv = new WmsReportCPV { CPVValue = "1", CustomParam = new WmsCustomParam { CustomParamCode = WmsReportCPV.ReportUseODACParameter }, REPORT = new WmsReport { Report = Path.GetFileNameWithoutExtension(reportParam.OutputParamValue) } }; using (ShimsContext.Create()) { ShimLinqExtensionMethods.QueryOf1ISession(s => new[] { reportUseODACCpv }.AsQueryable()); var resultConfig = configurator.Configure(output, session.Object, (i, exception, arg3) => { }); resultConfig.JobId.Should().Be(output.OutputID); resultConfig.Tasks.Should().HaveCount(1); resultConfig.Reports.Should().HaveCount(1); var resultEmailTask = resultConfig.Tasks.Single(i => i.TaskId == emailTask.OutputTaskID); ("OTC_" + resultEmailTask.TaskExecutorType).Should().Be(emailTask.OutputTaskCode.ToString()); resultEmailTask.IsNeedZip.Should().BeTrue(); resultEmailTask.IsNeedReserveCopy.Should().BeTrue(); resultEmailTask.ExportType.Should().NotBeNull(); resultEmailTask.ExportType.Encoding.Should().Be(Encoding.UTF32); resultEmailTask.ExportType.Spacelife.Should().BeTrue(); resultEmailTask.ExportType.Format.Should().Be("wmsMLC.EPS.wmsEPS.ExportTypes.FRExcel2007"); resultEmailTask.HandleTaskComplete.Should().NotBeNull(); var resultReport = resultConfig.Reports.Single(i => i.ReportName == reportParam.OutputParamValue); resultReport.ReportCode.Should().Be(Path.GetFileNameWithoutExtension(reportParam.OutputParamValue)); resultReport.ConnectionString.Should().Be(epsConfig.OdacConnectionString); resultReport.ReportFullFileName.Should().Be(Path.Combine(epsConfig.ReportPath, output.ReportFileSubFolder_r, reportParam.OutputParamValue)); resultReport.Parameters.Should().Contain("Parameter1", "value1"); resultReport.Parameters.Should().Contain("Parameter2", "value2"); resultReport.Parameters.Should().Contain(EpsReportParameterTypes.UserCode, output.Login_r); resultReport.ReportResultFileName.Should().Be(resultReportName); } }