Example #1
0
 /// <summary>
 /// Class parameterized construtor
 /// </summary>
 /// <param name="id"></param>
 /// <param name="type"></param>
 /// <param name="zipCode"></param>
 /// <param name="status"></param>
 public Vehicle(int id, EmergencyVehicles type, string zipCode, bool status)
 {
     this.id      = id;
     this.type    = type;
     this.zipCode = zipCode;
     this.status  = status;
 }
Example #2
0
        /// <summary>
        /// Function to fetch list of specific emergency vehicles available across.
        /// </summary>
        /// <param name="vehicleType">Type of emergency vehicle</param>
        /// <returns></returns>
        public Dictionary <string, List <int> > FetchVehicleByType(EmergencyVehicles vehicleType)
        {
            Dictionary <string, List <int> > vehicleDetails = new Dictionary <string, List <int> >();

            vehicleDetails = vehicleMap[vehicleType];
            return(vehicleDetails);
        }
Example #3
0
 /// <summary>
 /// Function to mark vehicle as selected
 /// </summary>
 /// <param name="vehicleType">Vehicle type</param>
 /// <param name="zipCode">Zip code at which vehicle is available</param>
 /// <param name="vehicleId">Vehicle id number</param>
 /// <returns>returns boolean if vehicles status is changed</returns>
 public bool VehicleUnSelected(EmergencyVehicles vehicleType, string zipCode, int vehicleId)
 {
     //Dictionary<string, List<int>> vehicleDetails = new Dictionary<string, List<int>>();
     //vehicleDetails = vehicleMap[vehicleType];
     //List<int> vehicleIds = new List<int>();
     //vehicleIds = vehicleDetails[zipCode];
     if (vehicleId != 0)
     {
         //vehicleStatus[vehicleId] = false;
         //vehicle = new Vehicle(vehicleId, vehicleType, zipCode, true);
         vehicleStatus[vehicleId].status = true;
         return(true);
     }
     else
     {
         return(false);
     }
 }
Example #4
0
 /// <summary>
 /// Parameterized class constructor which takes request parameters as inputs
 /// </summary>
 /// <param name="requestId">Unique request Id</param>
 /// <param name="vehicleType">Type of the vehicle requested</param>
 /// <param name="zipCode">Zip ocde from where the request was made</param>
 public Request(int requestId, EmergencyVehicles vehicleType, string zipCode)
 {
     try
     {
         this.requestId   = requestId;
         this.vehicleType = vehicleType;
         this.zipCode     = zipCode;
         gap = int.MaxValue;
         //Once the input is given to class, request would be processed by default
         ProcessRequest();
         //avoiding object creation and throwing exception when there are no vehicle to process.
         if (vehicleId == 0)
         {
             throw new Exception();
         }
     }
     catch (Exception e)
     {
         Console.WriteLine("{0}: {1}", e.GetType().Name, e.Message);
     }
 }
Example #5
0
        /// <summary>
        /// Default Constructor
        /// </summary>


        /// <summary>
        /// Function to fetch Vehicle Data from VehicleDetails.xml document
        /// </summary>
        public Dictionary <EmergencyVehicles, Dictionary <string, List <int> > > FetchVehicleData()
        {
            XmlDocument xmlDoc = new XmlDocument();
            XmlNodeList xmlNodeList;

            FileStream fs = new FileStream(@"..\\..\\VehicleDetails.xml", FileMode.Open, FileAccess.Read);

            xmlDoc.Load(fs);
            xmlNodeList = xmlDoc.GetElementsByTagName("Vehicle");
            for (int i = 0; i < xmlNodeList.Count; i++)
            {
                xmlNodeList[i].ChildNodes.Item(0).InnerText.Trim();
                int id = int.Parse(xmlNodeList[i].ChildNodes.Item(0).InnerText.Trim());
                EmergencyVehicles type    = (EmergencyVehicles)int.Parse(xmlNodeList[i].ChildNodes.Item(1).InnerText.Trim());
                string            zipCode = xmlNodeList[i].ChildNodes.Item(2).InnerText.Trim().ToString();
                PopulateVehicleDetails(type, zipCode, id);
            }

            fs.Close();
            return(vehicleMap);
        }
