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
69
src/ServerManager.Common/Model/CustomSectionList.cs
Normal file
69
src/ServerManager.Common/Model/CustomSectionList.cs
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
using ServerManagerTool.Common.Interfaces;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace ServerManagerTool.Common.Model
|
||||
{
|
||||
public class CustomList : SortableObservableCollection<CustomSection>, IIniSectionCollection
|
||||
{
|
||||
public IIniValuesCollection[] Sections
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
public void Add(string sectionName, string[] values)
|
||||
{
|
||||
Add(sectionName, values, true);
|
||||
}
|
||||
|
||||
public void Add(string sectionName, string[] values, bool clearExisting)
|
||||
{
|
||||
var section = this.Items.FirstOrDefault(s => s.SectionName.Equals(sectionName, StringComparison.OrdinalIgnoreCase) && !s.IsDeleted);
|
||||
if (section == null)
|
||||
{
|
||||
section = new CustomSection();
|
||||
section.SectionName = sectionName;
|
||||
|
||||
this.Add(section);
|
||||
}
|
||||
|
||||
if (clearExisting)
|
||||
section.Clear();
|
||||
section.FromIniValues(values);
|
||||
}
|
||||
|
||||
public new void Clear()
|
||||
{
|
||||
foreach (var section in this)
|
||||
{
|
||||
section.IsDeleted = true;
|
||||
}
|
||||
Update();
|
||||
}
|
||||
|
||||
public new void Remove(CustomSection item)
|
||||
{
|
||||
if (item != null)
|
||||
item.IsDeleted = true;
|
||||
Update();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"Count={Count}";
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
foreach (var section in this)
|
||||
{
|
||||
section.Update();
|
||||
}
|
||||
|
||||
this.Sort(s => s.SectionName);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue