Beispiel #1
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);
                }
            }
        }
Beispiel #2
0
        public async Task <bool> InsertMaterialAmount(MaterialAmount material)
        {
            using var db = Connection;
            const string sql = @"INSERT INTO [MaterialAmounts] (Amount, Material_MaterialId, Item_ItemId) VALUES (@Amount, @MaterialId, @ItemId)";

            var result = await db.ExecuteAsync(sql, new { material.Amount, material.MaterialId, material.ItemId }).ConfigureAwait(false);

            return(result != 0);
        }
Beispiel #3
0
        public void TestMaterialAmountFromJson()
        {
            string         json           = @"{
                ""amount"": 1,
                ""material"": ""Molybdenum""
            }";
            MaterialAmount materialAmount = JsonConvert.DeserializeObject <MaterialAmount>(json);

            Assert.AreEqual(1, materialAmount.amount);
            Assert.AreEqual("Molybdenum", materialAmount.material);
        }
Beispiel #4
0
 /// <summary>
 /// Set the current amount of a material
 /// </summary>
 private void setMaterial(string edname, int amount)
 {
     lock (inventoryLock)
     {
         Material       material = Material.FromEDName(edname);
         MaterialAmount ma       = inventory.Where(inv => inv.edname == material.edname).FirstOrDefault();
         if (ma == null)
         {
             // No information for the current material - create one and set it to amount
             ma = new MaterialAmount(material, amount);
             Logging.Debug(ma.edname + ": " + ma.amount);
             inventory.Add(ma);
         }
         ma.amount = amount;
     }
 }
Beispiel #5
0
        public void TestMaterialMonitor()
        {
            MaterialMonitorConfiguration config = MaterialMonitorConfiguration.FromJsonString(json);

            Assert.AreEqual(2, config.materials.Count);

            MaterialAmount zirconiumAmount = config.materials[1];

            Assert.AreEqual("zirconium", zirconiumAmount.edname);
            Assert.AreEqual(13, zirconiumAmount.amount);
            Assert.AreEqual(EddiDataDefinitions.Properties.Materials.zirconium, Material.FromEDName(config.materials[1].edname).localizedName);
            Assert.AreEqual(100, config.materials[1].maximum);
            Assert.AreEqual(50, config.materials[1].desired);
            Assert.IsNull(config.materials[1].minimum);
            Assert.AreEqual(EddiDataDefinitions.Properties.MaterialCategories.Element, Material.FromEDName(config.materials[1].edname).Category.localizedName);
        }
Beispiel #6
0
        /// <summary>
        /// Decrement the current amount of a material, potentially triggering events as a result
        /// </summary>
        private void decMaterial(string edname, int amount, bool fromLogLoad = false)
        {
            lock (inventoryLock)
            {
                var material = Material.FromEDName(edname);
                var ma       = inventory.FirstOrDefault(inv => inv.edname == material.edname);
                if (ma == null)
                {
                    // No information for the current material - create one and set it to amount
                    ma = new MaterialAmount(material, amount);
                    inventory.Add(ma);
                }

                var previous = ma.amount;
                ma.amount -= Math.Min(amount, previous); // Never subtract more than we started with
                Logging.Debug(ma.edname + ": " + previous + "->" + ma.amount);

                // We have limits for this material; carry out relevant checks
                if (ma.minimum != null && decMaterialThreshold(previous, ma.amount, ma.minimum))
                {
                    // We have crossed the minimum threshold for this material
                    pendingEvents.Enqueue(new MaterialThresholdEvent(DateTime.UtcNow, Material.FromEDName(edname), "Minimum", (int)ma.minimum, ma.amount, "Decrease")
                    {
                        fromLoad = fromLogLoad
                    });
                }
                if (ma.desired != null && decMaterialThreshold(previous, ma.amount, ma.desired))
                {
                    // We have crossed the desired threshold for this material
                    pendingEvents.Enqueue(new MaterialThresholdEvent(DateTime.UtcNow, Material.FromEDName(edname), "Desired", (int)ma.desired, ma.amount, "Decrease")
                    {
                        fromLoad = fromLogLoad
                    });
                }
                if (ma.maximum != null && decMaterialThreshold(previous, ma.amount, ma.maximum))
                {
                    // We have crossed the maximum threshold for this material
                    pendingEvents.Enqueue(new MaterialThresholdEvent(DateTime.UtcNow, Material.FromEDName(edname), "Maximum", (int)ma.maximum, ma.amount, "Decrease")
                    {
                        fromLoad = fromLogLoad
                    });
                }

                writeMaterials();
            }
        }
Beispiel #7
0
        public void Add(VoxelMesh voxelMesh)
        {
            DefaultMesh.Add(voxelMesh.DefaultMesh);
            TexCoord3D.AddRange(voxelMesh.TexCoord3D);
            MaterialAmount.AddRange(voxelMesh.MaterialAmount);
            MaterialId.AddRange(voxelMesh.MaterialId);
            uint max = 0;

            if (VoxelId.Count > 0)
            {
                max = (uint)(VoxelId.Last() + 1);
            }
            foreach (var voxelId in voxelMesh.VoxelId)
            {
                VoxelId.Add(voxelId + max);
            }
        }
Beispiel #8
0
        /// <summary>
        /// Increment the current amount of a material, potentially triggering events as a result
        /// </summary>
        private void incMaterial(string edname, int amount, bool fromLogLoad = false)
        {
            lock (inventoryLock)
            {
                var material = Material.FromEDName(edname);
                var ma       = inventory.FirstOrDefault(inv => inv.edname == material.edname);
                if (ma == null)
                {
                    // No information for the current material - create one and set it to 0
                    ma = new MaterialAmount(material, 0);
                    inventory.Add(ma);
                }

                var previous = ma.amount;
                ma.amount += amount;
                Logging.Debug(ma.edname + ": " + previous + "->" + ma.amount);

                if (ma.maximum != null && incMaterialThreshold(previous, ma.amount, ma.maximum))
                {
                    // We have crossed the high water threshold for this material
                    pendingEvents.Enqueue(new MaterialThresholdEvent(DateTime.UtcNow, material, "Maximum", (int)ma.maximum, ma.amount, "Increase")
                    {
                        fromLoad = fromLogLoad
                    });
                }
                if (ma.desired != null && incMaterialThreshold(previous, ma.amount, ma.desired))
                {
                    // We have crossed the desired threshold for this material
                    pendingEvents.Enqueue(new MaterialThresholdEvent(DateTime.UtcNow, material, "Desired", (int)ma.desired, ma.amount, "Increase")
                    {
                        fromLoad = fromLogLoad
                    });
                }
                if (ma.minimum != null && incMaterialThreshold(previous, ma.amount, ma.minimum))
                {
                    // We have crossed the minimum threshold for this material
                    pendingEvents.Enqueue(new MaterialThresholdEvent(DateTime.UtcNow, material, "Minimum", (int)ma.minimum, ma.amount, "Increase")
                    {
                        fromLoad = fromLogLoad
                    });
                }

                writeMaterials();
            }
        }
