public void ChangePriority(DBSourceInfo source, DataType type, bool raise)
{
if (source.IsDisabled(type)) {
if (raise)
SetDisabled(source, type, false);
else return;
}
// grab the correct list
List<DBSourceInfo> sourceList = getEditableList(type);
// make sure the specified source is in our list
if (!sourceList.Contains(source))
return;
if (source.GetPriority(type) == null) {
logger.Error("No priority set for " + type.ToString());
return;
}
// make sure our index is in sync
int index = sourceList.IndexOf(source);
int oldPriority = (int) source.GetPriority(type);
if (index != oldPriority)
logger.Warn("Priority and List.IndexOf out of sync...");
// raise priority
if (raise) {
if (source.GetPriority(type) > 0) {
source.SetPriority(type, oldPriority - 1);
sourceList[index - 1].SetPriority(type, oldPriority);
source.Commit();
sourceList[index - 1].Commit();
}
}
// lower priority
else {
if (source.GetPriority(type) < sourceList.Count - 1 &&
sourceList[index + 1].GetPriority(type) != -1) {
source.SetPriority(type, oldPriority + 1);
sourceList[index + 1].SetPriority(type, oldPriority);
source.Commit();
sourceList[index + 1].Commit();
}
}
// resort the list
lock (sourceList) sourceList.Sort(sorters[type]);
}