SectionUpdates
class SectionUpdates
using System.Collections;
namespace System.Configuration
{
internal class SectionUpdates
{
private readonly Hashtable _groups;
private readonly string _name;
private readonly Hashtable _sections;
private int _cMoved;
private int _cUnretrieved;
private Update _sectionGroupUpdate;
internal bool IsNew { get; set; }
internal bool IsEmpty {
get {
if (_groups.Count == 0)
return _sections.Count == 0;
return false;
}
}
internal SectionUpdates(string name)
{
_name = name;
_groups = new Hashtable();
_sections = new Hashtable();
}
private SectionUpdates FindSectionUpdates(string configKey, bool isGroup)
{
string group;
if (isGroup)
group = configKey;
else
BaseConfigurationRecord.SplitConfigKey(configKey, out group, out string _);
SectionUpdates sectionUpdates = this;
if (group.Length != 0) {
string[] array = group.Split(BaseConfigurationRecord.s_configPathSeparatorParams);
string[] array2 = array;
foreach (string text in array2) {
SectionUpdates sectionUpdates2 = (SectionUpdates)sectionUpdates._groups[text];
if (sectionUpdates2 == null) {
sectionUpdates2 = new SectionUpdates(text);
sectionUpdates._groups[text] = sectionUpdates2;
}
sectionUpdates = sectionUpdates2;
}
}
return sectionUpdates;
}
internal void CompleteUpdates()
{
bool flag = true;
foreach (SectionUpdates value in _groups.Values) {
value.CompleteUpdates();
if (!value.IsNew)
flag = false;
}
IsNew = (flag && _cMoved == _sections.Count);
}
internal void AddSection(Update update)
{
SectionUpdates sectionUpdates = FindSectionUpdates(update.ConfigKey, false);
sectionUpdates._sections.Add(update.ConfigKey, update);
sectionUpdates._cUnretrieved++;
if (update.Moved)
sectionUpdates._cMoved++;
}
internal void AddSectionGroup(Update update)
{
SectionUpdates sectionUpdates = FindSectionUpdates(update.ConfigKey, true);
sectionUpdates._sectionGroupUpdate = update;
}
private Update GetUpdate(string configKey)
{
Update update = (Update)_sections[configKey];
if (update != null) {
if (update.Retrieved)
update = null;
else {
update.Retrieved = true;
_cUnretrieved--;
if (update.Moved)
_cMoved--;
}
}
return update;
}
internal DeclarationUpdate GetSectionGroupUpdate()
{
if (_sectionGroupUpdate != null && !_sectionGroupUpdate.Retrieved) {
_sectionGroupUpdate.Retrieved = true;
return (DeclarationUpdate)_sectionGroupUpdate;
}
return null;
}
internal DefinitionUpdate GetDefinitionUpdate(string configKey)
{
return (DefinitionUpdate)GetUpdate(configKey);
}
internal DeclarationUpdate GetDeclarationUpdate(string configKey)
{
return (DeclarationUpdate)GetUpdate(configKey);
}
internal SectionUpdates GetSectionUpdatesForGroup(string group)
{
return (SectionUpdates)_groups[group];
}
internal bool HasUnretrievedSections()
{
if (_cUnretrieved > 0 || (_sectionGroupUpdate != null && !_sectionGroupUpdate.Retrieved))
return true;
foreach (SectionUpdates value in _groups.Values) {
if (value.HasUnretrievedSections())
return true;
}
return false;
}
internal void MarkAsRetrieved()
{
_cUnretrieved = 0;
foreach (SectionUpdates value in _groups.Values) {
value.MarkAsRetrieved();
}
if (_sectionGroupUpdate != null)
_sectionGroupUpdate.Retrieved = true;
}
internal void MarkGroupAsRetrieved(string groupName)
{
(_groups[groupName] as SectionUpdates)?.MarkAsRetrieved();
}
internal bool HasNewSectionGroups()
{
foreach (SectionUpdates value in _groups.Values) {
if (value.IsNew)
return true;
}
return false;
}
internal string[] GetUnretrievedSectionNames()
{
if (_cUnretrieved == 0)
return null;
string[] array = new string[_cUnretrieved];
int num = 0;
foreach (Update value in _sections.Values) {
if (!value.Retrieved) {
array[num] = value.ConfigKey;
num++;
}
}
Array.Sort(array);
return array;
}
internal string[] GetMovedSectionNames()
{
if (_cMoved == 0)
return null;
string[] array = new string[_cMoved];
int num = 0;
foreach (Update value in _sections.Values) {
if (value.Moved && !value.Retrieved) {
array[num] = value.ConfigKey;
num++;
}
}
Array.Sort(array);
return array;
}
internal string[] GetUnretrievedGroupNames()
{
ArrayList arrayList = new ArrayList();
IDictionaryEnumerator enumerator = _groups.GetEnumerator();
try {
while (enumerator.MoveNext()) {
DictionaryEntry dictionaryEntry = (DictionaryEntry)enumerator.Current;
string value = (string)dictionaryEntry.Key;
SectionUpdates sectionUpdates = (SectionUpdates)dictionaryEntry.Value;
if (sectionUpdates.HasUnretrievedSections())
arrayList.Add(value);
}
} finally {
(enumerator as IDisposable)?.Dispose();
}
if (arrayList.Count == 0)
return null;
string[] array = new string[arrayList.Count];
arrayList.CopyTo(array);
Array.Sort(array);
return array;
}
internal string[] GetNewGroupNames()
{
ArrayList arrayList = new ArrayList();
IDictionaryEnumerator enumerator = _groups.GetEnumerator();
try {
while (enumerator.MoveNext()) {
DictionaryEntry dictionaryEntry = (DictionaryEntry)enumerator.Current;
string value = (string)dictionaryEntry.Key;
SectionUpdates sectionUpdates = (SectionUpdates)dictionaryEntry.Value;
if (sectionUpdates.IsNew && sectionUpdates.HasUnretrievedSections())
arrayList.Add(value);
}
} finally {
(enumerator as IDisposable)?.Dispose();
}
if (arrayList.Count == 0)
return null;
string[] array = new string[arrayList.Count];
arrayList.CopyTo(array);
Array.Sort(array);
return array;
}
}
}