2017-08-30 202 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文件包含來自構建主機的路徑。

相關問題