internal static async Task RunNuGetPluginsAsync(IPlugin plugin, ILogger logger, TimeSpan timeout, CancellationToken cancellationToken)
        {
            SemaphoreSlim semaphore = new SemaphoreSlim(0);

            plugin.Connection.Faulted += (sender, a) =>
            {
                logger.Error(string.Format(Resources.FaultedOnMessage, $"{a.Message?.Type} {a.Message?.Method} {a.Message?.RequestId}"));
                logger.Error(a.Exception.ToString());
            };

            plugin.Closed += (sender, a) => semaphore.Release();

            bool complete = await semaphore.WaitAsync(timeout, cancellationToken).ConfigureAwait(continueOnCapturedContext: false);

            if (!complete)
            {
                logger.Error(Resources.PluginTimedOut);
            }
        }
Esempio n. 2
0
        internal static async Task WaitForPluginExitAsync(IPlugin plugin, ILogger logger, TimeSpan shutdownTimeout)
        {
            var beginShutdownTaskSource = new TaskCompletionSource <object>();
            var endShutdownTaskSource   = new TaskCompletionSource <object>();

            plugin.Connection.Faulted += (sender, a) =>
            {
                logger.Error(string.Format(Resources.FaultedOnMessage, $"{a.Message?.Type} {a.Message?.Method} {a.Message?.RequestId}"));
                logger.Error(a.Exception.ToString());
            };

            plugin.BeforeClose += (sender, args) =>
            {
                Volatile.Write(ref shuttingDown, true);
                beginShutdownTaskSource.TrySetResult(null);
            };

            plugin.Closed += (sender, a) =>
            {
                // beginShutdownTaskSource should already be set in BeforeClose, but just in case do it here too
                beginShutdownTaskSource.TrySetResult(null);

                endShutdownTaskSource.TrySetResult(null);
            };

            await beginShutdownTaskSource.Task;

            using (new Timer(_ => endShutdownTaskSource.TrySetCanceled(), null, shutdownTimeout, TimeSpan.FromMilliseconds(-1)))
            {
                await endShutdownTaskSource.Task;
            }

            if (endShutdownTaskSource.Task.IsCanceled)
            {
                logger.Error(Resources.PluginTimedOut);
            }
        }
 public VstsBuildTaskCredentialProvider(ILogger logger)
     : base(logger)
 {
 }