Exemple #1
0
        private void getAndSetEnergySource(string i_LicensePlateNumber)
        {
            bool  setSuccessfuly             = false;
            float energyAmountInEnergySource = 0;

            while (!setSuccessfuly)
            {
                try
                {
                    if (this.m_MyGarage.CheckIfElectricByLicensePlate(i_LicensePlateNumber))
                    {
                        energyAmountInEnergySource = Comunicator.GetBatteryCurrentStatus(i_LicensePlateNumber);
                    }
                    else
                    {
                        energyAmountInEnergySource = Comunicator.GetFuelTankCurrentStatus(i_LicensePlateNumber);
                    }

                    this.m_MyGarage.SetEnergySource(i_LicensePlateNumber, energyAmountInEnergySource);
                    setSuccessfuly = true;
                }
                catch (ValueOutOfRangeException e)
                {
                    Printer.PrintValueOutOfRangeMessage(e.MaxValue, e.MinValue);
                }
            }
        }
Exemple #2
0
        internal void Run()
        {
            eInstructionOption currentInstreuction;
            int    nextInstruction = 0;
            string garageName;

            garageName     = Comunicator.GreetUser();
            this.m_Manager = new GarageManager(garageName);
            while (true)
            {
                try
                {
                    nextInstruction = Comunicator.GetInstructionFromUser();
                    switch (nextInstruction)
                    {
                    case 1:
                        this.m_Manager.AddNewVehicle();
                        Printer.PrintUpdateSuccessfully(eInstructionOption.AddNewVehicle);
                        break;

                    case 2:
                        this.m_Manager.FillEnergyInVehicle();
                        Printer.PrintUpdateSuccessfully(eInstructionOption.FuelOrChargeVehicle);
                        break;

                    case 3:
                        this.m_Manager.CheckVehicleState();
                        break;

                    case 4:
                        this.m_Manager.ChangeVehicleState();
                        Printer.PrintUpdateSuccessfully(eInstructionOption.ChangeVehicleState);
                        break;

                    case 5:
                        this.m_Manager.InflateWheels();
                        Printer.PrintUpdateSuccessfully(eInstructionOption.InflateWheels);
                        break;

                    case 6:
                        this.m_Manager.GetVehicleDetails();
                        break;

                    case 7:
                        this.m_Manager.ShowLicencePlatesInGarageByFilter();
                        break;

                    default:
                        Printer.PrintBadChosenOptionMessage();
                        break;
                    }
                }
                catch (FormatException e)
                {
                    Printer.PrintMessage(e.Message);
                }
            }
        }
Exemple #3
0
        internal void ShowLicencePlatesInGarageByFilter()
        {
            bool[] filters = new bool[3];
            string filteredLicensePlates;

            Comunicator.ChooseFilters(ref filters);
            filteredLicensePlates = m_MyGarage.LicensePlatesByState(ref filters);
            Printer.PrintMessage(filteredLicensePlates);
        }
Exemple #4
0
        private string getLicensePlateNumber()
        {
            string licensePlateNumber = Comunicator.GetLicensePlateNumber();

            while (!this.m_MyGarage.ExistsInGarage(licensePlateNumber))
            {
                Printer.PrintLicensePlateNotFoundMessage(licensePlateNumber);
                licensePlateNumber = Comunicator.GetLicensePlateNumber();
            }

            return(licensePlateNumber);
        }
Exemple #5
0
        internal void FillEnergyInVehicle()
        {
            bool      chargedSuccessfully = false;
            bool      isElectricVehicle;
            float     amountToFill = 0;
            eFuelType fuelType;
            string    fuelTypeCode;
            string    licensePlateNumber = getLicensePlateNumber();

            while (!chargedSuccessfully)
            {
                try
                {
                    isElectricVehicle = this.m_MyGarage.CheckIfElectricByLicensePlate(licensePlateNumber);
                    if (isElectricVehicle)
                    {
                        amountToFill = Comunicator.GetChargingDetails(licensePlateNumber);
                        this.m_MyGarage.FillEnergySource(licensePlateNumber, amountToFill);
                    }
                    else
                    {
                        Comunicator.GetFuelingDetails(licensePlateNumber, out amountToFill, out fuelTypeCode);
                        eFuelType.TryParse(fuelTypeCode, out fuelType);
                        this.m_MyGarage.FillEnergySource(licensePlateNumber, amountToFill, fuelType);
                    }

                    chargedSuccessfully = true;
                }
                catch (VehicleNotInGarageException e)
                {
                    Printer.PrintLicensePlateNotFoundMessage(licensePlateNumber);
                }
                catch (ValueOutOfRangeException e)
                {
                    Printer.PrintValueOutOfRangeMessage(e.MaxValue, e.MinValue);
                }
                catch (System.ArgumentException e)
                {
                    eFuelType.TryParse(e.Message, out fuelType);
                    Printer.PrintFuelTypeErrorMessage(fuelType);
                }
                catch (System.FormatException e)
                {
                    Printer.PrintMessage(e.Message);
                }
            }
        }
