Наследование: Animal, ISound
Пример #1
0
 protected virtual void ExecuteInsertUnitCommand(string[] commandWords)
 {
     switch (commandWords[1])
     {
         case "Dog":
             var dog = new Dog(commandWords[2]);
             this.InsertUnit(dog);
             break;
         case "Human":
             var human = new Human(commandWords[2]);
             this.InsertUnit(human);
             break;
         case "Tank":
             var tank = new Tank(commandWords[2]);
             this.InsertUnit(tank);
             break;
         case "Marine":
             var marine = new Marine(commandWords[2]);
             this.InsertUnit(marine);
             break;
         case "Parasite":
             var parasite = new Parasite(commandWords[2]);
             this.InsertUnit(parasite);
             break;
         case "Queen":
             var queen = new Queen(commandWords[2]);
             this.InsertUnit(queen);
             break;
         default:
             break;
     }
 }
Пример #2
0
        public void GetField()
        {
            var getter = _ageField.GetGetter();
              var dog = new Dog();

              Assert.Equal(getter(dog), dog.Age);
        }
Пример #3
0
        public static void Main()
        {
            var animals = new List<Animal>();

            var kitten = new Kitten("Kitty", 2);

            SayAngAddToList(kitten, animals);

            var tomcat = new Tomcat("Tom", 1);

            SayAngAddToList(tomcat, animals);

            var frog = new Frog("Froggy", 5, Sex.Male);

            SayAngAddToList(frog, animals);

            var dog = new Dog("Sharo", 4, Sex.Male);

            SayAngAddToList(dog, animals);

            var anotherDog = new Dog("Lassy", 7, Sex.Female);

            SayAngAddToList(anotherDog, animals);

            Console.WriteLine("The average age of all animal is {0}", animals.Average(x => x.Age));
        }
Пример #4
0
        static void Main(string[] args)
        {
            Cat mimi = new Cat("mimi");
            mimi.SHOUTCOUNT = 4;
            mimi.shout();
            Console.WriteLine();

            Cat coco = new Cat("coco");
            coco.SHOUTCOUNT = 2;
            coco.shout();
            Console.WriteLine();

            Dog wangcai = new Dog("wangcai");
            wangcai.SHOUTCOUNT = 8;
            wangcai.shout();
            Console.WriteLine();

            Cow moumou = new Cow("moumou");
            moumou.SHOUTCOUNT = 3;
            moumou.shout();
            Console.WriteLine();

            Sheep miemie = new Sheep("miemie");
            miemie.SHOUTCOUNT = 5;
            miemie.shout();
            Console.WriteLine();

            coco.CatchAnimal();
            wangcai.CatchAnimal();
            Console.ReadLine();
        }
Пример #5
0
 public Person(string name, int age, string dogName)
 {
     Name = name;
     Age = age;
     Pet = new Dog(dogName);
     action += (val) => val * val;
 }
Пример #6
0
    static void Main(string[] args)
    {
        //Create a hierarchy Dog, Frog, Cat, Kitten, Tomcat and define useful
        //constructors and methods. Dogs, frogs and cats are Animals. All animals
        //can produce sound (specified by the ISound interface). Kittens and
        //tomcats are cats. All animals are described by age, name and sex. Kittens
        //can be only female and tomcats can be only male. Each animal produces a specific
        //sound. Create arrays of different kinds of animals and calculate the average
        //age of each kind of animal using a static method (you may use LINQ).

        //Make some animals and test their properties
        Kitten kitty = new Kitten(3, "Kitty");//the sex is aways female
        Console.WriteLine(kitty.Name + "-" + kitty.Age + "-" + kitty.sex);
        kitty.ProduceSound();
        Tomkat tom = new Tomkat(5, "Tom");//the sex is aways male
        Console.WriteLine(tom.Name + "-" + tom.Age + "-" + tom.sex);
        tom.ProduceSound();
        Dog doggy = new Dog(8, "Doggy", Sex.male);
        Console.WriteLine(doggy.Name + "-" + doggy.Age + "-" + doggy.sex);
        doggy.ProduceSound();
        Frog froggy = new Frog(1, "Froggy", Sex.female);
        Console.WriteLine(froggy.Name + "-" + froggy.Age + "-" + froggy.sex);
        froggy.ProduceSound();

        //Make array with diferent animals and calculate the average age for every animal type in the array
        Animal[] animals = {kitty,tom,froggy,doggy,
                                   new Kitten(4,"Keit"),
                                   new Tomkat(5,"Tomas"),
                                   new Dog(11,"Rex",Sex.male),
                                   new Frog(3,"Curmit",Sex.male)};
        CalculateEveryAnimalAverageAge(animals);
    }
Пример #7
0
    static void Main()
    {
        Console.Write("Enter first dog's name: ");
        string dogName = Console.ReadLine();
        Console.Write("Enter first dog's breed: ");
        string dogBreed = Console.ReadLine();
        // Use the Dog CONSTRUCTOR to assign name and breed
        Dog firstDog = new Dog(dogName, dogBreed);

        // Create a new dog using the parameterless constructor
        Dog secondDog = new Dog();
        // Use PROPERTIES to set name and breed
        Console.Write("Enter second dog's name: ");
        secondDog.Name = Console.ReadLine();
        Console.Write("Enter second dog's breed: ");
        secondDog.Breed = Console.ReadLine();

        // Create a Dog with no name and breed
        Dog thirdDog = new Dog();

        // Save the dogs in an array
        Dog[] dogs = new Dog[] { firstDog, secondDog, thirdDog };
        // Ask each of the dogs to bark
        foreach(Dog dog in dogs)
        {
            dog.SayBau();
        }
    }
Пример #8
0
 static void Main()
 {
     Dog D = new Dog();
     D.Sound();
     Cat C = new Cat();
     C.Sound();
 }
