ZeroInstall.DesktopIntegration.ConflictException.NewConflict C# (CSharp) Method

NewConflict() public static method

Creates an exception indicating a new desktop integration conflict.
public static NewConflict ( ConflictData existingEntry, ConflictData newEntry ) : ConflictException
existingEntry ConflictData The existing entry that is preventing from being applied.
newEntry ConflictData The new entry that is in conflict with .
return ConflictException
        public static ConflictException NewConflict(ConflictData existingEntry, ConflictData newEntry)
        {
            string message = string.Format(Resources.AccessPointNewConflict, existingEntry, newEntry);
            return new ConflictException(message) {Entries = new[] {existingEntry, newEntry}};
        }

Usage Example

示例#1
0
        /// <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);
                    }
                }
            }
        }
All Usage Examples Of ZeroInstall.DesktopIntegration.ConflictException::NewConflict