Best practice to retrieve cameras

Hello, I am currently using the following code to retrieve Hanwha Vision cameras.

IEnumerable<Hardware> hardwares = ms.RecordingServerFolder.RecordingServers
    .Where(rs => rs.HardwareFolder != null)
    .SelectMany(rs => rs.HardwareFolder.Hardwares);
var hardwareList = hardwares.ToList();
foreach (Hardware h in hardwareList)
{
    if (h.CameraFolder == null || h.CameraFolder.Cameras == null || h.CameraFolder.Cameras.Count == 0)
        continue;
 
    Guid deviceId = Guid.Empty;
    string model = h.GetProperty("Model");
    if (model == null)
        continue;
 
    // Check if it's a Hanwha camera
    if (model.ToUpper().Contains("HANWHA") == false)
        continue;
 
    ICollection<Camera> cams = h.CameraFolder.Cameras;
    if (cams != null)
    {
        List<Camera> hanwhaCameras =
            cams
            .ToList();
    }
    ...
}

The current code is very slow, especially when looping through the hardwareList. Could you recommend a way to get a specific vendor’s (Hanwha) camera list with better performance?

One idea I think can speed this up a lot. Hardware has a Model property so you do not have to make the GetProperty method.

List<Camera> myCams = new List<Camera>();
var rss = ms.RecordingServerFolder.RecordingServers;
foreach (var rs in rss)
{
	var hws = rs.HardwareFolder.Hardwares.Where(hw => hw.Model.StartsWith("Stable"));
	foreach (var hw in hws)
	{
		myCams.AddRange(hw.CameraFolder.Cameras);
	}
}