예제 #1
0
        /// <summary>Clone existing repository.</summary>
        /// <param name="parameters"><see cref="CloneRepositoryParameters"/>.</param>
        /// <exception cref="ArgumentNullException"><paramref name="parameters"/> == <c>null</c>.</exception>
        public void Invoke(CloneRepositoryParameters parameters)
        {
            /*
             * git clone [--template=<template_directory>] [-l] [-s] [--no-hardlinks]
             * [-q] [-n] [--bare] [--mirror] [-o <name>] [-b <name>] [-u <upload-pack>]
             * [--reference <repository>] [--depth <depth>] [--recursive] [--] <repository> [<directory>]
             */
            Verify.Argument.IsNotNull(parameters, nameof(parameters));

            try
            {
                if (!Directory.Exists(parameters.Path))
                {
                    Directory.CreateDirectory(parameters.Path);
                }
            }
            catch (Exception exc) when(!exc.IsCritical())
            {
                throw new GitException(exc.Message, exc);
            }
            var command = _commandFactory(parameters, false);
            var output  = _commandExecutor.ExecuteCommand(command, CommandExecutionFlags.None);

            output.ThrowOnBadReturnCode();
        }
예제 #2
0
        public string Execute(string path)
        {
            StringBuilder messages = new StringBuilder();

            try
            {
                bool isValid = _validateFileType.IsValid(path);
                if (isValid)
                {
                    IEnumerable <string> commands = _fileReader.ReadFile(path);
                    if (commands != null)
                    {
                        foreach (string command in commands)
                        {
                            ICommandExecutor executpr = _provider.InitExecutor(command);
                            string           message  = executpr.ExecuteCommand(command);
                            messages.AppendLine(message);
                        }
                    }
                    else
                    {
                        messages.Append("Invalid file path");
                    }
                }
                else
                {
                    messages.Append("Invalid file type");
                }
                return(messages.ToString());
            }
            catch (Exception ex)
            {
                throw;
            }
        }
예제 #3
0
 public void Handle(ArtistWasUpdated domainEvent)
 {
     Task <CommandResult> .Factory.StartNew(() => _commandExecutor.ExecuteCommand(new LookForLastFmInformation()
     {
         Artist = domainEvent.Artist
     }));
 }
예제 #4
0
 public void Handle(Events.ArtistWasAdded domainEvent)
 {
     Task <CommandResult> .Factory.StartNew(() => _commandExecutor.ExecuteCommand(new FindArtistInformationOnExternalServices()
     {
         Artist = domainEvent.Artist
     }));
 }
예제 #5
0
        public void Install()
        {
            ActivateItem(_initializingViewModel);

            Task.Run(async() =>
            {
                try
                {
                    await _executor.ExecuteCommand(Options);
                }
                catch (PackageNotFoundException e)
                {
                    ActivateItem(e.CreateDialog());
                }
                catch (InstallerException e)
                {
                    ActivateItem(e.CreateDialog());
                }
                catch (Win32Exception e)
                {
                    ActivateItem(e.CreateDialog());
                }
                catch (Exception e)
                {
                    ActivateItem(e.CreateDialog());
                }
            });
        }
예제 #6
0
        public async Task Start()
        {
            if (_isWorking)
            {
                return;
            }

            _isWorking = true;

            var offset = 0;

            while (_isWorking)
            {
                var updates = await _bot.GetUpdatesAsync(offset);

                foreach (var update in updates)
                {
                    if (update.Type == UpdateType.MessageUpdate)
                    {
                        var command = new TelegramSimpleCommand(update);
                        _executor.ExecuteCommand(command);
                    }
                    offset = update.Id + 1;
                }
                await Task.Delay(1000);
            }
        }
예제 #7
0
        private void ExecuteNextCommand()
        {
            if (_injector.HasMapping <Action <IAsyncCommand, bool> >(AsyncCommandExecutedCallbackName))
            {
                _injector.Unmap <Action <IAsyncCommand, bool> >(AsyncCommandExecutedCallbackName);
            }

            while (!IsAborted && _commandMappingQueue.Count > 0)
            {
                ICommandMapping mapping = _commandMappingQueue.Dequeue();

                if (mapping != null)
                {
                    _injector.Map <Action <IAsyncCommand, bool> >(AsyncCommandExecutedCallbackName).ToValue((Action <IAsyncCommand, bool>)CommandExecutedCallback);
                    _commandExecutor.ExecuteCommand(mapping, _payload);
                    return;
                }
            }

            if (IsAborted)
            {
                _commandMappingQueue.Clear();
                _commandsAbortedCallback?.Invoke();
            }
            else if (_commandMappingQueue.Count == 0)
            {
                _commandsExecutedCallback?.Invoke();
            }
        }
