示例#1
0
 private static void GasVehicleArgumentsCollection(
     ArgumentsCollection i_ArgumentsCollection)
 {
     i_ArgumentsCollection.AddArgument(
         VehicleFactory.eArgumentKeys.CurrentAmountOfGasoline,
         new ArgumentWrapper("Current amount of fuel in liters", null, false, typeof(float)));
 }
        public void Enumerate_WithNestedResponseFiles_ReturnsOriginalInputWithContentsOfResponseFilesInline()
        {
            string tempFileName1 = GetTempFileName();
            string tempFileName2 = GetTempFileName();

            File.WriteAllLines(tempFileName1, new[]
            {
                "2", "@" + tempFileName2, "5"
            });
            File.WriteAllLines(tempFileName2, new[]
            {
                "3", "4"
            });

            IEnumerable <string> input = new[]
            {
                "1", "@" + tempFileName1, "6"
            };
            IEnumerable <string> expected = new[]
            {
                "1", "2", "3", "4", "5", "6"
            };

            string[] output = new ArgumentsCollection(input).ToArray();

            CollectionAssert.AreEqual(expected, output);
        }
示例#3
0
 public Directive(string name)
     : base(name)
 {
     this.m_nodeType = NodeTypes.DIRECTIVE;
     this.m_arguments = new ArgumentsCollection();
     this.m_text = name;
 }
示例#4
0
 private static void ElectricVehicleArgumentsCollection(
     ArgumentsCollection i_ArgumentsCollection)
 {
     i_ArgumentsCollection.AddArgument(
         VehicleFactory.eArgumentKeys.CurrentAmountOfEnergy,
         new ArgumentWrapper("Current amount of hours remaining in battery", null, false, typeof(float)));
 }
示例#5
0
 public Block(string name)
     : base(name)
 {
     this.m_nodeType = NodeTypes.BLOCK;
     this.m_arguments = new ArgumentsCollection();
     this.m_text = name;
 }
示例#6
0
        public void AddVehicleToGarage(ArgumentsCollection i_Arguments, string i_VehicleTypeString, string i_OwnerName, string i_OwnerPhoneNumber)
        {
            eSupportedVehicles vehicleType = parseVehicleTypeFromString(i_VehicleTypeString);
            Vehicle            newVehicle  = VehicleFactory.BuildVehicle(vehicleType, i_Arguments);

            r_VehicleInventory.Add(newVehicle.LicensePlateNumber, newVehicle);
            AddTicket(newVehicle.LicensePlateNumber, new GarageTicket(i_OwnerName, i_OwnerPhoneNumber, newVehicle.LicensePlateNumber));
        }
示例#7
0
        internal static ArgumentsUtils.ArgumentsCollection GetElectricMotorcycleArguments()
        {
            ArgumentsUtils.ArgumentsCollection argumentsCollection = new ArgumentsCollection();
            vehicleArgumentsCollection(argumentsCollection);
            ElectricVehicleArgumentsCollection(argumentsCollection);
            MotorcycleArgumentsCollection(argumentsCollection);

            return(argumentsCollection);
        }
示例#8
0
        internal static ArgumentsUtils.ArgumentsCollection GetGasolineTruckArguments()
        {
            ArgumentsUtils.ArgumentsCollection argumentsCollection = new ArgumentsCollection();
            vehicleArgumentsCollection(argumentsCollection);
            GasVehicleArgumentsCollection(argumentsCollection);
            TruckArgumentsCollection(argumentsCollection);

            return(argumentsCollection);
        }
示例#9
0
 private static void vehicleArgumentsCollection(
     ArgumentsCollection i_ArgumentsCollection)
 {
     i_ArgumentsCollection.AddArgument(
         eArgumentKeys.LicensePlate,
         new ArgumentWrapper("License plate number", null, false, typeof(string)));
     i_ArgumentsCollection.AddArgument(
         eArgumentKeys.Model,
         new ArgumentWrapper("Model", null, false, typeof(string)));
 }
