protected virtual CommandExecutionResult ExecuteFolderListCommand(RemoteCommand command)
        {
            if (string.IsNullOrWhiteSpace(command.CommandParameters))
            {
                return new CommandExecutionResult("Parameter not supplied");

            }

            try
            {
                var listparameters=command.CommandParameters.Split(';');

                var directories=Directory.EnumerateDirectories(listparameters[0],listparameters.Length>1?listparameters[1]:"*");
                var result = new CommandExecutionResult();
                result.Result.Add(directories);
                return result;
            }
            catch (Exception ex)
            {
                return new CommandExecutionResult(ex.Message);
                throw;
            }

            return new CommandExecutionResult();
        }
        public override CommandExecutionResult ExecuteCommand(RemoteCommand command)
        {
            var commandPrompt = new Process();

            commandPrompt.StartInfo.FileName=  "CMD.exe";
            commandPrompt.StartInfo.Arguments = command.CommandParameters;
            //commandPrompt.StartInfo.RedirectStandardOutput = true;
            commandPrompt.Start();
               // var output = commandPrompt.StandardOutput.ReadToEnd();
            var result = new CommandExecutionResult();
              //  result.Result.Add(output);
            return result;
        }
        public override CommandExecutionResult ExecuteCommand(RemoteCommand command)
        {
            var lowerCommand=command.CommandName.ToLowerInvariant();
            switch (lowerCommand)
            {
                case CoreCommands.FolderList:

                    return ExecuteFolderListCommand(command);
                    break;
                default:
                    break;
            }

            return new CommandExecutionResult();
        }
 protected override IList<string> GetCommands(RemoteCommand command)
 {
     return new List<string>() { CoreCommands.FolderList };
 }
 public override bool CanExecuteCommand(RemoteCommand command)
 {
     return base.CanExecuteCommand(command);
 }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            var loginManager=new LoginManager();
            //Console.WriteLine("User Name : ");

            var uName = "ishwor";// Console.ReadLine();
               // Console.WriteLine("Password : "******"passw0rd";// Console.ReadLine();

            var authCookie = new Cookie();
            var loginSuccess = loginManager.Login(uName, pwd, out authCookie);
            if (!loginSuccess)
            {
                return;
            }

            HubConnection hub = new HubConnection(System.Configuration.ConfigurationManager.AppSettings["RemoteServer"]);
            hub.CookieContainer = new CookieContainer();
            hub.CookieContainer.Add(authCookie);

            var prxy = hub.CreateHubProxy("RemoteServer");
            prxy.On<string, string,string>("commandReceived", (command, parameters,requestToken) =>
            {
                Console.WriteLine(string.Format("Command : {0}, Parameters : {1} ", command, parameters));
                if (!string.IsNullOrWhiteSpace(command))
                {
                    var remoteCommand=new RemoteCommand(){CommandName=command,CommandParameters=parameters};
                    var executor = GetCommandExecutor(remoteCommand);
                    var responses = new List<CommandExecutionResult>();
                    if(executor !=null)
                    {
                        var response = executor.ExecuteCommand(remoteCommand);
                        if (response==null)
                        {
                            response = new CommandExecutionResult();
                        }

                    }
                    else
                    {
                        //return new CommandExecutionResult(string.Format(CultureInfo.InvariantCulture,"No command executor found for the command named : {0}",remoteCommand.CommandName);
                    }
                }
                else
                {

                }

            });

            hub.Start().Wait();

            try
            {
                prxy.Invoke("SendCommand", "tempcommand", "tempparameter", "nothing").Wait();
            }
            catch (AggregateException ae)
            {
                ae.Handle(e =>
                {
                    return true;
                });
                throw;
            }

            Console.ReadLine();
        }
Ejemplo n.º 7
0
 static ICommandExecutor GetCommandExecutor(RemoteCommand command)
 {
     var executors = new List<ICommandExecutor>() { new FileSystemCommandExecutor(), new CmdPromptCommandExecutor() };
     return executors.FirstOrDefault(m => m.CanExecuteCommand(command));
 }
Ejemplo n.º 8
0
 protected virtual IList<string> GetCommands(RemoteCommand command)
 {
     return new List<string>();
 }
Ejemplo n.º 9
0
 public virtual CommandExecutionResult ExecuteCommand(RemoteCommand command)
 {
     return new CommandExecutionResult();
 }
Ejemplo n.º 10
0
 public virtual bool CanExecuteCommand(RemoteCommand command)
 {
     var commands = GetCommands(command);
     var canExecuteCommand = commands.Contains(command.CommandName, StringComparer.OrdinalIgnoreCase);
     return canExecuteCommand;
 }