public void Run() { State = DriverState.Starting; while (State != DriverState.Finishing) { // Get the next command Command command = null; if (State == DriverState.Starting) { command = this.Factory.NewStartCommand(); State = DriverState.Running; } else if (State == DriverState.Running) { command = Input.Next(); } // Process the command ModelAndView modelAndView = Controller.Process(command); // Present the model back to the user Output.Present(modelAndView); // Make sure we finish cleanly if (command is FinishCommand) { State = DriverState.Finishing; } } }
public void Present(ModelAndView modelAndView) { View view = ViewResolver.Resolve(modelAndView.ViewName); string output = view.Render(modelAndView.Model); Present(output); }
public new ModelAndView Process(Command command) { ModelAndView modelAndView = base.Process(command); CommandsProcessed.Add(command); return(modelAndView); }
public void Present(ModelAndView modelAndView) { View view = ViewResolver.Resolve(modelAndView.ViewName); Output.Add(view.Render(modelAndView.Model)); Logger.Info(modelAndView); }
private ModelAndView generateErrorView(string code, string description, Object[] args) { ModelAndView modelAndView = new ModelAndView(this.failureView); //string convertedDescription = getMessageSourceAccessor().getMessage(description, args, description); modelAndView.addObject("code", code); //modelAndView.addObject("description", convertedDescription); return modelAndView; }
private ModelAndView generateErrorView(string code, string description, Object[] args) { ModelAndView modelAndView = new ModelAndView(this.failureView); //string convertedDescription = getMessageSourceAccessor().getMessage(description, args, description); modelAndView.addObject("code", code); //modelAndView.addObject("description", convertedDescription); return(modelAndView); }
private ModelAndView generateErrorView(string code, string description, Object[] args) { ModelAndView modelAndView = new ModelAndView(CONST_PROXY_FAILURE); modelAndView.addObject("code", code); //modelAndView.addObject("description", getMessageSourceAccessor() // .getMessage(description, args, description)); return(modelAndView); }
public override ModelAndView ProcessUnknownCommand(UnknownCommand command) { UnknownCommandsProcessed.Add(command); IDictionary <string, object> model = new Dictionary <string, object>(); model.Add("command", command); string viewName = "MockView"; ModelAndView modelAndView = this.Factory.NewModelAndView(model, viewName); return(modelAndView); }
public void TestNewModelAndView() { IDictionary <string, object> model = new Dictionary <string, object>(); model.Add("modelComponent1", "modelValue1"); string viewName = "testViewName"; ModelAndView modelAndView = MvcFactory.NewModelAndView(model, viewName); Assert.IsNotNull(modelAndView); Assert.IsInstanceOf(typeof(ModelAndViewImpl), modelAndView); Assert.AreEqual(model, modelAndView.Model); Assert.AreEqual(viewName, modelAndView.ViewName); }
[Test] public void TestProcessFinishCommand() { FinishCommand finishCommand = this.MvcFactory.NewFinishCommand(); ModelAndView modelAndView = this.ChessControllerImpl.ProcessFinishCommand(finishCommand); this.AssertValidModelAndView(modelAndView); IDictionary <string, object> model = modelAndView.Model; Assert.AreEqual("BoardView", modelAndView.ViewName); Assert.IsTrue(model.ContainsKey("Board")); object boardObject = model["Board"]; Assert.IsInstanceOf(typeof(Board), boardObject); }
[Test] public void TestProcessUnknownCommand() { UnknownCommand unknownCommand = this.MvcFactory.NewUnknownCommand("a comment str"); ModelAndView modelAndView = this.ChessControllerImpl.ProcessUnknownCommand(unknownCommand); this.AssertValidModelAndView(modelAndView); IDictionary <string, object> model = modelAndView.Model; Assert.AreEqual("UnknownCommandView", modelAndView.ViewName); Assert.IsTrue(model.ContainsKey("Board")); Assert.IsTrue(model.ContainsKey("Comment")); object boardObject = model["Board"]; Assert.IsInstanceOf(typeof(Board), boardObject); object commentObject = model["Comment"]; Assert.That(commentObject, Is.InstanceOf(typeof(string))); }
[Test] public void TestProcessMoveCommand() { Board board = this.ArrangedBoard; Move move = this.ChessModelFactory.NewMove(typeof(Pawn), File.FileA, Rank.Rank7, File.FileA, Rank.Rank6, false); MoveCommand moveCommand = this.MvcFactory.NewMoveCommand(move); ModelAndView modelAndView = this.ChessControllerImpl.ProcessMoveCommand(moveCommand); this.AssertValidModelAndView(modelAndView); IDictionary <string, object> model = modelAndView.Model; Assert.AreEqual("BoardView", modelAndView.ViewName); Assert.IsTrue(model.ContainsKey("Board")); object boardObject = model["Board"]; Assert.IsInstanceOf(typeof(Board), boardObject); board = (Board)boardObject; Location location = board.GetLocationAt(File.FileA, Rank.Rank6); Assert.That(location.Piece, Is.Not.Null); Assert.That(location.Piece.PieceType, Is.EqualTo(typeof(Pawn))); }
//@Override public void postHandle(HttpRequest request, HttpResponse response, Object o, ModelAndView modelAndView) { if (!"POST".Equals(request.HttpMethod)) { return; } //HttpContext context = (HttpContext)request.getAttribute("flowRequestContext"); //HttpContext context = (HttpContext)request.RequestContext; //if (context == null) //|| context.getCurrentEvent() == null) //{ // return; //} //// User successfully authenticated //if (SUCCESSFUL_AUTHENTICATION_EVENT.equals(context.getCurrentEvent().getId())) //{ // return; //} // User submitted invalid credentials, so we update the invalid login count this.recordSubmissionFailure(request); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: @Override public void postHandle(javax.servlet.http.HttpServletRequest arg0, javax.servlet.http.HttpServletResponse arg1, Object arg2, org.springframework.web.servlet.ModelAndView arg3) throws Exception public override void postHandle(HttpServletRequest arg0, HttpServletResponse arg1, object arg2, ModelAndView arg3) { }
private ModelAndView generateErrorView( string code, string description, Object[] args) { ModelAndView modelAndView = new ModelAndView(CONST_PROXY_FAILURE); modelAndView.addObject("code", code); //modelAndView.addObject("description", getMessageSourceAccessor() // .getMessage(description, args, description)); return modelAndView; }
protected ModelAndView handleRequestInternal(HttpRequest request, HttpResponse response) { WebApplicationService service = this.argumentExtractor.extractService(request); string serviceTicketId = service != null ? service.getArtifactId() : null; if (service == null || serviceTicketId == null) { //if (logger.isDebugEnabled()) { // logger.debug(string.format("Could not process request; Service: %s, Service Ticket Id: %s", service, serviceTicketId)); //} return this.generateErrorView("INVALID_REQUEST", "INVALID_REQUEST", null); } try { Credentials serviceCredentials = this.getServiceCredentialsFromRequest(request); string proxyGrantingTicketId = null; // XXX should be able to validate AND THEN use if (serviceCredentials != null) { try { proxyGrantingTicketId = this.centralAuthenticationService .delegateTicketGrantingTicket(serviceTicketId, serviceCredentials); } catch (TicketException e) { //logger.error("TicketException generating ticket for: " // + serviceCredentials, e); } } Assertion assertion = this.centralAuthenticationService.validateServiceTicket(serviceTicketId, service); ValidationSpecification validationSpecification = this.getCommandClass(); ServletRequestDataBinder binder = new ServletRequestDataBinder(validationSpecification, "validationSpecification"); this.initBinder(request, binder); binder.bind(request); if (!validationSpecification.isSatisfiedBy(assertion)) { //if (logger.isDebugEnabled()) { // logger.debug("ServiceTicket [" + serviceTicketId + "] does not satisfy validation specification."); //} return this.generateErrorView("INVALID_TICKET", "INVALID_TICKET_SPEC", null); } this.onSuccessfulValidation(serviceTicketId, assertion); ModelAndView success = new ModelAndView(this.successView); success.addObject(MODEL_ASSERTION, assertion); if (serviceCredentials != null && proxyGrantingTicketId != null) { string proxyIou = this.proxyHandler.handle(serviceCredentials, proxyGrantingTicketId); success.addObject(MODEL_PROXY_GRANTING_TICKET_IOU, proxyIou); } //if (logger.isDebugEnabled()) { // logger.debug(string.format("Successfully validated service ticket: %s", serviceTicketId)); //} return success; } catch (TicketValidationException e) { return this.generateErrorView(e.getCode(), e.getCode(), new Object[] { serviceTicketId, e.getOriginalService().getId(), service.getId() }); } catch (TicketException te) { return this.generateErrorView(te.getCode(), te.getCode(), new Object[] { serviceTicketId }); } catch (UnauthorizedServiceException e) { //return generateErrorView(e.getMessage(), e.getMessage(), null); throw new NotImplementedException(); } }
protected ModelAndView handleRequestInternal(HttpRequest request, HttpResponse response) { WebApplicationService service = this.argumentExtractor.extractService(request); string serviceTicketId = service != null?service.getArtifactId() : null; if (service == null || serviceTicketId == null) { //if (logger.isDebugEnabled()) { // logger.debug(string.format("Could not process request; Service: %s, Service Ticket Id: %s", service, serviceTicketId)); //} return(this.generateErrorView("INVALID_REQUEST", "INVALID_REQUEST", null)); } try { Credentials serviceCredentials = this.getServiceCredentialsFromRequest(request); string proxyGrantingTicketId = null; // XXX should be able to validate AND THEN use if (serviceCredentials != null) { try { proxyGrantingTicketId = this.centralAuthenticationService .delegateTicketGrantingTicket(serviceTicketId, serviceCredentials); } catch (TicketException e) { //logger.error("TicketException generating ticket for: " // + serviceCredentials, e); } } Assertion assertion = this.centralAuthenticationService.validateServiceTicket(serviceTicketId, service); ValidationSpecification validationSpecification = this.getCommandClass(); ServletRequestDataBinder binder = new ServletRequestDataBinder(validationSpecification, "validationSpecification"); this.initBinder(request, binder); binder.bind(request); if (!validationSpecification.isSatisfiedBy(assertion)) { //if (logger.isDebugEnabled()) { // logger.debug("ServiceTicket [" + serviceTicketId + "] does not satisfy validation specification."); //} return(this.generateErrorView("INVALID_TICKET", "INVALID_TICKET_SPEC", null)); } this.onSuccessfulValidation(serviceTicketId, assertion); ModelAndView success = new ModelAndView(this.successView); success.addObject(MODEL_ASSERTION, assertion); if (serviceCredentials != null && proxyGrantingTicketId != null) { string proxyIou = this.proxyHandler.handle(serviceCredentials, proxyGrantingTicketId); success.addObject(MODEL_PROXY_GRANTING_TICKET_IOU, proxyIou); } //if (logger.isDebugEnabled()) { // logger.debug(string.format("Successfully validated service ticket: %s", serviceTicketId)); //} return(success); } catch (TicketValidationException e) { return(this.generateErrorView(e.getCode(), e.getCode(), new Object[] { serviceTicketId, e.getOriginalService().getId(), service.getId() })); } catch (TicketException te) { return(this.generateErrorView(te.getCode(), te.getCode(), new Object[] { serviceTicketId })); } catch (UnauthorizedServiceException e) { //return generateErrorView(e.getMessage(), e.getMessage(), null); throw new NotImplementedException(); } }
private void AssertValidModelAndView(ModelAndView modelAndView) { Assert.IsNotNull(modelAndView); Assert.IsNotNull(modelAndView.ViewName); Assert.IsNotNull(modelAndView.Model); }
private void InitializePopups() { try { if (ViewModel == null || ViewModel.Popups == null || ViewModel.Popups.Count == 0) { _modelAndViews.Clear(); this.RemoveAllViews(); return; } // Remove any that don't exist anymore for (int i = 0; i < _modelAndViews.Count; i++) { if (!ViewModel.Popups.Contains(_modelAndViews[i].Model)) { _modelAndViews.RemoveAt(i); this.RemoveViewAt(i); i--; } } // Now we just have new or moved views for (int i = 0; i < ViewModel.Popups.Count; i++) { var viewModel = ViewModel.Popups[i]; // If it's already there, good if (i < _modelAndViews.Count && viewModel == _modelAndViews[i].Model) { continue; } // Otherwise it potentially needs to be moved forward int indexOfExisting = _modelAndViews.FindIndex(x => x.Model == viewModel); if (indexOfExisting != -1) { var existingModelAndView = _modelAndViews[indexOfExisting]; _modelAndViews.RemoveAt(indexOfExisting); _modelAndViews.Insert(i, existingModelAndView); this.RemoveViewAt(indexOfExisting); this.AddView(existingModelAndView.View, i); continue; } // Otherwise, it's new var newModelAndView = new ModelAndView(viewModel, CreateViewFromPopup(viewModel)); _modelAndViews.Insert(i, newModelAndView); this.AddView(newModelAndView.View, i); } } #if DEBUG catch (Exception ex) { System.Diagnostics.Debugger.Break(); throw ex; } #endif finally { UpdatePopupContainerVisibility(); } }