示例#10
0
 private static void TicketArgumentsCollection(
     ArgumentsCollection i_ArgumentsCollection)
 {
     i_ArgumentsCollection.AddArgument(
         eArgumentKeys.OwnerName,
         new ArgumentWrapper("Owner's name", null, false, typeof(string)));
     i_ArgumentsCollection.AddArgument(
         eArgumentKeys.OwnerPhoneNumber,
         new ArgumentWrapper("Owner's phone number", null, false, typeof(string)));
 }
示例#11
0
        private static Car createCar(ArgumentsCollection i_Arguments, Motor i_Motor)
        {
            string            licensePlate  = (string)i_Arguments[eArgumentKeys.LicensePlate].Response;
            string            model         = (string)i_Arguments[eArgumentKeys.Model].Response;
            eNumberOfCarDoors numberOfDoors = (eNumberOfCarDoors)Enum.Parse(typeof(eNumberOfCarDoors), i_Arguments[eArgumentKeys.NumberOfDoors].Response);
            eCarColors        carColor      = (eCarColors)Enum.Parse(typeof(eCarColors), i_Arguments[eArgumentKeys.Color].Response);

            Wheel[] wheels = wheelsCollectionBuilder(i_Arguments, Car.k_NumberOfWheels, VehicleMaxConstantsCollection[eVehicleMaxConstantTypes.CarMaxWheelPressure]);
            return(new Car(i_Motor, wheels, VehicleMaxConstantsCollection[eVehicleMaxConstantTypes.CarMaxWheelPressure], licensePlate, model, carColor, numberOfDoors));
        }
示例#12
0
        private static Motor getElectricMotor(ArgumentsCollection i_Arguments, float i_MaxCapacity)
        {
            float   currentAmountOfBattery = float.Parse(i_Arguments[eArgumentKeys.CurrentAmountOfEnergy].Response);
            Battery battery = new Battery(
                sr_EnergyTypesDictionary[eSupportedVehicles.ElectricCar],
                i_MaxCapacity,
                currentAmountOfBattery);

            return(new Motor(battery, eMotorType.Electric));
        }
示例#13
0
        private static Motor getGasolineMotor(ArgumentsCollection i_Arguments, float i_MaxCapacity)
        {
            float        currentAmountOfGasoline = float.Parse(i_Arguments[eArgumentKeys.CurrentAmountOfGasoline].Response);
            GasolineTank gasolineTank            = new GasolineTank(
                sr_EnergyTypesDictionary[eSupportedVehicles.GasolineCar],
                i_MaxCapacity,
                currentAmountOfGasoline);

            return(new Motor(gasolineTank, eMotorType.Gasoline));
        }
示例#14
0
 private static void CarArgumentsCollection(
     ArgumentsCollection i_ArgumentsCollection)
 {
     wheelsArgumentsCollectionCreator(i_ArgumentsCollection, Car.k_NumberOfWheels);
     i_ArgumentsCollection.AddArgument(
         eArgumentKeys.Color,
         new ArgumentWrapper("Exterior color", Enum.GetNames(typeof(eCarColors)), true, typeof(string)));
     i_ArgumentsCollection.AddArgument(
         eArgumentKeys.NumberOfDoors,
         new ArgumentWrapper("Number of doors", Enum.GetNames(typeof(eNumberOfCarDoors)), true, typeof(string)));
 }
示例#15
0
        public void Enumerate_WithSimpleArgumentsInput_ReturnsOriginalInput()
        {
            IEnumerable <string> arguments = new[]
            {
                "1", "2", "3", "A", "B", "C", string.Empty
            };

            string[] output = new ArgumentsCollection(arguments).ToArray();

            CollectionAssert.AreEqual(arguments, output);
        }
示例#16
0
 private static void MotorcycleArgumentsCollection(
     ArgumentsCollection i_ArgumentsCollection)
 {
     wheelsArgumentsCollectionCreator(i_ArgumentsCollection, Motorcycle.k_NumberOfWheels);
     i_ArgumentsCollection.AddArgument(
         eArgumentKeys.LicenseType,
         new ArgumentWrapper("License type", Enum.GetNames(typeof(Motorcycle.eLicenseType)), true, typeof(Motorcycle.eLicenseType)));
     i_ArgumentsCollection.AddArgument(
         eArgumentKeys.EngineVolume,
         new ArgumentWrapper("Engine volume in cubic centimeter", null, false, typeof(float)));
 }
