Пример #1
0
        public virtual async Task <T> RunAsync(CancellationToken token)
        {
            if (token.IsCancellationRequested)
            {
                return(await Task.FromCanceled <T>(token));
            }
            if (!Client.IsConnected())
            {
                Logger.Instance.Info("Client not connected, ConnectAsync.");
                await Client.ConnectAsync();
            }
            Logger.Instance.Info($"Running command async : {CmdString}.");

            //TODO Doods : SshConnectionException
            var cmd = Client.Client.CreateCommand(CmdString);
            var str = await Client.RunCommandAsync(cmd, token);

            Logger.Instance.Info($"Return Value from command async: {str}.");
            var result = await PaseResultAsync(str, token);

            //TODO Doods : QueryResult
            var objres = new QueryResult <T>
            {
                Query      = CmdString,
                Result     = result,
                BashLines  = str,
                ExitStatus = cmd.ExitStatus,
                Error      = cmd.Error
            };

            return(result);
        }
Пример #2
0
        /// <summary>
        ///     Create the command end execute it at the client level.
        /// </summary>
        /// <param name="token"></param>
        /// <returns>Result from client in string.</returns>
        public async Task <string> SendCommandAsync(CancellationToken token)
        {
            try
            {
                await Client.ReadLock.WaitAsync(token);

                if (token.IsCancellationRequested)
                {
                    return(await Task.FromResult(default(string)));
                }

                if (!Client.IsConnected())
                {
                    Client.Logger.Info("Client not connected, ConnectAsync.");
                    var res = await Client.ConnectAsync();
                }

                Client.Logger.Info($"Creta command async : {CmdString}.");
                //TODO Doods : SshConnectionException
                Sshcmd = Client.Client.CreateCommand(CmdString);

                Client.Logger.Info($"Running command async : {CmdString}.");
                var restask = Client.RunCommandAsync(Sshcmd, token);
                _resultStr = restask.Result;
                Client.Logger.Info($"Return Value from command async: {_resultStr}.");
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                Client.ReadLock.Release();
            }

            return(_resultStr);
        }