我想借助调度程序自动生成ACH文件。 计划程序调用给我例外,而从URL直接调用却没有 我已经实现了以下用于创建ACH文件的代码
//scheduler job
Task IJob.Execute(IJobExecutionContext context)
{
SchedularMethodsController obj = new SchedularMethodsController();
var T = Task.Run(() => obj.AchFileGenerator(DateTime.Now));\
T.Wait();
return T;
}
生成和写入ACH文件的方法如下:-
public void AchFileGenerator(DateTime Dt)
{
ChoNACHAConfiguration config = new ChoNACHAConfiguration();
config.DestinationBankRoutingNumber = "999999999";
config.OriginatingCompanyId = "7999999999";
config.DestinationBankName = ("PNC Bank").ToUpper();
config.OriginatingCompanyName = ("automatecondominium").ToUpper();
config.ReferenceCode = ("mgmt").ToUpper();
config.BlockingFactor = 10;
var unitowners = Achbll.GetUnitOwnerPaymentList(Dt).ToList();
var FileName = "ACH_" + ((DateTime.Now.ToString()).Replace(" ", "_").Replace(":", "_")) + ".txt";
var backpath = "CondoDocuments\\DocumentLibrary\\" + FileName;
var path = HttpRuntime.AppDomainAppPath + backpath;
using (var fs = System.IO.File.Create(path))
{
fs.Close();
fs.Dispose();
}
try
{
using (var nachaWriter = new ChoNACHAWriter(path, config))
{
using (var bw2 = nachaWriter.CreateBatch(200, "PPD", "DIR DEBIT", DateTime.Now, DateTime.Now.AddDays(1), null, null, '1', null, null))
{
foreach (var owner in unitowners)
{
if (!string.IsNullOrEmpty(owner.AccountNo) && !string.IsNullOrEmpty(owner.BankRoutingCode))
{
var UA = Cipher.decrypt(owner.AccountNo);
var BR = Cipher.decrypt(owner.BankRoutingCode);
var Name = owner.UnitOwnerName.Split(' ');
if (Name.Length > 1)
{
using (var entry = bw2.CreateDebitEntryDetail(27, BR.ToString(), UA.ToString(), 779, " 18H00A " + owner.UnitNo.ToString(), (Name[1] + ", " + Name[0]).ToUpper().ToString()))
{
//entry.CheckDigit = '0';
}
}
else
{
using (var entry = bw2.CreateDebitEntryDetail(27, BR.ToString(), UA.ToString(), 779, " 18H00B " + owner.UnitNo.ToString(), (Name[0]).ToUpper().ToString()))
{
//entry.CheckDigit = '0';
}
}
}
}
}
}
}
catch (Exception ex)
{
}
}
这是我在global.asax中的调度程序调用:-
protected void Application_Start()
{
Invoker ob = new Invoker();
ob.StartScheduling();
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
作业调用类:-
public async void StartScheduling()
{
// construct a scheduler factory
NameValueCollection props = new NameValueCollection
{
{ "quartz.serializer.type", "binary" }
};
StdSchedulerFactory factory = new StdSchedulerFactory(props);
IScheduler scheduler = await factory.GetScheduler();
await scheduler.Start();
IJobDetail job = JobBuilder.Create<ExecutableJobs>()
.WithIdentity("myJob", "group1") // name "myJob", group "group1"
.Build();
var start = DateTime.Now.AddMinutes(1);
ITrigger trigger = TriggerBuilder.Create()
.WithIdentity("trigger3", "group1")
//.StartAt(start) // if a start time is not given (if this line were omitted), "now" is implied
.WithSimpleSchedule(x => x
.WithIntervalInMinutes(1).
RepeatForever())
.ForJob(job)
.Build();
await scheduler.ScheduleJob(job, trigger);
}
我得到的例外是:-
1)异常信息 **************************************************异常类型:系统。 TypeInitializationException TypeName:ChoETL.ChoAppSettings 消息:“ ChoETL.ChoAppSettings”的类型初始值设定项引发了 例外。数据:System.Collections.ListDictionaryInternal TargetSite: System.String GetValue(System.String,System.String,布尔值) HelpLink:NULL来源:ChoETL H结果:-2146233036
StackTrace信息 **************************************************在ChoETL.ChoAppSettings。 GetValue(字符串键,字符串defaultValue, 布尔值saveDefaultValue) ChoETL.ChoETLFramework.GetConfigValue(字符串键,字符串defaultValue) 在ChoETL.ChoETLFramework.GetConfigValue [T](字符串键,T defaultValue),位于ChoETL.ChoETLFramework._Initialize()
2)异常信息 **************************************************异常类型:系统。 ArgumentException消息:不指定时必须指定exePath 在独立的exe中运行。 ParamName:NULL数据: System.Collections.ListDictionaryInternal TargetSite: System.Configuration.Configuration OpenExeConfigurationImpl(System.Configuration.ConfigurationFileMap, 布尔值,System.Configuration.ConfigurationUserLevel,System.String, 布尔值)HelpLink:NULL来源:System.Configuration H结果: -2147024809
StackTrace信息 **************************************************在System.Configuration。 ConfigurationManager.OpenExeConfigurationImpl(ConfigurationFileMap fileMap,布尔值isMachine,ConfigurationUserLevel,userLevel,字符串 exePath,布尔值preLoad)位于 System.Configuration.ConfigurationManager.OpenExeConfiguration(字符串 exePath)位于ChoETL.ChoAppSettings..cctor()
答案 0 :(得分:0)
似乎是ChoETL库中的错误。将在下一个版本中修复并发布。
同时,请执行以下操作以解决此问题
public void AchFileGenerator(DateTime Dt)
{
//Set this flag to fix the issue
ChoETLFrxBootstrap.IsSandboxEnvironment = true;
ChoNACHAConfiguration config = new ChoNACHAConfiguration();
config.DestinationBankRoutingNumber = "999999999";
config.OriginatingCompanyId = "7999999999";
.....
}
更新:
请安装最新的ChoETL(v1.0.8.4)nuget软件包。
让我知道。