Beispiel #9
0
        public void TestMaterialInventoryEvent()
        {
            var    materialMonitor        = new MaterialMonitor();
            string line                   = @"{ ""timestamp"":""2021-01-23T02:50:29Z"", ""event"":""Materials"", ""Raw"":[ { ""Name"":""phosphorus"", ""Count"":231 }, { ""Name"":""mercury"", ""Count"":100 }, { ""Name"":""germanium"", ""Count"":244 }, { ""Name"":""manganese"", ""Count"":222 }, { ""Name"":""zirconium"", ""Count"":107 }, { ""Name"":""niobium"", ""Count"":130 }, { ""Name"":""vanadium"", ""Count"":164 }, { ""Name"":""yttrium"", ""Count"":112 }, { ""Name"":""carbon"", ""Count"":278 }, { ""Name"":""polonium"", ""Count"":65 }, { ""Name"":""nickel"", ""Count"":266 }, { ""Name"":""zinc"", ""Count"":167 }, { ""Name"":""molybdenum"", ""Count"":119 }, { ""Name"":""tungsten"", ""Count"":103 }, { ""Name"":""tin"", ""Count"":177 }, { ""Name"":""iron"", ""Count"":189 }, { ""Name"":""selenium"", ""Count"":75 }, { ""Name"":""arsenic"", ""Count"":101 }, { ""Name"":""chromium"", ""Count"":239 }, { ""Name"":""tellurium"", ""Count"":18 }, { ""Name"":""ruthenium"", ""Count"":39 }, { ""Name"":""technetium"", ""Count"":101 }, { ""Name"":""sulphur"", ""Count"":241 }, { ""Name"":""cadmium"", ""Count"":166 }, { ""Name"":""rhenium"", ""Count"":285 }, { ""Name"":""lead"", ""Count"":283 }, { ""Name"":""boron"", ""Count"":188 } ], ""Manufactured"":[ { ""Name"":""salvagedalloys"", ""Name_Localised"":""Salvaged Alloys"", ""Count"":257 }, { ""Name"":""shieldemitters"", ""Name_Localised"":""Shield Emitters"", ""Count"":227 }, { ""Name"":""conductivecomponents"", ""Name_Localised"":""Conductive Components"", ""Count"":179 }, { ""Name"":""mechanicalcomponents"", ""Name_Localised"":""Mechanical Components"", ""Count"":149 }, { ""Name"":""protolightalloys"", ""Name_Localised"":""Proto Light Alloys"", ""Count"":138 }, { ""Name"":""heatvanes"", ""Name_Localised"":""Heat Vanes"", ""Count"":122 }, { ""Name"":""hybridcapacitors"", ""Name_Localised"":""Hybrid Capacitors"", ""Count"":209 }, { ""Name"":""fedcorecomposites"", ""Name_Localised"":""Core Dynamics Composites"", ""Count"":29 }, { ""Name"":""highdensitycomposites"", ""Name_Localised"":""High Density Composites"", ""Count"":183 }, { ""Name"":""thermicalloys"", ""Name_Localised"":""Thermic Alloys"", ""Count"":150 }, { ""Name"":""heatexchangers"", ""Name_Localised"":""Heat Exchangers"", ""Count"":184 }, { ""Name"":""fedproprietarycomposites"", ""Name_Localised"":""Proprietary Composites"", ""Count"":116 }, { ""Name"":""improvisedcomponents"", ""Name_Localised"":""Improvised Components"", ""Count"":5 }, { ""Name"":""biotechconductors"", ""Name_Localised"":""Biotech Conductors"", ""Count"":71 }, { ""Name"":""gridresistors"", ""Name_Localised"":""Grid Resistors"", ""Count"":241 }, { ""Name"":""militarygradealloys"", ""Name_Localised"":""Military Grade Alloys"", ""Count"":100 }, { ""Name"":""heatdispersionplate"", ""Name_Localised"":""Heat Dispersion Plate"", ""Count"":238 }, { ""Name"":""exquisitefocuscrystals"", ""Name_Localised"":""Exquisite Focus Crystals"", ""Count"":99 }, { ""Name"":""mechanicalequipment"", ""Name_Localised"":""Mechanical Equipment"", ""Count"":231 }, { ""Name"":""conductiveceramics"", ""Name_Localised"":""Conductive Ceramics"", ""Count"":126 }, { ""Name"":""mechanicalscrap"", ""Name_Localised"":""Mechanical Scrap"", ""Count"":190 }, { ""Name"":""conductivepolymers"", ""Name_Localised"":""Conductive Polymers"", ""Count"":101 }, { ""Name"":""polymercapacitors"", ""Name_Localised"":""Polymer Capacitors"", ""Count"":93 }, { ""Name"":""compoundshielding"", ""Name_Localised"":""Compound Shielding"", ""Count"":124 }, { ""Name"":""refinedfocuscrystals"", ""Name_Localised"":""Refined Focus Crystals"", ""Count"":117 }, { ""Name"":""protoheatradiators"", ""Name_Localised"":""Proto Heat Radiators"", ""Count"":92 }, { ""Name"":""heatconductionwiring"", ""Name_Localised"":""Heat Conduction Wiring"", ""Count"":250 }, { ""Name"":""chemicalmanipulators"", ""Name_Localised"":""Chemical Manipulators"", ""Count"":135 }, { ""Name"":""configurablecomponents"", ""Name_Localised"":""Configurable Components"", ""Count"":120 }, { ""Name"":""precipitatedalloys"", ""Name_Localised"":""Precipitated Alloys"", ""Count"":195 }, { ""Name"":""unknowntechnologycomponents"", ""Name_Localised"":""Thargoid Technological Components"", ""Count"":30 }, { ""Name"":""unknownorganiccircuitry"", ""Name_Localised"":""Thargoid Organic Circuitry"", ""Count"":12 }, { ""Name"":""unknownenergycell"", ""Name_Localised"":""Thargoid Energy Cell"", ""Count"":19 }, { ""Name"":""unknownenergysource"", ""Name_Localised"":""Sensor Fragment"", ""Count"":13 }, { ""Name"":""unknowncarapace"", ""Name_Localised"":""Thargoid Carapace"", ""Count"":36 }, { ""Name"":""chemicaldistillery"", ""Name_Localised"":""Chemical Distillery"", ""Count"":200 }, { ""Name"":""shieldingsensors"", ""Name_Localised"":""Shielding Sensors"", ""Count"":188 }, { ""Name"":""focuscrystals"", ""Name_Localised"":""Focus Crystals"", ""Count"":189 }, { ""Name"":""wornshieldemitters"", ""Name_Localised"":""Worn Shield Emitters"", ""Count"":222 }, { ""Name"":""electrochemicalarrays"", ""Name_Localised"":""Electrochemical Arrays"", ""Count"":190 }, { ""Name"":""militarysupercapacitors"", ""Name_Localised"":""Military Supercapacitors"", ""Count"":3 }, { ""Name"":""uncutfocuscrystals"", ""Name_Localised"":""Flawed Focus Crystals"", ""Count"":235 }, { ""Name"":""protoradiolicalloys"", ""Name_Localised"":""Proto Radiolic Alloys"", ""Count"":44 }, { ""Name"":""phasealloys"", ""Name_Localised"":""Phase Alloys"", ""Count"":200 }, { ""Name"":""pharmaceuticalisolators"", ""Name_Localised"":""Pharmaceutical Isolators"", ""Count"":59 }, { ""Name"":""imperialshielding"", ""Name_Localised"":""Imperial Shielding"", ""Count"":97 }, { ""Name"":""chemicalprocessors"", ""Name_Localised"":""Chemical Processors"", ""Count"":230 }, { ""Name"":""galvanisingalloys"", ""Name_Localised"":""Galvanising Alloys"", ""Count"":241 }, { ""Name"":""basicconductors"", ""Name_Localised"":""Basic Conductors"", ""Count"":286 }, { ""Name"":""heatresistantceramics"", ""Name_Localised"":""Heat Resistant Ceramics"", ""Count"":231 }, { ""Name"":""temperedalloys"", ""Name_Localised"":""Tempered Alloys"", ""Count"":270 }, { ""Name"":""crystalshards"", ""Name_Localised"":""Crystal Shards"", ""Count"":232 }, { ""Name"":""guardian_powerconduit"", ""Name_Localised"":""Guardian Power Conduit"", ""Count"":219 }, { ""Name"":""guardian_powercell"", ""Name_Localised"":""Guardian Power Cell"", ""Count"":231 }, { ""Name"":""guardian_techcomponent"", ""Name_Localised"":""Guardian Technology Component"", ""Count"":30 }, { ""Name"":""guardian_sentinel_wreckagecomponents"", ""Name_Localised"":""Guardian Wreckage Components"", ""Count"":78 }, { ""Name"":""guardian_sentinel_weaponparts"", ""Name_Localised"":""Guardian Sentinel Weapon Parts"", ""Count"":162 }, { ""Name"":""compactcomposites"", ""Name_Localised"":""Compact Composites"", ""Count"":209 }, { ""Name"":""chemicalstorageunits"", ""Name_Localised"":""Chemical Storage Units"", ""Count"":269 }, { ""Name"":""filamentcomposites"", ""Name_Localised"":""Filament Composites"", ""Count"":224 }, { ""Name"":""tg_propulsionelement"", ""Name_Localised"":""Propulsion Elements"", ""Count"":66 }, { ""Name"":""tg_biomechanicalconduits"", ""Name_Localised"":""Bio-Mechanical Conduits"", ""Count"":75 }, { ""Name"":""tg_wreckagecomponents"", ""Name_Localised"":""Wreckage Components"", ""Count"":61 }, { ""Name"":""tg_weaponparts"", ""Name_Localised"":""Weapon Parts"", ""Count"":111 } ], ""Encoded"":[ { ""Name"":""shieldsoakanalysis"", ""Name_Localised"":""Inconsistent Shield Soak Analysis"", ""Count"":241 }, { ""Name"":""scrambledemissiondata"", ""Name_Localised"":""Exceptional Scrambled Emission Data"", ""Count"":263 }, { ""Name"":""encodedscandata"", ""Name_Localised"":""Divergent Scan Data"", ""Count"":73 }, { ""Name"":""hyperspacetrajectories"", ""Name_Localised"":""Eccentric Hyperspace Trajectories"", ""Count"":133 }, { ""Name"":""encryptioncodes"", ""Name_Localised"":""Tagged Encryption Codes"", ""Count"":217 }, { ""Name"":""disruptedwakeechoes"", ""Name_Localised"":""Atypical Disrupted Wake Echoes"", ""Count"":267 }, { ""Name"":""wakesolutions"", ""Name_Localised"":""Strange Wake Solutions"", ""Count"":169 }, { ""Name"":""symmetrickeys"", ""Name_Localised"":""Open Symmetric Keys"", ""Count"":158 }, { ""Name"":""securityfirmware"", ""Name_Localised"":""Security Firmware Patch"", ""Count"":85 }, { ""Name"":""decodedemissiondata"", ""Name_Localised"":""Decoded Emission Data"", ""Count"":148 }, { ""Name"":""shieldpatternanalysis"", ""Name_Localised"":""Aberrant Shield Pattern Analysis"", ""Count"":150 }, { ""Name"":""unknownshipsignature"", ""Name_Localised"":""Thargoid Ship Signature"", ""Count"":45 }, { ""Name"":""unknownwakedata"", ""Name_Localised"":""Thargoid Wake Data"", ""Count"":9 }, { ""Name"":""ancienttechnologicaldata"", ""Name_Localised"":""Pattern Epsilon Obelisk Data"", ""Count"":75 }, { ""Name"":""ancientlanguagedata"", ""Name_Localised"":""Pattern Delta Obelisk Data"", ""Count"":150 }, { ""Name"":""ancienthistoricaldata"", ""Name_Localised"":""Pattern Gamma Obelisk Data"", ""Count"":150 }, { ""Name"":""ancientbiologicaldata"", ""Name_Localised"":""Pattern Alpha Obelisk Data"", ""Count"":150 }, { ""Name"":""ancientculturaldata"", ""Name_Localised"":""Pattern Beta Obelisk Data"", ""Count"":150 }, { ""Name"":""fsdtelemetry"", ""Name_Localised"":""Anomalous FSD Telemetry"", ""Count"":249 }, { ""Name"":""bulkscandata"", ""Name_Localised"":""Anomalous Bulk Scan Data"", ""Count"":282 }, { ""Name"":""emissiondata"", ""Name_Localised"":""Unexpected Emission Data"", ""Count"":142 }, { ""Name"":""shieldcyclerecordings"", ""Name_Localised"":""Distorted Shield Cycle Recordings"", ""Count"":300 }, { ""Name"":""embeddedfirmware"", ""Name_Localised"":""Modified Embedded Firmware"", ""Count"":39 }, { ""Name"":""legacyfirmware"", ""Name_Localised"":""Specialised Legacy Firmware"", ""Count"":247 }, { ""Name"":""encryptedfiles"", ""Name_Localised"":""Unusual Encrypted Files"", ""Count"":283 }, { ""Name"":""archivedemissiondata"", ""Name_Localised"":""Irregular Emission Data"", ""Count"":213 }, { ""Name"":""consumerfirmware"", ""Name_Localised"":""Modified Consumer Firmware"", ""Count"":212 }, { ""Name"":""shieldfrequencydata"", ""Name_Localised"":""Peculiar Shield Frequency Data"", ""Count"":36 }, { ""Name"":""tg_residuedata"", ""Name_Localised"":""Thargoid Residue Data"", ""Count"":24 }, { ""Name"":""tg_structuraldata"", ""Name_Localised"":""Thargoid Structural Data"", ""Count"":33 }, { ""Name"":""tg_compositiondata"", ""Name_Localised"":""Thargoid Material Composition Data"", ""Count"":30 }, { ""Name"":""classifiedscandata"", ""Name_Localised"":""Classified Scan Fragment"", ""Count"":38 }, { ""Name"":""compactemissionsdata"", ""Name_Localised"":""Abnormal Compact Emissions Data"", ""Count"":31 }, { ""Name"":""encryptionarchives"", ""Name_Localised"":""Atypical Encryption Archives"", ""Count"":121 }, { ""Name"":""shielddensityreports"", ""Name_Localised"":""Untypical Shield Scans "", ""Count"":182 }, { ""Name"":""industrialfirmware"", ""Name_Localised"":""Cracked Industrial Firmware"", ""Count"":25 }, { ""Name"":""dataminedwake"", ""Name_Localised"":""Datamined Wake Exceptions"", ""Count"":29 }, { ""Name"":""scandatabanks"", ""Name_Localised"":""Classified Scan Databanks"", ""Count"":181 }, { ""Name"":""scanarchives"", ""Name_Localised"":""Unidentified Scan Archives"", ""Count"":234 }, { ""Name"":""adaptiveencryptors"", ""Name_Localised"":""Adaptive Encryptors Capture"", ""Count"":40 }, { ""Name"":""guardian_vesselblueprint"", ""Name_Localised"":""Guardian Vessel Blueprint Fragment"", ""Count"":5 }, { ""Name"":""guardian_moduleblueprint"", ""Name_Localised"":""Guardian Module Blueprint Fragment"", ""Count"":6 } ] }";
            var    events                 = JournalMonitor.ParseJournalEntry(line);
            MaterialInventoryEvent @event = (MaterialInventoryEvent)events[0];

            int?InventoryAmount(string edname)
            {
                return(materialMonitor.inventory
                       .SingleOrDefault(m => string.Equals(m.edname, edname, StringComparison.InvariantCultureIgnoreCase))
                       ?.amount);
            }

            // Add antimony so that we can test whether obsolete data in our inventory but not listed in the event is corrected
            var antimony = materialMonitor.inventory.Single(m => string.Equals(m.edname, "antimony", StringComparison.InvariantCultureIgnoreCase));

            if (antimony is null)
            {
                antimony = new MaterialAmount("antimony", 5, 25, 50, 75);
                materialMonitor.inventory.Add(antimony);
            }
            else
            {
                antimony.amount = 5;
            }
            Assert.AreEqual(5, InventoryAmount("antimony"));

            // Handle our event
            materialMonitor.PreHandle(@event);

            // Test materials listed in the event
            Assert.AreEqual(231, InventoryAmount("phosphorus"));
            Assert.AreEqual(100, InventoryAmount("mercury"));
            Assert.AreEqual(244, InventoryAmount("germanium"));

            // Test materials not listed in the event
            Assert.AreEqual(0, InventoryAmount("antimony"));
            Assert.AreEqual(0, InventoryAmount("guardian_weaponblueprint"));

            // Test unknown materials
            Assert.IsNull(InventoryAmount("unobtainum"));
        }
