public HttpResponseMessage Put([FromBody] MotionModel modelJson) { try { var collection = GetMongoCollection <MotionModel>(); var update = Builders <MotionModel> .Update .Set("Name", modelJson.Name) .Set("Library", modelJson.Library) .Set("ClassName", modelJson.ClassName) .Set("Duration", modelJson.Duration) .Set("Delta", modelJson.Delta) .Set("Interpolation", modelJson.Interpolation) .Set("Tags", modelJson.Tags) .Set("Notes", modelJson.Notes) .Set("CodeSample", modelJson.CodeSample) .CurrentDate("EditDate"); var filter = new FilterDefinitionBuilder <MotionModel>().Eq("_id", modelJson._id); collection.FindOneAndUpdate(filter, update); return(Request.CreateResponse(HttpStatusCode.OK, "Done")); } catch (Exception e) { return(Request.CreateResponse(HttpStatusCode.BadRequest, e)); } }
//Positiv test af Add og Delete metoder, med gyldige input public void MangerMotionAddAndDeletePositiveTest() { //Henter liste List <MotionModel> motionList = _manager.GetAll(); int sizeOfMotionList = motionList.Count(); //Tilføjer ny motion til databasen MotionModel newMotion = new MotionModel(); newMotion.SensorId = 1; newMotion.Status = "Nothing detected"; newMotion.TimeOfDetection = DateTime.Now; _manager.Add(newMotion); //Tester at den nye motion er tilføjet databasen, ved at tjekke størrelsen på array motionList = _manager.GetAll(); Assert.AreEqual(sizeOfMotionList + 1, motionList.Count); //Benytter managerens deletemetode til at slette den nye motion fra databasen MotionModel deleteThis = motionList[motionList.Count - 1]; sizeOfMotionList = motionList.Count(); _manager.DeleteById(deleteThis.MotionId, Secrets.ourKey); //henter listen igen motionList = _manager.GetAll(); //Tester at den nye motion er slettet fra databasen, ved at tjekke størrelsen på array Assert.AreEqual(sizeOfMotionList - 1, motionList.Count); }
public void ManagerMotionAddNegativeTest() { List <MotionModel> motionList = _manager.GetAll(); int sizeOfMotionList = motionList.Count(); MotionModel newMotion = null; Assert.ThrowsException <ArgumentNullException>(() => _manager.Add(newMotion)); }
public CarModel(CarTemplate template) { CarTransform = template.InstantiateCar(); _rigidbody = CarTransform.GetComponentInChildren <Rigidbody>(); _weightComponents = CarTransform.GetComponentsInChildren <IWeightComponent>(); _motionModel = new MotionModel(CarTransform, template); }
public ActionResult <MotionModel> Delete(int id, [FromQuery] int key = 0) { if (key == Secrets.ourKey) { MotionModel toDelete = _manager.DeleteById(id, key); if (toDelete == null) { return(NotFound("No such Id")); } return(Ok(toDelete)); } return(Unauthorized("Wrong key, try again")); }
public ActionResult <MotionModel> Post([FromBody] MotionModel value) { try { MotionModel ToPost = _manager.Add(value); string uri = Url.RouteUrl(RouteData.Values) + "/" + ToPost.MotionId; return(Created(uri, ToPost)); } catch (ArgumentException ex) { return(BadRequest(ex.Message)); } }
MotionModel spawnVehicle(float[] origin, string name, float orientation) { Vector3 newOrientation = new Vector3(Mathf.Cos(orientation), 0, Mathf.Sin(orientation)); Vector3 position = new Vector3(origin[0], vehicleHeight, origin[1]); GameObject vehicle = Instantiate(vehicleObject, vehicleBoundingObject.transform, true); vehicle.name = name; vehicle.transform.position = position; vehicle.transform.forward = newOrientation; MotionModel mm = vehicle.AddComponent <MotionModel>(); mm.setParams(problem.vehicle_v_max, problem.vehicle_L, problem.vehicle_phi_max, problem.vehicle_a_max); return(mm); }
public HttpResponseMessage Post([FromBody] MotionModel modelJson) { try { var collection = GetMongoCollection <MotionModel>(); collection.InsertOne(modelJson); return(Request.CreateResponse(HttpStatusCode.OK, "Done")); } catch (Exception e) { return(Request.CreateResponse(HttpStatusCode.BadRequest, e)); } }
/// <summary> /// Method to Delete specific row in motion-table, key in Secrets /// </summary> /// <param name="id"></param> /// <param name="key"></param> public MotionModel DeleteById(int id, int key) { if (key == Secrets.ourKey) { MotionModel motionToDelete = _context.MotionList.Find(id); if (motionToDelete == null) { return(null); } _context.MotionList.Remove(motionToDelete); _context.SaveChanges(); return(motionToDelete); } else { return(null); } }
public RobotInitial RobotPositionAndCommands() { CoordinatesValidator coordinatesValidator = new CoordinatesValidator(); MotionValidator motionValidator = new MotionValidator(); Console.CursorVisible = true; Coordinates initialRobotPositionOnScreen = new Coordinates(); Coordinates robotPositionInMarthSurface = new Coordinates(); MotionModel commands = new MotionModel(); RobotInitial robotInitial = new RobotInitial(); Console.WriteLine("Now, initial coordinates of the robot and It´s orientation (N, S, E, W): "); LinesCleaner.BlankLine(); int left = Console.CursorLeft; int top = Console.CursorTop; while (true) { left = Console.CursorLeft; top = Console.CursorTop; try { LinesCleaner.BlankLine(); Console.Write("Enter the X: "); robotInitial.RobotPositionInMarthSurface.XPosition = 9; robotInitial.RobotPositionInMarthSurface.XPosition = Convert.ToInt32(Console.ReadLine()); LinesCleaner.Clean(); Console.Write("Enter the Y: "); robotInitial.RobotPositionInMarthSurface.YPosition = Convert.ToInt32(Console.ReadLine()); LinesCleaner.Clean(); break; } catch (Exception) { Console.WriteLine($"Write numbers! error"); Thread.Sleep(1000); LinesCleaner.Clean(); LinesCleaner.Clean(); Console.SetCursorPosition(left, top); } } while (true) { left = Console.CursorLeft; top = Console.CursorTop; try { Console.Write("Enter the Orientation of Robot(N, S, E, W): "); robotInitial.InitialRobotPositionOnScreen.Orientation = Console.ReadLine().ToUpper(); LinesCleaner.Clean(); Console.SetCursorPosition(left, top); IList <ValidationFailure> orientationErrors = coordinatesValidator.Validate(robotInitial.InitialRobotPositionOnScreen, options => options.IncludeProperties("Orientation")).Errors; if (orientationErrors.Any()) { foreach (var error in orientationErrors) { Console.WriteLine($"Error!: {error}"); Thread.Sleep(2000); LinesCleaner.Clean(); LinesCleaner.Clean(); Console.SetCursorPosition(left, top); } throw new Exception("Please (N, S, E, W):"); } break; } catch (Exception ex) { Console.WriteLine($"{ex.Message}"); Thread.Sleep(1000); LinesCleaner.Clean(); LinesCleaner.Clean(); Console.SetCursorPosition(left, top); } } while (true) { left = Console.CursorLeft; top = Console.CursorTop; try { Console.Write("Give the instructions for the Robot (L/R/F): "); commands.Instructions = Console.ReadLine().ToUpper(); robotInitial.Instructions = commands.Instructions; LinesCleaner.Clean(); Console.SetCursorPosition(left, top); IList <ValidationFailure> motionErrors = motionValidator.Validate(commands).Errors; if (motionErrors.Any()) { foreach (var error in motionErrors) { Console.WriteLine($"Error!: {error} "); Thread.Sleep(2000); LinesCleaner.Clean(); LinesCleaner.Clean(); Console.SetCursorPosition(left, top); } throw new Exception("Please (L/R/F):"); } break; } catch (Exception ex) { Console.WriteLine($"{ex.Message}"); Thread.Sleep(1000); LinesCleaner.Clean(); LinesCleaner.Clean(); Console.SetCursorPosition(left, top); } } Thread.Sleep(10); Console.CursorVisible = false; return(robotInitial); }
public void setLeader(MotionModel leader) { this.leader = leader; }
/// <summary> /// Method to Add to Pir-table /// </summary> /// <param name="value"></param> //TODO validate data public MotionModel Add(MotionModel value) { _context.MotionList.Add(value); _context.SaveChanges(); return(value); }