Невозможно запланировать задачи по Quartz.NET - PullRequest
0 голосов
/ 20 мая 2019

Вот основная процедура планирования выходного задания

Public Sub ScheduleOutput()

    Dim sf As ISchedulerFactory = New StdSchedulerFactory()

    Dim scheduler As IScheduler = sf.GetScheduler()
        scheduler.Start()

    Dim job As IJobDetail = JobBuilder.Create(Of OutputJob)().
                WithIdentity("output", "output").Build()

    Dim trigger As ITrigger = TriggerBuilder.Create().
                WithIdentity("trigger", "trigger").ForJob("output").
                WithSchedule(CronScheduleBuilder.DailyAtHourAndMinute(setHour.Text, setMinute.Text)).
                Build()
    MsgBox("end")

End Sub

и класс работы

Public Class OutputJob
    Implements IJob

    Public Sub Execute(context As IJobExecutionContext) Implements IJob.Execute

        Output()

    End Sub

    Public Sub Output()

        Dim b = Convert.FromBase64String(HttpContext.Current.Request.Form("encodedhtml"))
        Dim html = System.Text.Encoding.UTF8.GetString(b)

        HttpContext.Current.Response.Clear()
        HttpContext.Current.Response.ContentType = "text/html"
        HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=""Dashboard.html""")
        HttpContext.Current.Response.Write(html)
        HttpContext.Current.Response.End()

    End Sub

End Class

Файл Web.config

<configuration>
  <configSections>
    <sectionGroup name="common">
      <section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
    </sectionGroup>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
  </configSections>
  <common>
    <logging>
      <factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net1213">
        <arg key="configType" value="INLINE"/>
        <arg key="configFile" value="~/log4net.config"/>
        <arg key="level" value="INFO" />
      </factoryAdapter>
    </logging>
  </common>
  <log4net>
    <appender name="EventLogAppender" type="log4net.Appender.EventLogAppender">
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%d [%t] %-5p %l - %m%n" />
      </layout>
    </appender>
    <root>
      <level value="INFO" />
      <appender-ref ref="EventLogAppender" />
    </root>
  </log4net>
</configuration>

Когда я пытаюсь запустить код, в Dim sf As ISchedulerFactory = New StdSchedulerFactory()

возникает исключение

Исключение типа 'System.TypeInitializationException' возникло в нечто .dll, но не было обработано в коде пользователя

Дополнительная информация: инициализатор типа для 'Quartz.Impl.StdSchedulerFactory' вызвал исключение.

Сообщения об исключениях в выводе (отображаются внизу Visual Studio):

Первое исключение типа «Common.Logging.ConfigurationException» произошло в Common.Logging.dll Первое исключение типа «System.TypeInitializationException» произошло что-то.dll

Как я могу исправить исключение?

А какие-нибудь другие части кода, которые могут вызвать ошибки / исключения?

Я долго боролся за это и искал много решений, но ни одно из них не может реально помочь мне (или просто я не знаю, как изменить, чтобы соответствовать моему коду), потому что мне действительно не хватает знаний о планировании задач и настройках конфигурации.

1 Ответ

0 голосов
/ 25 мая 2019

Кварц зависит только от одной сторонней библиотеки Common.Logging (которая содержит абстракции журналирования, которые позволяют вам использовать поставщика журналирования, который подходит вам лучше всего). Для успешной работы Quartz.NET

у вас должны быть Quartz.dll, Commong.Logging.dll и Commong.Logging.Core.dll.

И замените раздел Common.Logging.Log4Net1213.dll на:

  <common>
    <logging>
      <factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net1213">
        <arg key="configType" value="INLINE"/>
        <arg key="level" value="INFO" />
      </factoryAdapter>
    </logging>
  </common>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
            <assemblyIdentity name="Common.Logging" publicKeyToken="af08829b84f0328e" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-3.3.1.0" newVersion="3.3.1.0" />
        </dependentAssembly>
    </assemblyBinding>
  </runtime>
...