Пример #9
0
        private static void Main()
        {
            IList<Animal> animals = new List<Animal>
            {
                new Cat("Maca",2, Genders.Female),
                new Cat("Kotio", 4, Genders.Male),
                new Dog("Balkan", 1, Genders.Male),
                new Dog("Sharo", 6, Genders.Male),
                new Frog("Tinka", 4, Genders.Female),
                new Frog("Gruncho", 7, Genders.Male),
                new Kitten("Mariika", 2),
                new Tomcat("Gancho", 2)
            };

            var groupAnimals = from animal in animals
                               group animal by (animal is Cat) ? typeof(Cat) : animal.GetType()
                                   into g
                                   select new { GroupName = g.Key, AverageAge = g.ToList().Average(a => a.Age) };
            foreach (var animal in groupAnimals)
            {
                Console.WriteLine("{0} - average age: {1:N2}", animal.GroupName.Name, animal.AverageAge);
            }
            Console.WriteLine();

            Animal rex = new Dog("Rex", 10, Genders.Male);
            Animal gosho = new Cat("Gosho", 5, Genders.Male);
            Animal tina = new Frog("Tina", 4, Genders.Female);

            rex.ProduceSound();
            gosho.ProduceSound();
            tina.ProduceSound();
        }
Пример #10
0
        public void Performance()
        {
            var getter = _ageField.GetGetter();
              var setter = _ageField.GetSetter();

              var dog1 = new Dog();
              var dog2 = new Dog();

              var iterations = 100000;

              var stopWatch = new Stopwatch();
              stopWatch.Start();

              for (var i = 0; i < iterations; i++)
              {
            setter(dog2, getter(dog1));
              }

              stopWatch.Stop();

              Console.WriteLine("Using delegates: {0}.", stopWatch.Elapsed.TotalMilliseconds);

              stopWatch.Reset();
              stopWatch.Start();

              for (var i = 0; i < iterations; i++)
              {
            _ageField.SetValue(dog2, _ageField.GetValue(dog1));
              }

              Console.WriteLine("Using reflection: {0}.", stopWatch.Elapsed.TotalMilliseconds);
        }
Пример #11
0
        static void Main(string[] args)
        {
            int? x = null;
            Dog? d = new Dog(); //идентично Nullable<Dog> y = null;
            Nullable<Dog> y = null;
            Console.WriteLine(d.HasValue);  //true если d!=null

            int z = x ?? 30;    //если х null z=30 иначе z=х
            Console.WriteLine(z);
            x = 100;
            z = x ?? 30;
            Console.WriteLine(z);

            //расширение класса строк
            Console.WriteLine("^^^^^^^^^^^^");
            string str = "Vasya";
            Console.WriteLine(str.Double());
            Console.WriteLine(StringExtention.Double(str));

            Console.WriteLine("^^^^^^^^^^^^");
            Console.WriteLine(str.AddStr("Olga"));
            Console.WriteLine(StringExtention.AddStr(str,"Katya",false));

            Console.WriteLine("^^^^^^^^^^^^");
            Human man = new Human { Name = "Gorge" };
            man.Show();
            man.Show("is good man");

            HumanExtention.Show(man);

            Console.ReadKey();
        }
Пример #12
0
 void SendInputs(Dog d)
 {
     d.h = h;
     d.v = v;
     d.run = run;
     d.jump = jump;
 }
Пример #13
0
        private Dog GetNewDog()
        {
            Dog dog = new Dog();

            if (mRandom.Next(2) == 0) {
                // Row
                dog.Y = mRandom.Next(8);
                dog.VX = mRandom.NextDouble() / 5;
                dog.X = 0;
                if (mRandom.Next(2) == 0) {
                    dog.X = 7;
                    dog.VX *= -1;
                }

            } else {
                // Column
                dog.X = mRandom.Next(8);
                dog.VY = mRandom.NextDouble() / 5;
                dog.Y = 0;
                if (mRandom.Next(2) == 0) {
                    dog.Y = 7;
                    dog.VY *= -1;
                }
            }

            return dog;
        }
Пример #14
0
 public static void Main()
 {
     Dog spot = new Dog("Spot");
        Cat puff = new Cat("Puff");
        DisplayAnimal(spot);
        DisplayAnimal(puff);
 }
Пример #15
0
        //This method computes a match score between 2 dog instances, a lower score is a better match.
        private int computeMatchScore(Dog UserDog, Dog DatabaseDog)
        {
            int score = INITIAL_MATCH_SCORE;

            //if the dog is no good with children, do not check any further and return a high score.
            if((UserDog.GoodWithChildren == true) && (DatabaseDog.GoodWithChildren == false))
            {
                return No_MATCH;
            }

            //if the dog drools, do not check any further and return a high score.
            if((UserDog.Drools == true) && (DatabaseDog.Drools == true))
            {
                return No_MATCH;
            }

            //For-each other property work out the numeric difference between the properties of the dogs and add this difference to the over all score. If the properties
            //match the difference will be 0 eg 2 - 2 = 0. If the user picks low for a property and the comparing dogs property value is high the difference
            //between these two values will be 1 - 3 = -2 this value is then converted to a positive number and added to the score. No preference value is 0.
            score += Math.Abs((int)UserDog.ActivityLevel - (int)DatabaseDog.ActivityLevel);

            score += Math.Abs((int)UserDog.SheddingLevel - (int)DatabaseDog.SheddingLevel);

            score += Math.Abs((int)UserDog.IntelligenceLevel - (int)DatabaseDog.IntelligenceLevel);

            score += Math.Abs((int)UserDog.Coatlength - (int)DatabaseDog.Coatlength);

            score += Math.Abs((int)UserDog.Size - (int)DatabaseDog.Size);

            return score;
        }
Пример #16
0
 public void Collect(Dog winningDog)
 {
     Cash += MyBet.PayOut(winningDog);
     MyLabel.Text = Name + "'s bet: ";
     fHasPlacedBet = false;
     MyBet = new Bet(); // todo same question as line 28
 }
Пример #17
0
 static void Main()
 {
     //
     Cat somecat = new Cat("Monika_Cat",4,"female");
     somecat.ProduceSound();
     Kitten kitten = new Kitten("Vesi_Kitten", 5);
     kitten.ProduceSound();
     Console.WriteLine(kitten.Sex);
     Tomcat tomCat = new Tomcat("Tomas_TomCat", 6);
     tomCat.ProduceSound();
     Console.WriteLine(tomCat.Sex);
     Frog kyrmit = new Frog("Kyrmit_Jabok", 2, "male");
     Dog rex = new Dog("Rex_Dog", 7, "male");
     Dog hera = new Dog("Hera_Dog", 8, "female");
     List<Animal> animalsList = new List<Animal>();
     Cat lora = new Cat("Lora_Cat", 3, "female");
     animalsList.Add(somecat);
     animalsList.Add(kitten);
     animalsList.Add(tomCat);
     animalsList.Add(kyrmit);
     animalsList.Add(rex);
     animalsList.Add(hera);
     animalsList.Add(lora);
     //Average groups age
     var animalGroups =
         from animal in animalsList
         group animal by animal.GetType();
     foreach (var animals in animalGroups)
     {
         Console.WriteLine(animals.myAverage());
     }
 }