Example #6
0
 /// <summary>
 /// Function to populate vehicle details in the Hash Map for easy access.
 /// </summary>
 /// <param name="type">Vehicle Type</param>
 /// <param name="zipCode">Zip code at which vehicle is available</param>
 /// <param name="id">Vehicle id number</param>
 public void PopulateVehicleDetails(EmergencyVehicles type, string zipCode, int id)
 {
     if (type == EmergencyVehicles.Ambulance)
     {
         if (vehicleMap.ContainsKey(type))
         {
             if (vehicleMap[type].ContainsKey(zipCode))
             {
                 List <int> ids = vehicleMap[type][zipCode];
                 ids.Add(id);
                 vehicleMap[type][zipCode] = ids;
                 vehicle = new Vehicle(id, type, zipCode, true);
                 vehicleStatus.Add(id, vehicle);
             }
             else
             {
                 vehicleMap[type].Add(zipCode, new List <int> {
                     id
                 });
                 vehicle = new Vehicle(id, type, zipCode, true);
                 vehicleStatus.Add(id, vehicle);
             }
         }
         else
         {
             vehicleMap[type] = new Dictionary <string, List <int> >();
             vehicleMap[type].Add(zipCode, new List <int> {
                 id
             });
             vehicle = new Vehicle(id, type, zipCode, true);
             vehicleStatus.Add(id, vehicle);
         }
     }
     else if (type == EmergencyVehicles.FireTruck)
     {
         if (vehicleMap.ContainsKey(type))
         {
             if (vehicleMap[type].ContainsKey(zipCode))
             {
                 List <int> ids = vehicleMap[type][zipCode];
                 ids.Add(id);
                 vehicleMap[type][zipCode] = ids;
                 vehicle = new Vehicle(id, type, zipCode, true);
                 vehicleStatus.Add(id, vehicle);
             }
             else
             {
                 vehicleMap[type].Add(zipCode, new List <int> {
                     id
                 });
                 vehicle = new Vehicle(id, type, zipCode, true);
                 vehicleStatus.Add(id, vehicle);
             }
         }
         else
         {
             vehicleMap[type] = new Dictionary <string, List <int> >();
             vehicleMap[type].Add(zipCode, new List <int> {
                 id
             });
             vehicle = new Vehicle(id, type, zipCode, true);
             vehicleStatus.Add(id, vehicle);
         }
     }
     else
     {
         if (vehicleMap.ContainsKey(type))
         {
             if (vehicleMap[type].ContainsKey(zipCode))
             {
                 List <int> ids = vehicleMap[type][zipCode];
                 ids.Add(id);
                 vehicleMap[type][zipCode] = ids;
                 vehicle = new Vehicle(id, type, zipCode, true);
                 vehicleStatus.Add(id, vehicle);
             }
             else
             {
                 vehicleMap[type].Add(zipCode, new List <int> {
                     id
                 });
                 vehicle = new Vehicle(id, type, zipCode, true);
                 vehicleStatus.Add(id, vehicle);
             }
         }
         else
         {
             vehicleMap[type] = new Dictionary <string, List <int> >();
             vehicleMap[type].Add(zipCode, new List <int> {
                 id
             });
             vehicle = new Vehicle(id, type, zipCode, true);
             vehicleStatus.Add(id, vehicle);
         }
     }
 }
Example #7
0
 /// <summary>
 /// Function to populate vehicle details in the Hash Map for easy access.
 /// </summary>
 /// <param name="type">Vehicle Type</param>
 /// <param name="zipCode">Zip code at which vehicle is available</param>
 /// <param name="id">Vehicle id number</param>
 public void PopulateVehicleDetails(EmergencyVehicles type, string zipCode, int id)
 {
     //Adding vehicles as per the type of the vehicle
     //If vehicle type is Ambulance
     if (type == EmergencyVehicles.Ambulance)
     {
         //If vehicle type is already available, new vehicle id will be concatinated to the list
         if (vehicleMap.ContainsKey(type))
         {
             //If zip code already has same vehicle type in it. the new vehicle id will be concatinated parallel to exisisting one
             if (vehicleMap[type].ContainsKey(zipCode))
             {
                 List <int> ids = vehicleMap[type][zipCode];
                 ids.Add(id);
                 vehicleMap[type][zipCode] = ids;
                 vehicle = new Vehicle(id, type, zipCode, true);
                 vehicleStatus.Add(id, vehicle);
             }
             //Else new entry would be made for the zip code and vehicle will be added
             else
             {
                 vehicleMap[type].Add(zipCode, new List <int> {
                     id
                 });
                 vehicle = new Vehicle(id, type, zipCode, true);
                 vehicleStatus.Add(id, vehicle);
             }
         }
         //If vehicle type is not available so far. New entry will be made.
         else
         {
             vehicleMap[type] = new Dictionary <string, List <int> >();
             vehicleMap[type].Add(zipCode, new List <int> {
                 id
             });
             vehicle = new Vehicle(id, type, zipCode, true);
             vehicleStatus.Add(id, vehicle);
         }
     }
     //If vehicle type is Fire Truck
     else if (type == EmergencyVehicles.FireTruck)
     {
         if (vehicleMap.ContainsKey(type))
         {
             if (vehicleMap[type].ContainsKey(zipCode))
             {
                 List <int> ids = vehicleMap[type][zipCode];
                 ids.Add(id);
                 vehicleMap[type][zipCode] = ids;
                 vehicle = new Vehicle(id, type, zipCode, true);
                 vehicleStatus.Add(id, vehicle);
             }
             else
             {
                 vehicleMap[type].Add(zipCode, new List <int> {
                     id
                 });
                 vehicle = new Vehicle(id, type, zipCode, true);
                 vehicleStatus.Add(id, vehicle);
             }
         }
         else
         {
             vehicleMap[type] = new Dictionary <string, List <int> >();
             vehicleMap[type].Add(zipCode, new List <int> {
                 id
             });
             vehicle = new Vehicle(id, type, zipCode, true);
             vehicleStatus.Add(id, vehicle);
         }
     }
     //If vehicle type is Police car
     else
     {
         if (vehicleMap.ContainsKey(type))
         {
             if (vehicleMap[type].ContainsKey(zipCode))
             {
                 List <int> ids = vehicleMap[type][zipCode];
                 ids.Add(id);
                 vehicleMap[type][zipCode] = ids;
                 vehicle = new Vehicle(id, type, zipCode, true);
                 vehicleStatus.Add(id, vehicle);
             }
             else
             {
                 vehicleMap[type].Add(zipCode, new List <int> {
                     id
                 });
                 vehicle = new Vehicle(id, type, zipCode, true);
                 vehicleStatus.Add(id, vehicle);
             }
         }
         else
         {
             vehicleMap[type] = new Dictionary <string, List <int> >();
             vehicleMap[type].Add(zipCode, new List <int> {
                 id
             });
             vehicle = new Vehicle(id, type, zipCode, true);
             vehicleStatus.Add(id, vehicle);
         }
     }
 }