2017-08-30 203 views
0

尝试在System.Data.Sqlite.Core(1.0.105.2)上使用带有Quartz scheduler 3.0.0-alpha3的Sqlite,并使用以下配置.NET 2.0核心控制台应用程序编译在我的Mac OSX的Visual Studio:使用Quartz.net 3.x和Sqlite 3.0的.NET Core 2.0控制台应用程序

NameValueCollection props = new NameValueCollection { 
{ "quartz.threadPool.type", "Quartz.Simpl.SimpleThreadPool, Quartz" }, 
{ "quartz.threadPool.threadCount", "10" }, 
{ "quartz.jobStore.type", "Quartz.Impl.AdoJobStore.JobStoreTX, Quartz" }, 
{ "quartz.jobStore.misfireThreshold", "60000" }, 
{ "quartz.jobStore.lockHandler.type", "Quartz.Impl.AdoJobStore.UpdateLockRowSemaphore, Quartz" }, 
{ "quartz.jobStore.useProperties", "true" }, 
{ "quartz.jobStore.dataSource", "default" }, 
{ "quartz.jobStore.tablePrefix", "QRTZ_" }, 
{ "quartz.jobStore.driverDelegateType", "Quartz.Impl.AdoJobStore.SQLiteDelegate, Quartz" }, 
{ "quartz.dataSource.default.provider", "SQLite-10" }, 
{ "quartz.dataSource.default.connectionString", "Data Source=quartznet.db;Version=3;" } 
}; 

实际行为

Quartz.SchedulerException:无法初始化数据源:SqliteDS ---> System.ArgumentOutOfRangeException:没有元数据信息n提供者'SQLite-10'参数名称:providerName

at Quartz.Impl.AdoJobStore.Common.DbProvider.GetDbMetadata(String providerName)in C:\ projects \ quartznet-6fcn8 \ src \ Quartz \ Impl \ AdoJobStore \ Common \ DbProvider.cs:line 118 at C:\ projects \ quartznet-6fcn8 \ src \ Quartz \ Impl \ AdoJobStore \ Common \ DbProvider中Quartz.Impl.AdoJobStore.Common.DbProvider..ctor(String dbProviderName,String connectionString) .cs:line 74 at Quartz.Impl.StdSchedulerFactory.d__65.MoveNext()in C:\ projects \ quartznet-6fcn8 \ src \ Quartz \ Impl \ StdSchedulerFactory.cs:line 614 ---内部异常堆栈跟踪结束--- at Quartz.Impl.StdSchedulerFactory.d__65.MoveNext()in C:\ projects \ quartznet-6fcn8 \ src \ Quartz \ Impl \ StdSchedulerFactory.cs:line 623 - - 从抛出异常的上一个位置结束堆栈跟踪---在Quartz.Impl的System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务) 处的 。 StdSchedulerFactory.d__69.MoveNext()在C:\ projects \ quartznet-6fcn8 \ src \ Quartz \ Impl \ StdSchedulerFactory.cs中:第1118行 ---从之前位置抛出异常的堆栈跟踪结束--- at System .Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务task) 在System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() 在BackgroundProcessingWithQuartz.Program.d__1.MoveNext( )in/Users/ja kesmith/Projects/BackgroundProcessingWithQuartz/BackgroundProcessingWithQuartz/BackgroundProcessingWithQuartz/Program.cs:line 44 [请参阅嵌套异常:System.ArgumentOutOfRangeException:没有提供程序'SQLite-10'的元数据信息 参数名称:providerName at Quartz.Impl.AdoJobStore。 C:\ projects \ quartznet-6fcn8 \ src \ Quartz \ Impl \ AdoJobStore \ Common \ DbProvider.cs中的Common.DbProvider.GetDbMetadata(String providerName):第118行 at Quartz.Impl.AdoJobStore.Common.DbProvider..ctor字符串dbProviderName,字符串connectionString)在C:\ projects \ quartznet-6fcn8 \ src \ Quartz \ Impl \ AdoJobStore \ Common \ DbProvider.cs中:第74行 at Quartz.Impl.StdSchedulerFactory.d__65.MoveNext()in C:\ projects \ quartznet-6fcn8 \ src \ Quartz \ Impl \ StdSchedulerFactory.cs:line 614

我缺少什么?一切都通过我的Visual Studio for Mac上的NuGet安装。另外,为什么当dll实际上在Mac上运行时,有C盘的引用。请帮忙。

回答

3

石英3.0测试1支持Microsoft.Data.Sqlite开箱

添加所需的包的引用:

