public void Save(Aircraft aircraft)
        {
            AircraftLauncherInformation launcherInfo = new AircraftLauncherInformation {
                TargetLocation               = new List <Location>(),
                LocationInformations         = new Dictionary <Location, LocationInformation>(),
                SummaryDistanceNauticalMiles = aircraft.SummaryDistanceNauticalMiles,
                SummaryHours = aircraft.SummaryHours
            };

            foreach (RoutePoint routePoint in aircraft.Route)
            {
                launcherInfo.TargetLocation.Add(routePoint.Location);
                if (!string.IsNullOrWhiteSpace(routePoint.Name) || !string.IsNullOrWhiteSpace(routePoint.Description))
                {
                    launcherInfo.LocationInformations.Add(
                        routePoint.Location,
                        new LocationInformation {
                        Name    = routePoint.Name,
                        Comment = routePoint.Description
                    });
                }
            }

            _launcherInformationDao.SaveToFile(aircraft.LauncherInfoFile, launcherInfo);
        }
        public async Task ReloadAsync()
        {
            _aircraftModelProvider.Aircrafts.Clear();
            IList <AircraftInformation> aircraftInformations = await _aircraftInformationDao.GetAllAsync();

            foreach (AircraftInformation aircraftInformation in aircraftInformations)
            {
                AircraftLauncherInformation aircraftLauncherInformation = await _launcherInformationDao.FindForAircraftAsync(aircraftInformation);

                Aircraft aircraft = new Aircraft(aircraftInformation, aircraftLauncherInformation);
                aircraft.Init();
                aircraft.Update(_sitFileDao.FindSit(aircraftInformation));
                aircraft.Update(_thumbnailDao.FindThumbnail(aircraftInformation));
                aircraft.Update(_routeService.GetRouteLenght(aircraft));
                _aircraftModelProvider.Aircrafts.Add(aircraft);
            }
        }
        public async Task <AircraftLauncherInformation> FindForAircraftAsync(AircraftInformation aircraftInformation)
        {
            FileInfo aircraftFile = aircraftInformation.File;
            FileInfo launcherFile = new FileInfo(aircraftFile.FullName.Replace(aircraftFile.Extension, ".launcherV2"));

            if (launcherFile.Exists)
            {
                string launcherContent;
                using (StreamReader reader = File.OpenText(launcherFile.FullName)) {
                    launcherContent = await reader.ReadToEndAsync();
                }

                AircraftLauncherInformation aircraftLauncherInformation = JsonConvert.DeserializeObject <AircraftLauncherInformation>(launcherContent);
                aircraftLauncherInformation.LauncherInfoFile = launcherFile;
                return(aircraftLauncherInformation);
            }

            return(null);
        }
Esempio n. 4
0
 public Aircraft(AircraftInformation aircraftInformation, AircraftLauncherInformation launcherInfo)
 {
     Id                  = Guid.NewGuid();
     _launcherInfo       = launcherInfo;
     AircraftInformation = aircraftInformation;
 }
 public void SaveToFile(FileInfo launcherInfoFile, AircraftLauncherInformation launcherInfo)
 {
     File.WriteAllText(launcherInfoFile.FullName, JsonConvert.SerializeObject(launcherInfo));
 }