コード例 #1
0
        /// <summary>
        /// Obtain materials configuration from a file.  If the file name is not supplied the the default
        /// path of Constants.Data_DIR\materialmonitor.json is used
        /// </summary>
        public static MaterialMonitorConfiguration FromFile(string filename = null)
        {
            if (filename == null)
            {
                filename = Constants.DATA_DIR + @"\materialmonitor.json";
            }

            MaterialMonitorConfiguration configuration = new MaterialMonitorConfiguration();

            if (File.Exists(filename))
            {
                try
                {
                    string json = Files.Read(filename);
                    if (json != null)
                    {
                        configuration = FromJsonString(json);
                    }
                }
                catch (Exception ex)
                {
                    Logging.Debug("Failed to read materials configuration", ex);
                }
            }
            if (configuration == null)
            {
                configuration = new MaterialMonitorConfiguration();
            }

            configuration.dataPath = filename;
            return(configuration);
        }
コード例 #2
0
        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);
                }
            }
        }
コード例 #3
0
 public void writeMaterials()
 {
     lock (inventoryLock)
     {
         // Write material configuration with current inventory
         MaterialMonitorConfiguration configuration = new MaterialMonitorConfiguration();
         configuration.materials = inventory;
         configuration.ToFile();
     }
 }
コード例 #4
0
        public ConfigurationWindow()
        {
            InitializeComponent();

            materialsData.ItemsSource = materialMonitor()?.inventory;

            MaterialMonitorConfiguration configuration = MaterialMonitorConfiguration.FromFile();

            maxStationDistanceInt.Text = configuration.maxStationDistanceFromStarLs?.ToString(CultureInfo.InvariantCulture);
        }
コード例 #5
0
ファイル: MaterialMonitor.cs プロジェクト: pekwalker/EDDI
 public void writeMaterials()
 {
     lock (inventoryLock)
     {
         // Write material configuration with current inventory
         MaterialMonitorConfiguration configuration = new MaterialMonitorConfiguration();
         configuration.materials = inventory;
         configuration.ToFile();
     }
     // Make sure the UI is up to date
     RaiseOnUIThread(InventoryUpdatedEvent, inventory);
 }
        /// <summary>
        /// Obtain materials configuration from a file.  If the file name is not supplied the the default
        /// path of Constants.Data_DIR\materialmonitor.json is used
        /// </summary>
        public static MaterialMonitorConfiguration FromFile(string filename = null)
        {
            if (filename == null)
            {
                filename = Constants.DATA_DIR + @"\materialmonitor.json";
            }

            MaterialMonitorConfiguration configuration = new MaterialMonitorConfiguration();

            if (File.Exists(filename))
            {
                string data = Files.Read(filename);
                if (data != null)
                {
                    try
                    {
                        configuration = JsonConvert.DeserializeObject <MaterialMonitorConfiguration>(data);
                    }
                    catch (Exception ex)
                    {
                        Logging.Debug("Failed to read materials configuration", ex);
                    }
                }
            }
            if (configuration == null)
            {
                configuration = new MaterialMonitorConfiguration();
            }

            //// We fully populate the list with all known materials
            //foreach (Material material in Material.MATERIALS)
            //{
            //    Limits cur;
            //    if (!configuration.limits.TryGetValue(material.EDName, out cur))
            //    {
            //        configuration.limits[material.EDName] = new Limits(null, null, null);
            //    }
            //}

            configuration.dataPath = filename;
            return(configuration);
        }
コード例 #7
0
        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
            }
        }
コード例 #8
0
        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);
                }
            }
        }
コード例 #9
0
        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);
                }
            }
        }