示例#17
0
 private static void TruckArgumentsCollection(
     ArgumentsCollection i_ArgumentsCollection)
 {
     wheelsArgumentsCollectionCreator(i_ArgumentsCollection, Truck.k_NumberOfWheels);
     i_ArgumentsCollection.AddArgument(
         eArgumentKeys.HazardousMaterials,
         new ArgumentWrapper("Contains hazardous materials", new[] { "True", "False" }, true, typeof(bool)));
     i_ArgumentsCollection.AddArgument(
         eArgumentKeys.HaulVolume,
         new ArgumentWrapper("Container volume in cubic centimeter", null, false, typeof(float)));
 }
示例#18
0
        private static Truck createTruck(ArgumentsCollection i_Arguments, Motor i_Motor)
        {
            string licensePlate = (string)i_Arguments[eArgumentKeys.LicensePlate].Response;
            string model        = (string)i_Arguments[eArgumentKeys.Model].Response;
            bool   isCarryingHazardousMaterials = bool.Parse(i_Arguments[eArgumentKeys.HazardousMaterials].Response);
            int    haulingVolume = int.Parse(i_Arguments[eArgumentKeys.HaulVolume].Response);

            Wheel[] wheels = wheelsCollectionBuilder(i_Arguments, Truck.k_NumberOfWheels, VehicleMaxConstantsCollection[eVehicleMaxConstantTypes.TruckMaxWheelPressure]);

            return(new Truck(i_Motor, wheels, VehicleMaxConstantsCollection[eVehicleMaxConstantTypes.TruckMaxWheelPressure], licensePlate, model, isCarryingHazardousMaterials, haulingVolume));
        }
示例#19
0
        private static Motorcycle createMotorcycle(ArgumentsCollection i_Arguments, Motor i_Motor)
        {
            string licensePlate = (string)i_Arguments[eArgumentKeys.LicensePlate].Response;
            string model        = (string)i_Arguments[eArgumentKeys.Model].Response;

            Motorcycle.eLicenseType licenseType = (Motorcycle.eLicenseType)Enum.Parse(typeof(Motorcycle.eLicenseType), i_Arguments[eArgumentKeys.LicenseType].Response);
            int engineVolume = int.Parse(i_Arguments[eArgumentKeys.EngineVolume].Response);

            Wheel[] wheels = wheelsCollectionBuilder(i_Arguments, Motorcycle.k_NumberOfWheels, VehicleMaxConstantsCollection[eVehicleMaxConstantTypes.MotorcycleMaxWheelPressure]);

            return(new Motorcycle(i_Motor, wheels, VehicleMaxConstantsCollection[eVehicleMaxConstantTypes.MotorcycleMaxWheelPressure], licensePlate, model, licenseType, engineVolume));
        }
示例#20
0
        public void Enumerate_WithNullElements_ReturnsOriginalInputMinusNullElements()
        {
            IEnumerable <string> input = new[]
            {
                "1", "2", null, "3", "A", null, "B", "C", string.Empty, null
            };
            IEnumerable <string> expected = new[]
            {
                "1", "2", "3", "A", "B", "C", string.Empty
            };

            string[] output = new ArgumentsCollection(input).ToArray();

            CollectionAssert.AreEqual(expected, output);
        }
示例#21
0
 private static void wheelsArgumentsCollectionCreator(ArgumentsCollection i_ArgumentsCollection, int i_NumberOfWheels)
 {
     for (int i = 1; i <= i_NumberOfWheels; i++)
     {
         i_ArgumentsCollection.AddArgument(
             eArgumentKeys.WheelManufacturer,
             i,
             new ArgumentWrapper(string.Format("Wheel {0} manufacturerer", i), null, false, typeof(string)));
         i_ArgumentsCollection.AddArgument(
             eArgumentKeys.WheelCurrentPressure,
             i,
             new ArgumentWrapper(
                 string.Format("Wheel {0} current air pressure", i), null, false, typeof(float)));
     }
 }
