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; }
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(); }