mirror of
https://github.com/Prowlarr/Prowlarr.git
synced 2025-09-26 20:11:49 +02:00
Commands are stored in memory and prevents duplicate jobs
This commit is contained in:
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();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user