Beispiel #10
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);
                }
            }
        }
        /// <summary>
        /// Decrement the current amount of a material, potentially triggering events as a result
        /// </summary>
        private void decMaterial(string edname, int amount)
        {
            lock (inventoryLock)
            {
                Material       material = Material.FromEDName(edname);
                MaterialAmount ma       = inventory.Where(inv => inv.edname == material.EDName).FirstOrDefault();
                if (ma == null)
                {
                    // No information for the current material - create one and set it to amount
                    ma = new MaterialAmount(material, amount);
                    inventory.Add(ma);
                }

                int previous = ma.amount;
                ma.amount -= amount;
                Logging.Debug(ma.edname + ": " + previous + "->" + ma.amount);

                // We have limits for this material; carry out relevant checks
                if (ma.minimum.HasValue)
                {
                    if (previous >= ma.minimum && ma.amount < ma.minimum)
                    {
                        // We have crossed the low water threshold for this material
                        pendingEvents.Enqueue(new MaterialThresholdEvent(DateTime.Now, Material.FromEDName(edname), "Minimum", (int)ma.minimum, ma.amount, "Decrease"));
                    }
                }
                if (ma.desired.HasValue)
                {
                    if (previous >= ma.desired && ma.amount < ma.desired)
                    {
                        // We have crossed the desired threshold for this material
                        pendingEvents.Enqueue(new MaterialThresholdEvent(DateTime.Now, Material.FromEDName(edname), "Desired", (int)ma.desired, ma.amount, "Decrease"));
                    }
                }

                writeMaterials();
            }
        }
