コード例 #1
0
        /// <summary>
        /// This middleware will check if a newer release is available in GitHub releases
        /// and output an alert with a download link if a new release exists.
        /// </summary>
        /// <param name="appRunner">the <see cref="AppRunner"/> to run the middleware</param>
        /// <param name="organizationName">The name of the organization in GitHub</param>
        /// <param name="repositoryName">The name of the repository in GitHub</param>
        /// <param name="getVersionFromReleaseName">Provide this in cases where the release name does not follow a standard 'v1.0.0-prefix' naming convention.</param>
        /// <param name="overrideHttpRequestCallback">use this callback to append headers and auth info for tests. Also useful for mocking requests for unit tests.</param>
        /// <param name="skipCommand">
        /// Use this to skip the alert for commands where the alert would result in bad output.
        /// i.e. Command output that could be piped to another command.
        /// </param>
        public static AppRunner UseNewerReleaseAlertOnGitHub(this AppRunner appRunner,
                                                             string organizationName, string repositoryName,
                                                             Func <string, string> getVersionFromReleaseName         = null,
                                                             OverrideHttpRequestCallback overrideHttpRequestCallback = null,
                                                             Predicate <Command> skipCommand = null)
        {
            if (getVersionFromReleaseName == null)
            {
                getVersionFromReleaseName = name => name;
            }

            return(appRunner.UseNewerReleaseAlert(
                       BuildLatestReleaseUrl(organizationName, repositoryName),
                       response => getVersionFromReleaseName(GetNameFromReleaseBody(response)),
                       version => $"Download from {BuildDownloadUrl(organizationName, repositoryName, version)}",
                       overrideHttpRequestCallback, skipCommand));
        }
コード例 #2
0
 /// <summary>
 /// This middleware will call the <see cref="latestReleaseUrl"/> and
 /// use <see cref="parseSemanticVersionFromResponseBodyCallback"/> to parse a
 /// semantic version from the response.<br/>
 /// If the version is greater than the file version of the assembly,
 /// an alert is output to the console.<br/>
 /// See <see cref="GitHubMiddleware"/> for an example of how to use this method.
 /// </summary>
 /// <param name="appRunner">the <see cref="AppRunner"/> to run the middleware</param>
 /// <param name="latestReleaseUrl">the url for metadata about the latest release</param>
 /// <param name="parseSemanticVersionFromResponseBodyCallback">callback to get the semantic version for response from the <see cref="latestReleaseUrl"/></param>
 /// <param name="postfixAlertMessageCallback">the results of this callback will be post-fixed to the alert message.  i.e. download link.</param>
 /// <param name="overrideHttpRequestCallback">use this callback to append headers and auth info for tests. Also useful for mocking requests for unit tests.</param>
 /// <param name="skipCommand">
 /// Use this to skip the alert for commands where the alert would result in bad output.
 /// i.e. Command output that could be piped to another command.
 /// </param>
 public static AppRunner UseNewerReleaseAlert(this AppRunner appRunner,
                                              string latestReleaseUrl,
                                              ParseSemanticVersionFromResponseBodyDelegate parseSemanticVersionFromResponseBodyCallback,
                                              PostfixAlertMessageDelegate postfixAlertMessageCallback = null,
                                              OverrideHttpRequestCallback overrideHttpRequestCallback = null,
                                              Predicate <Command> skipCommand = null)
 {
     return(appRunner.Configure(c =>
     {
         c.Services.Add(new NewerReleaseConfig
         {
             LatestReleaseUrl = latestReleaseUrl,
             ParseSematicVersionFromResponseBodyCallback = parseSemanticVersionFromResponseBodyCallback,
             PostfixAlertMessageCallback = postfixAlertMessageCallback,
             OverrideHttpRequestCallback = overrideHttpRequestCallback,
             SkipCommand = skipCommand
         });
         c.UseMiddleware(AlertOnNewVersion, MiddlewareStages.PostParseInputPreBindValues);
     }));
 }