Пример #1
0
        public void ModifierParentUnitNullTest()
        {
            Modifier testObj = new Modifier ();
            testObj.ParentUnit = null;

            Assert.IsNull (testObj.ParentUnit);
        }
Пример #2
0
        public void ModifierOrderTest()
        {
            Modifier testObj = new Modifier ();
            testObj.Order = 10;

            Assert.AreEqual (10, testObj.Order);
        }
Пример #3
0
        public void ModifierIDTest()
        {
            Modifier testObj = new Modifier ();
            testObj.ID = 99;

            Assert.AreEqual (99, testObj.ID);
        }
Пример #4
0
        public void ModifierNewTest()
        {
            Modifier testObj = new Modifier ();

            Assert.IsNotNull (testObj);
            Assert.IsTrue (testObj.ID == 0);
            Assert.IsTrue (testObj.Value == 0);
            Assert.IsNull (testObj.ParentUnit);
        }
Пример #5
0
        public void ModifierParentUnitTest()
        {
            Unit testUnitObj = new Unit {
                ID = 99,
                Name = "Name"
            };

            Modifier testObj = new Modifier ();
            testObj.ParentUnit = testUnitObj;

            Assert.IsNotNull (testObj.ParentUnit);
            Assert.AreEqual (testUnitObj.ID, testObj.ParentUnit.ID);
            Assert.AreEqual (testUnitObj.Name, testObj.ParentUnit.Name);
        }
Пример #6
0
        public void ModifierValueTest()
        {
            Modifier testObj = new Modifier ();
            testObj.Value = Convert.ToDecimal (0.001);

            Assert.AreEqual (Convert.ToDecimal (0.001), testObj.Value);
        }
Пример #7
0
        public void ModifierTypeTest()
        {
            Modifier testObj = new Modifier ();
            testObj.ModifierType = ModifierType.Multiply;

            Assert.AreEqual (ModifierType.Multiply, testObj.ModifierType);
        }
Пример #8
0
        void ProcessUnitModifiers(XmlNode parentNode)
        {
            _individualModifiers = new Dictionary<int, List<Modifier>> ();

            foreach (XmlNode node in parentNode.ChildNodes) {
                if (node.Name == "UnitModifier") {
                    var mod = new Modifier ();

                    foreach (XmlAttribute attrib in node.Attributes) {
                        switch (attrib.Name) {
                        case "ID":
                            mod.ID = Convert.ToInt32 (attrib.Value);
                            break;
                        case "Value":
                            mod.Value = Convert.ToDecimal (attrib.Value);
                            break;
                        case "Order":
                            mod.Order = Convert.ToInt32 (attrib.Value);
                            break;
                        case "ModifierID":
                            mod.ModifierType = (ModifierType)Convert.ToInt32 (attrib.Value);
                            break;
                        case "UnitSourceID":
                            mod.UnitSourceID = Convert.ToInt32 (attrib.Value);
                            break;
                        case "UnitTargetID":
                            mod.UnitTargetID = Convert.ToInt32 (attrib.Value);
                            break;
                        case "Precision":
                            mod.Precision = Convert.ToInt32 (attrib.Value);
                            break;
                        }

                    }

                    if (_individualModifiers.ContainsKey (mod.UnitTargetID)) {
                        var data = _individualModifiers [mod.UnitTargetID];
                        data.Add (mod);
                    } else {
                        var data = new List<Modifier> { mod };
                        _individualModifiers.Add (mod.UnitTargetID, data);
                    }

                }
            }
        }
Пример #9
0
        private void ProcessUnitConverterData2(Cubico.UnitData.RootObject RootObject)
        {
            var data = RootObject.UnitConverterData;
            //Load Modifier Data
            _individualModifiers = new Dictionary<int, List<Modifier>>();
            foreach (var itm in data.UnitModifiers.UnitModifier)
            {
                var mod = new Modifier();
                mod.ID = Convert.ToInt32(itm.ID);
                mod.Value = Convert.ToDecimal(itm.Value);
                mod.Order = Convert.ToInt32(itm.Order);
                mod.ModifierType = (ModifierType)Convert.ToInt32(itm.ModifierID);
                mod.UnitSourceID = Convert.ToInt32(itm.UnitSourceID);
                mod.UnitTargetID = Convert.ToInt32(itm.UnitTargetID);

                if (string.IsNullOrWhiteSpace(itm.Precision))
                {
                    mod.Precision = null;
                }
                else
                {
                    mod.Precision = Convert.ToInt32(itm.Precision);
                }

                if (_individualModifiers.ContainsKey(mod.UnitTargetID))
                {
                    var modList = _individualModifiers[mod.UnitTargetID];
                    modList.Add(mod);
                }
                else
                {
                    var modList = new List<Modifier> { mod };
                    _individualModifiers.Add(mod.UnitTargetID, modList);
                }
            }

            //Load Symbol Data
            _symbolLookUp = new Dictionary<int, List<Symbol>>();
            foreach (var itm in data.Symbols.UnitSymbol)
            {
                var sym = new Symbol();
                sym.Id = Convert.ToInt32(itm.ID);
                sym.Value = itm.Symbol;
                sym.UnitId = Convert.ToInt32(itm.UnitID);
                int value = Convert.ToInt32(itm.IsDefault);
                if (value == 1)
                    sym.IsDefault = true;
                else
                    sym.IsDefault = false;

                if (_symbolLookUp.ContainsKey(sym.UnitId))
                {
                    var symList = _symbolLookUp[sym.UnitId];
                    symList.Add(sym);
                }
                else
                {
                    var symList = new List<Symbol> { sym };
                    _symbolLookUp.Add(sym.UnitId, symList);
                }
            }

            _units = new Dictionary<string, Unit>();
            foreach (var itm in data.Units.Unit)
            {
                var unit = new Unit();
                unit.ID = Convert.ToInt32(itm.ID);
                unit.Name = itm.Name;
                unit.UnitTypeID = Convert.ToInt32(itm.UnitTypeID);

                if (_symbolLookUp.ContainsKey(unit.ID))
                {
                    unit.Symbols = _symbolLookUp[unit.ID];

                    foreach (Symbol sym in unit.Symbols)
                    {
                        sym.Unit = unit;
                    }
                }
                if (_individualModifiers.ContainsKey(unit.ID))
                {
                    unit.Modifiers = _individualModifiers[unit.ID];

                    foreach (Modifier mod in unit.Modifiers)
                    {
                        mod.ParentUnit = unit;
                    }
                }
                _units.Add(unit.Name, unit);
            }

            //Load Unit Types
            _unitTypes = new Dictionary<string, UnitType>();
            foreach (var itm in data.UnitTypes.UnitType)
            {
                var ut = new UnitType();
                ut.ID = Convert.ToInt32(itm.ID);
                ut.Name = itm.Name;
                ut.Description = itm.Description;

                // Make this a for loop for speed reasons or use a multikey dictionary.
                var unitData = (from unit in _units.Values
                                where unit.UnitTypeID == ut.ID
                                select unit).ToList();
                ut.Units = unitData;

                foreach (Unit unitItem in ut.Units)
                {
                    unitItem.UnitType = ut;
                }

                _unitTypes.Add(ut.Name, ut);
            }
        }