Beispiel #12
0
        /// <summary>
        /// Increment the current amount of a material, potentially triggering events as a result
        /// </summary>
        private void incMaterial(string edname, int amount)
        {
            lock (inventoryLock)
            {
                Material       material = Material.FromEDName(edname);
                MaterialAmount ma       = inventory.Where(inv => inv.edname == material.edname).FirstOrDefault();
                if (ma == null)
                {
                    // No information for the current material - create one and set it to 0
                    ma = new MaterialAmount(material, 0);
                    inventory.Add(ma);
                }

                int previous = ma.amount;
                ma.amount += amount;
                Logging.Debug(ma.edname + ": " + previous + "->" + ma.amount);

                if (ma.maximum.HasValue)
                {
                    if (previous <= ma.maximum && ma.amount > ma.maximum)
                    {
                        // We have crossed the high water threshold for this material
                        pendingEvents.Enqueue(new MaterialThresholdEvent(DateTime.UtcNow, Material.FromEDName(edname), "Maximum", (int)ma.maximum, ma.amount, "Increase"));
                    }
                }
                if (ma.desired.HasValue)
                {
                    if (previous < ma.desired && ma.amount >= ma.desired)
                    {
                        // We have crossed the desired threshold for this material
                        pendingEvents.Enqueue(new MaterialThresholdEvent(DateTime.UtcNow, Material.FromEDName(edname), "Desired", (int)ma.desired, ma.amount, "Increase"));
                    }
                }

                writeMaterials();
            }
        }
