private SimulationEntry Tick() { var simulationEntry = new SimulationEntry(); var tasks = new List <Task>(); foreach (var car in _cars.Where(c => c.InUse)) { var carEntry = new CarEntry(); tasks.Add(Task.Factory.StartNew(() => { carEntry.Id = car.Id; carEntry.Position = _moveService.Move(car); carEntry.VisibleElements = car.GetVisibleElements(_map); if (carEntry.VisibleElements.Count > 0) { Console.WriteLine("found"); } carEntry.Collisions = car.CheckCollision(_cars.Where(c => c.Id != car.Id).ToList()); carEntry.Direction = car.UpdateDirection(); })); simulationEntry.Cars.Add(carEntry); } Task.WaitAll(tasks.ToArray()); if (_cars.All(c => !c.InUse)) { _simulationEnabled = false; } return(simulationEntry); }
public void Create(CarEntry entry) { using (var context = new DataModelContext()) { context.CarEntries.Add(entry); context.SaveChanges(); } }
void Start() { foreach (CarManager.CarData car in CarManager.instance.cars) { GameObject entryGameObject = Instantiate(carEntryPrefab) as GameObject; CarEntry entry = entryGameObject.GetComponent <CarEntry>(); entry.SetCar(car); entry.transform.SetParent(transform); } }
// POST api/carentry public HttpResponseMessage Post([FromBody] CarEntry entry) { try { _repository.Create(entry); return(Request.CreateResponse(HttpStatusCode.OK)); } catch (Exception e) { return(Request.CreateResponse(HttpStatusCode.InternalServerError, e.Message)); } }
public async Task CreateCar(CarEntry car) { if (car == null) { throw new ArgumentNullException(nameof(car)); } car.CreateDate = DateTimeOffset.UtcNow; _context.CarEntries.Add(car); await _context.SaveChangesAsync(); }
/// <summary> /// Without saving. Please, check for FixedCar value before calling this method. /// </summary> /// <param name="value">New value.</param> public bool SetSelectedCarEntry([CanBeNull] CarEntry value) { if (value == null) { value = Cars?.FirstOrDefault(x => x.IsAvailable) ?? Cars?.FirstOrDefault(); } if (Equals(value, _selectedCarEntry)) { return(false); } _selectedCarEntry = value; RaiseSelectedCarChanged(); return(true); }
public async Task <IActionResult> OnGetAsync(int?id) { if (id == null) { return(NotFound()); } var car = await _repository.GetCar(id.Value); if (car == null) { return(NotFound()); } CarEntry = car; return(Page()); }
/// <summary> /// Reads the complete garage of the current active persona. /// </summary> /// <returns>A string instance containing all of the persona's cars in indented XML.</returns> public String GetCompleteGarage() { XElement CarEntries = new XElement("CarsOwnedByPersona"); foreach (Car CarEntry in Cars) { CarEntries.Add(CarEntry.GetCarEntry()); } XDocument docAllCars = new XDocument( new XDeclaration("1.0", Encoding.UTF8.HeaderName, String.Empty), new XElement("CarSlotInfoTrans", new XAttribute(XNamespace.Xmlns + "i", ServerAttributes.nilNS), CarEntries, new XElement("DefaultOwnedCarIndex", "DebugNil"), new XElement("ObtainableSlots", Economy.Basket.GetProductTransactionEntry ( Economy.Currency.Boost, "Grants you 1 extra car slot.", 0, -1143680669, "128_cash", 0, "Only for 100 boost you will get a car slot instantly!", 100, 0, Economy.ServerItemType.CarSlot, 0, "Car Slot", Economy.GameItemType.CarSlot, Economy.Special.None ) ), new XElement("OwnedCarSlotsCount", "DebugNil") ) ); docAllCars.Root.SetDefaultXmlNamespace(ServerAttributes.srlNS); return(docAllCars.ToString()); }
static void Main(string[] args) { try { var restClient = new RestClient("http://emp-busyapp:1402/train/"); // TIME (GET) Execute <DateTimeResult>(restClient, "time"); // DAYNAME (GET) Execute <List <string> >(restClient, "dayName"); // RANDOM (GET) var parameterList = new List <KeyValuePair <string, object> >() { new KeyValuePair <string, object>("minValue", 100), new KeyValuePair <string, object>("maxValue", 0) }; Execute <RandomResult>(restClient, "random", requestParameters: parameterList); // CAR (GET) parameterList = new List <KeyValuePair <string, object> >() { new KeyValuePair <string, object>("id", 5) }; Execute <CarEntry>(restClient, "car", requestParameters: parameterList); // PERSON (POST) var person = new Person() { LastName = "Testmann", FirstName = "Testi", Birthday = new DateTime(1111, 11, 11) }; Execute <PersonDefaultObjectResult>(restClient, "person", Method.POST, requestBody: person); // CAR/UPDATE (PUT) var car = new CarEntry() { Id = 3, Manufacturer = "Test", Model = "Test", Color = "Test", Km = 666 }; Execute <DefaultResponse>(restClient, "car/update", Method.PUT, requestBody: car); // CAR/DELETE parameterList = new List <KeyValuePair <string, object> >() { new KeyValuePair <string, object>("id", 3) }; Execute <CarEntryDefaultObjectResult>(restClient, "car/delete", Method.DELETE, parameterList); } catch (JsonSerializationException ex) { Console.WriteLine(); Console.WriteLine("Something went wrong with the JSON (de)serialization."); Console.WriteLine(); Console.WriteLine("Error:"); Console.WriteLine(ex); } catch (Exception ex) { Console.WriteLine(); Console.WriteLine("Something went wrong."); Console.WriteLine(); Console.WriteLine("Error:"); Console.WriteLine(ex); } finally { Console.WriteLine(Environment.NewLine); Console.WriteLine("DONE."); } }
protected bool Equals(CarEntry other) { return(Id.Equals(other.Id, StringComparison.OrdinalIgnoreCase)); }
public CarEndpoint() { var carDataPath = @"C:\Users\leon hemme\Projects\VS Projects\RestApiTeil3\RestApiTeil3\DemoData\CarData.csv"; List <CarEntry> carEntries = Helper.LoadFromCsv <CarEntry>(carDataPath); Get("car", _ => { if (Request.Query.Count == 0) { return(Response.AsJson(carEntries)); } else { int?id = null; if (int.TryParse(Request.Query["id"], out int _)) { id = Request.Query["id"]; } if (id == null) { return(Response.AsJson(new DefaultResponse ("The given id was not a number."))); } foreach (CarEntry carEntry in carEntries) { if (carEntry.Id == id) { return(Response.AsJson(carEntry)); } } return(Response.AsJson(new DefaultResponse ($"The given id ({id}) does not exist."))); } }); Put("car/update", _ => { CarEntry requestBody = null; if (Request.Body.Length == 0) { return(Response.AsJson(new DefaultResponse ("The request body was empty."))); } else { try { requestBody = this.Bind <CarEntry>(); } catch { return(Response.AsJson(new DefaultResponse ("The request body was not valid."))); } } var id = requestBody.Id; foreach (CarEntry carEntry in carEntries) { if (carEntry.Id == id) { return(Response.AsJson(new DefaultObjectResult <CarEntry> { Message = "The following car entry has been updated:", Value = requestBody })); } } return(Response.AsJson(new DefaultResponse ($"The given id ({id}) does not exist."))); }); Delete("car/delete", _ => { if (Request.Query.Count == 0) { return(Response.AsJson(new DefaultResponse ("There was no id given."))); } else { int?id = null; if (int.TryParse(Request.Query["id"], out int _)) { id = Request.Query["id"]; } if (id == null) { return(Response.AsJson(new DefaultResponse ("The given id was not a number."))); } foreach (CarEntry carEntry in carEntries) { if (carEntry.Id != id) { continue; } return(Response.AsJson(new DefaultObjectResult <CarEntry> { Message = "The following car entry has been deleted:", Value = carEntry })); } return(Response.AsJson(new DefaultResponse ($"The given id ({id}) does not exist."))); } }); }
private void SelectedCarChanged(object sender, EventArgs e) { SelectedCarEntry = CarsView?.CurrentItem as CarEntry; var selectedCar = SelectedCarEntry?.CarObject; LimitedStorage.Set(LimitedSpace.OnlineSelectedCar, Id, selectedCar?.Id); AvailableUpdate(); }
protected bool Equals(CarEntry other) { return Equals(_availableSkin, other._availableSkin) && CarObject.Equals(other.CarObject) && Total == other.Total && Available == other.Available; }