Example #1
0
        public override SECSItem XElementToSECSItem(XElement element)
        {
            if (element == null)
            {
                return(null);
            }
            string name = ((string)element.Element("Name")).Trim();
            string desc = ((string)element.Element("Description")).Trim();
            string str3 = ((string)element.Element("Format")).Trim().ToUpper(CultureInfo.InvariantCulture);

            if (str3 == "LIST")
            {
                SECSItem item = new SECSItem(eSECS_FORMAT.LIST, name, desc);
                foreach (XElement element2 in element.Elements("Item"))
                {
                    SECSItem child = this.XElementToSECSItem(element2);
                    item.Add(child);
                }
                return(item);
            }
            SECSItem item2 = null;
            string   data  = ((string)element.Element("Value")).Trim();
            string   key;

            switch (key = str3)
            {
            case "ASCII":
                item2 = new SECSItem(eSECS_FORMAT.ASCII, name, desc);
                break;

            case "CHAR2":
                item2 = new SECSItem(eSECS_FORMAT.CHAR2, name, desc);
                break;

            case "BINARY":
                item2 = new SECSItem(eSECS_FORMAT.BINARY, name, desc);
                break;

            case "BOOLEAN":
                item2 = new SECSItem(eSECS_FORMAT.BOOLEAN, name, desc);
                break;

            case "I1":
                item2 = new SECSItem(eSECS_FORMAT.I1, name, desc);
                break;

            case "I2":
                item2 = new SECSItem(eSECS_FORMAT.I2, name, desc);
                break;

            case "I4":
                item2 = new SECSItem(eSECS_FORMAT.I4, name, desc);
                break;

            case "I8":
                item2 = new SECSItem(eSECS_FORMAT.I8, name, desc);
                break;

            case "U1":
                item2 = new SECSItem(eSECS_FORMAT.U1, name, desc);
                break;

            case "U2":
                item2 = new SECSItem(eSECS_FORMAT.U2, name, desc);
                break;

            case "U4":
                item2 = new SECSItem(eSECS_FORMAT.U4, name, desc);
                break;

            case "U8":
                item2 = new SECSItem(eSECS_FORMAT.U8, name, desc);
                break;

            case "F4":
                item2 = new SECSItem(eSECS_FORMAT.F4, name, desc);
                break;

            case "F8":
                item2 = new SECSItem(eSECS_FORMAT.F8, name, desc);
                break;

            case "JIS-8":
            case "JIS8":
                item2 = new SECSItem(eSECS_FORMAT.JIS8, name, desc);
                break;
            }
            if (string.IsNullOrEmpty(data))
            {
                if (item2 != null)
                {
                    item2.Value = null;
                }
                return(item2);
            }
            if (item2 != null && (item2.Format == eSECS_FORMAT.ASCII || item2.Format == eSECS_FORMAT.JIS8 || item2.Format == eSECS_FORMAT.CHAR2))
            {
                item2.Value = data;
                return(item2);
            }
            if (item2 != null)
            {
                switch (item2.Format)
                {
                case eSECS_FORMAT.BINARY:
                {
                    byte[] binary = Str2SecsItem.GetBinary(data);
                    if (binary.Length <= 1)
                    {
                        item2.Value = binary[0];
                        return(item2);
                    }
                    item2.Value = binary;
                    return(item2);
                }

                case eSECS_FORMAT.BOOLEAN:
                {
                    bool[] boolean = Str2SecsItem.GetBoolean(data);
                    if (boolean.Length != 1)
                    {
                        item2.Value = boolean;
                        return(item2);
                    }
                    item2.Value = boolean[0];
                    return(item2);
                }

                case eSECS_FORMAT.I8:
                {
                    long[] numArray7 = Str2SecsItem.GetI8(data);
                    if (numArray7.Length != 1)
                    {
                        item2.Value = numArray7;
                        return(item2);
                    }
                    item2.Value = numArray7[0];
                    return(item2);
                }

                case eSECS_FORMAT.I1:
                {
                    sbyte[] numArray8 = Str2SecsItem.GetI1(data);
                    if (numArray8.Length != 1)
                    {
                        item2.Value = numArray8;
                        return(item2);
                    }
                    item2.Value = numArray8[0];
                    return(item2);
                }

                case eSECS_FORMAT.I2:
                {
                    short[] numArray9 = Str2SecsItem.GetI2(data);
                    if (numArray9.Length != 1)
                    {
                        item2.Value = numArray9;
                        return(item2);
                    }
                    item2.Value = numArray9[0];
                    return(item2);
                }

                case (eSECS_FORMAT)27:
                case (eSECS_FORMAT)29:
                case (eSECS_FORMAT)30:
                case (eSECS_FORMAT)31:
                    return(item2);

                case eSECS_FORMAT.I4:
                {
                    int[] numArray10 = Str2SecsItem.GetI4(data);
                    if (numArray10.Length != 1)
                    {
                        item2.Value = numArray10;
                        return(item2);
                    }
                    item2.Value = numArray10[0];
                    return(item2);
                }

                case eSECS_FORMAT.F8:
                {
                    double[] numArray11 = Str2SecsItem.GetF8(data);
                    if (numArray11.Length != 1)
                    {
                        item2.Value = numArray11;
                        return(item2);
                    }
                    item2.Value = numArray11[0];
                    return(item2);
                }

                case eSECS_FORMAT.F4:
                {
                    float[] numArray12 = Str2SecsItem.GetF4(data);
                    if (numArray12.Length != 1)
                    {
                        item2.Value = numArray12;
                        return(item2);
                    }
                    item2.Value = numArray12[0];
                    return(item2);
                }

                case (eSECS_FORMAT)37:
                case (eSECS_FORMAT)38:
                case (eSECS_FORMAT)39:
                case (eSECS_FORMAT)43:
                    return(item2);

                case eSECS_FORMAT.U8:
                {
                    ulong[] numArray13 = Str2SecsItem.GetU8(data);
                    if (numArray13.Length != 1)
                    {
                        item2.Value = numArray13;
                        return(item2);
                    }
                    item2.Value = numArray13[0];
                    return(item2);
                }

                case eSECS_FORMAT.U1:
                {
                    byte[] buffer2 = Str2SecsItem.GetU1(data);
                    if (buffer2.Length != 1)
                    {
                        item2.Value = buffer2;
                        return(item2);
                    }
                    item2.Value = buffer2[0];
                    return(item2);
                }

                case eSECS_FORMAT.U2:
                {
                    ushort[] numArray14 = Str2SecsItem.GetU2(data);
                    if (numArray14.Length != 1)
                    {
                        item2.Value = numArray14;
                        return(item2);
                    }
                    item2.Value = numArray14[0];
                    return(item2);
                }

                case eSECS_FORMAT.U4:
                {
                    uint[] numArray15 = Str2SecsItem.GetU4(data);
                    if (numArray15.Length != 1)
                    {
                        item2.Value = numArray15;
                        return(item2);
                    }
                    item2.Value = numArray15[0];
                    return(item2);
                }
                }
            }
            return(item2);
        }