PackageReference包括= “Microsoft.Data.Sqlite” 版本=“2.0。0" />

PackageReference包括= “石英” 版本= “3.0.0-β1”/>

class Program 
{ 
    static void Main() 
    { 
     try 
     { 
      Run().GetAwaiter().GetResult(); 
     } 
     catch (Exception e) 
     { 
      Console.Error.WriteLine(e); 
     } 
     finally 
     { 
      Console.ReadLine(); 
     } 
    } 

    private static async Task Run() 
    { 
     var properties = new NameValueCollection 
     { 
      ["quartz.jobStore.type"] = "Quartz.Impl.AdoJobStore.JobStoreTX, Quartz", 
      ["quartz.jobStore.useProperties"] = "true", 
      ["quartz.jobStore.dataSource"] = "default", 
      ["quartz.jobStore.tablePrefix"] = "QRTZ_", 
      ["quartz.jobStore.driverDelegateType"] = "Quartz.Impl.AdoJobStore.SQLiteDelegate, Quartz", 
      ["quartz.dataSource.default.provider"] = "SQLite-Microsoft", 
      ["quartz.dataSource.default.connectionString"] = "Data Source=test.db", 
      ["quartz.serializer.type"] = "binary" 
     }; 


     ISchedulerFactory sf = new StdSchedulerFactory(properties); 
     IScheduler sched = await sf.GetScheduler(); 

     await sched.Start(); 

     Thread.Sleep(TimeSpan.FromMinutes(10)); 
    } 
} 

注册自定义提供元数据

只有当你想需要一些其他提供商比Microsoft.Data.Sqlite或使用版本比beta老1

您需要注册元数据首先能够引用自定义SQLite提供程序。这里有一个例子:

项目文件:

<Project Sdk="Microsoft.NET.Sdk"> 
    <PropertyGroup> 
    <OutputType>Exe</OutputType> 
    <TargetFramework>netcoreapp2.0</TargetFramework> 
    </PropertyGroup> 
    <ItemGroup> 
    <PackageReference Include="Microsoft.Data.Sqlite" Version="2.0.0" /> 
    <PackageReference Include="Quartz" Version="3.0.0-alpha3" /> 
    </ItemGroup> 
</Project> 

代码:

using System; 
using System.Collections.Specialized; 
using System.Data; 
using System.Threading; 
using System.Threading.Tasks; 

using Microsoft.Data.Sqlite; 

using Quartz; 
using Quartz.Impl; 
using Quartz.Impl.AdoJobStore.Common; 

namespace ConsoleApplication1 
{ 
    class Program 
    { 
     static void Main() 
     { 
      Run().GetAwaiter().GetResult(); 
     } 

     private static async Task Run() 
     { 
      DbProvider.RegisterDbMetadata("sqlite-custom", new DbMetadata() 
      { 
       AssemblyName = typeof(SqliteConnection).Assembly.GetName().Name, 
       ConnectionType = typeof(SqliteConnection), 
       CommandType = typeof(SqliteCommand), 
       ParameterType = typeof(SqliteParameter), 
       ParameterDbType = typeof(DbType), 
       ParameterDbTypePropertyName = "DbType", 
       ParameterNamePrefix = "@", 
       ExceptionType = typeof(SqliteException), 
       BindByName = true 
      }); 


      var properties = new NameValueCollection 
      { 
       ["quartz.jobStore.type"] = "Quartz.Impl.AdoJobStore.JobStoreTX, Quartz", 
       ["quartz.jobStore.useProperties"] = "true", 
       ["quartz.jobStore.dataSource"] = "default", 
       ["quartz.jobStore.tablePrefix"] = "QRTZ_", 
       ["quartz.jobStore.driverDelegateType"] = "Quartz.Impl.AdoJobStore.SQLiteDelegate, Quartz", 
       ["quartz.dataSource.default.provider"] = "sqlite-custom", 
       ["quartz.dataSource.default.connectionString"] = "Data Source=test.db", 
       ["quartz.jobStore.lockHandler.type"] = "Quartz.Impl.AdoJobStore.UpdateLockRowSemaphore, Quartz", 
       ["quartz.serializer.type"] = "binary" 
      }; 


      ISchedulerFactory sf = new StdSchedulerFactory(properties); 
      IScheduler sched = await sf.GetScheduler(); 

      await sched.Start(); 

      Thread.Sleep(TimeSpan.FromMinutes(10)); 
     } 
    } 
} 

您所看到的,由于这样的事实,Quartz库是在Windows机器上编译到C盘引用这将使PDB文件包含来自构建主机的路径。

相关问题