예제 #8
0
        public IActionResult ExecuteCommand([FromBody] JObject input)
        {
            if (input == null)
            {
                return(BadRequest());
            }

            string command          = input.Value <string>("command");
            string workingDirectory = input.Value <string>("dir");

            using (_tracer.Step("Executing " + command, new Dictionary <string, string> {
                { "CWD", workingDirectory }
            }))
            {
                try
                {
                    CommandResult result = _commandExecutor.ExecuteCommand(command, workingDirectory);
                    return(Ok(result));
                }
                catch (CommandLineException ex)
                {
                    _tracer.TraceError(ex);
                    return(Ok(new CommandResult {
                        Error = ex.Error, ExitCode = ex.ExitCode
                    }));
                }
                catch (Exception ex)
                {
                    _tracer.TraceError(ex);
                    return(Ok(new CommandResult {
                        Error = ex.ToString(), ExitCode = -1
                    }));
                }
            }
        }
 public void Handle(UserDisconnectedWithSignalR domainEvent)
 {
     _commandExecutor.ExecuteCommand(new RemoveConnectionIdToUserCommand()
         {
             ConnectionId = domainEvent.ConnectionId,
         });
 }
예제 #10
0
        public HttpResponseMessage ExecuteCommand(JObject input)
        {
            if (input == null)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }

            string command          = input.Value <string>("command");
            string workingDirectory = input.Value <string>("dir");

            using (_tracer.Step("Executing " + command, new Dictionary <string, string> {
                { "CWD", workingDirectory }
            }))
            {
                try
                {
                    CommandResult result = _commandExecutor.ExecuteCommand(command, workingDirectory);
                    return(Request.CreateResponse(HttpStatusCode.OK, result));
                }
                catch (CommandLineException ex)
                {
                    _tracer.TraceError(ex);
                    return(Request.CreateResponse(HttpStatusCode.OK, new CommandResult {
                        Error = ex.Error, ExitCode = ex.ExitCode
                    }));
                }
                catch (Exception ex)
                {
                    _tracer.TraceError(ex);
                    return(Request.CreateResponse(HttpStatusCode.OK, new CommandResult {
                        Error = ex.ToString(), ExitCode = -1
                    }));
                }
            }
        }
 public void Handle(UserConnectedWithSignalR domainEvent)
 {
     _commandExecutor.ExecuteCommand(new AddConnectionIdToUserCommand()
         {
             Username = domainEvent.Username,
             ConnectionId = domainEvent.ConnectionId
         });
 }
예제 #12
0
            public void Invoke(TParameters parameters)
            {
                Verify.Argument.IsNotNull(parameters, nameof(parameters));

                var command = _commandFactory(parameters);
                var output  = _commandExecutor.ExecuteCommand(command, _flags);

                _resultHandler(parameters, output);
            }
예제 #13
0
            public void Invoke(TParameters parameters)
            {
                Verify.Argument.IsNotNull(parameters, nameof(parameters));

                var command = _commandFactory(parameters);
                var output  = _commandExecutor.ExecuteCommand(command, _flags);

                output.ThrowOnBadReturnCode();
            }
예제 #14
0
        public void Invoke(TParameters parameters)
        {
            Verify.Argument.IsNotNull(parameters, "parameters");

            var command = _commandFactory(parameters, false);
            var output  = _commandExecutor.ExecuteCommand(command, null, CommandExecutionFlags.None);

            output.ThrowOnBadReturnCode();
        }
예제 #15
0
            public TOutput Invoke(TParameters parameters)
            {
                Verify.Argument.IsNotNull(parameters, nameof(parameters));

                var command = _commandFactory(parameters);
                var output  = _commandExecutor.ExecuteCommand(command, _flags);

                return(_resultParser(parameters, output));
            }
예제 #16
0
        private string GetMergedCommits(string branch, string head, string lineFormat)
        {
            var cmd = new LogCommand(
                LogCommand.TFormat(lineFormat),
                new CommandParameter(head + ".." + branch));
            var output = _commandExecutor.ExecuteCommand(cmd, CommandExecutionFlags.None);

            output.ThrowOnBadReturnCode();
            return(output.Output);
        }
