You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

137 lines
4.1 KiB
C#

9 months ago
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace JwKdsV.Entity.Common
{
public class DeviceInfo
{
public string ComputerName { get; set; }
public string Cpu { get; set; }
public string Disk { get; set; }
public string Mac { get; set; }
//public string Masterleaf { get; set; }
public override int GetHashCode()
{
return base.GetHashCode();
}
public override bool Equals(object obj)
{
DeviceInfo other = null;
if (obj is DeviceInfo)
{
other = (DeviceInfo)obj;
}
else
{
return false;
}
int score = 0;
//四项选三项相等就ture
if(!string.IsNullOrEmpty(other.ComputerName) && this.ComputerName == other.ComputerName)
{
score++;
}
if (!string.IsNullOrEmpty(other.Cpu) && !string.IsNullOrEmpty(this.Cpu))
{
string[] cpuItems = this.Cpu.Split(',');
string[] otherCpuItems = other.Cpu.Split(',');
bool isEqual = false;
foreach(string item in cpuItems)
{
foreach(string otherItem in otherCpuItems)
{
if(item == otherItem)
{
isEqual = true;
break;
}
}
if (isEqual)
{
score++;
break;
}
}
}
if (!string.IsNullOrEmpty(other.Disk) && !string.IsNullOrEmpty(this.Disk))
{
string[] items = this.Disk.Split(',');
string[] otherItems = other.Disk.Split(',');
bool isEqual = false;
foreach (string item in items)
{
foreach (string otherItem in otherItems)
{
if (item == otherItem)
{
isEqual = true;
break;
}
}
if (isEqual)
{
score++;
break;
}
}
}
if (!string.IsNullOrEmpty(other.Mac) && !string.IsNullOrEmpty(this.Mac))
{
string[] items = this.Mac.Split(',');
string[] otherItems = other.Mac.Split(',');
bool isEqual = false;
foreach (string item in items)
{
foreach (string otherItem in otherItems)
{
if (item == otherItem)
{
isEqual = true;
break;
}
}
if (isEqual)
{
score++;
break;
}
}
}
//if (!string.IsNullOrEmpty(other.Masterleaf) && !string.IsNullOrEmpty(this.Masterleaf))
//{
// string[] items = this.Masterleaf.Split(',');
// string[] otherItems = other.Masterleaf.Split(',');
// bool isEqual = false;
// foreach (string item in items)
// {
// foreach (string otherItem in otherItems)
// {
// if (item == otherItem)
// {
// isEqual = true;
// break;
// }
// }
// if (isEqual)
// {
// score++;
// break;
// }
// }
//}
return score > 2 ? true : false;
}
}
}