Ejemplo n.º 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();
        }
Ejemplo n.º 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;
            }
        }
Ejemplo n.º 3
0
 public void Handle(ArtistWasUpdated domainEvent)
 {
     Task <CommandResult> .Factory.StartNew(() => _commandExecutor.ExecuteCommand(new LookForLastFmInformation()
     {
         Artist = domainEvent.Artist
     }));
 }
Ejemplo n.º 4
0
 public void Handle(Events.ArtistWasAdded domainEvent)
 {
     Task <CommandResult> .Factory.StartNew(() => _commandExecutor.ExecuteCommand(new FindArtistInformationOnExternalServices()
     {
         Artist = domainEvent.Artist
     }));
 }
Ejemplo n.º 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());
                }
            });
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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();
            }
        }
Ejemplo n.º 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,
         });
 }
Ejemplo n.º 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
         });
 }
Ejemplo n.º 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);
            }
Ejemplo n.º 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();
            }
Ejemplo n.º 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();
        }
Ejemplo n.º 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));
            }
Ejemplo n.º 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);
        }
Ejemplo n.º 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.");
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
     }
 }
Ejemplo n.º 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));
        }
Ejemplo n.º 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());
        }
Ejemplo n.º 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);
         }
     }
 }
Ejemplo n.º 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));
        }
Ejemplo n.º 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());
            }
Ejemplo n.º 29
0
 public void Run(JsonObject input)
 {
     _executor.ExecuteCommand((string)input["command"]);
 }
Ejemplo n.º 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;
        }
Ejemplo n.º 31
0
 private CommandResult ExecuteCommand(TCommand command)
 {
     return(_commandExecutor.ExecuteCommand(command));
 }