예제 #17
0
        public void ExecuteCommandTest()
        {
            ICommandExecutor target  = CreateICommandExecutor(); // TODO: Initialize to an appropriate value
            ICatalog         catalog = null;                     // TODO: Initialize to an appropriate value
            ICommand         command = null;                     // TODO: Initialize to an appropriate value
            StringBuilder    output  = null;                     // TODO: Initialize to an appropriate value

            target.ExecuteCommand(catalog, command, output);
            Assert.Inconclusive("A method that does not return a value cannot be verified.");
        }
예제 #18
0
        public IList <ReferencePushResult> Invoke(PushParameters parameters)
        {
            Verify.Argument.IsNotNull(parameters, nameof(parameters));

            var command = _commandFactory(parameters, false);
            var output  = _commandExecutor.ExecuteCommand(command, CommandExecutionFlags.None);

            output.ThrowOnBadReturnCode();
            return(_resultsParser(output.Output));
        }
예제 #19
0
        private string ParseTagMessage(Command command, GitOutput output)
        {
            Assert.IsNotNull(output);

            output.ThrowOnBadReturnCode();
            var parser = new GitParser(output.Output);

            while (!parser.IsAtEndOfLine)
            {
                parser.SkipLine();
            }
            parser.SkipLine();
            if (parser.RemainingSymbols > 1)
            {
                var        message = parser.ReadStringUpTo(parser.Length - 1);
                const char c       = '�';
                if (message.ContainsAnyOf(c))
                {
                    output = _commandExecutor.ExecuteCommand(command, Encoding.Default, CommandExecutionFlags.None);
                    output.ThrowOnBadReturnCode();
                    parser = new GitParser(output.Output);
                    while (!parser.IsAtEndOfLine)
                    {
                        parser.SkipLine();
                    }
                    parser.SkipLine();
                    if (parser.RemainingSymbols > 1)
                    {
                        message = parser.ReadStringUpTo(parser.Length - 1);
                    }
                    else
                    {
                        message = string.Empty;
                    }
                }
                return(message);
            }
            else
            {
                return(string.Empty);
            }
        }
예제 #20
0
        public HttpResponseMessage ExecuteCommand(JObject input)
        {
            if (input == null)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }

            string        command = input.Value <string>("command");
            CommandResult result  = _commandExecutor.ExecuteCommand(command);

            return(Request.CreateResponse(HttpStatusCode.OK, result));
        }
예제 #21
0
        public IList <ReflogRecordData> Invoke(QueryReflogParameters parameters)
        {
            Verify.Argument.IsNotNull(parameters, "parameters");

            var command = _commandFactory(parameters);
            var output  = _commandExecutor.ExecuteCommand(command, CommandExecutionFlags.None);

            output.ThrowOnBadReturnCode();

            var cache = new Dictionary <Hash, RevisionData>(Hash.EqualityComparer);
            var list  = ParseResult1(output, cache);

            // get real commit parents
            command = GetCommand2(parameters);
            output  = _commandExecutor.ExecuteCommand(command, CommandExecutionFlags.None);
            output.ThrowOnBadReturnCode();
            var parser = new GitParser(output.Output);

            parser.ParseCommitParentsFromRaw(list.Select(rrd => rrd.Revision), cache);

            return(list);
        }
예제 #22
0
        public void TestPlaceCommand(string commandText, int xPos, int yPos, Orientation orientation)
        {
            _mockMovementProcessor.Place(xPos, yPos, orientation).Returns(info => new ActionOutcome(OutcomeStatus.Success));
            var outcome = _executor.ExecuteCommand(commandText);

            _mockMovementProcessor.Received().Place(xPos, yPos, orientation);
            outcome.Result.ShouldBe(OutcomeStatus.Success);
        }
