mirror of
https://github.com/lidarr/lidarr.git
synced 2025-07-30 19:50:15 -07:00
Commands are stored in memory and prevents duplicate jobs
This commit is contained in:
parent
a86c131761
commit
c917cdc0cc
16 changed files with 244 additions and 13 deletions
44
NzbDrone.Common/Messaging/CommandEqualityComparer.cs
Normal file
44
NzbDrone.Common/Messaging/CommandEqualityComparer.cs
Normal file
|
@ -0,0 +1,44 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
|
||||
namespace NzbDrone.Common.Messaging
|
||||
{
|
||||
public class CommandEqualityComparer : IEqualityComparer<ICommand>
|
||||
{
|
||||
public bool Equals(ICommand x, ICommand y)
|
||||
{
|
||||
var xProperties = x.GetType().GetProperties();
|
||||
var yProperties = y.GetType().GetProperties();
|
||||
|
||||
foreach (var xProperty in xProperties)
|
||||
{
|
||||
if (xProperty.Name == "CommandId")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var yProperty = yProperties.SingleOrDefault(p => p.Name == xProperty.Name);
|
||||
|
||||
if (yProperty == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!xProperty.GetValue(x, null).Equals(yProperty.GetValue(y, null)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public int GetHashCode(ICommand obj)
|
||||
{
|
||||
return obj.CommandId.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue