Ejemplo n.º 1
0
            public Task <int> Intercept(InterceptorExecutionDelegate next,
                                        Password password,
                                        IConsole console,
                                        [Option]
                                        string username = "******")
            {
                // mimic auth

                if (username == null)
                {
                    console.Out.WriteLine("username not provided");
                    return(ExitCodes.Error);
                }

                var pwd = password?.GetPassword();

                if (string.IsNullOrWhiteSpace(pwd))
                {
                    console.Out.WriteLine("password not provided");
                    return(ExitCodes.Error);
                }

                console.Out.WriteLine($"authenticated as user:{username} with password:{password}  (actual password:{pwd})");

                return(next());
            }
            // Method name does not matter but must include an InterceptorExecutionDelegate parameter.
            // All other parameters listed here are optional.
            public Task <int> Interceptor(
                InterceptorExecutionDelegate next,
                CommandContext ctx,
                // options are assigned to this command
                // and must be provided before any child commands
                [Option('u')] string?username,
                [Option('p')] Password?password,
                // AssignToExecutableSubcommands moves the option to the final commands
                // and cannot be provided with this command
                [Option('v', AssignToExecutableSubcommands = true)] bool?verbose
                )
            {
                _username = username;
                _password = password;
                _verbose  = verbose;

                // access to AppConfig, AppSettings and other services
                var settings = ctx.AppConfig.AppSettings;
                // access to parse results, including remaining and separated arguments
                var parseResult = ctx.ParseResult;
                // access to target command method and its hosting object,
                // and all interceptor methods in the path to the target command.
                var pipeline = ctx.InvocationPipeline;

                // pre-execution logic here

                // next() will execute the TargetCommand and all
                // remaining interceptors in the ctx.InvocationPipeline
                var result = next();

                // post-execution logic here

                return(result);
            }
Ejemplo n.º 3
0
            public object Invoke(CommandContext commandContext, object instance, ExecutionDelegate next)
            {
                if (_nextParameterInfo != null)
                {
                    if (next == null)
                    {
                        throw new InvalidConfigurationException(
                                  $"Invalid operation. {nameof(ExecutionDelegate)} {_nextParameterInfo.Name} parameter not provided for method: {_nextParameterInfo.Member.FullName()}. " +
                                  $"Check middleware to ensure it hasn't misconfigured the {nameof(CommandContext.InvocationPipeline)}");
                    }

                    if (_nextParameterInfo.ParameterType == InterceptorNextParameterType)
                    {
                        var nextLite = new InterceptorExecutionDelegate(() => next(commandContext));
                        Values[_nextParameterInfo.Position] = nextLite;
                    }
                    else
                    {
                        Values[_nextParameterInfo.Position] = next;
                    }
                }

                _resolvers?.ForEach(r => r(commandContext));

                return(_methodInfo.Invoke(instance, Values));
            }
 public Task <int> Interceptor(
     InterceptorExecutionDelegate next, CancellationToken cancellationToken,
     JiraApiSettings jiraApiSettings, WorkspaceSettings workspaceSettings)
 {
     _jiraContext         = new JiraContext(jiraApiSettings, workspaceSettings, cancellationToken);
     _migrationRepository = new MigrationRepository(_jiraContext.LocalDirs);
     return(next());
 }
            public Task <int> Interceptor(InterceptorExecutionDelegate next, Verbosity verbosity)
            {
                // pre-execution logic here

                return(next()); // Create method is executed here

                // post-execution logic here
            }
Ejemplo n.º 6
0
            // begin-snippet: argument_models_notify_with_interceptor

            public Task <int> Interceptor(InterceptorExecutionDelegate next, CommandContext ctx,
                                          DryRunOptions dryRunOptions, VerbosityOptions verbosityOptions)
            {
                IEnumerable <IArgumentModel> models = ctx.InvocationPipeline.All
                                                      .SelectMany(s => s.Invocation.FlattenedArgumentModels);

                return(next());
            }
Ejemplo n.º 7
0
 public Task <int> Interceptor(InterceptorExecutionDelegate next,
                               [Option('i')] bool ignoreCache        = false,
                               [Option('s')] bool skipCacheRefresh   = false,
                               [Option('f')] bool forceCacheRefresh  = false,
                               [Option('w')] bool warnOnCacheRefresh = false)
 {
     _bbService.RefreshCaches(ignoreCache, skipCacheRefresh, forceCacheRefresh, warnOnCacheRefresh);
     return(next());
 }
Ejemplo n.º 8
0
 public Task <int> Intercept(InterceptorExecutionDelegate next,
                             string interceptorOpt,
                             [Option(AssignToExecutableSubcommands = true)] string inheritedOpt)
 {
     TestOutputs.Capture(new InterceptResult {
         InheritedOpt = inheritedOpt, InterceptorOpt = interceptorOpt
     });
     return(next());
 }
        public Task <int> Interceptor(
            InterceptorExecutionDelegate next,
            JiraApiSettings jiraApiSettings, WorkspaceSettings workspaceSettings)
        {
            _jiraContext              = new JiraContext(jiraApiSettings, workspaceSettings, _cancellationToken);
            _jiraApi                  = _jiraContext.Api;
            _jiraApiSettings          = _jiraContext.ApiSettings;
            _migrationMetaDataService = new MigrationMetaDataService(_jiraContext);

            return(next());
        }
Ejemplo n.º 10
0
 public Task <int> Intercept(InterceptorExecutionDelegate next, string name2)
 {
     Name = name2;
     if (MyChild != null)
     {
         // will be null if this.Greet is called
         MyChild.ParentName      = name2;
         MyChild.GrandParentName = ParentName;
     }
     return(next());
 }