Пример #18
0
    public void DogTalkToOwnerTest()
    {
        string expected = "Woof!";
        string actual = new Dog().TalkToOwner();

        Assert.Equal(expected, actual);
    }
Пример #19
0
    static void Main()
    {
        Console.WriteLine("Enter first dog's name: ");
        string dogName = Console.ReadLine();
        Console.WriteLine("Enter first dog's breed: ");
        string dogBreed = Console.ReadLine();

        // Use constructor to set the name and breed
        Dog firstDog = new Dog(dogName, dogBreed);

        // Create new dog using the parameterless constructor
        Dog secondDog = new Dog();

        // Use properties to set name and breed
        Console.WriteLine("Enter second dog's name: ");
        secondDog.Name = Console.ReadLine();
        Console.WriteLine("Enter second dog's breed: ");
        secondDog.Breed = Console.ReadLine();

        // Create a Dog with default name and breed
        Dog thirdDog = new Dog();

        // Save the dogs in an array
        Dog[] dogs = new Dog[] { firstDog, secondDog, thirdDog };

        // Ask each of the dogs to bark
        foreach(Dog dog in dogs)
        {
            dog.SayBau();
        }
    }
    // Ctor & Methods //
    public CharacterManager()
    {
        _human = new Human("Bobby");
        _dog = new Dog("Billy");

        SelectedCharacter = _human;

        _enemies = new List<Enemy>();
        _enemies.Add(new Enemy("Steve"));
        _enemies.Add(new Enemy("Steve"));
        _enemies.Add(new Enemy("Steve"));
        _enemies.Add(new Enemy("Steve"));
        _enemies.Add(new Enemy("Steve"));
        _enemies.Add(new Enemy("Steve"));
        _enemies.Add(new Enemy("Steve"));
        _enemies.Add(new Enemy("Steve"));
        _enemies.Add(new Enemy("Steve"));
        _enemies.Add(new Enemy("Steve"));
        _enemies.Add(new Enemy("Steve"));
        _enemies.Add(new Enemy("Steve"));
        _enemies.Add(new Enemy("Steve"));
        _enemies.Add(new Enemy("Steve"));
        _enemies.Add(new Enemy("Steve"));
        _enemies.Add(new Enemy("Steve"));
        _enemies.Add(new Enemy("Steve"));
        _enemies.Add(new Enemy("Steve"));
        _enemies.Add(new Enemy("Steve"));
        _enemies.Add(new Enemy("Steve"));
        _enemies.Add(new Enemy("Steve"));
        _enemies.Add(new Enemy("Steve"));
        _enemies.Add(new Enemy("Steve"));
        _enemies.Add(new Enemy("Steve"));
    }
        public void Can_index_be_used_to_concurrently_get_items_with_one_key()
        {
            //Arrange
            var results = new ConcurrentDictionary<int, List<Dog>>();

            var dog1 = new Dog {Name = "Tony", Age = 1};
            var dog2 = new Dog {Name = "Andrew", Age = 2};
            var dog3 = new Dog {Name = "John", Age = 3};

            var sut = CacheFactory.CreateFor<Dog>()
                .WithIndex(dog => dog.Age >= 2)
                .BuildUp(new[] {dog1, dog2, dog3});

            //Act
            ThreadsRunnerFactory.Create()
                .PlanExecution(() => sut.Index(dog => dog.Age >= 2).Get(true))
                    .Threads(10)
                    .StoreResult(results)
                .StartAndWaitAll();

            //Assert
            foreach (var value in results.Values)
            {
                value.ShouldAllBeEquivalentTo(new[] {dog2, dog3});
            }
        }
        internal DogSearchResultsListBuilder ListOf14Beagels()
        {
            var category = new Category() { Description = "Dogs for hunting foxes and badgers etc.", Id = 3, Name = "Hunting" };
            var beagle = new Breed() { Name = "Beagel", Category = category, Id = 3, Species = null };

            var beagleHuntingDog = new Dog() { Name = "Shep", Breed = beagle };
            var fourteenMatchedDogs = new ObservableCollection<Dog>()
            {   beagleHuntingDog
                ,beagleHuntingDog
                ,beagleHuntingDog
                ,beagleHuntingDog
                ,beagleHuntingDog
                ,beagleHuntingDog
                ,beagleHuntingDog
                ,beagleHuntingDog
                ,beagleHuntingDog
                ,beagleHuntingDog
                ,beagleHuntingDog
                ,beagleHuntingDog
                ,beagleHuntingDog
                ,beagleHuntingDog
            };
            _dogs.AddRange(fourteenMatchedDogs);
            return this;
        }
Пример #23
0
 public static void Main()
 {
     Dog spot = new Dog("Spot");
        Cat puff = new Cat("Puff");
        Console.WriteLine(spot.Name + " says " + spot.Speak());
        Console.WriteLine(puff.Name + " says " + puff.Speak());
 }
Пример #24
0
    static void Main(string[] args)
    {
        Dog Pesho = new Dog();
        Dog sharo = new Dog("Sharo","Ovchar");

        sharo.Bark();
    }
        public void Can_index_be_rebuilt()
        {
            //Arrange
            var dog1 = new Dog { Breed = "Breed A", Name = "Tony", Age = 1 };
            var dog2 = new Dog { Breed = "Breed A", Name = "Andrew", Age = 2 };
            var dog3 = new Dog { Breed = "Breed A", Name = "John", Age = 3 };

            var sut = CacheFactory.CreateFor<Dog>()
               .WithSortedIndex(dog => dog.Breed, dog => dog.Age).Ascending()
               .BuildUp(new[] { dog1, dog2, dog3 });

            //Act
            dog3.Breed = "Changed Breed";
            dog3.Age = 1;

            sut.RebuildIndexes();

            var rebuiltState = sut.Index(dog => dog.Breed).Get("Breed A").ToArray();

            //Assert
            rebuiltState
                .Should()
                .BeEquivalentTo(dog1, dog2)
                .And
                .BeInAscendingOrder(dog => dog.Age);
        }
Пример #26
0
    public static void Main()
    {
        Dog lol = new Dog("Ivan", 12, Sex.Male);
        lol.MakeSound();

        Kitten test = new Kitten("Ivanka", 12, Sex.Female);

        Animal[] myZoo = 
        {
            new Cat("Ivanka", 12, Sex.Female),
            new Kitten("Ivanka", 12, Sex.Female),
            new Frog("Ivanka", 20, Sex.Female),
            new Frog("Ivanka", 10, Sex.Female),
            new Dog("Ivanka", 12, Sex.Female),
            new Cat("Ivanka", 12, Sex.Female),
            new Kitten("Ivanka", 12, Sex.Female),
            new Frog("Ivanka", 20, Sex.Female),
            new Frog("Ivanka", 10, Sex.Female),
            new Dog("Ivanka", 12, Sex.Female),
            new Cat("Ivanka", 12, Sex.Female),
            new Kitten("Ivanka", 12, Sex.Female),
            new Frog("Ivanka", 20, Sex.Female),
            new Frog("Ivanka", 10, Sex.Female),
            new Dog("Ivanka", 12, Sex.Female),
            new Cat("Ivanka", 12, Sex.Female),
            new Kitten("Ivanka", 12, Sex.Female),
            new Frog("Ivanka", 20, Sex.Female),
            new Frog("Ivanka", 10, Sex.Female),
            new Dog("Ivanka", 12, Sex.Female),
        };

        Animal.AgeAverage(myZoo);
    }
Пример #27
0
    static void Main()
    {
        Dog dogOne = new Dog("Sharo", "male", 7);
        Dog dogTwo = new Dog("Sara", "female", 17);
        Dog dogThree = new Dog("Tara", "female", 1);
        Dog[] dogArr = new Dog[] { dogOne, dogTwo, dogThree };
        Console.WriteLine("The average age of dogs is {0:F2} years old.", Animal.CalculateAverage(dogArr));
        Console.WriteLine("Dog {0} says {1}.", dogThree.Name, dogThree.PrintSound());

        Frog frogOne = new Frog("Skokla", "female", 23);
        Frog frogTwo = new Frog("Handsome", "male", 9);
        Frog frogThree = new Frog("Skokancho", "male", 2);
        Frog[] frogArr = new Frog[] { frogOne, frogTwo, frogThree };
        Console.WriteLine("The average age of frogs is {0:F2} years old.", Animal.CalculateAverage(frogArr));
        Console.WriteLine("Frog {0} says {1}.", frogThree.Name, frogThree.PrintSound());

        Kitten kittenOne = new Kitten("Hihi", 1);
        Kitten kittenTwo = new Kitten("Kiki", 1);
        Kitten kittenThree = new Kitten("Kenny", 2);
        Kitten[] kittenArr = new Kitten[] { kittenOne, kittenTwo, kittenThree };
        Console.WriteLine("The average age of kittens is {0:F2} years old.", Animal.CalculateAverage(kittenArr));
        Console.WriteLine("Kitten {0} says {1}.", kittenThree.Name, kittenThree.PrintSound());

        Tomcat tomcatOne = new Tomcat("Pancho", 4);
        Tomcat tomcatTwo = new Tomcat("Robby", 3);
        Tomcat tomcatThree = new Tomcat("Vasko", 8);
        Tomcat[] tomcatArr = new Tomcat[] { tomcatOne, tomcatTwo, tomcatThree };
        Console.WriteLine("The average age of tomcats is {0:F2} years old.", Animal.CalculateAverage(tomcatArr));
        Console.WriteLine("Tomcat {0} says {1}.", tomcatThree.Name, tomcatThree.PrintSound());
    }
Пример #28
0
 static void Main()
 {
     Animal A;
     //A=new Animal();
     A = new Dog(); A.Sound();
     A = new Cow(); A.Sound();
     A = new Cat(); A.Sound();
 }
Пример #29
0
 public void TestInh()
 {
     IClassValidator classValidator = GetClassValidator(typeof(Dog));
     Dog dog = new Dog();
     classValidator.GetInvalidValues(dog).Should().Have.Count.EqualTo(3);
     dog.FavoriteBone = "DE";  //failure
                 classValidator.GetInvalidValues(dog).Should().Have.Count.EqualTo(3);
 }
 static void Main()
 {
     Dog joe = new Dog(8, "Labrador");
     joe.Sleep();
     joe.WagTail();
     Console.WriteLine("Joe is {0} years old dog of breed {1}.",
         joe.Age, joe.Breed);
 }
Пример #31
0
        public ActionResult Delete(int id)
        {
            Dog dog = _dogRepo.GetDogById(id);

            return(View(dog));
        }
Пример #32
0
 public DogController(Dog model, DogShow view)
 {
     this.model = model;
     this.view  = view;
 }
Пример #33
0
 public IActionResult Index(Dog dog)
 {
     Dog.PostDog(dog);
     return(RedirectToAction("Index"));
 }
Пример #34
0
 public IActionResult Details(int id, Dog dog)
 {
     dog.DogId = id;
     Dog.PutDog(dog);
     return(RedirectToAction("Details", id));
 }
Пример #35
0
 public SniffForTree(Dog d) : base(d)
 {
     actionDelay = 2;
     moodState.ChangeMood(50f, 0f, 30f, 0f);
     moodEffect.ChangeMood(5f, 5f, 5f, 0f);
 }
        public async Task <IActionResult> Get(
            [FromQuery] string dogName,
            [FromQuery] string breed,
            [FromQuery] int?dogOwnerId,
            [FromQuery] string notes)
        {
            using (SqlConnection conn = Connection)
            {
                conn.Open();
                using (SqlCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = @"
                        SELECT Id, DogName, Breed, DogOwnerId, Notes FROM Dog WHERE 1 = 1";

                    if (dogName != null)
                    {
                        cmd.CommandText += " AND DogName LIKE @dogName";
                        cmd.Parameters.Add(new SqlParameter("@dogName", "%" + dogName + "%"));
                    }

                    if (breed != null)
                    {
                        cmd.CommandText += " AND Breed LIKE @breed";
                        cmd.Parameters.Add(new SqlParameter("@breed", "%" + breed + "%"));
                    }

                    if (dogOwnerId != null)
                    {
                        cmd.CommandText += " AND DogOwnerId = @dogOwnerId";
                        cmd.Parameters.Add(new SqlParameter("@dogOwnerId", dogOwnerId));
                    }

                    if (notes != null)
                    {
                        cmd.CommandText += " AND Notes LIKE @notes";
                        cmd.Parameters.Add(new SqlParameter("@notes", "%" + notes + "%"));
                    }

                    SqlDataReader reader = cmd.ExecuteReader();

                    List <Dog> dogs = new List <Dog>();

                    while (reader.Read())
                    {
                        int    id           = reader.GetInt32(reader.GetOrdinal("Id"));
                        int    dogOwnId     = reader.GetInt32(reader.GetOrdinal("DogOwnerId"));
                        string dogNameValue = reader.GetString(reader.GetOrdinal("DogName"));
                        string breedValue   = reader.GetString(reader.GetOrdinal("Breed"));
                        string notesValue   = reader.GetString(reader.GetOrdinal("Notes"));

                        Dog dog = new Dog
                        {
                            Id         = id,
                            DogName    = dogNameValue,
                            Breed      = breedValue,
                            Notes      = notesValue,
                            DogOwnerId = dogOwnId
                        };

                        dogs.Add(dog);
                    }
                    reader.Close();

                    return(Ok(dogs));
                }
            }
        }
 public WellFormedZoo(Dog dog, Cat cat)
 {
 }
Пример #38
0
        public IActionResult Index()
        {
            var dogs = Dog.GetDogs();

            return(View(dogs));
        }
Пример #39
0
 /// <summary>
 /// Initializes new <see cref="Dog"/> instance dog in state.
 /// </summary>
 public void NewDoggo() => Doggo = new Dog();
Пример #40
0
 void Start()
 {
     doug     = GetComponent <Dog>();
     bothered = false;
 }
Пример #41
0
        public void CollectionNamesTest()
        {
            var a  = new MongoRepository <Animal>();
            var am = new MongoRepositoryManager <Animal>();
            var va = new Dog();

            Assert.IsFalse(am.Exists);
            a.Update(va);
            Assert.IsTrue(am.Exists);
            Assert.IsInstanceOfType(a.GetById(va.Id), typeof(Dog));
            Assert.AreEqual(am.Name, "AnimalsTest");
            Assert.AreEqual(a.CollectionName, "AnimalsTest");

            var cl  = new MongoRepository <CatLike>();
            var clm = new MongoRepositoryManager <CatLike>();
            var vcl = new Lion();

            Assert.IsFalse(clm.Exists);
            cl.Update(vcl);
            Assert.IsTrue(clm.Exists);
            Assert.IsInstanceOfType(cl.GetById(vcl.Id), typeof(Lion));
            Assert.AreEqual(clm.Name, "Catlikes");
            Assert.AreEqual(cl.CollectionName, "Catlikes");

            var b  = new MongoRepository <Bird>();
            var bm = new MongoRepositoryManager <Bird>();
            var vb = new Bird();

            Assert.IsFalse(bm.Exists);
            b.Update(vb);
            Assert.IsTrue(bm.Exists);
            Assert.IsInstanceOfType(b.GetById(vb.Id), typeof(Bird));
            Assert.AreEqual(bm.Name, "Birds");
            Assert.AreEqual(b.CollectionName, "Birds");

            var l  = new MongoRepository <Lion>();
            var lm = new MongoRepositoryManager <Lion>();
            var vl = new Lion();

            //Assert.IsFalse(lm.Exists);   //Should already exist (created by cl)
            l.Update(vl);
            Assert.IsTrue(lm.Exists);
            Assert.IsInstanceOfType(l.GetById(vl.Id), typeof(Lion));
            Assert.AreEqual(lm.Name, "Catlikes");
            Assert.AreEqual(l.CollectionName, "Catlikes");

            var d  = new MongoRepository <Dog>();
            var dm = new MongoRepositoryManager <Dog>();
            var vd = new Dog();

            //Assert.IsFalse(dm.Exists);
            d.Update(vd);
            Assert.IsTrue(dm.Exists);
            Assert.IsInstanceOfType(d.GetById(vd.Id), typeof(Dog));
            Assert.AreEqual(dm.Name, "AnimalsTest");
            Assert.AreEqual(d.CollectionName, "AnimalsTest");

            var m  = new MongoRepository <Bird>();
            var mm = new MongoRepositoryManager <Bird>();
            var vm = new Macaw();

            //Assert.IsFalse(mm.Exists);
            m.Update(vm);
            Assert.IsTrue(mm.Exists);
            Assert.IsInstanceOfType(m.GetById(vm.Id), typeof(Macaw));
            Assert.AreEqual(mm.Name, "Birds");
            Assert.AreEqual(m.CollectionName, "Birds");

            var w  = new MongoRepository <Whale>();
            var wm = new MongoRepositoryManager <Whale>();
            var vw = new Whale();

            Assert.IsFalse(wm.Exists);
            w.Update(vw);
            Assert.IsTrue(wm.Exists);
            Assert.IsInstanceOfType(w.GetById(vw.Id), typeof(Whale));
            Assert.AreEqual(wm.Name, "Whale");
            Assert.AreEqual(w.CollectionName, "Whale");
        }
Пример #42
0
 public void Enter(Dog dog)
 {
     _dog = dog;
     _dog.isDrinkState = true;
 }
Пример #43
0
        static void Main(string[] args)
        {
            Dog dog = new Dog("Json");

            Console.WriteLine(dog.Name);

            Dog dog1 = new Dog("Css");

            Console.WriteLine(dog1.Name);

            Cat cat = new Cat("Sass");

            Console.WriteLine(cat.Name);
            Console.WriteLine(cat.Sound());


            //Gun gun = new Gun(30);
            //Console.WriteLine("===========================================");
            //Console.WriteLine("                 Gun App                   ");
            //Console.WriteLine("===========================================");

            //int selection;
            //do
            //{

            //    Console.WriteLine("===========================================");
            //    Console.WriteLine(gun.ToString());
            //    Console.WriteLine("===========================================");

            //    Console.WriteLine("1. Shoot");
            //    Console.WriteLine("2. Reload");
            //    Console.WriteLine("3. Add Pistol");
            //    Console.WriteLine("4. Change Mode");
            //    Console.WriteLine("0. Exit");

            //    Console.WriteLine("===========================================");
            //    string selectionStr = Console.ReadLine();

            //    while (!int.TryParse(selectionStr, out selection))
            //    {
            //        Console.WriteLine("Düzgün seçim edin");
            //        selectionStr = Console.ReadLine();
            //    }

            //    switch (selection)
            //    {
            //        case 1:
            //            Console.WriteLine("===========================================");
            //            Console.WriteLine("You select shoot");
            //            Console.WriteLine("===========================================");

            //            bool r = gun.Shoot();

            //            if (!r)
            //            {
            //                Console.WriteLine("You have no pistol");
            //            }

            //            Console.WriteLine("===========================================");
            //            break;
            //        case 2:
            //            Console.WriteLine("===========================================");
            //            Console.WriteLine("You select reload");
            //            Console.WriteLine("===========================================");

            //            gun.Reload();

            //            Console.WriteLine("===========================================");
            //            break;
            //        case 3:
            //            Console.WriteLine("===========================================");
            //            Console.WriteLine("You select add pistol");
            //            Console.WriteLine("===========================================");
            //            Console.WriteLine("Elave etmek isteyiniz gulle sayi yazin");

            //            string pistolStr = Console.ReadLine();

            //            int pistolCount;
            //            while (!int.TryParse(pistolStr, out pistolCount))
            //            {
            //                Console.WriteLine("Duzgun litr yazin");
            //                pistolStr = Console.ReadLine();
            //            }

            //            gun.AddPistol(pistolCount);

            //            Console.WriteLine("===========================================");
            //            break;
            //        case 4:
            //            Console.WriteLine("===========================================");
            //            Console.WriteLine("You select change mode");
            //            Console.WriteLine("===========================================");

            //            gun.ChangeMode();

            //            Console.WriteLine("===========================================");
            //            break;
            //        case 0:
            //            break;
            //        default:
            //            Console.WriteLine("Duzgun secim etmediniz");
            //            Console.WriteLine("===========================================");
            //            break;
            //    }

            //} while (selection != 0);
        }
Пример #44
0
        public void ShouldNotBeAbleToSelectVetIfNotOwnerOfTheDog()
        {
            var fakeOwner = new User
            {
                Email = "*****@*****.**"
            };

            this.context.Users.Add(fakeOwner);

            this.context.SaveChanges();

            var fakeDog = new Dog
            {
                Name    = "Grojan",
                OwnerId = this.context.Users.FirstOrDefault(u => u.Email == "*****@*****.**").Id
            };

            this.context.Dogs.Add(fakeDog);

            this.context.SaveChanges();

            var fakeUserOne = new User
            {
                Email      = "*****@*****.**",
                ImageUrl   = "imageurl",
                FirstName  = "Manol",
                LastName   = "Denkov",
                BirthDate  = DateTime.Parse("22.02.2002"),
                VetLicence = "1111111111"
            };

            this.context.Users.Add(fakeUserOne);

            this.context.SaveChanges();

            var fakeUserTwo = new User
            {
                Email      = "*****@*****.**",
                ImageUrl   = "imageurl2",
                FirstName  = "Manolo",
                LastName   = "Denkov",
                BirthDate  = DateTime.Parse("22.03.2003"),
                VetLicence = "2222222222"
            };

            this.context.Users.Add(fakeUserTwo);

            this.context.SaveChanges();

            var fakeUserThree = new User
            {
                Email      = "*****@*****.**",
                ImageUrl   = "imageurl2",
                FirstName  = "Manolov",
                LastName   = "Denkov",
                BirthDate  = DateTime.Parse("22.03.2003"),
                VetLicence = "2222222222"
            };

            this.context.Users.Add(fakeUserThree);

            this.context.SaveChanges();

            var result = this.vetsController.Aprove(fakeUserOne.Id).Result as ViewResult;

            var resultTwo = this.vetsController.Aprove(fakeUserTwo.Id).Result as ViewResult;

            var listToChooseFrom = this.vetsController.Choose(fakeDog.Id) as ViewResult;

            var chosenOne = fakeDog.Id + "tire" + fakeUserOne.Id;

            this.vetsController.Select(chosenOne);

            Assert.AreEqual(null, fakeDog.VetId);
        }
Пример #45
0
 public WrappedDog(Dog dog)
 {
     this.dog = dog;
 }
 public FactoryDrivenZoo(Dog dog, Func <string, Cat> catFactory)
 {
 }
Пример #47
0
 // Start is called before the first frame update
 void Start()
 {
     dog              = GetComponent <Dog>();
     anim             = GetComponentInChildren <Animator>();
     origRootRotation = RootBone.localRotation;
 }
Пример #48
0
        public static void Run()
        {
            Dog tony = new Dog
            {
                Breed  = DogBreed.BostonTerrier,
                Vitals = new AnimalVitals {
                    Age = 11, Gender = Gender.Male, Name = "Tony"
                }
            };
            Dog rocket = new Dog
            {
                Breed  = DogBreed.GoldenRetriever,
                Vitals = new AnimalVitals {
                    Age = 8, Gender = Gender.Female, Name = "Rocket"
                }
            };
            Dog peaches = new Dog
            {
                Breed  = DogBreed.GermanShepard,
                Vitals = new AnimalVitals {
                    Age = 14, Gender = Gender.Female, Name = "Peaches"
                }
            };

            // RIP
            Cat grumpyCat = new Cat
            {
                Breed  = CatBreed.GrumpyCat,
                Vitals = new AnimalVitals {
                    Age = 17, Gender = Gender.Female, Name = "Tardar Sauce"
                }
            };

            Person person = new Person
            {
                Age         = 24,
                Cats        = new[] { grumpyCat },
                Dogs        = new[] { tony, rocket, peaches },
                FavoritePet = new FavoritePet(rocket),
                Name        = "Nikola Tesla"
            };

            // SpanWriter is the core code that writes data to a span. Flatsharp provides a couple:
            SpanWriter spanWriter       = new SpanWriter();
            SpanWriter unsafeSpanWriter = new UnsafeSpanWriter();

            byte[] buffer = new byte[Person.Serializer.GetMaxSize(person)];

            int bytesWritten = Person.Serializer.Write(spanWriter, buffer, person);

            bytesWritten = Person.Serializer.Write(unsafeSpanWriter, buffer, person);

            // For reading data, we use InputBuffer. There are more options here:

            // Array and Memory input buffers are general purpose and support all scenarios.
            var p1 = Person.Serializer.Parse(new ArrayInputBuffer(buffer));
            var p2 = Person.Serializer.Parse(new MemoryInputBuffer(new Memory <byte>(buffer)));

            // ReadOnlyMemory input buffer will fail to Parse any objects that have Memory<T> in them (that is -- non read only memory).
            var p3 = Person.Serializer.Parse(new ReadOnlyMemoryInputBuffer(new ReadOnlyMemory <byte>(buffer)));

            // The unsafe variants are available in the FlatSharp.Unsafe package and use pointers and other unsafe code to squeeze
            // out some more performance.
            var p4 = Person.Serializer.Parse(new UnsafeArrayInputBuffer(buffer));

            using (var unsafeMemoryInput = new UnsafeMemoryInputBuffer(new Memory <byte>(buffer)))
            {
                // Unsafe memory input buffer must be disposed of because it pins the memory in place.
                var p5 = Person.Serializer.Parse(unsafeMemoryInput);
            }
        }
Пример #49
0
        static void Main(string[] args)
        {
            var lab = new Lab1();

            lab.Run();

            var l2 = new Lab2();

            l2.ToPercentage(0.12m);

            var mittHus = new Hus();

            mittHus.AntalRum   = 3;
            mittHus.FasadColor = "Blue";

            var syrransHus = new Hus();

            syrransHus.AntalRum   = 5;
            syrransHus.FasadColor = "Red";

            mittHus.Repaint("Green");


            var dog1 = new Dog();

            dog1.Namn = "Karo";
            Console.WriteLine(Dog.IsAnimal());

            var dog2 = new Dog();

            dog2.Namn = "Pluto";



            var labben = new Lab10();

            labben.Run();



            var lab9 = new Lab9();

            lab9.Run();


            var lab8 = new Lab8();

            lab8.Run();

            var lab7 = new Lab7();

            lab7.Run();

            var lab6 = new Lab6();

            lab6.Run();



            var    lab3   = new Lab3();
            string result = lab3.PlussaStringar("hej", "heopp");

            var lab2 = new Lab2();

            decimal input = Convert.ToDecimal(Console.ReadLine());
            int     d     = lab2.ToPercentage(input);

            var lab4 = new Lab4();

            lab4.Run();



            var lab5 = new Lab5();

            lab5.Run();
        }
Пример #50
0
 //5.注册事件处理程序
 public Host(Dog dog)
 {
     dog.Alarm += new Dog.AlarmEventHandler(HostHandleAlarm);
 }
Пример #51
0
 public IActionResult Delete(int id)
 {
     Dog.DeleteDog(id);
     return(RedirectToAction("Index"));
 }
 public UnknownBirdZoo(Dog dog, Cat cat, Bird bird)
 {
 }
Пример #53
0
        public IActionResult Edit(int id)
        {
            var dog = Dog.GetDetails(id);

            return(View(dog));
        }
Пример #54
0
        public IActionResult Dog(Guid id)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("Index", "Home"));
            }

            var dog = new Dog();


            dog = context.Dogs
                  .Include(d => d.Owner)
                  .Include(d => d.Vet)
                  .Include(d => d.Images)
                  .Include(d => d.VetNotes)
                  .Include(d => d.LikedBy)
                  .ThenInclude(l => l.User)
                  .SingleOrDefault(d => d.Id == id);

            if (dog == null)
            {
                return(RedirectToAction("Index", "Home"));
            }


            var result = new DogViewModel
            {
                Id            = dog.Id,
                Name          = dog.Name,
                Gender        = dog.Gender,
                BirthDate     = dog.BirthDate,
                Province      = dog.Province,
                IsVaccinated  = dog.IsVaccinated,
                IsDisinfected = dog.IsDisinfected,
                IsCastrated   = dog.IsCastrated,
                Adopted       = dog.Adopted,
                Owner         = dog.Owner.FirstName + " " + dog.Owner.LastName,
                OwnerNotes    = dog.OwnerNotes,
                OwnerId       = dog.Owner.Id,
                Vet           = dog.Vet != null ? dog.Vet.FirstName + " " + dog.Vet.LastName : "No vet",
                VetId         = dog.VetId,
                Breed         = dog.Breed
            };

            foreach (var pic in dog.Images)
            {
                result.Images.Add(pic.Id, pic.ImageUrl);
            }

            foreach (var like in dog.LikedBy)
            {
                result.Likes.Add(new LikeViewModel
                {
                    Id           = like.UserId + "tire" + like.DogId,
                    DogId        = dog.Id,
                    UserId       = like.UserId,
                    UserImageUrl = like.User.ImageUrl,
                    UserName     = like.User.FirstName + " " + like.User.LastName
                });
            }

            foreach (var note in dog.VetNotes)
            {
                result.VetNotes.Add(note.CreatedOn, note.Content);
            }

            return(View(result));
        }
