/// <summary> /// Determines whether this catalog contains a <see cref="Feed"/> with a specific URI. /// </summary> /// <param name="uri">The <see cref="Feed.Uri"/> to look for.</param> /// <returns><c>true</c> if a matching feed was found; <c>false</c> otherwise.</returns> public bool ContainsFeed(FeedUri uri) { #region Sanity checks if (uri == null) { throw new ArgumentNullException(nameof(uri)); } #endregion return(Feeds.Any(feed => feed.Uri == uri)); }
/// <summary> /// Returns the <see cref="Feed"/> with a specific URI. Safe for missing elements. /// </summary> /// <param name="uri">The <see cref="Feed.Uri"/> to look for.</param> /// <returns>The identified <see cref="Feed"/>; <c>null</c> if no matching entry was found.</returns> public Feed?GetFeed(FeedUri uri) { #region Sanity checks if (uri == null) { throw new ArgumentNullException(nameof(uri)); } #endregion return(Feeds.FirstOrDefault(feed => feed.Uri == uri)); }
public void TestNormalizeLocalPath() { var localUri = new FeedUri(WindowsUtils.IsWindows ? @"C:\local\feed.xml" : "/local/feed.xml"); var implementation1 = new Implementation { ID = "./subdir" }; implementation1.Normalize(localUri); implementation1.ID.Should().Be(WindowsUtils.IsWindows ? @"C:\local\.\subdir" : "/local/./subdir"); implementation1.LocalPath.Should().Be(WindowsUtils.IsWindows ? @"C:\local\.\subdir" : "/local/./subdir"); var implementation2 = new Implementation { ID = "./wrong", LocalPath = "subdir" }; implementation2.Normalize(localUri); implementation2.ID.Should().Be("./wrong"); implementation2.LocalPath.Should().Be(WindowsUtils.IsWindows ? @"C:\local\subdir" : "/local/subdir"); }
/// <summary> /// Returns the <see cref="Feed"/> with a specific URI. /// </summary> /// <param name="uri">The <see cref="Feed.Uri"/> to look for.</param> /// <returns>The identified <see cref="Feed"/>.</returns> /// <exception cref="KeyNotFoundException">No <see cref="Feed"/> matching <paramref name="uri"/> was found in <see cref="Feeds"/>.</exception> public Feed this[FeedUri uri] { get { #region Sanity checks if (uri == null) { throw new ArgumentNullException(nameof(uri)); } #endregion try { return(Feeds.First(feed => feed.Uri == uri)); } #region Error handling catch (InvalidOperationException) { throw new KeyNotFoundException(string.Format(Resources.FeedNotInCatalog, uri)); } #endregion } }
/// <summary> /// Creates a new feed target. /// </summary> /// <param name="uri">The URI or local path (must be absolute) to the feed.</param> /// <param name="feed">The data acquired from <paramref name="uri"/>. <see cref="Model.Feed.Normalize"/> has already been called.</param> public FeedTarget(FeedUri uri, Feed feed) { Uri = uri ?? throw new ArgumentNullException(nameof(uri)); Feed = feed ?? throw new ArgumentNullException(nameof(feed)); }