public CommandResponse Do() { if (this.ExecutedCommand == null) { throw new NullReferenceException("ExecutedCommand property must be set before calling Do"); } try { var session = this.ExecutedCommand.SessionId; this.Session = SessionsManager.GetSessionbyId(session); return(CommandResponse.Create(HttpStatusCode.OK, this.DoImpl())); } catch (AutomationException ex) { return(CommandResponse.Create(HttpStatusCode.OK, this.JsonResponse(ex.Status, ex.Message))); } catch (InnerDriverRequestException ex) { // Bad status returned by Inner Driver when trying to forward command return(CommandResponse.Create(ex.StatusCode, ex.Message)); } catch (NotImplementedException exception) { return(CommandResponse.Create( HttpStatusCode.NotImplemented, this.JsonResponse(ResponseStatus.UnknownCommand, exception.Message))); } catch (Exception exception) { return(CommandResponse.Create( HttpStatusCode.OK, this.JsonResponse(ResponseStatus.UnknownError, "Unknown error: " + exception.Message))); } }
public CommandResponse Do() { if (this.ExecutedCommand == null) { throw new NullReferenceException("ExecutedCommand property must be set before calling Do"); } try { var session = this.ExecutedCommand.SessionId; this.Automator = Automator.InstanceForSession(session); return(CommandResponse.Create(HttpStatusCode.OK, this.DoImpl())); } catch (AutomationException exception) { return(CommandResponse.Create(HttpStatusCode.OK, this.JsonResponse(exception.Status, exception))); } catch (NotImplementedException exception) { return(CommandResponse.Create( HttpStatusCode.NotImplemented, this.JsonResponse(ResponseStatus.UnknownCommand, exception))); } catch (Exception exception) { return(CommandResponse.Create( HttpStatusCode.OK, this.JsonResponse(ResponseStatus.UnknownError, exception))); } }
public CommandResponse Handle(CommandRequest request) { if (string.IsNullOrEmpty(request.Target)) { return(CommandResponse.Create(false)); } var groupName = new StitchGroupName(request.Target); var job = _jobManager.CreateJob("Command=" + request.Command); var stitches = _data.GetStitchesInGroup(groupName); foreach (var stitch in stitches) { var subtask = job.CreateSubtask(CommandType, stitch.Id, _nodeId); if (stitch.NodeId == _nodeId) { SendLocal(job, subtask, stitch); } else { SendRemote(job, subtask, stitch); } } // Save the job to get an Id _jobManager.Save(job); return(CommandResponse.Started(job.Id)); }
private CommandResponse RequestHandler(string uri, string content) { var command = JsonConvert.DeserializeObject <Command>(content); if (command.Name.Equals(DriverCommand.Quit)) { this.socketServer.ShouldStopAfterResponse = true; return(CommandResponse.Create(HttpStatusCode.OK, null)); } var executor = this.commandsExecutorsDispatcher.GetExecutor <CommandExecutorBase>(command.Name); if (executor == null) { return(CommandResponse.Create( HttpStatusCode.NotImplemented, string.Format("Command '{0}' not yet implemented.", command.Name))); } Logger.LogMessage("Executing command: {0}", command.Name); executor.Session = this.Session; executor.ExecutedCommand = command; executor.ElementsRegistry = this.elementsRegistry; executor.WindowsRegistry = this.windowsesRegistry; return(executor.Do()); }
public CommandResponse DispatchCommandRequest(CommandRequest arg) { var handler = _commandHandlers.GetOrDefault(arg.Command); if (handler == null) { return(CommandResponse.Create(false)); } return(handler.Handle(arg)); }
private CommandResponse HandleRemote(CommandRequest request, StitchSummary stitch) { string nodeId = stitch.NodeId; var node = _data.Get <NodeStatus>(nodeId); if (node == null) { return(CommandResponse.Create(false)); } // Create a job to track status var job = _jobManager.CreateJob("Command=" + request.Command); var subtask = job.CreateSubtask(request.Command, request.Target, stitch.NodeId); // Create the message and send it over the backplane _sender.SendCommandRequest(node.NetworkNodeId, request, job, subtask); _jobManager.Save(job); return(CommandResponse.Started(job.Id)); }
public CommandResponse Do() { try { return(CommandResponse.Create(HttpStatusCode.OK, this.DoImpl())); } catch (AutomationException exception) { return(CommandResponse.Create(HttpStatusCode.OK, this.JsonResponse(exception.Status, exception.Message))); } catch (NotImplementedException exception) { return(CommandResponse.Create( HttpStatusCode.NotImplemented, this.JsonResponse(ResponseStatus.UnknownCommand, exception.Message))); } catch (Exception exception) { return(CommandResponse.Create(HttpStatusCode.BadRequest, exception.ToString())); } }
public CommandResponse Handle(CommandRequest request) { var stitch = _data.GetStitchSummary(request.Target); if (stitch == null || stitch.Locale == StitchLocaleType.NotFound) { return(CommandResponse.Create(false)); } if (stitch.Locale == StitchLocaleType.Local) { // Send the request to the local Stitches module var ok = HandleLocal(request); return(CommandResponse.Create(ok)); } if (stitch.Locale == StitchLocaleType.Remote) { return(HandleRemote(request, stitch)); } return(CommandResponse.Create(false)); }
public CommandResponse Handle(CommandRequest request) { string nodeId = request.Target; if (nodeId == _nodeId) { return(CommandResponse.Create(true)); } var node = _data.Get <NodeStatus>(nodeId); if (node == null) { return(CommandResponse.Create(false)); } var job = _jobManager.CreateJob("Command=Ping"); var subtask = job.CreateSubtask(request.Command, request.Target, nodeId); // Create the message and send it over the backplane _sender.SendCommandRequest(node.NetworkNodeId, request, job, subtask); _jobManager.Save(job); return(CommandResponse.Started(job.Id)); }