Exemple #6
0
        internal void ChangeVehicleState()
        {
            string licensePlateNumber = getLicensePlateNumber();
            string newStateCode;
            eState newState;

            try
            {
                newStateCode = Comunicator.GetUpdatedState(licensePlateNumber);
                eState.TryParse(newStateCode, out newState);
                m_MyGarage.ChangeState(licensePlateNumber, newState);
            }
            catch (VehicleNotInGarageException e)
            {
                Printer.PrintLicensePlateNotFoundMessage(licensePlateNumber);
            }
        }
Exemple #7
0
        private void getAndSetOwnerNameAndPhoneNumber(out string o_OwnerName, out string o_OwnerPhoneNumber)
        {
            bool phoneNumberSetSuccessfully = false;

            o_OwnerPhoneNumber = "";
            Comunicator.GetOwnerName(out o_OwnerName);
            while (!phoneNumberSetSuccessfully)
            {
                try
                {
                    Comunicator.GetOwnerPhoneNumber(o_OwnerName, out o_OwnerPhoneNumber);
                    phoneNumberSetSuccessfully = true;
                }
                catch (FormatException e)
                {
                    Printer.PrintMessage(e.Message);
                }
            }
        }
Exemple #8
0
        private void getAndSetSpecialFeatures(string i_LicensePlateNumber, ref Dictionary <string, string> io_VehicleSpecialFeatures)
        {
            bool specialFeaturesSetSuccessfully = false;

            Comunicator.GetVehicleSpecificDetails(ref io_VehicleSpecialFeatures);
            while (!specialFeaturesSetSuccessfully)
            {
                try
                {
                    this.m_MyGarage.SetVehicleSpecialFeatures(i_LicensePlateNumber, ref io_VehicleSpecialFeatures);
                    specialFeaturesSetSuccessfully = true;
                }
                catch (ArgumentException e)
                {
                    string[] errorMessages = e.Message.Split(':');
                    Printer.PrintArgumentException(errorMessages[1]);
                    Comunicator.GetVehicleSpecificDetail(ref io_VehicleSpecialFeatures, errorMessages[0]);
                }
            }
        }
Exemple #9
0
        private void getAndSetWheels(string i_LicensePlateNumber)
        {
            string manufacturerName;
            float  currentAirPressure = 0;
            bool   setSuccessfuly     = false;

            Comunicator.GetWheelsManufacturer(i_LicensePlateNumber, out manufacturerName);
            while (!setSuccessfuly)
            {
                try
                {
                    currentAirPressure = Comunicator.GetCurrentAirPressure(i_LicensePlateNumber);
                    m_MyGarage.SetWheels(i_LicensePlateNumber, manufacturerName, currentAirPressure);
                    setSuccessfuly = true;
                }
                catch (ValueOutOfRangeException e)
                {
                    Printer.PrintValueOutOfRangeMessage(e.MaxValue, e.MinValue);
                }
            }
        }
Exemple #10
0
        internal void AddNewVehicle()
        {
            int    vehicleType = 0;
            string modelName;
            string licensePlateNumber;
            string ownerName;
            string ownerPhoneNumber;
            bool   isElectric;
            Dictionary <string, string> vehicleSpecialFeatures;

            Comunicator.GetVehicleGeneralDetails(out vehicleType, out modelName, out isElectric, out licensePlateNumber);
            getAndSetOwnerNameAndPhoneNumber(out ownerName, out ownerPhoneNumber);
            vehicleSpecialFeatures = this.m_MyGarage.AddVehicle(vehicleType, modelName, isElectric, licensePlateNumber, ownerName, ownerPhoneNumber);
            getAndSetEnergySource(licensePlateNumber);
            getAndSetWheels(licensePlateNumber);
            if (vehicleSpecialFeatures == null)
            {
                Printer.PrintVehicleAlreadyInGarage(licensePlateNumber);
            }
            else
            {
                getAndSetSpecialFeatures(licensePlateNumber, ref vehicleSpecialFeatures);
            }
        }