Esempio n. 1
0
		public void MoveTheAnimals()
		{
			Console.WriteLine("Starting Move the Animals at " + DateTime.Now.ToLongTimeString());
			List<AnimalPath> myPaths = new List<AnimalPath>();
			Mover.Mover mover = new Mover.Mover();
			for (int i = 0; i < 1000; i++)
			{
				//foreach (Animals.Animal a in myAnimals)
				Parallel.ForEach(myAnimals, a =>
				{
					AnimalPath ap = new AnimalPath();
					a.Move_Values.PercentTimeStep = 0;
					ap.AnimalID = a.ID;
					ap.TimeStep = i;
					a.Move_Values.TimeStep = i;
					mover.move(a.Move_Values);
					ap.CurrLocation = a.Move_Values.End;
					a.AnimalPaths.Add(ap);
				}
				);
				this.UpdateAllAnimalsModifiers();
			}
			Console.WriteLine("Done moving at " + DateTime.Now.ToLongTimeString());
			Console.WriteLine("now the data base part");
			UpdateAllAnimalsLocation(myAnimals);
			Console.WriteLine("Finish Move the Animals at " + DateTime.Now.ToLongTimeString());
		}
Esempio n. 2
0
		private void UpdateAllAnimalsLocation(List<Animal> inA)
		{
			Parallel.ForEach(inA, a =>
				  {
					  using (AnimalsEntities ae = new AnimalsEntities())
					  {
						  Animal CurrAnimal = ae.Animals.Find(a.ID);
						  CurrAnimal.CurrLocation = a.Move_Values.End;
						  CurrAnimal.Move_Values.Start = a.Move_Values.End;
						  AnimalPath path = a.AnimalPaths.LastOrDefault();
						  CurrAnimal.AnimalPaths = a.AnimalPaths;
						  ae.SaveChanges();
					  }// end using
				  }//end foreach scope
				  );//end foreach loop
		}