/// <summary>
/// Checks new <see cref="AccessPoint"/> candidates for conflicts with existing ones.
/// </summary>
/// <param name="appList">The <see cref="AppList"/> containing the existing <see cref="AccessPoint"/>s.</param>
/// <param name="accessPoints">The set of <see cref="AccessPoint"/>s candidates to check.</param>
/// <param name="appEntry">The <see cref="AppEntry"/> the <paramref name="accessPoints"/> are intended for.</param>
/// <exception cref="KeyNotFoundException">An <see cref="AccessPoint"/> reference to a <see cref="Capability"/> is invalid.</exception>
/// <exception cref="ConflictException">One or more of the <paramref name="accessPoints"/> would cause a conflict with the existing <see cref="AccessPoint"/>s in <see cref="AppList"/>.</exception>
public static void CheckForConflicts(this AppList appList, IEnumerable <AccessPoint> accessPoints, AppEntry appEntry)
{
#region Sanity checks
if (appList == null)
{
throw new ArgumentNullException(nameof(appList));
}
if (accessPoints == null)
{
throw new ArgumentNullException(nameof(accessPoints));
}
if (appEntry == null)
{
throw new ArgumentNullException(nameof(appEntry));
}
#endregion
var newConflictData = accessPoints.GetConflictData(appEntry);
var existingConflictData = appList.Entries.GetConflictData();
foreach ((string conflictId, var newEntry) in newConflictData)
{
if (existingConflictData.TryGetValue(conflictId, out var existingEntry))
{
// Ignore conflicts that are actually just re-applications of existing access points
if (existingEntry != newEntry)
{
throw ConflictException.NewConflict(existingEntry, newEntry);
}
}
}
}