internal static CircuitViewModel GetCircuitFromHierarchy(SetupFileInfo setupFileInfo,
                                                                 ICollection <VehicleViewModel> hierarchy)
        {
            var vehicle = hierarchy.FirstOrDefault(v => v.Identifier == setupFileInfo.VehicleIdentifier);

            if (vehicle == null)
            {
                vehicle = new VehicleViewModel
                {
                    Identifier = setupFileInfo.VehicleIdentifier,
                    Name       = FolderNameMapper.GetFriendlyVehicleName(setupFileInfo.VehicleIdentifier)
                };
                dispatcher.InvokeAsync(() => hierarchy.Add(vehicle));
            }

            var circuit =
                vehicle.Circuits.FirstOrDefault(c => c.Identifier == setupFileInfo.CircuitIdentifier);

            if (circuit == null)
            {
                circuit = new CircuitViewModel
                {
                    Identifier = setupFileInfo.CircuitIdentifier,
                    Name       = FolderNameMapper.GetFriendlyCircuitName(setupFileInfo.CircuitIdentifier)
                };

                dispatcher.InvokeAsync(() => vehicle.Circuits.Insert(0, circuit));
            }

            return(circuit);
        }
        private static IEnumerable <VehicleViewModel> BuildHierarchy(string rootFolder, bool isVersion)
        {
            var result = new List <VehicleViewModel>();

            var vehicleFolderPaths = Directory.GetDirectories(rootFolder);

            foreach (var vehicleFolderPath in vehicleFolderPaths)
            {
                var vehicleIdentifier = PathProvider.GetLastFolderName(vehicleFolderPath);
                var vehicle           = new VehicleViewModel
                {
                    Identifier = vehicleIdentifier,
                    Name       = FolderNameMapper.GetFriendlyVehicleName(vehicleIdentifier)
                };

                var circuitFolderPaths = Directory.GetDirectories(vehicleFolderPath);
                foreach (var circuitFolderPath in circuitFolderPaths)
                {
                    var circuitIdentifier = PathProvider.GetLastFolderName(circuitFolderPath);
                    var circuit           = new CircuitViewModel
                    {
                        Identifier = circuitIdentifier,
                        Name       = FolderNameMapper.GetFriendlyCircuitName(circuitIdentifier)
                    };

                    var setupFilePaths = Directory.GetFiles(circuitFolderPath);
                    foreach (var setupFilePath in setupFilePaths)
                    {
                        var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(setupFilePath);
                        var setup = new SetupViewModel
                        {
                            Name              = fileNameWithoutExtension,
                            FilePath          = setupFilePath,
                            VehicleIdentifier = vehicleIdentifier,
                            CircuitIdentifier = circuitIdentifier,
                            IsVersion         = isVersion
                        };
                        circuit.Setups.Add(setup);
                    }

                    vehicle.Circuits.Add(circuit);
                }

                result.Add(vehicle);
            }

            return(result);
        }