示例#22
0
        internal static Vehicle BuildVehicle(
            eSupportedVehicles i_SupportedVehicle,
            ArgumentsCollection i_ArgumentsCollection)
        {
            Vehicle vehicle;

            switch (i_SupportedVehicle)
            {
            case eSupportedVehicles.ElectricCar:
            {
                vehicle = GetElectricCar(i_ArgumentsCollection);
                break;
            }

            case eSupportedVehicles.GasolineCar:
            {
                vehicle = GetGasolineCar(i_ArgumentsCollection);
                break;
            }

            case eSupportedVehicles.ElectricMotorcycle:
            {
                vehicle = GetElectricMotorcycle(i_ArgumentsCollection);
                break;
            }

            case eSupportedVehicles.GasolineMotorcycle:
            {
                vehicle = GetGasolineMotorcycle(i_ArgumentsCollection);
                break;
            }

            case eSupportedVehicles.GasolineTruck:
            {
                vehicle = GetGasolineTruck(i_ArgumentsCollection);
                break;
            }

            default:
            {
                vehicle = null;
                break;
            }
            }

            return(vehicle);
        }
示例#23
0
        public void NonGenericEnumerate_WithSimpleArgumentsInput_ReturnsOriginalInput()
        {
            IEnumerable <string> arguments = new[]
            {
                "1", "2", "3", "A", "B", "C", string.Empty
            };

            var collection = new ArgumentsCollection(arguments);
            var enumerable = collection as IEnumerable;

            var output = new List <string>();

            foreach (string element in enumerable)
            {
                output.Add(element);
            }

            CollectionAssert.AreEqual(arguments, output);
        }
示例#24
0
        public void Enumerate_WithEmptyResponseFile_ReturnsOriginalInputMinusResponseFileElement()
        {
            string tempFileName = GetTempFileName();

            File.WriteAllText(tempFileName, String.Empty);

            IEnumerable <string> input = new[]
            {
                "1", "@" + tempFileName, "2"
            };
            IEnumerable <string> expected = new[]
            {
                "1", "2"
            };

            string[] output = new ArgumentsCollection(input).ToArray();

            CollectionAssert.AreEqual(expected, output);
        }
示例#25
0
        private static Wheel[] wheelsCollectionBuilder(ArgumentsCollection i_ArgumentsCollection, int i_NumberOfWheels, float i_MaxWheelPressure)
        {
            Wheel[] wheels = new Wheel[i_NumberOfWheels];

            for (int i = 1; i <= i_NumberOfWheels; i++)
            {
                string wheelManufacturer = (string)i_ArgumentsCollection[string.Format(
                                                                             "{0}{1}",
                                                                             eArgumentKeys.WheelManufacturer.ToString(),
                                                                             i).ToString()].Response;
                float wheelWheelPressure = float.Parse(i_ArgumentsCollection[string.Format(
                                                                                 "{0}{1}",
                                                                                 eArgumentKeys.WheelCurrentPressure.ToString(),
                                                                                 i).ToString()].Response);

                wheels[i - 1] = new Wheel(wheelManufacturer, i_MaxWheelPressure, wheelWheelPressure);
            }

            return(wheels);
        }
示例#26
0
 internal static Vehicle GetGasolineTruck(ArgumentsCollection i_Arguments)
 {
     return(createTruck(i_Arguments, getGasolineMotor(i_Arguments, VehicleMaxConstantsCollection[eVehicleMaxConstantTypes.TruckMaxGasolineTankCapacity])));
 }
示例#27
0
 internal static Vehicle GetElectricMotorcycle(ArgumentsCollection i_Arguments)
 {
     return(createMotorcycle(i_Arguments, getElectricMotor(i_Arguments, VehicleMaxConstantsCollection[eVehicleMaxConstantTypes.MotorcycleMaxElectricCapacity])));
 }
