Skip to content

Commit a3a606e

Browse files
author
Renaud
committed
Naive attempt in progress
1 parent 04143f0 commit a3a606e

12 files changed

+943
-84
lines changed

pkg/nuget/nuspec/Quartz.Impl.MongoDB.nuspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
33
<metadata>
44
<id>quartz.impl.mongodb</id>
5-
<version>0.0.1</version>
5+
<version>1.0.0</version>
66
<title>Quartz.NET on MongoDB (requires manual config)</title>
77
<authors>Renaud Calmont</authors>
88
<owners>Renaud Calmont</owners>
@@ -14,7 +14,7 @@
1414
<language>en-US</language>
1515
<tags>nosql quartz scheduler</tags>
1616
<dependencies>
17-
<dependency id="quartz" version="2.0" />
17+
<dependency id="quartz" version="2.0.0" />
1818
<dependency id="mongocsharpdriver" version="1.4" />
1919
</dependencies>
2020
</metadata>
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using MongoDB.Bson.Serialization;
6+
using MongoDB.Bson;
7+
8+
namespace Quartz.Impl.MongoDB
9+
{
10+
public class JobDataMapSerializer : IBsonSerializer
11+
{
12+
public object Deserialize(global::MongoDB.Bson.IO.BsonReader bsonReader, Type nominalType, Type actualType, IBsonSerializationOptions options)
13+
{
14+
if (nominalType != typeof(JobDataMap) || actualType != typeof(JobDataMap))
15+
{
16+
var message = string.Format("Can't deserialize a {0} from {1}.", nominalType.FullName, this.GetType().Name);
17+
throw new BsonSerializationException(message);
18+
}
19+
20+
var bsonType = bsonReader.CurrentBsonType;
21+
if (bsonType == BsonType.Document)
22+
{
23+
JobDataMap item = new JobDataMap();
24+
bsonReader.ReadStartDocument();
25+
26+
while (bsonReader.ReadBsonType() != BsonType.EndOfDocument)
27+
{
28+
string key = bsonReader.ReadName();
29+
object value = BsonSerializer.Deserialize<object>(bsonReader);
30+
item.Add(key, value);
31+
}
32+
33+
bsonReader.ReadEndDocument();
34+
35+
return item;
36+
}
37+
else if (bsonType == BsonType.Null)
38+
{
39+
bsonReader.ReadNull();
40+
return null;
41+
}
42+
else
43+
{
44+
var message = string.Format("Can't deserialize a {0} from BsonType {1}.", nominalType.FullName, bsonType);
45+
throw new BsonSerializationException(message);
46+
}
47+
}
48+
49+
public object Deserialize(global::MongoDB.Bson.IO.BsonReader bsonReader, Type nominalType, IBsonSerializationOptions options)
50+
{
51+
return this.Deserialize(bsonReader, nominalType, nominalType, options);
52+
}
53+
54+
public IBsonSerializationOptions GetDefaultSerializationOptions()
55+
{
56+
throw new NotImplementedException();
57+
}
58+
59+
public bool GetDocumentId(object document, out object id, out Type idNominalType, out IIdGenerator idGenerator)
60+
{
61+
throw new NotImplementedException();
62+
}
63+
64+
public BsonSerializationInfo GetItemSerializationInfo()
65+
{
66+
throw new NotImplementedException();
67+
}
68+
69+
public BsonSerializationInfo GetMemberSerializationInfo(string memberName)
70+
{
71+
throw new NotImplementedException();
72+
}
73+
74+
public void Serialize(global::MongoDB.Bson.IO.BsonWriter bsonWriter, Type nominalType, object value, IBsonSerializationOptions options)
75+
{
76+
JobDataMap item = (JobDataMap)value;
77+
bsonWriter.WriteStartDocument();
78+
79+
foreach (KeyValuePair<string, object> data in item.Values)
80+
{
81+
bsonWriter.WriteName(data.Key);
82+
BsonSerializer.Serialize(bsonWriter, data.Value);
83+
}
84+
85+
bsonWriter.WriteEndDocument();
86+
}
87+
88+
public void SetDocumentId(object document, object id)
89+
{
90+
throw new NotImplementedException();
91+
}
92+
}
93+
}
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using MongoDB.Bson.Serialization;
6+
using MongoDB.Bson;
7+
using System.Reflection;
8+
9+
namespace Quartz.Impl.MongoDB
10+
{
11+
public class JobDetailImplSerializer : IBsonSerializer
12+
{
13+
public object Deserialize(global::MongoDB.Bson.IO.BsonReader bsonReader, Type nominalType, Type actualType, IBsonSerializationOptions options)
14+
{
15+
if (nominalType != typeof(JobDetailImpl) || actualType != typeof(JobDetailImpl))
16+
{
17+
var message = string.Format("Can't deserialize a {0} from {1}.", nominalType.FullName, this.GetType().Name);
18+
throw new BsonSerializationException(message);
19+
}
20+
21+
var bsonType = bsonReader.GetCurrentBsonType();
22+
if (bsonType == BsonType.Document)
23+
{
24+
bsonReader.ReadStartDocument();
25+
26+
// Ignore _id
27+
BsonSerializer.Deserialize(bsonReader, typeof(JobKey));
28+
29+
Assembly assembly = Assembly.Load(bsonReader.ReadString("_assembly"));
30+
Type type = assembly.GetType(bsonReader.ReadString("_class"));
31+
32+
IJobDetail jobDetail = new JobDetailImpl(
33+
bsonReader.ReadString("Name"),
34+
bsonReader.ReadString("Group"),
35+
type,
36+
bsonReader.ReadBoolean("RequestRecovery"),
37+
bsonReader.ReadBoolean("Durable"));
38+
39+
bsonReader.ReadBsonType();
40+
jobDetail = jobDetail.GetJobBuilder()
41+
.UsingJobData((JobDataMap)BsonSerializer.Deserialize(bsonReader, typeof(JobDataMap))).Build();
42+
43+
bsonReader.ReadEndDocument();
44+
45+
return jobDetail;
46+
}
47+
else if (bsonType == BsonType.Null)
48+
{
49+
bsonReader.ReadNull();
50+
return null;
51+
}
52+
else
53+
{
54+
var message = string.Format("Can't deserialize a {0} from BsonType {1}.", nominalType.FullName, bsonType);
55+
throw new BsonSerializationException(message);
56+
}
57+
}
58+
59+
public object Deserialize(global::MongoDB.Bson.IO.BsonReader bsonReader, Type nominalType, IBsonSerializationOptions options)
60+
{
61+
return this.Deserialize(bsonReader, nominalType, nominalType, options);
62+
}
63+
64+
public IBsonSerializationOptions GetDefaultSerializationOptions()
65+
{
66+
throw new NotImplementedException();
67+
}
68+
69+
public bool GetDocumentId(object document, out object id, out Type idNominalType, out IIdGenerator idGenerator)
70+
{
71+
throw new NotImplementedException();
72+
}
73+
74+
public BsonSerializationInfo GetItemSerializationInfo()
75+
{
76+
throw new NotImplementedException();
77+
}
78+
79+
public BsonSerializationInfo GetMemberSerializationInfo(string memberName)
80+
{
81+
throw new NotImplementedException();
82+
}
83+
84+
public void Serialize(global::MongoDB.Bson.IO.BsonWriter bsonWriter, Type nominalType, object value, IBsonSerializationOptions options)
85+
{
86+
JobDetailImpl item = (JobDetailImpl)value;
87+
bsonWriter.WriteStartDocument();
88+
89+
bsonWriter.WriteName("_id");
90+
BsonSerializer.Serialize(bsonWriter, item.Key);
91+
92+
bsonWriter.WriteString("_assembly", item.JobType.Assembly.FullName);
93+
bsonWriter.WriteString("_class", item.JobType.FullName);
94+
95+
bsonWriter.WriteString("Name", item.Name);
96+
bsonWriter.WriteString("Group", item.Name);
97+
bsonWriter.WriteBoolean("RequestRecovery", item.RequestsRecovery);
98+
bsonWriter.WriteBoolean("Durable", item.Durable);
99+
100+
bsonWriter.WriteName("JobDataMap");
101+
BsonSerializer.Serialize(bsonWriter, item.JobDataMap);
102+
103+
bsonWriter.WriteEndDocument();
104+
}
105+
106+
public void SetDocumentId(object document, object id)
107+
{
108+
throw new NotImplementedException();
109+
}
110+
}
111+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using MongoDB.Bson.Serialization;
6+
using MongoDB.Bson;
7+
8+
namespace Quartz.Impl.MongoDB
9+
{
10+
public class JobKeySerializer : IBsonSerializer
11+
{
12+
public object Deserialize(global::MongoDB.Bson.IO.BsonReader bsonReader, Type nominalType, Type actualType, IBsonSerializationOptions options)
13+
{
14+
if (nominalType != typeof(JobKey) || actualType != typeof(JobKey))
15+
{
16+
var message = string.Format("Can't deserialize a {0} from {1}.", nominalType.FullName, this.GetType().Name);
17+
throw new BsonSerializationException(message);
18+
}
19+
20+
var bsonType = bsonReader.CurrentBsonType;
21+
if (bsonType == BsonType.Document)
22+
{
23+
JobKey item;
24+
bsonReader.ReadStartDocument();
25+
26+
string[] data = bsonReader.ReadString().Split('.');
27+
if (data.Count() > 1)
28+
item = new JobKey(data[1], data[0]);
29+
else
30+
item = new JobKey(data[0]);
31+
32+
bsonReader.ReadEndDocument();
33+
34+
return item;
35+
}
36+
else if (bsonType == BsonType.Null)
37+
{
38+
bsonReader.ReadNull();
39+
return null;
40+
}
41+
else
42+
{
43+
var message = string.Format("Can't deserialize a {0} from BsonType {1}.", nominalType.FullName, bsonType);
44+
throw new BsonSerializationException(message);
45+
}
46+
}
47+
48+
public object Deserialize(global::MongoDB.Bson.IO.BsonReader bsonReader, Type nominalType, IBsonSerializationOptions options)
49+
{
50+
return this.Deserialize(bsonReader, nominalType, nominalType, options);
51+
}
52+
53+
public IBsonSerializationOptions GetDefaultSerializationOptions()
54+
{
55+
throw new NotImplementedException();
56+
}
57+
58+
public bool GetDocumentId(object document, out object id, out Type idNominalType, out IIdGenerator idGenerator)
59+
{
60+
throw new NotImplementedException();
61+
}
62+
63+
public BsonSerializationInfo GetItemSerializationInfo()
64+
{
65+
throw new NotImplementedException();
66+
}
67+
68+
public BsonSerializationInfo GetMemberSerializationInfo(string memberName)
69+
{
70+
throw new NotImplementedException();
71+
}
72+
73+
public void Serialize(global::MongoDB.Bson.IO.BsonWriter bsonWriter, Type nominalType, object value, IBsonSerializationOptions options)
74+
{
75+
JobKey item = (JobKey)value;
76+
bsonWriter.WriteStartDocument();
77+
bsonWriter.WriteName("Key");
78+
bsonWriter.WriteString(string.Format("{0}.{1}", item.Group, item.Name));
79+
bsonWriter.WriteEndDocument();
80+
}
81+
82+
public void SetDocumentId(object document, object id)
83+
{
84+
throw new NotImplementedException();
85+
}
86+
}
87+
}

0 commit comments

Comments
 (0)