Fixed LINQ exception in Orchard.MessageBus.

This commit is contained in:
Daniel Stolt
2015-02-04 15:49:13 +01:00
parent dd2fb47cdb
commit 99072faf14

View File

@@ -30,7 +30,7 @@ namespace Orchard.MessageBus.Brokers.SqlServer {
private static int lastMessageId = 0; private static int lastMessageId = 0;
private bool _stopped; private bool _stopped;
private Dictionary<string, List<Action<string, string>>> _handlers = new Dictionary<string,List<Action<string,string>>>(); private Dictionary<string, List<Action<string, string>>> _handlers = new Dictionary<string, List<Action<string, string>>>();
public Worker(ShellSettings shellSettings, IHostNameProvider hostNameProvider) { public Worker(ShellSettings shellSettings, IHostNameProvider hostNameProvider) {
_hostNameProvider = hostNameProvider; _hostNameProvider = hostNameProvider;
@@ -101,6 +101,10 @@ namespace Orchard.MessageBus.Brokers.SqlServer {
private void ProcessMessages(IEnumerable<MessageRecord> messages) { private void ProcessMessages(IEnumerable<MessageRecord> messages) {
if (!messages.Any()) {
return;
}
// if this is the first time it's executed we just need to get the highest Id // if this is the first time it's executed we just need to get the highest Id
if (lastMessageId == 0) { if (lastMessageId == 0) {
lastMessageId = messages.Max(x => x.Id); lastMessageId = messages.Max(x => x.Id);
@@ -145,17 +149,17 @@ namespace Orchard.MessageBus.Brokers.SqlServer {
GetHandlersForChannel(channel).Add(handler); GetHandlersForChannel(channel).Add(handler);
} }
private List<Action<string, string>> GetHandlersForChannel(string channel) { private List<Action<string, string>> GetHandlersForChannel(string channel) {
List<Action<string, string>> channelHandlers; List<Action<string, string>> channelHandlers;
if(!_handlers.TryGetValue(channel, out channelHandlers)) { if (!_handlers.TryGetValue(channel, out channelHandlers)) {
channelHandlers = new List<Action<string,string>>(); channelHandlers = new List<Action<string, string>>();
_handlers.Add(channel, channelHandlers); _handlers.Add(channel, channelHandlers);
}
return channelHandlers;
} }
return channelHandlers;
}
public SqlCommand CreateCommand(SqlConnection connection) { public SqlCommand CreateCommand(SqlConnection connection) {
SqlCommand command = new SqlCommand(commandText, connection); SqlCommand command = new SqlCommand(commandText, connection);