Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added option to deserialize DateTimeOffset from BsonType.Array #31

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/Quartz.Impl.MongoDB.Tests/App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
<?xml version="1.0"?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<connectionStrings>
<add name="quartznet-mongodb" connectionString="server=localhost;database=quartznet_tests"/>
<add name="quartznet-mongodb" connectionString="server=localhost;database=quartznet_tests" />
</connectionStrings>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" /></startup>
<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.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Common.Logging, Version=2.1.2.0, Culture=neutral, PublicKeyToken=af08829b84f0328e, processorArchitecture=MSIL">
<Reference Include="Common.Logging, Version=3.0.0.0, Culture=neutral, PublicKeyToken=af08829b84f0328e, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Common.Logging.2.1.2\lib\net40\Common.Logging.dll</HintPath>
<HintPath>..\packages\Common.Logging.3.0.0\lib\net40\Common.Logging.dll</HintPath>
</Reference>
<Reference Include="Common.Logging.Core">
<HintPath>..\packages\Common.Logging.Core.3.0.0\lib\net40\Common.Logging.Core.dll</HintPath>
</Reference>
<Reference Include="Machine.Specifications">
<HintPath>..\packages\Machine.Specifications.0.5.10\lib\net40\Machine.Specifications.dll</HintPath>
Expand Down
3 changes: 2 additions & 1 deletion src/Quartz.Impl.MongoDB.Tests/packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Common.Logging" version="2.1.2" targetFramework="net45" />
<package id="Common.Logging" version="3.0.0" targetFramework="net40" />
<package id="Common.Logging.Core" version="3.0.0" targetFramework="net40" />
<package id="Machine.Specifications" version="0.5.10" targetFramework="net45" />
<package id="Quartz" version="2.1.2" />
</packages>
11 changes: 11 additions & 0 deletions src/Quartz.Impl.MongoDB/DateTimeOffsetSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,23 @@ public override object Deserialize(

var bsonType = bsonReader.GetCurrentBsonType();
DateTimeOffset value;
long ticks;
TimeSpan offset;


switch (bsonType)
{
case BsonType.DateTime:
// use an intermediate BsonDateTime so MinValue and MaxValue are handled correctly
value = (new BsonDateTime(bsonReader.ReadDateTime())).ToUniversalTime();
break;
case BsonType.Array:
bsonReader.ReadStartArray();
ticks = bsonReader.ReadInt64();
offset = TimeSpan.FromMinutes(bsonReader.ReadInt32());
bsonReader.ReadEndArray();
value= new DateTimeOffset(ticks, offset);
break;
case BsonType.Document:
bsonReader.ReadStartDocument();
bsonReader.ReadDateTime("DateTimeUTC"); // ignore value (use Ticks instead)
Expand Down
18 changes: 16 additions & 2 deletions src/Quartz.Impl.MongoDB/JobStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ public virtual void StoreJobAndTrigger(IJobDetail newJob, IOperableTrigger newTr
public virtual bool IsJobGroupPaused(string groupName)
{
var result = this.PausedJobGroups.FindOneByIdAs<BsonDocument>(groupName);
return !result.IsBsonNull;
return result != null && !result.IsBsonNull;
}

/// <summary>
Expand All @@ -373,7 +373,7 @@ public virtual bool IsJobGroupPaused(string groupName)
public virtual bool IsTriggerGroupPaused(string groupName)
{
var result = this.PausedTriggerGroups.FindOneByIdAs<BsonDocument>(groupName);
return !result.IsBsonNull;
return result != null && !result.IsBsonNull;
}

/// <summary>
Expand Down Expand Up @@ -786,6 +786,20 @@ public virtual TriggerState GetTriggerState(TriggerKey triggerKey)
}
}

/// <summary>
/// Determine whether a <see cref="ICalendar" /> with the given identifier already
/// exists within the scheduler.
/// </summary>
/// <param name="calName">calName the identifier to check for</param>
/// <returns>true if a Calendar exists with the given identifier</returns>
public virtual bool CalendarExists(string calName)
{
lock (lockObject)
{
return this.Calendars.FindOneByIdAs<BsonDocument>(calName) != null;
}
}

/// <summary>
/// Store the given <see cref="ICalendar" />.
/// </summary>
Expand Down
16 changes: 10 additions & 6 deletions src/Quartz.Impl.MongoDB/Quartz.Impl.MongoDB.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,20 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Common.Logging, Version=2.1.2.0, Culture=neutral, PublicKeyToken=af08829b84f0328e, processorArchitecture=MSIL">
<Reference Include="Common.Logging, Version=3.0.0.0, Culture=neutral, PublicKeyToken=af08829b84f0328e, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Common.Logging.2.1.2\lib\net40\Common.Logging.dll</HintPath>
<HintPath>..\packages\Common.Logging.3.0.0\lib\net40\Common.Logging.dll</HintPath>
</Reference>
<Reference Include="MongoDB.Bson, Version=1.8.1.20, Culture=neutral, PublicKeyToken=f686731cfb9cc103, processorArchitecture=MSIL">
<Reference Include="Common.Logging.Core">
<HintPath>..\packages\Common.Logging.Core.3.0.0\lib\net40\Common.Logging.Core.dll</HintPath>
</Reference>
<Reference Include="MongoDB.Bson, Version=1.9.2.235, Culture=neutral, PublicKeyToken=f686731cfb9cc103, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\mongocsharpdriver.1.8.1\lib\net35\MongoDB.Bson.dll</HintPath>
<HintPath>..\packages\mongocsharpdriver.1.9.2\lib\net35\MongoDB.Bson.dll</HintPath>
</Reference>
<Reference Include="MongoDB.Driver, Version=1.8.1.20, Culture=neutral, PublicKeyToken=f686731cfb9cc103, processorArchitecture=MSIL">
<Reference Include="MongoDB.Driver, Version=1.9.2.235, Culture=neutral, PublicKeyToken=f686731cfb9cc103, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\mongocsharpdriver.1.8.1\lib\net35\MongoDB.Driver.dll</HintPath>
<HintPath>..\packages\mongocsharpdriver.1.9.2\lib\net35\MongoDB.Driver.dll</HintPath>
</Reference>
<Reference Include="Quartz, Version=2.1.2.400, Culture=neutral, PublicKeyToken=f6b8c98a402cc8a4, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
Expand Down Expand Up @@ -72,6 +75,7 @@
<Compile Include="TriggerKeySerializer.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
11 changes: 11 additions & 0 deletions src/Quartz.Impl.MongoDB/app.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<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.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
5 changes: 3 additions & 2 deletions src/Quartz.Impl.MongoDB/packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Common.Logging" version="2.1.2" targetFramework="net40" />
<package id="mongocsharpdriver" version="1.8.1" targetFramework="net40" />
<package id="Common.Logging" version="3.0.0" targetFramework="net40" />
<package id="Common.Logging.Core" version="3.0.0" targetFramework="net40" />
<package id="mongocsharpdriver" version="1.9.2" targetFramework="net40" />
<package id="Quartz" version="2.1.2" />
</packages>