public void writeRecord() { lock (recordLock) { // Write criminal configuration with current criminal record claims = criminalrecord.Sum(r => r.claims); fines = criminalrecord.Sum(r => r.fines); bounties = criminalrecord.Sum(r => r.bounties); CrimeMonitorConfiguration configuration = new CrimeMonitorConfiguration() { criminalrecord = criminalrecord, claims = claims, fines = fines, bounties = bounties, maxStationDistanceFromStarLs = maxStationDistanceFromStarLs, prioritizeOrbitalStations = prioritizeOrbitalStations, targetSystem = targetSystem, homeSystems = homeSystems, updatedat = updateDat }; configuration.ToFile(); } // Make sure the UI is up to date RaiseOnUIThread(RecordUpdatedEvent, criminalrecord); }
/// <summary> /// Obtain criminal record configuration from a file. If the file name is not supplied the the default /// path of Constants.Data_DIR\crimemonitor.json is used /// </summary> public static CrimeMonitorConfiguration FromFile(string filename = null) { if (filename == null) { filename = Constants.DATA_DIR + @"\crimemonitor.json"; } CrimeMonitorConfiguration configuration = new CrimeMonitorConfiguration(); if (File.Exists(filename)) { string json = Files.Read(filename); if (json != null) { try { configuration = FromJsonString(json); } catch (Exception ex) { Logging.Debug("Failed to read crime configuration", ex); } } } if (configuration == null) { configuration = new CrimeMonitorConfiguration(); } configuration.dataPath = filename; return(configuration); }
public void readRecord(CrimeMonitorConfiguration configuration = null) { lock (recordLock) { // Obtain current criminal record from configuration configuration = configuration ?? CrimeMonitorConfiguration.FromFile(); claims = configuration.claims; fines = configuration.fines; bounties = configuration.bounties; maxStationDistanceFromStarLs = configuration.maxStationDistanceFromStarLs ?? Constants.maxStationDistanceDefault; prioritizeOrbitalStations = configuration.prioritizeOrbitalStations; targetSystem = configuration.targetSystem; homeSystems = configuration.homeSystems; updateDat = configuration.updatedat; // Build a new criminal record List <FactionRecord> records = configuration.criminalrecord.OrderBy(c => c.faction).ToList(); criminalrecord.Clear(); foreach (FactionRecord record in records) { criminalrecord.Add(record); } } }
public ConfigurationWindow() { InitializeComponent(); criminalRecord.ItemsSource = crimeMonitor()?.criminalrecord; CrimeMonitorConfiguration configuration = CrimeMonitorConfiguration.FromFile(); prioritizeOrbitalStations.IsChecked = configuration.prioritizeOrbitalStations; maxStationDistanceInt.Text = configuration.maxStationDistanceFromStarLs?.ToString(CultureInfo.InvariantCulture); }
private void updateCheckbox() { CrimeMonitorConfiguration configuration = CrimeMonitorConfiguration.FromFile(); bool isChecked = prioritizeOrbitalStations.IsChecked.Value; if (configuration.prioritizeOrbitalStations != isChecked) { crimeMonitor().prioritizeOrbitalStations = isChecked; configuration.prioritizeOrbitalStations = isChecked; configuration.ToFile(); crimeMonitor().UpdateStations(); } }
/// <summary> /// Obtain criminal record configuration from json. /// </summary> public static CrimeMonitorConfiguration FromJson(dynamic json) { CrimeMonitorConfiguration configuration = new CrimeMonitorConfiguration(); if (json != null) { try { configuration = JsonConvert.DeserializeObject <CrimeMonitorConfiguration>(json); } catch (Exception ex) { Logging.Debug("Failed to obtain cargo configuration", ex); } } return(configuration); }
private void maxStationDistance_Changed() { CrimeMonitorConfiguration configuration = CrimeMonitorConfiguration.FromFile(); try { int?distance = string.IsNullOrWhiteSpace(maxStationDistanceInt.Text) ? 10000 : Convert.ToInt32(maxStationDistanceInt.Text, CultureInfo.InvariantCulture); if (distance != configuration.maxStationDistanceFromStarLs) { crimeMonitor().maxStationDistanceFromStarLs = distance; configuration.maxStationDistanceFromStarLs = distance; configuration.ToFile(); crimeMonitor().UpdateStations(); } } catch { // Bad user input; ignore it } }
public void initializeCrimeMonitor(CrimeMonitorConfiguration configuration = null) { readRecord(configuration); Logging.Info("Initialised " + MonitorName() + " " + MonitorVersion()); }
public void initializeCrimeMonitor(CrimeMonitorConfiguration configuration = null) { readRecord(configuration); Logging.Info($"Initialized {MonitorName()}"); }