示例#28
0
        public static Arguments Parse(string[] args)
        {
            var argumentsCollection = ArgumentsCollection.Parse(args);

            return(new Arguments(argumentsCollection));
        }
示例#29
0
 private Arguments(ArgumentsCollection argumentsCollection)
 {
     m_argumentsCollection = argumentsCollection;
 }
示例#30
0
 public Directive(string name, string[] arguments)
     : this(name)
 {
     this.m_arguments = new ArgumentsCollection(arguments);
     this.BuildText();
 }
示例#31
0
		/*
		private const string TEST = @"
D:\Work-Efx\Flash\FlashCoreCs\FlashCoreCs\as3code\extremefx\Main.as(38): col: 9 Warning: Duplicate variable definition.

                                var ii:int = 123;
                                    ^
";

		static readonly Regex _errorMessage = new Regex(@"(.*?)\((\d+)\)\:\W+col\:\W+(\d+)\W+(\w+):\W+(.*)", RegexOptions.Compiled | RegexOptions.CultureInvariant);
		*/
		public static void Main(string[] pArguments) {
			/*
			string[] lines = TEST.Split(new[] { '\r', '\n' });
			List<Error> el = new List<Error>();
			foreach (string line in lines) {
				if (string.IsNullOrEmpty(line)) continue;

				Error e = new Error();

				Match m = _errorMessage.Match(line);
				if (m.Success) {//parse error message
					//capture 1: row
					//capture 2: col
					//capture 3: type (Warning/Error)
					//capture 4: Message

					e.File = m.Groups[1].Value;

					int i;
					int.TryParse(m.Groups[2].Value, out i);
					e.Line = i;

					int.TryParse(m.Groups[3].Value, out i);
					e.Column = i;

					switch (m.Groups[4].Value.ToLowerInvariant()) {
						case "warning":
							e.ErrorType = ErrorType.Warning;
							break;

						case "error":
							e.ErrorType = ErrorType.Error;
							break;

						default:
							e.ErrorType = ErrorType.Message;
							break;
					}

					e.Message = m.Groups[5].Value;
					el.Add(e);

				} else {
					if (line.Trim().Equals("^", StringComparison.Ordinal)) {
						el[el.Count - 2].AdditionalInfo = el[el.Count - 1].Message;
						el.RemoveAt(el.Count-1);
						continue;
					}

					e.ErrorType = ErrorType.Message;
					e.Message = line.Trim();
					el.Add(e);
				}
			}
			*/

			ConverterFactory.AddParser(new As3NamespaceParser(), "as3");
			ConverterFactory.AddParser(new JsNamespaceParser(), "js");

			ArgumentsCollection commandLine = new ArgumentsCollection(pArguments);
			string lang = "as3";

			if (!string.IsNullOrEmpty(commandLine[@"lang"])) {
				lang = commandLine[@"lang"];
				if (!ConverterFactory.HasConverter(lang)) {
					Console.WriteLine("The specified language does not has a parser associated.");
					return;
				}
			}

			if (commandLine["source"] == null) {
				Console.WriteLine("No source was specified.");
				return;
			}

			string[] sourceFiles = Project.GetSourceFiles(commandLine["source"]);
			if (sourceFiles == null || sourceFiles.Length == 0) {
				Console.WriteLine("Source files were not found at the specified location.");
				return;
			}

			if (commandLine["output"] == null) {
				Console.WriteLine("No output directory was specified.");
				return;
			}

			bool debug = !string.IsNullOrEmpty(commandLine["debug"]);
			string output = commandLine["output"];

			commandLine.Remove("output");
			commandLine.Remove("debug");
			commandLine.Remove("source");
			commandLine.Remove(@"lang");

			ICollection<Error> errors = Project.Parse(sourceFiles, lang, output, Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), debug, commandLine, Project.Root);
			foreach (Error error in errors) {
				Console.WriteLine(error.Message);	
			}
		}
示例#32
0
 private Arguments(ArgumentsCollection argumentsCollection)
 {
     m_argumentsCollection = argumentsCollection;
 }