Esempio n. 1
0
        public static XElement generateFromValueDescriptionDecorator(ValueDescriptionDecorator TLV)
        {
            XElement XE = generateFromTLValue(TLV);

            //add the options
            foreach (var item in TLV.ArrayOfOptions.Values.ToList())
            {
                XElement Options1 = new XElement("NamedValue");
                Options1.Add(new XAttribute("Name", item.Name));
                Options1.Add(new XAttribute("Length", item.Length));
                Options1.Add(new XAttribute("Position", item.Position));

                foreach (var option in item.getOptions())
                {
                    // create the option
                    XElement optionElement = new XElement("Options", option.Key);
                    optionElement.Add(new XAttribute("Name", option.Value));

                    //add it to options
                    Options1.Add(optionElement);
                }
                XE.Add(Options1);
            }

            return(XE);
        }
Esempio n. 2
0
        public void Composer_ValueDefinition_OK()
        {
            TLValue bareValue1 = new TLValue();

            bareValue1.Name   = "val 1";
            bareValue1.Value  = "0022";
            bareValue1.Length = 2;
            bareValue1.Tag    = "04";

            ValueDescriptionDecorator value1 = new ValueDescriptionDecorator(bareValue1);

            value1.ArrayOfOptions.Add(1, createOptions(3, 1, 1));
            value1.ArrayOfOptions.Add(2, createOptions(10, 2, 1));

            //value definition in XML
            XElement definition = new XElement("Definition");

            definition.Add(XElementHelper.generateFromValueDescriptionDecorator(value1));

            Composer composer = new Composer();

            composer.ParseValueDefinition(definition);

            // check the result
            Assert.AreEqual(1, composer.Vals.Count);
            Assert.IsInstanceOfType(composer.Vals[0], typeof(ValueDescriptionDecorator));
            AreEqualValueDescriptionDecorator(value1, (ValueDescriptionDecorator)composer.Vals[0]);
        }
Esempio n. 3
0
        private void AreEqualValueDescriptionDecorator(ValueDescriptionDecorator expected, ValueDescriptionDecorator result)
        {
            AreEqualTLValue(expected, result);

            Assert.AreEqual(expected.ArrayOfOptions.Count, result.ArrayOfOptions.Count);

            OptionContainer[] expectedArray = expected.ArrayOfOptions.Values.ToArray <OptionContainer>();
            OptionContainer[] resultArray   = result.ArrayOfOptions.Values.ToArray <OptionContainer>();


            for (int i = 0; i < expectedArray.Count(); i++)
            {
                Assert.AreEqual(expectedArray[i].Length, resultArray[i].Length);
                Assert.AreEqual(expectedArray[i].Name, resultArray[i].Name);
                Assert.AreEqual(expectedArray[i].Position, resultArray[i].Position);
            }
        }
Esempio n. 4
0
        public ValueItem getItem(XElement element)
        {
            ValueItem result = null;

            // create the basic value
            switch (element.Name.ToString().ToLower())
            {
            case "singlevalue":
                result = new SingleValue();
                break;

            case "tlvalue":
                result = new TLValue();
                break;
            }

            //add the decorator
            foreach (var descendant in element.Descendants())
            {
                switch (descendant.Name.ToString().ToLower())
                {
                case "namedvalue":
                    if (result is TLValue)
                    {
                        result = new ValueDescriptionDecorator((TLValue)result);
                    }
                    break;

                default:
                    break;
                }
            }



            if (result != null)
            {
                result.ParseDefinition(element);
            }

            return(result);
        }