Beispiel #13
0
        public async Task <IActionResult> PostMaterialAmount([FromBody] MaterialAmount material)
        {
            var result = await _repository.InsertMaterialAmount(material).ConfigureAwait(false);

            return(result ? new StatusCodeResult(200) : new StatusCodeResult(422));
        }
        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);
                }
            }
        }
Beispiel #15
0
        public static Task <string> FromExcel(Action <ICollection <Item>, Exception> callback, FileInfo excelFile, IDataService dataService)
        {
            var existingMaterials  = new List <Material>();
            var items              = new List <Item>();
            var addedMaterialCount = 0;
            var addedItemCount     = 0;

            dataService.GetItems(((itms, materials, exception) =>
            {
                if (exception != null)
                {
                    throw exception;
                }

                existingMaterials = materials.ToList();
                items = itms.ToList();
            }));

            if (!excelFile.Exists)
            {
                callback(null, new FileLoadException());
                return(Task.FromResult(result: "failurs"));
            }

            var addedMaterials = new List <Material>();

            //var items = new List<Item>();

            using (var excel = new ExcelPackage(excelFile))
            {
                var worksheet = excel.Workbook.Worksheets[1];

                for (var i = 1; i < worksheet.Dimension.End.Column; i += 2)
                {
                    var exists = items.Any(it =>
                                           string.Equals(it.ItemName, worksheet.Cells[1, i].Text.Trim(Environment.NewLine.ToCharArray()), StringComparison.InvariantCultureIgnoreCase));

                    if (exists)
                    {
                        continue;
                    }

                    var item = new Item
                    {
                        ItemName  = worksheet.Cells[1, i].Text.Trim(Environment.NewLine.ToCharArray()),
                        Materials = new ObservableCollection <MaterialAmount>()
                    };

                    var lastRow = worksheet.Cells.Last(c => c.Start.Column == i).End.Row;

                    for (var j = 2; j <= lastRow; j++)
                    {
                        var material = existingMaterials.SingleOrDefault(m =>
                                                                         string.Equals(m.MaterialName, worksheet.Cells[j, i].Text.Trim(Environment.NewLine.ToCharArray()),
                                                                                       StringComparison.OrdinalIgnoreCase));

                        MaterialAmount newMaterialWithUsage;

                        if (material != null)
                        {
                            newMaterialWithUsage = new MaterialAmount
                            {
                                Material = material,
                                Amount   = float.Parse(worksheet.Cells[j, i + 1].Text)
                            };
                        }
                        else
                        {
                            var newMaterial = new Material {
                                MaterialName = worksheet.Cells[j, i].Text.Trim(Environment.NewLine.ToCharArray())
                            };
                            existingMaterials.Add(newMaterial);
                            dataService.Add(newMaterial);

                            newMaterialWithUsage = new MaterialAmount
                            {
                                Material = newMaterial,
                                Amount   = float.Parse(worksheet.Cells[j, i + 1].Text)
                            };
                            addedMaterialCount++;
                            addedMaterials.Add(newMaterial);
                            //existingMaterials.Add(newMaterial);
                        }

                        item.Materials.Add(newMaterialWithUsage);
                    }

                    addedItemCount++;
                    items.Add(item);
                    dataService.Add(item);
                }
            }

            var message = string.Empty;

            if (addedItemCount > 0)
            {
                message = $"Successfully added {addedItemCount} new items and {addedMaterials} new materials.";
            }

            dataService.SaveData();

            return(Task.FromResult(result: message));
        }