public override void ActionRequest(APerson ch) { if (Characters.IndexOf(ch) != -1) { if (ch.IsBusy == false) { switch (ch.CurrentPurpose) { case PurposeType.Drink: ch.CurrentAction = new System.Threading.Thread(() => Drink(ch)); ch.CurrentAction.Start(); break; case PurposeType.Eat: ch.CurrentAction = new System.Threading.Thread(() => Eat(ch)); ch.CurrentAction.Start(); break; case PurposeType.Chat: if (isBarmenBusy == false) { ch.CurrentAction = new System.Threading.Thread(() => Chat(ch)); ch.CurrentAction.Start(); } break; case PurposeType.HaveFun: ch.CurrentAction = new System.Threading.Thread(() => Dance(ch)); ch.CurrentAction.Start(); break; } } } }
/// <summary> /// Casting /// </summary> private void workWithCasting( ) { Trace.WriteLineIf(ts.TraceInfo, "Trace: Call workWithCasting()"); Runner r1 = new Runner("John", new DateTime(1994, 4, 18), 15, 80); if (r1 is APerson) { APerson p1 = r1; tbTopLeft.Text += $"\n{p1.StringToWrite( )}\n"; } APerson p2 = new APerson(); p2.Name = "Kate"; p2.DateOfBirth = new DateTime(1985, 11, 23); Runner r2 = p2 as Runner; if (r2 != null) { tbTopLeft.Text += $"\n{r2.Name} was born at {r2.DateOfBirth}\n"; } else { tbTopLeft.Text += "p2 couldn't be cast to Runner type"; } }
public IActionResult PutForUpdate(int id, APerson person) { try { if (id != person.Id) { return(BadRequest("Invalid Data")); } var findData = _dataContext.Persons.FirstOrDefault(x => x.Id == id); if (findData == null) { return(NotFound("No Data ")); // } findData.Name = person.Name; findData.Age = person.Age; findData.Address = person.Address; _dataContext.Persons.Update(findData); _dataContext.SaveChanges(); return(NoContent()); //204 } catch (System.Exception) { return(BadRequest()); // 400 } }
public override void ActionRequest(APerson ch) { if (Characters.IndexOf(ch) != -1) { if (ch.id == Owner) { if (ch.IsBusy == false) { switch (ch.CurrentPurpose) { case PurposeType.Sleep: ch.CurrentAction = new System.Threading.Thread(() => Sleep(ch)); ch.CurrentAction.Start(); break; case PurposeType.Drink: ch.CurrentAction = new System.Threading.Thread(() => Drink(ch)); ch.CurrentAction.Start(); break; case PurposeType.Eat: ch.CurrentAction = new System.Threading.Thread(() => Eat(ch)); ch.CurrentAction.Start(); break; } } } } }
public override void CharacterLeft(APerson ch) { Console.WriteLine("{0} left tavern", ch.Name); int a = Characters.FindIndex(c => c.id == ch.id); Characters.RemoveAt(Characters.FindIndex(c => c.id == ch.id)); ch.CurrentRoleId = 0; }
public override void CharacterEnter(APerson ch) { Console.WriteLine("{0} entered tavern", ch.Name); ch.CurrentRoleId = 1; Characters.Add(ch); if (ch.CurrentPurpose != PurposeType.Nothing) { ActionRequest(ch); } }
public override void ActionRequest(APerson ch) { if (Characters.IndexOf(ch) != -1) { if (ch.CurrentAction == null) { switch (ch.CurrentPurpose) { } } } }
public IActionResult AddPerson(APerson person) { try { _dataContext.Persons.Add(person); _dataContext.SaveChanges(); return(CreatedAtAction("GetPerson", new { id = person.Id }, person)); //201 } catch (System.Exception) { return(BadRequest()); // 400 } }
private void Drink(APerson ch) { int initialThirst = ch.Needs.Thirst; int initialRate = ch.ThirstRate; ch.ThirstRate = SatisfiedPurpose[PurposeType.Drink]; ch.IsBusy = true; Console.WriteLine("{0} is drinking in {1}", ch.Name, Name); while (initialThirst - ch.Needs.Thirst < 70) { } ch.ThirstRate = initialRate; ch.IsBusy = false; ch.CurrentPurpose = PurposeType.Nothing; }
private void Eat(APerson ch) { int initialHunger = ch.Needs.Hunger; int initialRate = ch.HungerRate; ch.HungerRate = SatisfiedPurpose[PurposeType.Eat]; ch.IsBusy = true; Console.WriteLine("{0} is eating in {1}", ch.Name, Name); while (initialHunger - ch.Needs.Hunger < 60) { } ch.HungerRate = initialRate; ch.IsBusy = false; }
private void Sleep(APerson ch) { int initialRate = ch.TirednessRate; ch.TirednessRate = SatisfiedPurpose[PurposeType.Sleep]; ch.IsBusy = true; isBedOccupied = true; Console.WriteLine("{0} is sleeping in {1}", ch.Name, Name); while (ch.Needs.Tiredness > 60) { } ch.TirednessRate = initialRate; ch.IsBusy = false; ch.CurrentPurpose = PurposeType.Nothing; isBedOccupied = false; }
private void Dance(APerson ch) { int initialSorrow = ch.Needs.Sorrow; int initialRate = ch.SorrowRate; ch.SorrowRate = SatisfiedPurpose[PurposeType.HaveFun]; ch.IsBusy = true; Console.WriteLine("{0} is dancing in {1}", ch.Name, Name); while (initialSorrow - ch.Needs.Sorrow < 50) { if (ch.Needs.Sorrow < Math.Abs(ch.SorrowRate)) { break; } } ch.SorrowRate = initialRate; ch.IsBusy = false; ch.CurrentPurpose = PurposeType.Nothing; }
/// <summary> /// Using class's statis methods, instance methods, delegates, operator overload /// </summary> private void workWithPersonClass( ) { int bornNumber = 0; string bornAlert = ""; APerson.logProcreate += (APerson p1, APerson p2) => bornAlert += $"{DateTime.Now.TimeOfDay}\n"; APerson.logProcreate += (APerson p1, APerson p2) => bornAlert += $"{++bornNumber}) {p1.Name} and {p2.Name} made a baby\n"; APerson david = new APerson { Name = "David", DateOfBirth = new DateTime(1995, 3, 6) }; APerson kate = new APerson { Name = "Kate", DateOfBirth = new DateTime(1996, 4, 15) }; APerson molly = new APerson { Name = "Molly", DateOfBirth = new DateTime(1994, 2, 28) }; APerson baby1 = APerson.Procreate(david, kate); APerson baby2 = david.ProcreateWith(molly); APerson baby3 = david * molly; APerson baby4 = kate * david; string getPersonInfo(APerson p) => $"{p.Name} has {p.Children.Count} {(p.Children.Count == 1 ? "child" : "children")}\n"; string output = getPersonInfo(david) + getPersonInfo(kate) + getPersonInfo(molly); foreach (var child in david.Children) { output += $"\n{david.Children.IndexOf(child) + 1}) {child.Name}"; } tbTopLeft.Text = output; tbTopRight.Text = bornAlert; }
private void Chat(APerson ch) { int initialLonelyness = ch.Needs.Loneliness; int initialRate = ch.LonelinessRate; ch.LonelinessRate = SatisfiedPurpose[PurposeType.Chat]; ch.IsBusy = true; isBarmenBusy = true; Console.WriteLine("{0} is chating in {1}", ch.Name, Name); while (initialLonelyness - ch.Needs.Loneliness < 60) { if (ch.Needs.Loneliness < Math.Abs(ch.LonelinessRate)) { break; } } isBarmenBusy = false; ch.IsBusy = false; ch.LonelinessRate = initialRate; ch.CurrentPurpose = PurposeType.Nothing; }
public override void CharacterEnter(APerson ch) { Console.WriteLine("{0} visite {1}", ch.Name, Name); ch.CurrentRoleId = 1; Characters.Add(ch); }
public void Benchmark_Serialize_PersonClass() { var data = new APerson{ FirstName = "Dima", LastName="Sokolov", Age = 16, DOB = DateTime.Now}; serializeBenchmark("PersonClass", data); }
public void Benchmark_Serialize_ListObjects() { var p1 = new APerson{ FirstName = "Dima", LastName="Sokolov", Age = 16, DOB = DateTime.Now}; var p2 = new APerson{ FirstName = "Fima", LastName="Orloff", Age = 23, DOB = DateTime.Now}; var p3 = new APerson{ FirstName = "Dodik", LastName="Stevenson", Age = 99, DOB = DateTime.Now}; var data = new List<object>{ 1, true, p1, 12.34, p2, "yes!", p3, DateTime.Now, 'a'}; serializeBenchmark("ListObjects", data); }
//protected Thread thWeiter = new Thread(CharacterWeiter); public abstract void CharacterEnter(APerson ch);
public abstract void CharacterLeft(APerson ch);
public abstract void ActionRequest(APerson ch);