首页 > 解决方案 > 使用石英调度程序调用方法以使用 ChoNacha 创建 ACH 文件给出异常

问题描述

我想在调度程序的帮助下自动生成 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) 异常信息 ********************************************* 异常类型:System.TypeInitializationException 类型名称:ChoETL.ChoAppSettings 消息:“ChoETL.ChoAppSettings”的类型初始化程序引发异常。数据:System.Collections.ListDictionaryInternal TargetSite:System.String GetValue(System.String, System.String, Boolean) HelpLink:NULL 来源:ChoETL HResult:-2146233036

StackTrace 信息 ********************************************* 在 ChoETL。 ChoAppSettings.GetValue(String key, String defaultValue, Boolean saveDefaultValue) at ChoETL.ChoETLFramework.GetConfigValue(String key, String defaultValue) at ChoETL.ChoETLFramework.GetConfigValue[T](String key, T defaultValue) at ChoETL.ChoETLFramework._Initialize()

2) 异常信息 ********************************************* 异常类型:System.ArgumentException 消息:当不在独立 exe 中运行时,必须指定 exePath。ParamName:NULL 数据:System.Collections.ListDictionaryInternal TargetSite:System.Configuration.Configuration OpenExeConfigurationImpl(System.Configuration.ConfigurationFileMap,Boolean,System.Configuration.ConfigurationUserLevel,System.String,Boolean)HelpLink:NULL 源:System.Configuration HResult:- 2147024809

StackTrace 信息 ********************************************* 在 System. Configuration.ConfigurationManager.OpenExeConfigurationImpl(ConfigurationFileMap fileMap, Boolean isMachine, ConfigurationUserLevel userLevel, String exePath, Boolean preLoad) at System.Configuration.ConfigurationManager.OpenExeConfiguration(String exePath) at ChoETL.ChoAppSettings..cctor()


标签: c#quartz-schedulerchoetl

解决方案


似乎是 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 包。

让我知道。


推荐阅读