public override int Run(CacheDestroyCommandOptions options, InvocationContext context)
    {
        var strConfirmDestroy = string.Format(
            CliOutput.CacheDestroyCommandRunner_Run_Prompt,
            options.CacheDir);

        // Unless the --force flag is passed, prompt the user whether they want
        // to destroy the cache
        if (!options.Force && !Confirm(strConfirmDestroy, context))
        {
            context.Console.Out.WriteLine(
                CliOutput.CacheDestroyCommandRunner_Run_Abort);
            return(true.ToExitCode());
        }

        var strDestroyingCache = string.Format(
            CliOutput.CacheDestroyCommandRunner_Run_Destroying,
            options.CacheDir);

        context.Console.Out.WriteLine(strDestroyingCache);

        ActivityEngine.Dispatch(new DestroyCacheActivity(CacheManager, options.CacheDir));

        var exitCode = WaitForCacheDestroyEvents(context);

        return(exitCode);
    }
예제 #2
0
    public override int Run(EmptyCommandOptions options, InvocationContext context)
    {
        ActivityEngine.Dispatch(new DetectAgentsActivity(AgentsDetector));

        EventEngine.On <AgentsDetectedEvent>(detectionEvent =>
        {
            FormatAndWriteToConsole(detectionEvent.AgentsAndLocations ?? new Dictionary <string, string>());
        });

        ActivityEngine.Wait();

        return(0);
    }
    private int WaitForCacheDestroyEvents(InvocationContext context)
    {
        var exitCode = true.ToExitCode();

        EventEngine.On <CacheDestroyFailedEvent>(destroyEvent =>
        {
            context.Console.Error.WriteLine(destroyEvent.ResultMessage);
            exitCode = false.ToExitCode();
        });

        EventEngine.On <CacheDestroyedEvent>(destroyEvent => { exitCode = destroyEvent.ExitCode; });

        ActivityEngine.Wait();

        return(exitCode);
    }