/// <summary> /// Sort the cameras list into a the relevant categories. /// </summary> /// <param name="cameras">Unsorted list of cameras</param> /// <returns>Collection of Categories</returns> /// <exception cref="ArgumentException">Thrown when unable to identify camera type</exception> /// <exception cref="ArgumentOutOfRangeException">Thrown when unable to assign a camera to a category</exception> public static Collection <PointOfInterestCategory> SortCameras(List <PointOfInterest> cameras) { Collection <PointOfInterestCategory> categorisedCameras = new Collection <PointOfInterestCategory>(); foreach (PointOfInterest camera in cameras) { // Parse the Camera Type CameraType cameraType = IdentifyCameraType(camera.Name); if (cameraType == CameraType.None) { throw new ArgumentException(string.Format("Unknown camera Type - {0}", camera.Name)); } // Identify the correct Category CameraCategory cameraCategory = IdentifyCameraCategory(cameraType); if (cameraCategory == CameraCategory.None) { throw new ArgumentOutOfRangeException(string.Format("Unable to identify Camera Category - {0}", cameraType.ToDescriptionString())); } // Special Case for Provisional Mobile cameras if (cameraCategory.Equals(CameraCategory.Mobile)) { if (camera.Name.Contains("pMOBILE")) { cameraCategory = CameraCategory.PMobile; } } // Add to relevant category PointOfInterestCategory targetCategory = null; foreach (PointOfInterestCategory pointOfInterestCategory in categorisedCameras) { if (pointOfInterestCategory.Name.Equals(cameraCategory.ToDescriptionString())) { targetCategory = pointOfInterestCategory; break; } } if (targetCategory == null) { targetCategory = new PointOfInterestCategory((int)cameraCategory, cameraCategory.ToDescriptionString(), LookupIcon(cameraCategory)); categorisedCameras.Add(targetCategory); } targetCategory.Items.Add(camera); } return(categorisedCameras); }