Example #2
0
        public override SECSItem XElementToSECSItem(XElement element)
        {
            if (element == null)
            {
                return(null);
            }
            string   str  = element.Name.ToString().Trim().ToUpper();
            SECSItem item = null;

            if (str == "L")
            {
                item = new SECSItem(eSECS_FORMAT.LIST);
                using (IEnumerator <XElement> enumerator = element.Elements().GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        XElement element2 = enumerator.Current;
                        SECSItem child    = this.XElementToSECSItem(element2);
                        if (child != null)
                        {
                            item.Add(child);
                        }
                    }
                    goto IL_3F2;
                }
            }
            string data = element.Value.Trim();
            string key;

            switch (key = str)
            {
            case "A":
                item = new SECSItem(eSECS_FORMAT.ASCII)
                {
                    Value = data
                };
                break;

            case "B":
                item = new SECSItem(eSECS_FORMAT.BINARY)
                {
                    Value = Str2SecsItem.GetBinary(data)
                };
                break;

            case "BOOLEAN":
            {
                item = new SECSItem(eSECS_FORMAT.BOOLEAN);
                bool[] boolean = Str2SecsItem.GetBoolean(data);
                if (boolean.Length == 1)
                {
                    item.Value = boolean[0];
                }
                else
                {
                    item.Value = boolean;
                }
                break;
            }

            case "U1":
            {
                item = new SECSItem(eSECS_FORMAT.U1);
                byte[] buffer = Str2SecsItem.GetU1(data);
                if (buffer.Length == 1)
                {
                    item.Value = buffer[0];
                }
                else
                {
                    item.Value = buffer;
                }
                break;
            }

            case "U2":
            {
                item = new SECSItem(eSECS_FORMAT.U2);
                ushort[] numArray = Str2SecsItem.GetU2(data);
                if (numArray.Length == 1)
                {
                    item.Value = numArray[0];
                }
                else
                {
                    item.Value = numArray;
                }
                break;
            }

            case "U4":
            {
                item = new SECSItem(eSECS_FORMAT.U4);
                uint[] numArray2 = Str2SecsItem.GetU4(data);
                if (numArray2.Length == 1)
                {
                    item.Value = numArray2[0];
                }
                else
                {
                    item.Value = numArray2;
                }
                break;
            }

            case "U8":
            {
                item = new SECSItem(eSECS_FORMAT.U8);
                ulong[] numArray3 = Str2SecsItem.GetU8(data);
                if (numArray3.Length == 1)
                {
                    item.Value = numArray3[0];
                }
                else
                {
                    item.Value = numArray3;
                }
                break;
            }

            case "I1":
            {
                item = new SECSItem(eSECS_FORMAT.I1);
                sbyte[] numArray4 = Str2SecsItem.GetI1(data);
                if (numArray4.Length == 1)
                {
                    item.Value = numArray4[0];
                }
                else
                {
                    item.Value = numArray4;
                }
                break;
            }

            case "I2":
            {
                item = new SECSItem(eSECS_FORMAT.I2);
                short[] numArray5 = Str2SecsItem.GetI2(data);
                if (numArray5.Length == 1)
                {
                    item.Value = numArray5[0];
                }
                else
                {
                    item.Value = numArray5;
                }
                break;
            }

            case "I4":
            {
                item = new SECSItem(eSECS_FORMAT.I4);
                int[] numArray6 = Str2SecsItem.GetI4(data);
                if (numArray6.Length == 1)
                {
                    item.Value = numArray6[0];
                }
                else
                {
                    item.Value = numArray6;
                }
                break;
            }

            case "I8":
            {
                item = new SECSItem(eSECS_FORMAT.I8);
                long[] numArray7 = Str2SecsItem.GetI8(data);
                if (numArray7.Length == 1)
                {
                    item.Value = numArray7[0];
                }
                else
                {
                    item.Value = numArray7;
                }
                break;
            }

            case "CHAR2":
                item = new SECSItem(eSECS_FORMAT.CHAR2)
                {
                    Value = data
                };
                break;

            case "JIS8":
                item = new SECSItem(eSECS_FORMAT.JIS8)
                {
                    Value = data
                };
                break;
            }
IL_3F2:
            if (item != null)
            {
                if (element.Attribute("ItemName") != null)
                {
                    item.Name = element.Attribute("ItemName").Value;
                }
                if (element.Attribute("Count") != null)
                {
                    item.Length = int.Parse(element.Attribute("Count").Value);
                }
                if (element.Attribute("Fixed") != null)
                {
                    item.Fixed = (element.Attribute("Fixed").Value.Trim().ToUpper() == "TRUE");
                }
            }
            return(item);
        }