Пример #1
0
        private static Bike.eTypeOfLicence getTypeOfLicenceValueFromDict(Dictionary <string, object> i_VehicleCharaterstic, string i_Key)
        {
            bool   didGetWork;
            object typeOfLicenceInObjectForm;

            didGetWork = i_VehicleCharaterstic.TryGetValue(i_Key, out typeOfLicenceInObjectForm);
            if (!didGetWork)
            {
                throw new FormatException(string.Format("Wrong Dictionary Format, no {0} field", i_Key));
            }

            Bike.eTypeOfLicence typeOfLicence = (Bike.eTypeOfLicence)typeOfLicenceInObjectForm;

            return(typeOfLicence);
        }
Пример #2
0
        private static void getInputParamtersForBike(
            Dictionary <string, object> i_VeichleCharaterstic,
            out Bike.eTypeOfLicence o_TypeOfLicence,
            out int o_EngineVolume,
            out string o_ModelName,
            out string o_LicenceNumber,
            out float o_PercentOfEnergyLeft)
        {
            o_TypeOfLicence = getTypeOfLicenceValueFromDict(i_VeichleCharaterstic, k_TypeOfLicenceKey);
            o_EngineVolume  = getIntFromDict(i_VeichleCharaterstic, k_EngineVolumeKey);
            if (o_EngineVolume < 0)
            {
                throw new ArgumentException("Engine Volume cannot be negative");
            }

            getVehicleParameters(i_VeichleCharaterstic, out o_ModelName, out o_LicenceNumber, out o_PercentOfEnergyLeft);
        }
Пример #3
0
        private void validateAndInsertToParametersDict(Dictionary <string, object> parametersForFactory, Dictionary <string, string> parametersFromUser, string key)
        {
            if (key.Equals(VeichleFactory.k_CarColorKey))
            {
                try
                {
                    Car.ePossibleCarColors newValueToEnterToDict = (Car.ePossibleCarColors)Enum.Parse(typeof(Car.ePossibleCarColors), parametersFromUser[key]);
                    parametersForFactory.Add(key, newValueToEnterToDict);
                }
                catch (OverflowException)
                {
                    throw new FormatException("Wrong Car Color - possible values are Yellow, White, Black or Blue");
                }
            }
            else if (key.Equals(VeichleFactory.k_CurrentEnergyLevelKey) ||
                     key.Equals(VeichleFactory.k_MaxCargoWeightForTruckKey) ||
                     key.Equals(VeichleFactory.k_PercentOfEnergyLeftKey))
            {
                float newValueToEnterToDict;
                bool  didParseWork = float.TryParse(parametersFromUser[key], out newValueToEnterToDict);
                parametersForFactory.Add(key, newValueToEnterToDict);
                if (!didParseWork)
                {
                    throw new ArgumentException(string.Format("Wrong {0} Type! Must be a Decimal Number!", key));
                }
            }
            else if (key.Equals(VeichleFactory.k_CurrentPressureInWheelsKey))
            {
                List <float> newValueToEnterToDict     = new List <float>();
                string[]     parametersFromUserDivided = parametersFromUser[key].Split(k_SplitAccordingToThisDelimiter);
                foreach (string airPressure in parametersFromUserDivided)
                {
                    float tempAirPressurePlaceHolder;
                    bool  didParseWork = float.TryParse(airPressure, out tempAirPressurePlaceHolder);

                    if (!didParseWork)
                    {
                        throw new ArgumentException(string.Format("Wrong {0} Type! Must be a Decimal Number!", key));
                    }

                    newValueToEnterToDict.Add(tempAirPressurePlaceHolder);
                }

                parametersForFactory.Add(key, newValueToEnterToDict);
            }
            else if (key.Equals(VeichleFactory.k_EngineVolumeKey))
            {
                int  newValueToEnterToDict;
                bool didParseWork = int.TryParse(parametersFromUser[key], out newValueToEnterToDict);
                parametersForFactory.Add(key, newValueToEnterToDict);
                if (!didParseWork)
                {
                    throw new ArgumentException(string.Format("Wrong {0} Type! Must be an Integer Number!", key));
                }
            }
            else if (key.Equals(VeichleFactory.k_HasDangerousCargoKey))
            {
                bool newValueToEnterToDict;
                bool didParseWork = bool.TryParse(parametersFromUser[key], out newValueToEnterToDict);
                parametersForFactory.Add(key, newValueToEnterToDict);
                if (!didParseWork)
                {
                    throw new ArgumentException(string.Format("Wrong {0} Type! Must be a true/false value", key));
                }
            }
            else if (key.Equals(VeichleFactory.k_NumberOfDoorsInCarKey))
            {
                try
                {
                    Car.eNumberOfDoors newValueToEnterToDict = (Car.eNumberOfDoors)Enum.Parse(typeof(Car.eNumberOfDoors), parametersFromUser[key]);
                    parametersForFactory.Add(key, newValueToEnterToDict);
                }
                catch (OverflowException)
                {
                    throw new FormatException("Wrong Number Of Doors - possible values are 2 3 4 or 5");
                }
            }
            else if (key.Equals(VeichleFactory.k_TypeOfLicenceKey))
            {
                try
                {
                    Bike.eTypeOfLicence newValueToEnterToDict = (Bike.eTypeOfLicence)Enum.Parse(typeof(Bike.eTypeOfLicence), parametersFromUser[key]);
                    parametersForFactory.Add(key, newValueToEnterToDict);
                }
                catch (OverflowException)
                {
                    throw new FormatException("Wrong Licence Type - possible values are A AB A2 or B1");
                }
            }
            else if (key.Equals(VeichleFactory.k_WheelMakerKey))
            {
                List <string> newValueToEnterToDict     = new List <string>();
                string[]      parametersFromUserDivided = parametersFromUser[key].Split(k_SplitAccordingToThisDelimiter);
                newValueToEnterToDict.AddRange(parametersFromUserDivided);
                parametersForFactory.Add(key, newValueToEnterToDict);
            }
            else
            {
                string newValueToEnterToDict = parametersFromUser[key];
                parametersForFactory.Add(key, newValueToEnterToDict);
            }
        }