コード例 #1
0
        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);
        }
コード例 #2
0
        internal static void AddMasterSetupFileToHierarchy(SetupFileInfo setupFileInfo,
                                                           ICollection <VehicleViewModel> hierarchy)
        {
            var circuit = GetCircuitFromHierarchy(setupFileInfo, hierarchy);

            dispatcher.InvokeAsync(() => circuit.Setups.Add(new SetupViewModel
            {
                Name = Path.GetFileName(setupFileInfo
                                        .MasterSetupFilePath),
                FilePath = setupFileInfo.MasterSetupFilePath
            }));
        }
コード例 #3
0
        internal static SetupFileInfo ParseFilePath(string filePath)
        {
            var result = new SetupFileInfo();

            var elements  = filePath.Split("\\", StringSplitOptions.RemoveEmptyEntries);
            var lastIndex = elements.Length - 1;

            result.FileName          = elements[lastIndex];
            result.CircuitIdentifier = elements[lastIndex - 1];
            result.VehicleIdentifier = elements[lastIndex - 2];

            result.MasterSetupFilePath = Path.Combine(PathProvider.MasterSetupsFolderPath,
                                                      result.VehicleIdentifier,
                                                      result.CircuitIdentifier,
                                                      result.FileName);

            return(result);
        }
コード例 #4
0
        internal static void DeleteSetupFromHierarchy(SetupFileInfo setupFileInfo,
                                                      ICollection <VehicleViewModel> hierarchy)
        {
            var vehicle = hierarchy.FirstOrDefault(v => v.Identifier == setupFileInfo.VehicleIdentifier);

            if (vehicle != null)
            {
                var circuit =
                    vehicle.Circuits.FirstOrDefault(c => c.Identifier == setupFileInfo.CircuitIdentifier);
                if (circuit == null)
                {
                    return;
                }

                var setup =
                    circuit.Setups.FirstOrDefault(s => s.FilePath == setupFileInfo.MasterSetupFilePath);
                if (setup != null)
                {
                    dispatcher.InvokeAsync(() => circuit.Setups.Remove(setup));
                }
            }
        }