mirror of
https://github.com/tribufu/ServerManagers
synced 2026-05-06 15:17:34 +00:00
source code checkin
This commit is contained in:
parent
5f8fb2c825
commit
7e57b72e35
675 changed files with 168433 additions and 0 deletions
67
src/ServerManager.Common/Model/ProcessorAffinityList.cs
Normal file
67
src/ServerManager.Common/Model/ProcessorAffinityList.cs
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
using ServerManagerTool.Common.Utils;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
|
||||
namespace ServerManagerTool.Common.Model
|
||||
{
|
||||
public class ProcessorAffinityList : SortableObservableCollection<ProcessorAffinityItem>
|
||||
{
|
||||
private bool _allProcessors;
|
||||
|
||||
public ProcessorAffinityList(BigInteger affinityValue)
|
||||
{
|
||||
AllProcessors = true;
|
||||
PopulateAffinities(affinityValue);
|
||||
}
|
||||
|
||||
public bool AllProcessors
|
||||
{
|
||||
get { return this._allProcessors; }
|
||||
set
|
||||
{
|
||||
this._allProcessors = value;
|
||||
OnPropertyChanged(new System.ComponentModel.PropertyChangedEventArgs(nameof(AllProcessors)));
|
||||
}
|
||||
}
|
||||
|
||||
public BigInteger AffinityValue
|
||||
{
|
||||
get
|
||||
{
|
||||
if (AllProcessors || this.Count(i => i.Selected) == this.Count)
|
||||
return BigInteger.Zero;
|
||||
|
||||
var affinity = BigInteger.Zero;
|
||||
foreach (var value in this.Where(i => i.Selected).Select(i => i.AffinityValue))
|
||||
affinity += value;
|
||||
return affinity;
|
||||
}
|
||||
}
|
||||
|
||||
private void PopulateAffinities(BigInteger affinityValue)
|
||||
{
|
||||
var list = ProcessUtils.GetProcessorAffinityList();
|
||||
var index = 0;
|
||||
|
||||
if (!ProcessUtils.IsProcessorAffinityValid(affinityValue))
|
||||
affinityValue = BigInteger.Zero;
|
||||
|
||||
foreach (var item in list)
|
||||
{
|
||||
if (item == 0)
|
||||
continue;
|
||||
|
||||
this.Add(new ProcessorAffinityItem() { Selected = affinityValue == BigInteger.Zero || ((affinityValue & item) == item), AffinityValue = item, Description = $"{index}" });
|
||||
index++;
|
||||
}
|
||||
|
||||
var affinity = BigInteger.Zero;
|
||||
if (this.Count(i => i.Selected) != this.Count)
|
||||
{
|
||||
foreach (var value in this.Where(i => i.Selected).Select(i => i.AffinityValue))
|
||||
affinity += value;
|
||||
}
|
||||
AllProcessors = affinity == BigInteger.Zero;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue