예제 #1
0
        static void Main(string[] args)
        {
            // In an ideal world, programmers that use our Automobile class use it correctly.
            Automobile subaru = new Automobile();

            subaru.isStarted = true;  //start the car
            subaru.speed     = 10;    // accelerate to 10
            subaru.speed     = 20;    // accelerate to 20
            subaru.speed     = 30;    // accelerate to 30
            subaru.speed     = 20;    // decelerate to 20
            subaru.speed     = 10;    // decelerate to 30
            subaru.speed     = 0;     // decelerate to 30
            subaru.isReverse = true;  // go in reverse
            subaru.speed     = 10;    // reverse at 10mph
            subaru.speed     = 0;     // reverse to 0mph
            subaru.isStarted = false; //turn off the car

            // Probably how a programmer will end up using it though...
            Automobile toyota = new Automobile();

            // ?? wait we're not even going to start the car?
            toyota.speed = 100; // turbo mode to 100mph
            toyota.speed = 0;   // turbo brake to 0mph
            // ? and leave it running?


            // Lets have more fun (but not in real life)
            Automobile getawayVehicle = new Automobile();

            getawayVehicle.isStarted = true;
            getawayVehicle.isReverse = true; //<-- did it stall?
            getawayVehicle.isReverse = true;
            getawayVehicle.speed     = 100;  // let's not experience this ever, please?
        }
예제 #2
0
        public static void Main(string[] args)
        {
            Automobile     jeep    = new Automobile();
            ServiceStation station = new ServiceStation();

            RepairDelegate wheelAligment = new RepairDelegate(station.AlignWheels);
            RepairDelegate paint         = new RepairDelegate(station.PaintCar);
            RepairDelegate changeOil     = new RepairDelegate(station.ChangeOil);
            RepairDelegate carInspection = new RepairDelegate(station.CarInspection);
            RepairDelegate changeWheels  = new RepairDelegate(station.ChangeWheel);
            RepairDelegate repairBody    = new RepairDelegate(station.RepairBody);

            AllRepairDelegate allRepair = new AllRepairDelegate
                                              (wheelAligment + paint + changeOil + carInspection + changeWheels + repairBody);

            jeep.ShowDoneWork();

            paint(jeep);
            changeOil(jeep);
            repairBody(jeep);

            jeep.ShowDoneWork();

            allRepair(jeep);

            jeep.ShowDoneWork();
        }
예제 #3
0
        private async Task SeedVehicleData()
        {
            await using (var _context = _serviceProvider.GetService <AppDbContext>())
            {
                await _context.Drones.AddAsync(new Drone(Guid.NewGuid(), "DroneX12"));

                var superCar = new Automobile(TestData.automobileId, TestData.automobileName);
                superCar.AddDriver(Guid.NewGuid(), "1st Capt.", true)
                .AddDriver(Guid.NewGuid(), "2nd Capt.", false);
                await _context.Automobiles.AddAsync(superCar);

                var planeX = new Plane(TestData.planeId, TestData.planeName);
                planeX.AddDriver(Guid.NewGuid(), "1st Capt.", true)
                .AddDriver(Guid.NewGuid(), "2nd Capt.", false)
                .AddDriver(Guid.NewGuid(), "3rd Capt.", false)
                .AddDriver(Guid.NewGuid(), "4th Capt.", false);
                await _context.Planes.AddAsync(planeX);

                var yactFx = new Yact(TestData.yactId, "YactFx");
                yactFx.AddDriver(Guid.NewGuid(), "1st Capt.", true)
                .AddDriver(Guid.NewGuid(), "2nd Capt.", false)
                .AddDriver(Guid.NewGuid(), "3rd Capt.", false);
                await _context.Yacts.AddAsync(yactFx);

                await _context.SaveChangesAsync();
            }
        }
        public async Task UpdateAutomobileAsync(Automobile theAutomobile)
        {
            try
            {
                await Connection.OpenAsync().ConfigureAwait(false);

                var aCommand = new NpgsqlCommand(
                    "UPDATE automobile SET vin=:value1, vehiclenumber=:value2, name=:value3, class=:value4, style=:value5, color=:value6, manufacturer=:value7, model=:value8, code=:value9, locationid=:value10 where id=:value11;", Connection);
                aCommand.Parameters.AddWithValue("value1", theAutomobile.VIN);
                aCommand.Parameters.AddWithValue("value2", theAutomobile.VehicleNumber);
                aCommand.Parameters.AddWithValue("value3", theAutomobile.Name);
                aCommand.Parameters.AddWithValue("value4", theAutomobile.Class);
                aCommand.Parameters.AddWithValue("value5", theAutomobile.Style);
                aCommand.Parameters.AddWithValue("value6", theAutomobile.Color);
                aCommand.Parameters.AddWithValue("value7", theAutomobile.Manufacturer);
                aCommand.Parameters.AddWithValue("value8", theAutomobile.Model);
                aCommand.Parameters.AddWithValue("value9", theAutomobile.Code);
                aCommand.Parameters.AddWithValue("value10", theAutomobile.LocationId);
                aCommand.Parameters.AddWithValue("value11", theAutomobile.Id);

                await aCommand.ExecuteNonQueryAsync().ConfigureAwait(false);
            }
            // no catch here, this is a reference project
            // TODO: add catch and actions here
            finally
            {
                if (Connection.State == ConnectionState.Open)
                {
                    Connection.Close();
                }
            }
        }
예제 #5
0
 public void SnimiCSV(string datoteka)
 {
     using (TextWriter tw = File.CreateText(datoteka))
     {
         try
         {
             tw.WriteLine(Automobile.CSVZaglavlje());
             foreach (Automobile a in Lista)
             {
                 if (a != null)
                 {
                     string s = a.CSV().Trim();
                     if (s != null && !s.Equals(string.Empty))
                     {
                         tw.WriteLine(s);
                     }
                 }
             }
         }
         catch (Exception ex)
         {
             EventLogger.WriteEventError("Greška pri generisanju CSV fajla.", ex);
         }
         finally
         {
             tw.Close();
         }
     }
 }
예제 #6
0
파일: Program.cs 프로젝트: wzchua/docs
 void Test()
 {
     //<Snippet3>
     Automobile.Drive();
     int i = Automobile.NumberOfWheels;
     //</Snippet3>
 }
예제 #7
0
        public IHttpActionResult PutAutomobile(int id, Automobile automobile)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != automobile.IdAutomobile)
            {
                return(BadRequest());
            }

            db.Entry(automobile).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AutomobileExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public async Task CreateAutomobileAsync(MainCreateInputModel model)
        {
            var makeId = await this.dbContext.Makes //TODO maybe add another method that uses select list item so you dont have to use string search
                         .Where(x => x.Name == model.PrimaryProperties.Make)
                         .Select(x => x.Id)
                         .FirstOrDefaultAsync();

            var modelId = await this.dbContext.Models
                          .Where(x => x.Name == model.PrimaryProperties.Model)
                          .Select(x => x.Id)
                          .FirstOrDefaultAsync();

            Automobile automobile = this.mapper.Map <Automobile>(model);

            automobile.MakeId    = makeId;
            automobile.ModelId   = modelId;
            automobile.CreatedOn = DateTime.UtcNow;
            automobile.UserId    = this.userService.GetLoggedInUserId();
            automobile.Images    = await imagesHelper.SetAutomobileImages(model.Images, this.cloudinary);

            //TODO add images
            await dbContext.Automobiles.AddAsync(automobile);

            await dbContext.SaveChangesAsync();
        }
예제 #9
0
        public Automobile Create(string vin)
        {
            var automobile = new Automobile(vin);

            Build(ref automobile);
            return(automobile);
        }
예제 #10
0
        static void Two()
        {
            Console.WriteLine("-------------------AUTOMOBILE-------------------");
            Automobile automobile = new Automobile("Volkswage",
                                                   220,
                                                   "Black");

            Console.WriteLine(automobile.GetInfo());
            automobile.Update();
            Console.WriteLine(automobile.GetInfo());
            Console.WriteLine("-------------------SPORTCAR-------------------");
            Sportcar sportcar = new Sportcar("Lamborghini",
                                             350,
                                             "Yellow",
                                             2);

            Console.WriteLine(sportcar.GetInfo());
            sportcar.Update();
            Console.WriteLine(sportcar.GetInfo());
            Console.WriteLine("-------------------EXECUTIVECAR-------------------");
            ExecutiveCar executiveCar = new ExecutiveCar("BMW", 250,
                                                         "Grey", true);

            Console.WriteLine(executiveCar.GetInfo());
            executiveCar.Update();
            Console.WriteLine(executiveCar.GetInfo());
        }
예제 #11
0
        public async Task <IActionResult> DeleteAdvertisementPost(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Automobile avto = _context.Automobiles.Find(id);

            if (avto == null)
            {
                return(NotFound());
            }


            string currentFilePath = Path.Combine(_env.WebRootPath, "img", avto.PhotoUrl);

            if (System.IO.File.Exists(currentFilePath))
            {
                System.IO.File.Delete(currentFilePath);
            }
            _context.Automobiles.Remove(avto);
            await _context.SaveChangesAsync();

            return(RedirectToAction("Index", "Home"));
        }
예제 #12
0
        protected void SaveRepairCard_OnClick(object sender, EventArgs e)
        {
            CarServicePresentationUtility.ClearNotificationMsgList(this.notificationMsgList);
            CarServicePresentationUtility.HideNotificationMsgList(this.notificationMsgList);
            this.notificationMsgList.CssClass = CarServiceConstants.NEGATIVE_CSS_CLASS_NAME;

            DateTime?startRepairDate      = null;
            string   startRepairDateTxt   = this.startRepairDate.SelectedDate;
            bool     validStartRepairDate = CarServicePresentationUtility.ProcessStartRepairDate(startRepairDateTxt,
                                                                                                 this.notificationMsgList, out startRepairDate);

            decimal sparePartsPrice    = 0M;
            decimal repairPrice        = 0M;
            string  repairPriceTxt     = this.repairPrice.Text;
            string  sparePartsPriceTxt = this.sparePartsPrice.Text;
            bool    validPrices        = CarServicePresentationUtility.ProcessRepairPrices(sparePartsPriceTxt, repairPriceTxt,
                                                                                           this.notificationMsgList, out sparePartsPrice, out repairPrice);

            string     automobileIdTxt   = this.automobileDropDown.SelectedValue;
            Automobile automobile        = CarServiceUtility.GetAutomobile(automobileIdTxt, this.persister);
            bool       validAutomobileId = (automobile != null);

            ListItemCollection selectedSparePartItems = this.selectedSpareParts.Items;
            bool validSpareParts = CarServicePresentationUtility.IsSparePartItemsValid(selectedSparePartItems, this.notificationMsgList);

            if (validAutomobileId && validPrices && validSpareParts &&
                (validStartRepairDate && startRepairDate.HasValue))
            {
                string description        = this.repairCardDescription.Text;
                object repairCardIdObject = Session[CarServiceConstants.REPAIR_CARD_ID_PARAM_NAME];
                if (repairCardIdObject != null)
                {
                    int repairCardId;
                    if (Int32.TryParse(repairCardIdObject.ToString(), out repairCardId))
                    {
                        DateTime?finishRepairDate      = null;
                        string   finishRepairDateTxt   = this.finishRepairDate.SelectedDate;
                        bool     validFinishRepairDate = CarServicePresentationUtility.ProcessFinishRepairDate(finishRepairDateTxt,
                                                                                                               this.notificationMsgList, out finishRepairDate);
                        if (validFinishRepairDate == true)
                        {
                            RepairCard repairCard = this.persister.GetRepairCardById(repairCardId);
                            UpdateRepairCard(repairCard, automobile, finishRepairDate, description,
                                             sparePartsPrice, repairPrice, selectedSparePartItems);
                            CarServicePresentationUtility.AppendNotificationMsg("Repair card is updated successfully", this.notificationMsgList);
                            this.notificationMsgList.CssClass = CarServiceConstants.POSITIVE_CSS_CLASS_NAME;
                        }
                    }
                }
                else
                {
                    SaveRepairCard(automobile, startRepairDate.Value, description,
                                   sparePartsPrice, repairPrice, selectedSparePartItems);
                    CarServicePresentationUtility.AppendNotificationMsg("Repair card is saved successfully", this.notificationMsgList);
                    this.notificationMsgList.CssClass = CarServiceConstants.POSITIVE_CSS_CLASS_NAME;
                }
            }
            CarServicePresentationUtility.ShowNotificationMsgList(this.notificationMsgList);
        }
예제 #13
0
        public void ObjectExtensions_SetValue_fails()
        {
            var src = new Automobile {
                Make = "Chevy", Model = "Camaro", Color = "Blue", Year = 1969
            };

            Assert.ThrowsException <ArgumentException>(() => src.SetValue("Year", "bob"));
        }
예제 #14
0
        public void DefaultAutomobileIsInitializedCorrectly()
        {
            Automobile myAuto = new Automobile();

            //<Snippet1>
            Assert.IsTrue((myAuto.Model == "Not specified") && (myAuto.TopSpeed == -1));
            //</Snippet1>
        }
예제 #15
0
 // Use this for initialization
 void Start()
 {
     automobile = gameObject.GetComponent <Automobile>();
     //Создаем источник под сирену
     CreateSirenSource();
     Ini_siren();
     iniPlayer();
 }
예제 #16
0
 public CopernicusObservatory() : base(30)
 {
     Name         = "Copernicus' Observatory";
     RequiredTech = new Astronomy();
     ObsoleteTech = new Automobile();
     SetSmallIcon(6, 0);
     Type = Wonder.CopernicusObservatory;
 }
예제 #17
0
        public void ObjectExtensions_SetValue_fails2()
        {
            var src = new Automobile {
                Make = "Chevy", Model = "Camaro", Color = "Blue", Year = 1969
            };

            Assert.IsFalse(src.SetValue("Frank", "bob"));
        }
        public void FindTheFastestTest()
        {
            Automobile expected = automobiles[0];

            Automobile actual = Task.FindTheFastest(automobiles);

            Assert.AreEqual(expected, actual);
        }
예제 #19
0
 public Knights() : base(4, 4, 2, 2)
 {
     Type         = Unit.Knights;
     Name         = "Knights";
     RequiredTech = new Chivalry();
     ObsoleteTech = new Automobile();
     SetIcon('E', 1, 1);
 }
        public ActionResult DeleteConfirmed(int id)
        {
            Automobile automobile = db.Automobili.Find(id);

            db.Automobili.Remove(automobile);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
예제 #21
0
 public Armor() : base(8, 10, 5, 3)
 {
     Type         = UnitType.Armor;
     Name         = "Armor";
     RequiredTech = new Automobile();
     ObsoleteTech = null;
     SetIcon('D', 0, 1);
 }
예제 #22
0
        public void Should_truncate_Vin_when_too_long()
        {
            var random = new Random();
            var vin    = TestHelpers.RandomStrings(18, 18, 1, random).First();
            var auto   = Automobile.Create(VEHICLE_ID, MAKE, MODEL, YEAR, TRANSMISSION, FUEL_TYPE, BODY_STYLE, DRIVETRAIN, vin);

            auto.ShouldNotBeNull();
            auto.Vin.ShouldBe(vin.Truncate(17));
        }
예제 #23
0
        public void Should_truncate_Model_when_too_long()
        {
            var random = new Random();
            var model  = TestHelpers.RandomStrings(26, 26, 1, random).First();
            var auto   = Automobile.Create(VEHICLE_ID, MAKE, model, YEAR, TRANSMISSION, FUEL_TYPE, BODY_STYLE, DRIVETRAIN, VIN);

            auto.ShouldNotBeNull();
            auto.Model.ShouldBe(model.Truncate(25));
        }
예제 #24
0
        public void Should_truncate_VehicleId_when_too_long()
        {
            var random    = new Random();
            var vehicleId = TestHelpers.RandomStrings(101, 101, 1, random).First();
            var auto      = Automobile.Create(vehicleId, MAKE, MODEL, YEAR, TRANSMISSION, FUEL_TYPE, BODY_STYLE, DRIVETRAIN, VIN);

            auto.ShouldNotBeNull();
            auto.VehicleId.ShouldBe(vehicleId.Truncate(100));
        }
        public void FindEconomicalTest()
        {
            double     averSpeed = 80;
            Automobile expected  = automobiles[3];

            Automobile actual = Task.FindEconomical(automobiles, averSpeed);

            Assert.AreEqual(expected, actual);
        }
예제 #26
0
        public ActionResult Save(Automobile automobile, HttpPostedFileBase CarImage)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new NewAutomobileViewModel
                {
                    Automobile    = new Automobile(),
                    NumberOfDoors = _context.NumberOfDoors.ToList(),
                    CarBodies     = _context.CarBodies.ToList(),
                    Gearshifts    = _context.Gearshifts.ToList(),
                };
                Session["CarMessage"] = null;
                return(View("NewAutomobile", viewModel));
            }
            if (automobile.Id == 0)
            {
                if (CarImage != null)
                {
                    string filename = Path.GetFileName(CarImage.FileName);
                    automobile.ImagePath = "/Images/" + filename;
                    filename             = Path.Combine(Server.MapPath("~/Images/"), filename);
                    CarImage.SaveAs(filename);
                }
                else
                {
                    automobile.ImagePath = "/Images/template-car.jpg";
                }
                _context.Automobiles.Add(automobile);
                Session["CarMessage"] = "Auto successfully added.";
            }
            else
            {
                var automobileInDb = _context.Automobiles
                                     .Include(a => a.NumberOfDoor)
                                     .Include(a => a.CarBody)
                                     .Include(a => a.Gearshift)
                                     .Single(a => a.Id == automobile.Id);

                automobileInDb.CarBrand       = automobile.CarBrand;
                automobileInDb.CarModel       = automobile.CarModel;
                automobileInDb.ProductYear    = automobile.ProductYear;
                automobileInDb.Cubicase       = automobile.Cubicase;
                automobileInDb.NumberOfDoorId = automobile.NumberOfDoorId;
                automobileInDb.CarBodyId      = automobile.CarBodyId;
                automobileInDb.GearshiftId    = automobile.GearshiftId;
                if (CarImage != null)
                {
                    string filename = Path.GetFileName(CarImage.FileName);
                    automobileInDb.ImagePath = "/Images/" + filename;
                    filename = Path.Combine(Server.MapPath("~/Images/"), filename);
                    CarImage.SaveAs(filename);
                }
                Session["CarMessage"] = "Auto successfully updated.";
            }
            _context.SaveChanges();
            return(RedirectToAction("New", "Automobiles"));
        }
예제 #27
0
        public async Task <IActionResult> RecordAzureAuto([FromBody] Automobile automobile)
        {
            string filePath = Path.Combine(AzureDirMountedPath,
                                           $"{Guid.NewGuid().ToString()}.json");

            await System.IO.File.WriteAllLinesAsync(filePath, new[] { JsonSerializer.Serialize(automobile) });

            return(Ok(filePath));
        }
        public async Task <ActionResult> DeleteConfirmed(int id)
        {
            Automobile automobile = await db.Automobiles.FindAsync(id);

            db.Automobiles.Remove(automobile);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
예제 #29
0
        public override bool Procitaj()
        {
            bool rezultat = base.Procitaj();

            if (Sadrzaj != null)
            {
                automobil = Http.AutomobileAd.ParseAutomobileAd(Sadrzaj, adresa);
            }
            return(rezultat && Sadrzaj != null && automobil != null);
        }
예제 #30
0
        static void Main(string[] args)
        {
            Automobile a = new Automobile();

            a.Modello = "Ferrari";
            a.Colore  = "Rosso";

            Console.WriteLine(a);
            Console.ReadLine();
        }