Exemple #1
0
        public CLIRequest(ICLIClient client, Master ctrl, string cmdLine)
        {
            this.ctrl = ctrl;
            Client    = client;
            Commands  = new Queue <ICommand>();
            cmdRepo   = new CommandRepository(ctrl);
            DirigentCommandRegistrator.Register(cmdRepo);

            // parse commands and fill cmd queue
            string?restAfterUid;

            SplitToUuidAndRest(cmdLine, out Uid, out restAfterUid);
            if (string.IsNullOrEmpty(restAfterUid))
            {
                Finished = true;
                _mutex   = new SemaphoreSlim(1);
                return;
            }

            try
            {
                var cmdList = cmdRepo.ParseCmdLine(client.Name, restAfterUid, WriteResponseLine);
                Commands = new Queue <ICommand>(cmdList);
                _mutex   = new SemaphoreSlim(0);
            }
            catch (Exception e)
            {
                // take just first line of exception description
                string excMsg = e.ToString();
                var    crPos  = excMsg.IndexOf('\r');
                var    lfPos  = excMsg.IndexOf('\n');
                if (crPos >= 0 || lfPos >= 0)
                {
                    excMsg = excMsg.Substring(0, Math.Min(crPos, lfPos));
                }

                WriteResponseLine("ERROR: " + Tools.JustFirstLine(e.Message));

                Finished = true;
                _mutex   = new SemaphoreSlim(1);
                _except  = e;
            }
        }
        public void RegisterCLICommand(string commandText, string commandDescription, ICLIClient cliClient)
        {
            if (string.IsNullOrEmpty(commandText))
            {
                throw new Exception("CommandText is null");
            }
            if (cliClient == null)
            {
                throw new Exception("Client is null");
            }
            if (GetCommand(commandText) != null)
            {
                throw new Exception("This command is already in use by another CLI client");
            }
            if (RegisteredCommands().Any(c => c.ExecutorClient.GetType() == cliClient.GetType()))
            {
                throw new Exception($"CLI client type '{cliClient.GetType().FullName}' is already in use");
            }

            commands.Add(new CLICommand(commandText, commandDescription, cliClient));
        }
Exemple #3
0
 // Adds CLI request to be processed by the master during its next tick(s).
 // Returns the request object.
 // The caller can asynchronously await the completion of the operation (using "await operation.WaitAsync();")
 // Thread safe, can be called from async context.
 public CLIRequest AddCliRequest(ICLIClient client, string cmdLine) => _cliProc.AddRequest(client, cmdLine);
 /// <summary>
 /// It allows integration with the CLI of the framework, which allows execution of specific routines from commands typed at the ConsoleApp prompt
 /// </summary>
 /// <param name="commandText">Initial command that triggers the execution client</param>
 /// <param name="commandDescription">Brief description of the purpose of the command</param>
 /// <param name="executorClient">Instance of the implementation of the ICLIClient interface, which connects the CLI of ConsoleApp with the target class that will perform the tasks</param>
 protected void RegisterCLICommand(string commandText, string commandDescription, ICLIClient executorClient)
 {
     Services.GetService <ICLIHostService>().RegisterCLICommand(commandText, commandDescription, executorClient);
 }
 public CLICommand(string commandText, string commandDescription, ICLIClient executorClient)
 {
     CommandText        = commandText;
     CommandDescription = commandDescription;
     ExecutorClient     = executorClient;
 }