Пример #55
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            Dog fido1 = new Dog();

            fido1.Id    = 1;
            fido1.Name  = "Fido";
            fido1.Breed = "Doberman";

            //C# has property initializer syntax.
            Dog fido2 = new Dog
            {
                Id    = 1,
                Name  = "Fido",
                Breed = "Doberman"
            };

            fido1.GoTo("park");
            fido1.MakeNoise();

            //IAnimal is a parent type of Dog
            //Dog is a subtype of IAnimal

            IAnimal animal = fido1;
            //Conveting from Dog variable to IAnimal variable is "upcasting"
            //Upcasting is guarenteed to succeed, so it's implicit

            //converting the OTHER way, from IAnimal down to Dog, is "downcasting"
            //NOT guaranteed to succeed, so it must explicit with () casting
            //Bird bird = (Bird)animal; : Error

            //when the Dog object is contained in an IAnimal variable, we can't
            //  see the Dog specific stuff anymore
            //  animal.Breed = ""; //error

            Dog dog3 = (Dog)animal; // : Works

            //not all casting is upcasting or downcasting, e.g. int to double and back
            int    integer = (int)3.4;
            double num     = integer;

            var animals = new IAnimal[2];

            animals[0] = fido1;
            animals[1] = new Eagle()
            {
                Id   = 3,
                Name = "Bill"
            };

            //this code doesn't care how the members are implmented,
            //  only that thye can do the job specified by the interface
            foreach (var item in animals)
            {
                Console.WriteLine(item.Name);
                item.MakeNoise();
                item.GoTo("park"); //here when we weren't using virtual/override
                                   //here we can't see Eagle.GoTo, whinc only hides
                                   //ABird.GoTo without truly overriding it

                //once we use virtual/override, it really does replace the method implementation
                //on the object itself
            }

            Eagle eagle1 = (Eagle)animals[1];

            eagle1.GoTo("park");

            try
            {
                Console.WriteLine("What should the dog say?");
                string input = Console.ReadLine();
                fido1.SetNoise(input);
            }
            catch
            {
                Console.WriteLine("caught ArgumentException! using fallback value");
                fido1.SetNoise("woof");
            }
            Console.WriteLine(fido1.GetNoise());
        }
Пример #56
0
 internal virtual void ActionDog(Dog dog, ActionDogType actionDogType)
 {
     ChangeState(dog, actionDogType);
 }
Пример #57
0
        public void DogOwnerShouldBeAbleToSeeAListOfAprovedVets()
        {
            var fakeDog = new Dog
            {
                Name    = "Grojan",
                OwnerId = this.context.Users.FirstOrDefault(u => u.Email == "*****@*****.**").Id
            };

            this.context.Dogs.Add(fakeDog);

            this.context.SaveChanges();

            var fakeUserOne = new User
            {
                Email      = "*****@*****.**",
                ImageUrl   = "imageurl",
                FirstName  = "Manol",
                LastName   = "Denkov",
                BirthDate  = DateTime.Parse("22.02.2002"),
                VetLicence = "1111111111"
            };

            this.context.Users.Add(fakeUserOne);

            this.context.SaveChanges();

            var fakeUserTwo = new User
            {
                Email      = "*****@*****.**",
                ImageUrl   = "imageurl2",
                FirstName  = "Manolo",
                LastName   = "Denkov",
                BirthDate  = DateTime.Parse("22.03.2003"),
                VetLicence = "2222222222"
            };

            this.context.Users.Add(fakeUserTwo);

            this.context.SaveChanges();

            var fakeUserThree = new User
            {
                Email      = "*****@*****.**",
                ImageUrl   = "imageurl2",
                FirstName  = "Manolov",
                LastName   = "Denkov",
                BirthDate  = DateTime.Parse("22.03.2003"),
                VetLicence = "2222222222"
            };

            this.context.Users.Add(fakeUserThree);

            this.context.SaveChanges();

            var result = this.vetsController.Aprove(fakeUserOne.Id).Result as ViewResult;

            var resultTwo = this.vetsController.Aprove(fakeUserTwo.Id).Result as ViewResult;

            var listToChooseFrom = this.vetsController.Choose(fakeDog.Id) as ViewResult;

            Assert.IsAssignableFrom <List <DogChooseVetViewModel> >(listToChooseFrom.Model);

            var resultModel = listToChooseFrom.Model as List <DogChooseVetViewModel>;

            Assert.AreEqual(2, resultModel.Count);

            Assert.IsTrue(resultModel.Any(v => v.DogVet == fakeDog.Id + "tire" + fakeUserOne.Id));
        }
Пример #58
0
        public void OwnerShouldBeAbleToSelectAVetForHisDog()
        {
            var fakeDog = new Dog
            {
                Name    = "Grojan",
                OwnerId = this.context.Users.FirstOrDefault(u => u.Email == "*****@*****.**").Id
            };

            this.context.Dogs.Add(fakeDog);

            this.context.SaveChanges();

            var fakeUserOne = new User
            {
                Email      = "*****@*****.**",
                ImageUrl   = "imageurl",
                FirstName  = "Manol",
                LastName   = "Denkov",
                BirthDate  = DateTime.Parse("22.02.2002"),
                VetLicence = "1111111111"
            };

            this.context.Users.Add(fakeUserOne);

            this.context.SaveChanges();

            var fakeUserTwo = new User
            {
                Email      = "*****@*****.**",
                ImageUrl   = "imageurl2",
                FirstName  = "Manolo",
                LastName   = "Denkov",
                BirthDate  = DateTime.Parse("22.03.2003"),
                VetLicence = "2222222222"
            };

            this.context.Users.Add(fakeUserTwo);

            this.context.SaveChanges();

            var fakeUserThree = new User
            {
                Email      = "*****@*****.**",
                ImageUrl   = "imageurl2",
                FirstName  = "Manolov",
                LastName   = "Denkov",
                BirthDate  = DateTime.Parse("22.03.2003"),
                VetLicence = "2222222222"
            };

            this.context.Users.Add(fakeUserThree);

            this.context.SaveChanges();

            var result = this.vetsController.Aprove(fakeUserOne.Id).Result as ViewResult;

            var resultTwo = this.vetsController.Aprove(fakeUserTwo.Id).Result as ViewResult;

            var listToChooseFrom = this.vetsController.Choose(fakeDog.Id) as ViewResult;

            var resultModel = listToChooseFrom.Model as List <DogChooseVetViewModel>;

            var chosenOne = resultModel.Single(v => v.VetId == fakeUserOne.Id);

            var choose = this.vetsController.Select(chosenOne.DogVet) as ViewResult;

            Assert.AreEqual(fakeUserOne.Id, fakeDog.VetId);
        }
Пример #59
0
 protected abstract void ChangeState(Dog dog, ActionDogType actionDogType);
 public SniffOnGround(Dog d) : base(d)
 {
     actionDelay = 2;
     moodState.ChangeMood(50f, 40f, 40f, 0f);
     moodEffect.ChangeMood(10f, 5f, -5f, 0f);
 }