private void readMaterials() { lock (inventoryLock) { // Obtain current inventory from configuration MaterialMonitorConfiguration configuration = MaterialMonitorConfiguration.FromFile(); // Build a new inventory List <MaterialAmount> newInventory = new List <MaterialAmount>(); // Start with the materials we have in the log foreach (MaterialAmount ma in configuration.materials) { // Remove incorrect edname introduced in an earlier version of EDDI if (ma.edname == "tg_shipsystemdata") // Should be "shipsystemsdata" { continue; } MaterialAmount ma2 = new MaterialAmount(ma.edname, ma.amount, ma.minimum, ma.desired, ma.maximum); // Make sure the edname is unique before adding the material to the new inventory if (newInventory.Where(inv => inv.edname == ma2.edname).Count() == 0) { // Set material maximums if they aren't already defined if (ma2.maximum == null || !ma2.maximum.HasValue) { int rarityLevel = Material.FromEDName(ma2.edname).rarity.level; if (rarityLevel > 0) { ma2.maximum = -50 * (rarityLevel) + 350; } } newInventory.Add(ma2); } } // Add in any new materials foreach (Material material in Material.AllOfThem.ToList()) { MaterialAmount ma = newInventory.Where(inv => inv.edname == material.edname).FirstOrDefault(); if (ma == null) { // We don't have this one - add it and set it to zero Logging.Debug("Adding new material " + material.invariantName + " to the materials list"); ma = new MaterialAmount(material, 0); newInventory.Add(ma); } } // Now order the list by name newInventory = newInventory.OrderBy(m => m.material).ToList(); // Update the inventory inventory.Clear(); foreach (MaterialAmount ma in newInventory) { inventory.Add(ma); } } }
public ConfigurationWindow() { InitializeComponent(); materialsData.ItemsSource = materialMonitor()?.inventory; MaterialMonitorConfiguration configuration = MaterialMonitorConfiguration.FromFile(); maxStationDistanceInt.Text = configuration.maxStationDistanceFromStarLs?.ToString(CultureInfo.InvariantCulture); }
private void maxStationDistance_Changed() { MaterialMonitorConfiguration configuration = MaterialMonitorConfiguration.FromFile(); try { int?distance = string.IsNullOrWhiteSpace(maxStationDistanceInt.Text) ? 10000 : Convert.ToInt32(maxStationDistanceInt.Text, CultureInfo.InvariantCulture); if (distance != configuration.maxStationDistanceFromStarLs) { materialMonitor().maxStationDistanceFromStarLs = distance; configuration.maxStationDistanceFromStarLs = distance; configuration.ToFile(); } } catch { // Bad user input; ignore it } }
private void readMaterials() { lock (inventoryLock) { // Obtain current inventory from configuration MaterialMonitorConfiguration configuration = MaterialMonitorConfiguration.FromFile(); // Build a new inventory List <MaterialAmount> newInventory = new List <MaterialAmount>(); // Start with the materials we have in the log foreach (MaterialAmount ma in configuration.materials) { newInventory.Add(ma); } // Add in any new materials foreach (Material material in Material.MATERIALS) { MaterialAmount ma = newInventory.Where(inv => inv.material == material.name).FirstOrDefault(); if (ma == null) { // We don't have this one - add it ma = new MaterialAmount(material, 0); newInventory.Add(ma); } } // Now order the list by name newInventory = newInventory.OrderBy(m => m.material).ToList(); // Update the inventory inventory.Clear(); foreach (MaterialAmount ma in newInventory) { inventory.Add(ma); } } }
private void readMaterials() { lock (inventoryLock) { // Obtain current inventory from configuration MaterialMonitorConfiguration configuration = MaterialMonitorConfiguration.FromFile(); // Build a new inventory List <MaterialAmount> newInventory = new List <MaterialAmount>(); // Start with the materials we have in the log foreach (MaterialAmount ma in configuration.materials) { // Fix up & add any materials that are not deprecated material names if (Material.DeprecatedMaterials(ma.material) == false) { bool addToInv = false; // if the edname is not set, or if (ma.edname == null) { addToInv = true; } // if the edname is UNIQUE to the collection, or else if (configuration.materials.Any(item => item.edname == ma.edname) == false) { addToInv = true; } /// if the EDNAME IS NOT UNIQUE to the collection, the MATERIAL NAME IS UNIQUE, & THE EDNAME DOESN'T MATCH THE MATERIAL NAME /// (once an EDName is established, this will identify & "heal" any duplicate entries having the same EDName in the materialmonitor) else if ((configuration.materials.Any(item => item.edname == ma.edname) == true) && (configuration.materials.Any(item => item.material == ma.material) == true) && (ma.edname != ma.material)) { addToInv = true; } // then add the material to the new inventory list, preserving user preferences for that material if (addToInv == true) { MaterialAmount ma2 = new MaterialAmount(ma.material, ma.amount, ma.minimum, ma.desired, ma.maximum); newInventory.Add(ma2); } } } // Add in any new materials foreach (Material material in Material.MATERIALS) { MaterialAmount ma = newInventory.Where(inv => inv.edname == material.EDName).FirstOrDefault(); if (ma == null) { // We don't have this one - add it and set it to zero if ((Material.DeprecatedMaterials(material.name) == false)) { Logging.Debug("Adding new material " + material.name + " to the materials list"); ma = new MaterialAmount(material, 0); newInventory.Add(ma); } } } // Now order the list by name newInventory = newInventory.OrderBy(m => m.material).ToList(); // Update the inventory inventory.Clear(); foreach (MaterialAmount ma in newInventory) { inventory.Add(ma); } } }