示例#1
0
    /// <summary>
    /// Gets the latest revision for the file with the given title.
    /// </summary>
    /// <param name="options">An <see cref="IWikiOptions"/> instance.</param>
    /// <param name="dataStore">An <see cref="IDataStore"/> instance.</param>
    /// <param name="title">The title of the file to retrieve.</param>
    /// <returns>The latest revision for the file with the given title; or <see
    /// langword="null"/> if no such file exists.</returns>
    public static WikiFile?GetFile(
        IWikiOptions options,
        IDataStore dataStore,
        string title)
    {
        WikiFile?file      = null;
        var      reference = PageReference.GetPageReference(dataStore, title, options.FileNamespace);

        if (reference is not null)
        {
            file = dataStore.GetItem <WikiFile>(reference.Reference);
        }
        // If no exact match exists, ignore case if only one such match exists.
        if (file is null)
        {
            var normalizedReference = NormalizedPageReference.GetNormalizedPageReference(dataStore, title, options.FileNamespace);
            if (normalizedReference?.References.Count == 1)
            {
                file = dataStore.GetItem <WikiFile>(normalizedReference.References[0]);
            }
        }

        return(file);
    }