Example #1
0
        public void AddAnimal(object zoo, object aviary, object animalClass, object detachment, string family, string genus, string species)
        {
            Animal animal = null;

            switch ((animalClass as AnimalClassListElement).Class)
            {
            case AnimalClass.Mammal:
                animal = new Mammal((MammalDetachment)detachment, family, genus, species);
                break;

            case AnimalClass.Bird:
                animal = new Bird((BirdDetachment)detachment, family, genus, species);
                break;

            case AnimalClass.Reptile:
                animal = new Reptile((ReptileDetachment)detachment, family, genus, species);
                break;

            case AnimalClass.Amphibian:
                animal = new Reptile((ReptileDetachment)detachment, family, genus, species);
                break;

            case AnimalClass.Fish:
                animal = new Fish((FishDetachment)detachment, family, genus, species);
                break;
            }
            (zoo as ZooListElement).Zoo.SettleAnimal(animal, (aviary as AviaryListElement).Aviary);
        }
Example #2
0
        public void Insert(Reptile reptile)
        {
            reptile.Id = NextIdValue();
            _reptiles.Add(reptile);

            Save();
        }
Example #3
0
        public static Reptile CreateReptile(ReptileSpecies Species)
        {
            Reptile animalObj = null;//Animaltype unknown at this time.

            //Lets determine users choice of animal.
            switch (Species)
            {
            case ReptileSpecies.Alligator:
                animalObj = new Alligator();
                break;

            case ReptileSpecies.Cobra:
                animalObj = new Cobra();
                break;

            case ReptileSpecies.Komodo:
                animalObj = new Komodo();
                break;

            default:
                Debug.Assert(false, "Not implemented");
                break;
            }

            //Set animal category
            animalObj.Category = CategoryType.Reptile;

            return(animalObj);//Return created instance of object.
        }
Example #4
0
        // EXPLICIT CONVERSIONS (CASTS): Explicit conversions require a cast expression.
        // Casting is required when information might be lost in the conversion, or when the conversion might not succeed for other reasons.
        // Typical examples include numeric conversion to a type that has less precision or a smaller range,
        // and conversion of a base-class instance to a derived class.
        private static void Example3()
        {
            double x = 1234.7;
            int    a;

            // Cast double to int.
            a = (int)x;
            Console.WriteLine(a);
            // Output: 1234

            // For reference types, an explicit cast is required if you need to convert from a base type to a derived type:
            // Create a new derived type.
            Giraffe giraffe = new Giraffe();

            // Implicit conversion to base type is safe.
            Animal animal = giraffe;

            // Explicit conversion is required to cast back
            // to derived type. Note: This will compile but will
            // throw an exception at run time if the right-side
            // object is not in fact a Giraffe.
            Giraffe g2 = (Giraffe)animal;

            // In some reference type conversions, the compiler cannot determine whether a cast will be valid.
            // It is possible for a cast operation that compiles correctly to fail at run time.
            Reptile snake = (Reptile)animal;

            // C# provides the is operator to enable you to test for compatibility before actually performing a cast.
            if (animal is Giraffe)
            {
                return;
            }
        }
        public async Task <ActionResult> Feeding([Bind(Include = "FeedingId,Date,Feedings,FoodSize,NumItemsFed,Notes,ReptileId")] Feeding feeding)
        {
            /*   add this later
             * if(feeding.Feedings == null || feeding.FoodSize == null)
             * {
             *  ViewBag.Message = "Please select food size or food type.";
             * }
             * */
            if (ModelState.IsValid)
            {
                Reptile updateTimeStamp = await db.Reptiles.FirstOrDefaultAsync(r => r.ReptileId == feeding.ReptileId);

                updateTimeStamp.TimeStamp = feeding.Date.ToLocalTime();
                db.Reptiles.Attach(updateTimeStamp);
                db.Entry(updateTimeStamp).Property(r => r.TimeStamp).IsModified = true;

                db.Feedings.Add(feeding);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }


            return(View(feeding));
        }
        public Animal CreateReptile(ReptileSpecies reptileSpecies)
        {
            Reptile animalObj = null;

            switch (reptileSpecies)
            {
            case ReptileSpecies.Frog:
                animalObj = new Frog();
                break;

            case ReptileSpecies.Lizard:
                animalObj = new Lizard();
                break;

            case ReptileSpecies.Snake:
                animalObj = new Snake();
                break;

            default:
                Debug.Assert(false, "To be completed!");
                break;
            }


            animalObj.CategoryType = CategoryType.Reptile;

            return(animalObj);     //return the created animal object.
        }
