/// <summary> /// Removes a <see cref="FeedReference"/> from one or more <see cref="InterfacePreferences"/>. /// </summary> /// <returns>The interfaces that were actually affected.</returns> protected override ICollection <FeedUri> ApplyFeedToInterfaces(FeedUri feedUri, IEnumerable <FeedUri> interfaces) { #region Sanity checks if (feedUri == null) { throw new ArgumentNullException("feedUri"); } if (interfaces == null) { throw new ArgumentNullException("interfaces"); } #endregion var modified = new List <FeedUri>(); var reference = new FeedReference { Source = feedUri }; foreach (var interfaceUri in interfaces) { var preferences = InterfacePreferences.LoadFor(interfaceUri); if (preferences.Feeds.Remove(reference)) { modified.Add(interfaceUri); } preferences.SaveFor(interfaceUri); } return(modified); }
/// <inheritdoc/> public override ExitCode Execute() { var interfaceUri = GetCanonicalUri(AdditionalArgs[0]); var preferences = InterfacePreferences.LoadFor(interfaceUri); Handler.Output( string.Format(Resources.FeedsRegistered, interfaceUri), preferences.Feeds.Select(x => x.Source)); return(ExitCode.OK); }
/// <inheritdoc/> protected override ExitCode ExecuteHelper(IEnumerable <FeedUri> interfaces, FeedReference source, Stability suggestedStabilityPolicy) { #region Sanity checks if (interfaces == null) { throw new ArgumentNullException(nameof(interfaces)); } if (source == null) { throw new ArgumentNullException(nameof(source)); } #endregion var modifiedInterfaces = new List <FeedUri>(); foreach (var interfaceUri in interfaces) { var preferences = InterfacePreferences.LoadFor(interfaceUri); if (preferences.Feeds.AddIfNew(source)) { modifiedInterfaces.Add(interfaceUri); } var effectiveStabilityPolicy = (preferences.StabilityPolicy == Stability.Unset) ? (Config.HelpWithTesting ? Stability.Testing : Stability.Stable) : preferences.StabilityPolicy; if (effectiveStabilityPolicy < suggestedStabilityPolicy) { string stabilityMessage = string.Format(Resources.StabilityPolicySingleImplementation, suggestedStabilityPolicy); if (Handler.Ask( stabilityMessage + Environment.NewLine + string.Format(Resources.StabilityPolicyAutoSet, interfaceUri.ToStringRfc()), defaultAnswer: false, alternateMessage: stabilityMessage)) { preferences.StabilityPolicy = suggestedStabilityPolicy; } } preferences.SaveFor(interfaceUri); } if (modifiedInterfaces.Count == 0) { Handler.OutputLow(Resources.FeedManagement, Resources.FeedAlreadyRegistered); return(ExitCode.NoChanges); } else { Handler.OutputLow(Resources.FeedManagement, Resources.FeedRegistered + Environment.NewLine + StringUtils.Join(Environment.NewLine, modifiedInterfaces.Select(x => x.ToStringRfc()))); return(ExitCode.OK); } }
/// <inheritdoc/> protected override ExitCode ExecuteHelper(IEnumerable <FeedUri> interfaces, FeedReference source, Stability suggestedStabilityPolicy) { #region Sanity checks if (interfaces == null) { throw new ArgumentNullException(nameof(interfaces)); } if (source == null) { throw new ArgumentNullException(nameof(source)); } #endregion var modifiedInterfaces = new List <FeedUri>(); foreach (var interfaceUri in interfaces) { var preferences = InterfacePreferences.LoadFor(interfaceUri); if (preferences.Feeds.Remove(source)) { modifiedInterfaces.Add(interfaceUri); if (preferences.StabilityPolicy == suggestedStabilityPolicy && suggestedStabilityPolicy != Stability.Unset) { if (Handler.Ask(string.Format(Resources.StabilityPolicyReset, interfaceUri.ToStringRfc()), defaultAnswer: false)) { preferences.StabilityPolicy = Stability.Unset; } } preferences.SaveFor(interfaceUri); } } if (modifiedInterfaces.Count == 0) { Handler.OutputLow(Resources.FeedManagement, Resources.FeedNotRegistered); return(ExitCode.NoChanges); } else { Handler.OutputLow(Resources.FeedManagement, Resources.FeedUnregistered + Environment.NewLine + StringUtils.Join(Environment.NewLine, modifiedInterfaces.Select(x => x.ToStringRfc()))); return(ExitCode.OK); } }