Ejemplo n.º 11
0
        public Task <int> Intercept(
            InterceptorExecutionDelegate next,
            RepoAppOptions options,
            IConsole console)
        {
            _console = console;
            _writer  = new IndentableStreamWriter(console.Out);
            _writeln = _writer.WriteLine;

            _repo = new Repo(options.RepoDir, options.Branch);
            return(next());
        }
 public Task <int> Interceptor(InterceptorExecutionDelegate next, CommandContext commandContext, IConsole console, CancellationToken cancellationToken)
 {
     TestOutputs.Capture(new InterceptorResults
     {
         ParameterServices =
         {
             CommandContextIsNull    = commandContext == null,
             ConsoleIsNull           = console == null,
             CancellationTokenIsNone = cancellationToken == CancellationToken.None,
         }
     });
     return(next());
 }
            public Task <int> Intercept(InterceptorExecutionDelegate next,
                                        InterceptOptions interceptOptions)
            {
                if (interceptOptions.skipCmd)
                {
                    return(ExitCodes.Success);
                }

                var returnCode = next();

                return(interceptOptions.useReturnCode.HasValue
                    ? Task.FromResult(interceptOptions.useReturnCode.Value)
                    : returnCode);
            }
Ejemplo n.º 14
0
 public Task <int> Intercept(InterceptorExecutionDelegate next, string name)
 {
     Name = name;
     if (Child != null)
     {
         // will be null if GrandChild is called directly or this.Greet is called
         Child.ParentName = name;
     }
     if (GrandChild != null)
     {
         // will be null if GrandChild is NOT called directly or this.Greet is called
         GrandChild.GrandParentName = name;
     }
     return(next());
 }
            public Task <int> Intercept(InterceptorExecutionDelegate next,
                                        InterceptOptions interceptOptions)
            {
                TestOutputs.Capture(interceptOptions);
                if (interceptOptions.skipCmd)
                {
                    return(Task.FromResult(0));
                }

                var returnCode = next();

                return(interceptOptions.useReturnCode.HasValue
                    ? Task.FromResult(interceptOptions.useReturnCode.Value)
                    : returnCode);
            }
Ejemplo n.º 16
0
 public Task <int> Intercept(InterceptorExecutionDelegate next, string name)
 {
     Name = name;
     if (Level2 != null)
     {
         // will be null if GrandChild is called directly or this.Do is called
         Level2.ParentName = name;
     }
     if (Level3 != null)
     {
         // will be null if GrandChild is NOT called directly or this.Do is called
         Level3.GrandParentName = name;
     }
     return(next());
 }
Ejemplo n.º 17
0
        public Task <int> Intercept(
            InterceptorExecutionDelegate next,
            AdoApiSettings adoApiSettings, WorkspaceSettings workspaceSettings, JiraApiSettings jiraApiSettings)
        {
            _adoContext = new AdoContext(adoApiSettings, _cancellationToken);
            if (!_adoContext.TryConnect())
            {
                _console.Out.WriteLine("Unable to connect to TFS");
                return(Task.FromResult(1));
            }
            _jiraContext              = new JiraContext(jiraApiSettings, workspaceSettings, _cancellationToken);
            _migrationRepository      = new MigrationRepository(_jiraContext.LocalDirs);
            _migrationMetaDataService = new MigrationMetaDataService(_jiraContext);

            return(next());
        }
Ejemplo n.º 18
0
 public Task <int> Authenticate(InterceptorExecutionDelegate next, [Option] string username, [Option] string password)
 {
     return(next());
 }
 public Task <int> Intercept(InterceptorExecutionDelegate next)
 {
     TestOutputs.Capture(true);
     return(next());
 }
Ejemplo n.º 20
0
 public Task <int> Intercept(InterceptorExecutionDelegate next,
                             string interceptorOpt,
                             [Option(AssignToExecutableSubcommands = true)] string inheritedOpt)
 {
     return(next());
 }
Ejemplo n.º 21
0
 public Task <int> Interceptor(InterceptorExecutionDelegate next, CommandContext commandContext, IConsole console, CancellationToken cancellationToken)
 {
     return(next());
 }
 public Task <int> Intercept(InterceptorExecutionDelegate next)
 {
     return(next());
 }
Ejemplo n.º 23
0
 public Task <int> Intercept(InterceptorExecutionDelegate next, [Option] string lala)
 {
     return(next());
 }
Ejemplo n.º 24
0
 public Task <int> Intercept(InterceptorExecutionDelegate next, Password password)
 {
     return(next());
 }
 public Task <int> Interceptor(InterceptorExecutionDelegate next,
                               [Option] string iOption1) => next();
Ejemplo n.º 26
0
 public Task <int> Intercept(InterceptorExecutionDelegate next, string name3)
 {
     Name = name3;
     return(next());
 }
Ejemplo n.º 27
0
 public Task <int> Intercept(InterceptorExecutionDelegate next,
                             int intercept1,
                             [Option(AssignToExecutableSubcommands = true)] int inherited1)
 {
     return(next());
 }
 public Task <int> Interceptor(InterceptorExecutionDelegate next, [Required] string note)
 {
     return(next());
 }
Ejemplo n.º 29
0
 public void Intercept(InterceptorExecutionDelegate next)
 {
     next().Wait();
 }
Ejemplo n.º 30
0
 public Task <int> Interceptor(InterceptorExecutionDelegate next, bool printValues)
 {
     _printValues = printValues;
     return(next());
 }