Example #7
0
        public ActionResult DeleteConfirmed(int id)
        {
            Reptile reptile = db.Reptiles.Find(id);

            db.Reptiles.Remove(reptile);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Example #8
0
        public void SubclassesInheritConstantsFromParentClasses()
        {
            //If a Reptile is an Animal, zen is achieved
            //when you realize they too will have legs.
            var reptile = new Reptile();

            Assert.Equal(FILL_ME_IN, reptile.LegsInReptile());
        }
Example #9
0
        public void TestGetFullNotation()
        {
            var animal = new Reptile(ReptileDetachment.Squamata, "Гадюковые", "Настоящие гадюки", "Обыкновенная гадюка");

            //Проверка корректности формирования полного наименования животного
            var result = animal.GetFullNotation();

            Assert.AreEqual("Reptile*Squamata*Гадюковые*Настоящие гадюки*Обыкновенная гадюка", result);
        }
Example #10
0
 public ActionResult Edit([Bind(Include = "Animal,Camouflage,Pop,Dietry,ReptilesID")] Reptile reptile)
 {
     if (ModelState.IsValid)
     {
         db.Entry(reptile).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(reptile));
 }
 public ActionResult Edit([Bind(Include = "ReptilesID,ReptilesName,ReptilesType,animalSpecies_animalID,DietryType,PopulationNumber")] Reptile reptile)
 {
     if (ModelState.IsValid)
     {
         db.Entry(reptile).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.animalSpecies_animalID = new SelectList(db.animals, "animalID", "animalID", reptile.animalSpecies_animalID);
     return(View(reptile));
 }
Example #12
0
        public ActionResult Create([Bind(Include = "Animal,Camouflage,Pop,Dietry,ReptilesID")] Reptile reptile)
        {
            if (ModelState.IsValid)
            {
                db.Reptiles.Add(reptile);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(reptile));
        }
Example #13
0
        static void Main(string[] args)
        {
            var reptile = new Reptile("Crocodile");
            var mammal  = new Mammal("Koala");
            var bird    = new Bird("Parrot");

            Console.WriteLine("Who want a baby?");
            Console.WriteLine(reptile.Name + ", " + reptile.WantChild());
            Console.WriteLine(mammal.Name + ", " + mammal.WantChild());
            Console.WriteLine(bird.Name + ", " + bird.WantChild());
            Console.ReadKey();
        }
Example #14
0
        public void TestToString()
        {
            //Корректное формирование информационной строки
            var animal = new Reptile(ReptileDetachment.Squamata, "Гадюковые", "Настоящие гадюки", "Обыкновенная гадюка");
            var str    = "Id:" + animal.Id + "\n" +
                         "Класс:Reptile\n" +
                         "Отряд:Squamata\n" +
                         "Семейство:Гадюковые\n" +
                         "Род:Настоящие гадюки, Вид:Обыкновенная гадюка";

            Assert.AreEqual(str, animal.ToString());
        }
        public ActionResult Delete(int id)
        {
            ReptileRepository reptileRepository = new ReptileRepository();
            Reptile           reptile           = new Reptile();

            using (reptileRepository)
            {
                reptile = reptileRepository.SelectOne(id);
            }

            return(View(reptile));
        }
Example #16
0
        public void Update(Reptile UpdateReptile)
        {
            var oldReptile = _reptiles.Where(b => b.Id == UpdateReptile.Id).FirstOrDefault();

            if (oldReptile != null)
            {
                _reptiles.Remove(oldReptile);
                _reptiles.Add(UpdateReptile);
            }

            Save();
        }
Example #17
0
        public void TestFindAnimal()
        {
            var aviary = new GlassAviary(GlassAviaryType.WithWater);

            //Успешный поиск существующего животного
            var animal1 = new Reptile(ReptileDetachment.Crocodilia, "семейство1", "род1", "вид1");

            aviary.SettleAnimal(animal1);
            Assert.AreEqual(animal1, aviary.FindAnimal(animal1.Id));

            //Неуспешный поиск несуществующего животного
            Assert.AreEqual(null, aviary.FindAnimal("any id"));
        }
        // GET: Reptiles/Edit/5
        //  [Authorize(Roles = "canEdit")]
        public async Task <ActionResult> Edit(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Reptile reptile = await db.Reptiles.Include(r => r.Files).SingleOrDefaultAsync(r => r.ReptileId == id);

            if (reptile == null)
            {
                return(HttpNotFound());
            }
            return(View(reptile));
        }
        // GET: Reptile/Details/5
        public ActionResult Details(int id)
        {
            // repo
            ReptileRepository reptileRepository = new ReptileRepository();
            Reptile           reptile           = new Reptile();

            // get a reptile that has the matching id
            using (reptileRepository)
            {
                reptile = reptileRepository.SelectOne(id);
            }

            return(View(reptile));
        }
Example #20
0
        // GET: Reptiles/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Reptile reptile = db.Reptiles.Find(id);

            if (reptile == null)
            {
                return(HttpNotFound());
            }
            return(View(reptile));
        }
Example #21
0
        private void btnInit_Click(object sender, EventArgs e)
        {
            var url = comboBox2.Text;
            var str = (string)comboBox1.SelectedItem;

            Task.Run(() =>
            {
                reptile = Reptile.Instance();

                Console.WriteLine("Init WorkManager");
                workManager = new IbcWorkManager();
                workManager.Init();

                var id = Convert.ToInt32(str.Substring(4));
                reptile.Init(workManager, dicServerLine[id].ServerIP, dicServerLine[id].ServerPort);
                reptile.Start();
                subsManager  = IocUnity.GetService <ISubscriptionManager>("SubscriptionManager");
                matchManager = IocUnity.GetService <IMatchEntityManager>("MatchEntityManager");

                if (string.IsNullOrEmpty(user) || string.IsNullOrEmpty(passWord))
                {
                    Console.WriteLine("Has no user or passWord");
                    return;
                }

                var loginParam = new LoginParam()
                {
                    Username = user,
                    Password = passWord,
                    WebUrl   = url,
                    TakeMode = TakeMode.Pull
                };
                subsManager.Subscribe(loginParam);

                var ibcSyncTimeParam = new NormalParam()
                {
                    Stage         = (int)MatchStageEnum.Live,
                    TakeMode      = TakeMode.Push,
                    SubscribeType = "time",
                    TimeParam     = new SyncTimeParam()
                    {
                        id        = "c1",
                        rev       = 0,
                        condition = CommonTools.ToUnixTimeSpan(DateTime.Now) + ""
                    }
                };
                subsManager.Subscribe(ibcSyncTimeParam);
            });
        }
        //get
        public async Task <ActionResult> Length(string id, Length length)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Reptile reptile = await db.Reptiles.FindAsync(id);

            if (reptile == null)
            {
                return(HttpNotFound());
            }
            length.ReptileId = reptile.ReptileId;
            return(View(length));
        }
        // GET: Other/Create
        public async Task <ActionResult> Other(string id, Other other)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Reptile reptile = await db.Reptiles.FindAsync(id);

            if (reptile == null)
            {
                return(HttpNotFound());
            }
            other.ReptileId = reptile.ReptileId;
            return(View(other));
        }
        // GET: Sheds/Create
        public async Task <ActionResult> Shed(string id, Shed shed)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Reptile reptile = await db.Reptiles.FindAsync(id);

            if (reptile == null)
            {
                return(HttpNotFound());
            }
            shed.ReptileId = reptile.ReptileId;
            return(View(shed));
        }
        // GET: Defications/Create
        // inside reptile controller
        public async Task <ActionResult> Defication(string id, Defication defica)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Reptile reptile = await db.Reptiles.FindAsync(id);

            if (reptile == null)
            {
                return(HttpNotFound());
            }
            defica.ReptileId = reptile.ReptileId;
            return(View(defica));
        }
        // GET: Cleanings/Create
        public async Task <ActionResult> Cleaning(string id, Cleaning clean)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Reptile reptile = await db.Reptiles.FindAsync(id);

            if (reptile == null)
            {
                return(HttpNotFound());
            }
            clean.ReptileId = reptile.ReptileId;
            return(View(clean));
        }
        // GET: BreedingCycles/Create
        public async Task <ActionResult> BreedingCycle(string id, BreedingCycle BreedCyc)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Reptile reptile = await db.Reptiles.FindAsync(id);

            if (reptile == null)
            {
                return(HttpNotFound());
            }
            BreedCyc.ReptileId = reptile.ReptileId;
            return(View(BreedCyc));
        }
        // GET: Ultrasounds/Create
        public async Task <ActionResult> Ultrasound(string id, Ultrasound ultras)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Reptile reptile = await db.Reptiles.FindAsync(id);

            if (reptile == null)
            {
                return(HttpNotFound());
            }
            ultras.ReptileId = reptile.ReptileId;
            return(View(ultras));
        }
        // GET: Reptiles/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Reptile reptile = db.Reptiles.Find(id);

            if (reptile == null)
            {
                return(HttpNotFound());
            }
            ViewBag.animalSpecies_animalID = new SelectList(db.animals, "animalID", "animalID", reptile.animalSpecies_animalID);
            return(View(reptile));
        }
        // GET: Weights/Create

        public async Task <ActionResult> Weight(string id, Weight weight)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Reptile reptile = await db.Reptiles.FindAsync(id);

            if (reptile == null)
            {
                return(HttpNotFound());
            }
            weight.ReptileId = reptile.ReptileId;
            return(View(weight));
        }
		public void ShouldWorkLoadingComplexEntities()
		{
			const string crocodileFather = "Crocodile father";
			const string crocodileMother = "Crocodile mother";

			using (ISession s = sessions.OpenSession())
			using (ITransaction tx = s.BeginTransaction())
			{
				var rf = new Reptile { Description = crocodileFather };
				var rm = new Reptile { Description = crocodileMother };
				var rc1 = new Reptile { Description = "Crocodile" };
				var rc2 = new Reptile { Description = "Crocodile" };
				var rfamily = new Family<Reptile>
				{
					Father = rf,
					Mother = rm,
					Childs = new HashedSet<Reptile> { rc1, rc2 }
				};
				s.Save("ReptilesFamily", rfamily);
				tx.Commit();
			}

			const string humanFather = "Fred";
			const string humanMother = "Wilma";
			using (ISession s = sessions.OpenSession())
			using (ITransaction tx = s.BeginTransaction())
			{
				var hf = new Human { Description = "Flinstone", Name = humanFather };
				var hm = new Human { Description = "Flinstone", Name = humanMother };
				var hc1 = new Human { Description = "Flinstone", Name = "Pebbles" };
				var hfamily = new Family<Human>
				{
					Father = hf,
					Mother = hm,
					Childs = new HashedSet<Human> { hc1 }
				};
				s.Save("HumanFamily", hfamily);
				tx.Commit();
			}

			using (IStatelessSession s = sessions.OpenStatelessSession())
			using (ITransaction tx = s.BeginTransaction())
			{
				IList<Family<Human>> hf = s.CreateQuery("from HumanFamily").List<Family<Human>>();
				Assert.That(hf.Count, Is.EqualTo(1));
				Assert.That(hf[0].Father.Name, Is.EqualTo(humanFather));
				Assert.That(hf[0].Mother.Name, Is.EqualTo(humanMother));
				NHibernateUtil.IsInitialized(hf[0].Childs).Should("No lazy collection should be initialized").Be.True();
				//Assert.That(hf[0].Childs, Is.Null, "Collections should be ignored by stateless session.");

				IList<Family<Reptile>> rf = s.CreateQuery("from ReptilesFamily").List<Family<Reptile>>();
				Assert.That(rf.Count, Is.EqualTo(1));
				Assert.That(rf[0].Father.Description, Is.EqualTo(crocodileFather));
				Assert.That(rf[0].Mother.Description, Is.EqualTo(crocodileMother));
				NHibernateUtil.IsInitialized(hf[0].Childs).Should("No lazy collection should be initialized").Be.True();
				//Assert.That(rf[0].Childs, Is.Null, "Collections should be ignored by stateless session.");

				tx.Commit();
			}

			using (ISession s = sessions.OpenSession())
			using (ITransaction tx = s.BeginTransaction())
			{
				s.Delete("from HumanFamily");
				s.Delete("from ReptilesFamily");
				tx.Commit();
			}
		}