예제 #23
0
 static void Main(string[] args)
 {
     try
     {
         Program parkingLot = new Program();
         if (args.Length == 1)
         {
             string            filePath         = args[0];
             IInputFileReader  fileReader       = new InputFileReader();
             IValidateFileType validateFileType = new ValidateFileType();
             IExecuteFromFile  fileExecutor     = new ExecuteFromFile(parkingLot._provider, validateFileType, fileReader);
             string            messages         = fileExecutor.Execute(filePath);
             Console.WriteLine(messages);
         }
         else if (args.Length > 1)
         {
             Console.WriteLine("Takes only one argument");
         }
         else
         {
             string result = string.Empty;
             bool   isLive = true;
             while (isLive)
             {
                 string userInputCommand = Console.ReadLine();
                 if (userInputCommand.Equals("exit"))
                 {
                     isLive = false;
                 }
                 else
                 {
                     ICommandExecutor executor = parkingLot._provider.InitExecutor(userInputCommand);
                     if (executor != null)
                     {
                         result = executor.ExecuteCommand(userInputCommand);
                     }
                     else
                     {
                         result = "Invalid Command";
                     }
                     Console.WriteLine(result);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
 }
예제 #24
0
        public IActionResult ExecuteCommand([FromForm] string cluster, [FromForm] string command)
        {
            var result      = $"{cluster}:{command}\r\n";
            var certificate = Path.Combine("/certificates", cluster, "kubeconfig");

            try
            {
                result += _commandExecutor.ExecuteCommand($"{command} --kubeconfig={certificate}");
            }
            catch (Exception ex)
            {
                result = ex.Message;
            }

            return(Ok(result));
        }
예제 #25
0
        public TOutput Invoke(TParameters parameters)
        {
            Verify.Argument.IsNotNull(parameters, "parameters");

            var command        = CreateCommand(parameters);
            var parser         = CreateParser();
            var stdOutReceiver = new AsyncTextParser(parser);
            var stdErrReceiver = new AsyncTextReader();
            var exitCode       = _commandExecutor.ExecuteCommand(
                command, stdOutReceiver, stdErrReceiver, GetExecutionFlags());

            if (exitCode != 0)
            {
                HandleNonZeroExitCode(stdErrReceiver, exitCode);
            }
            return(parser.GetResult());
        }
예제 #26
0
 public void Run()
 {
     while (true)
     {
         string commandLine = this.userInterface.ReadLine();
         if (commandLine == "end")
         {
             break;
         }
         var    command       = new Command(commandLine);
         string commandResult = commandExecutor.ExecuteCommand(command);
         if (commandResult != null)
         {
             this.userInterface.WriteLine(commandResult);
         }
     }
 }
예제 #27
0
        public string AddOrUpdatePackage(string packageName, string version = null)
        {
            var versionArgument = string.Empty;

            if (!string.IsNullOrWhiteSpace(version))
            {
                versionArgument = $" -v {version}";
            }

            var result = _commandExecutor.ExecuteCommand("dotnet", $"add \"{FilePath}\" package {packageName}{versionArgument}");

            if (result.ExitCode != 0)
            {
                throw new InvalidOperationException("dotnet command failed.");
            }

            return(GetVersionFromStdout(result.StdOut, packageName));
        }
예제 #28
0
            public byte[] Invoke(TParameters parameters)
            {
                Verify.Argument.IsNotNull(parameters, nameof(parameters));

                var command        = _commandFactory(parameters);
                var stdInReceiver  = new AsyncBytesReader();
                var stdErrReceiver = new AsyncTextReader();
                var exitCode       = _commandExecutor.ExecuteCommand(
                    command,
                    stdInReceiver,
                    stdErrReceiver,
                    CommandExecutionFlags.None);

                if (exitCode != 0)
                {
                    throw new GitException(stdErrReceiver.GetText());
                }
                return(stdInReceiver.GetBytes());
            }
예제 #29
0
 public void Run(JsonObject input)
 {
     _executor.ExecuteCommand((string)input["command"]);
 }
예제 #30
0
        /// <summary>
        /// The launch sensor.
        /// </summary>
        /// <param name="caller">
        ///     The caller.
        /// </param>
        /// <param name="logger">
        ///     The logger.
        /// </param>
        /// <param name="filePath">
        ///     The file Path.
        /// </param>
        /// <param name="executor"></param>
        /// <param name="callBackHandlerIn">
        ///     The call back handler in.
        /// </param>
        /// <returns>
        /// The <see cref="Process"/>.
        /// </returns>
        public virtual FSharpList<string> LaunchSensor(
            object caller,
            EventHandler logger,
            string filePath,
            ICommandExecutor executor)
        {
            var commandline = "[" + Directory.GetParent(filePath) + "] : " + this.GetCommand() + " "
                              + this.GetArguments() + " " + filePath;
            CxxPlugin.WriteLogMessage(caller, logger, commandline);
            executor.ExecuteCommand(
                this.GetCommand(),
                this.GetArguments() + " " + filePath,
                this.GetEnvironment(),
                string.Empty);

            return this.UseStdout ? executor.GetStdOut : executor.GetStdError;
        }
예제 #31
0
 private CommandResult ExecuteCommand(TCommand command)
 {
     return(_commandExecutor.ExecuteCommand(command));
 }