internal override bool CheckSecsItemFormat(ref SECSItem rcvd, ref SECSItem format) { bool result; try { if (rcvd.Format != format.Format) { result = false; } else if (format.Format == eSECS_FORMAT.LIST) { if (rcvd.ItemCount < format.ItemCount) { for (int i = 0; i < rcvd.ItemCount; i++) { SECSItem item = format.Item(i + 1); SECSItem item2 = rcvd.Item(i + 1); if (!this.CheckSecsItemFormat(ref item2, ref item)) { result = false; return(result); } } rcvd.Name = format.Name; rcvd.Description = format.Description; result = true; } else { for (int j = 0; j < format.ItemCount; j++) { SECSItem item3 = format.Item(j + 1); SECSItem item4 = rcvd.Item(j + 1); if (!this.CheckSecsItemFormat(ref item4, ref item3)) { result = false; return(result); } } rcvd.Name = format.Name; rcvd.Description = format.Description; result = true; } } else { rcvd.Name = format.Name; rcvd.Description = format.Description; result = true; } } catch (Exception) { result = false; } return(result); }
public override XElement SECSItemToXElement(SECSItem root) { if (root == null) { return(null); } XElement element = new XElement("Item"); element.Add(new XElement("Name", new XText(root.Name))); element.Add(new XElement("Description", new XText(root.Description))); if (root.Format == eSECS_FORMAT.LIST) { XElement element2 = new XElement("Format", new XText("List")); element.Add(element2); for (int i = 0; i < root.ItemCount; i++) { XElement element3 = this.SECSItemToXElement(root.Item(i + 1)); element.Add(element3); } return(element); } XElement element4 = new XElement("Format"); XText text = null; eSECS_FORMAT format = root.Format; if (format <= eSECS_FORMAT.I4) { switch (format) { case eSECS_FORMAT.BINARY: text = new XText("Binary"); break; case eSECS_FORMAT.BOOLEAN: text = new XText("Boolean"); break; default: switch (format) { case eSECS_FORMAT.ASCII: text = new XText("ASCII"); break; case eSECS_FORMAT.JIS8: text = new XText("JIS8"); break; case eSECS_FORMAT.CHAR2: text = new XText("CHAR2"); break; case eSECS_FORMAT.I8: text = new XText("I8"); break; case eSECS_FORMAT.I1: text = new XText("I1"); break; case eSECS_FORMAT.I2: text = new XText("I2"); break; case eSECS_FORMAT.I4: text = new XText("I4"); break; } break; } } else if (format != eSECS_FORMAT.F8) { switch (format) { case eSECS_FORMAT.F4: text = new XText("F4"); break; case eSECS_FORMAT.U8: text = new XText("U8"); break; case eSECS_FORMAT.U1: text = new XText("U1"); break; case eSECS_FORMAT.U2: text = new XText("U2"); break; case eSECS_FORMAT.U4: text = new XText("U4"); break; } } else { text = new XText("F8"); } element4.Add(text); element.Add(element4); XElement element5 = new XElement("Value"); XText text2 = null; if (root.IsEmpty) { text2 = new XText(""); } else { eSECS_FORMAT format2 = root.Format; if (format2 <= eSECS_FORMAT.I4) { switch (format2) { case eSECS_FORMAT.BINARY: if (!root.IsArray) { text2 = new XText(root.Value.ToString().Trim()); } else { text2 = new XText(SecsItem2Str.GetBinaryStr((byte[])root.Value).Trim()); } break; case eSECS_FORMAT.BOOLEAN: if (!root.IsArray) { text2 = new XText(SecsItem2Str.GetBooleanStr(new bool[] { (bool)root.Value })); } else { text2 = new XText(SecsItem2Str.GetBooleanStr((bool[])root.Value)); } break; default: switch (format2) { case eSECS_FORMAT.ASCII: text2 = new XText((string)root.Value); break; case eSECS_FORMAT.JIS8: text2 = new XText((string)root.Value); break; case eSECS_FORMAT.CHAR2: text2 = new XText((string)root.Value); break; case eSECS_FORMAT.I8: if (!root.IsArray) { text2 = new XText(SecsItem2Str.GetI8Str(new long[] { (long)root.Value })); } else { text2 = new XText(SecsItem2Str.GetI8Str((long[])root.Value)); } break; case eSECS_FORMAT.I1: if (!root.IsArray) { text2 = new XText(SecsItem2Str.GetI1Str(new sbyte[] { (sbyte)root.Value })); } else { text2 = new XText(SecsItem2Str.GetI1Str((sbyte[])root.Value)); } break; case eSECS_FORMAT.I2: if (!root.IsArray) { text2 = new XText(SecsItem2Str.GetI2Str(new short[] { (short)root.Value })); } else { text2 = new XText(SecsItem2Str.GetI2Str((short[])root.Value)); } break; case eSECS_FORMAT.I4: if (!root.IsArray) { text2 = new XText(SecsItem2Str.GetI4Str(new int[] { (int)root.Value })); } else { text2 = new XText(SecsItem2Str.GetI4Str((int[])root.Value)); } break; } break; } } else if (format2 != eSECS_FORMAT.F8) { switch (format2) { case eSECS_FORMAT.F4: if (!root.IsArray) { text2 = new XText(SecsItem2Str.GetF4Str(new float[] { (float)root.Value })); } else { text2 = new XText(SecsItem2Str.GetF4Str((float[])root.Value)); } break; case eSECS_FORMAT.U8: if (!root.IsArray) { text2 = new XText(SecsItem2Str.GetU8Str(new ulong[] { (ulong)root.Value })); } else { text2 = new XText(SecsItem2Str.GetU8Str((ulong[])root.Value)); } break; case eSECS_FORMAT.U1: if (!root.IsArray) { text2 = new XText(SecsItem2Str.GetU1Str(new byte[] { (byte)root.Value })); } else { text2 = new XText(SecsItem2Str.GetU1Str((byte[])root.Value)); } break; case eSECS_FORMAT.U2: if (!root.IsArray) { text2 = new XText(SecsItem2Str.GetU2Str(new ushort[] { (ushort)root.Value })); } else { text2 = new XText(SecsItem2Str.GetU2Str((ushort[])root.Value)); } break; case eSECS_FORMAT.U4: if (!root.IsArray) { text2 = new XText(SecsItem2Str.GetU4Str(new uint[] { (uint)root.Value })); } else { text2 = new XText(SecsItem2Str.GetU4Str((uint[])root.Value)); } break; } } else if (root.IsArray) { text2 = new XText(SecsItem2Str.GetF8Str((double[])root.Value)); } else { text2 = new XText(SecsItem2Str.GetF8Str(new double[] { (double)root.Value })); } } element5.Add(text2); element.Add(element5); return(element); }
internal override bool CheckSecsItemFormat(ref SECSItem rcvd, ref SECSItem format) { bool result; try { if (rcvd.Format != format.Format) { result = false; } else if (format.Format == eSECS_FORMAT.LIST) { if (format.Fixed) { if (rcvd.ItemCount != format.Length) { result = false; } else { for (int i = 1; i <= format.ItemCount; i++) { SECSItem item = format.Item(i); SECSItem item2 = rcvd.Item(i); if (!this.CheckSecsItemFormat(ref item2, ref item)) { result = false; return(result); } } rcvd.Name = format.Name; rcvd.Description = format.Description; result = true; } } else if (rcvd.ItemCount > format.Length) { result = false; } else { for (int j = 1; j <= rcvd.ItemCount; j++) { SECSItem item3 = format.Item(1); SECSItem item4 = rcvd.Item(j); if (!this.CheckSecsItemFormat(ref item4, ref item3)) { result = false; return(result); } } rcvd.Name = format.Name; rcvd.Description = format.Description; result = true; } } else if (format.Format == eSECS_FORMAT.ASCII) { string str = (rcvd.Value as string) ?? ""; if (format.Fixed) { if (str.Length > format.Length) { result = false; } else { result = true; } } else if (str.Length > format.Length) { result = false; } else { result = true; } } else { result = true; } } catch (Exception) { result = false; } return(result); }
internal static string GetSecsItemStr(int level, SECSItem data) { StringBuilder builder = new StringBuilder(); for (int i = 0; i < level; i++) { builder.Append(" "); } eSECS_FORMAT format = data.Format; if (format == eSECS_FORMAT.LIST) { builder.Append("<L ["); builder.Append(data.ItemCount); builder.Append("]\n"); int itemCount = data.ItemCount; if (itemCount > 0) { for (int j = 0; j < itemCount; j++) { builder.Append(SecsItem2Str.GetSecsItemStr(level + 1, data.Item(j + 1))); } } for (int k = 0; k < level; k++) { builder.Append(" "); } builder.Append(">\n"); } else { eSECS_FORMAT eSECSFORMAT = format; if (eSECSFORMAT <= eSECS_FORMAT.ASCII) { switch (eSECSFORMAT) { case eSECS_FORMAT.BINARY: if (data.IsEmpty) { builder.Append("<B [0] ''>\n"); } else { byte[] buffer; if (!data.IsArray) { buffer = new byte[] { (byte)data.Value }; } else { buffer = (byte[])data.Value; } string binaryStr = SecsItem2Str.GetBinaryStr(buffer); builder.Append("<B ["); builder.Append(buffer.Length); builder.Append("] '"); builder.Append(binaryStr); builder.Append("' >\n"); } break; case eSECS_FORMAT.BOOLEAN: if (!data.IsEmpty) { bool[] flagArray; if (!data.IsArray) { flagArray = new bool[] { (bool)data.Value }; } else { flagArray = (bool[])data.Value; } string booleanStr = SecsItem2Str.GetBooleanStr(flagArray); builder.Append("<BOOLEAN ["); builder.Append(flagArray.Length); builder.Append("] "); builder.Append(booleanStr); builder.Append(" >\n"); } break; default: if (eSECSFORMAT == eSECS_FORMAT.ASCII) { string str = ""; if (!data.IsEmpty) { str = (string)data.Value; } builder.Append("<A ["); builder.Append(str.Length); builder.Append("] '"); builder.Append(str); builder.Append("' >\n"); } break; } } else { switch (eSECSFORMAT) { case eSECS_FORMAT.I8: if (!data.IsEmpty) { long[] numArray8; if (!data.IsArray) { numArray8 = new long[] { (long)data.Value }; } else { numArray8 = (long[])data.Value; } string str2 = SecsItem2Str.GetI8Str(numArray8); builder.Append("<I8 ["); builder.Append(numArray8.Length); builder.Append("] "); builder.Append(str2); builder.Append(" >\n"); } break; case eSECS_FORMAT.I1: if (!data.IsEmpty) { sbyte[] numArray9; if (!data.IsArray) { numArray9 = new sbyte[] { (sbyte)data.Value }; } else { numArray9 = (sbyte[])data.Value; } string str3 = SecsItem2Str.GetI1Str(numArray9); builder.Append("<I1 ["); builder.Append(numArray9.Length); builder.Append("] "); builder.Append(str3); builder.Append(" >\n"); } break; case eSECS_FORMAT.I2: if (!data.IsEmpty) { short[] numArray10; if (!data.IsArray) { numArray10 = new short[] { (short)data.Value }; } else { numArray10 = (short[])data.Value; } string str4 = SecsItem2Str.GetI2Str(numArray10); builder.Append("<I2 ["); builder.Append(numArray10.Length); builder.Append("] "); builder.Append(str4); builder.Append(" >\n"); } break; case (eSECS_FORMAT)27: case (eSECS_FORMAT)29: case (eSECS_FORMAT)30: case (eSECS_FORMAT)31: break; case eSECS_FORMAT.I4: if (!data.IsEmpty) { int[] numArray11; if (!data.IsArray) { numArray11 = new int[] { (int)data.Value }; } else { numArray11 = (int[])data.Value; } string str5 = SecsItem2Str.GetI4Str(numArray11); builder.Append("<I4 ["); builder.Append(numArray11.Length); builder.Append("] "); builder.Append(str5); builder.Append(" >\n"); } break; case eSECS_FORMAT.F8: if (!data.IsEmpty) { double[] numArray12; if (data.IsArray) { numArray12 = (double[])data.Value; } else { numArray12 = new double[] { (double)data.Value }; } string str6 = SecsItem2Str.GetF8Str(numArray12); builder.Append("<F8 ["); builder.Append(numArray12.Length); builder.Append("] "); builder.Append(str6); builder.Append(" >\n"); } break; default: switch (eSECSFORMAT) { case eSECS_FORMAT.F4: if (!data.IsEmpty) { float[] numArray13; if (!data.IsArray) { numArray13 = new float[] { (float)data.Value }; } else { numArray13 = (float[])data.Value; } string str7 = SecsItem2Str.GetF4Str(numArray13); builder.Append("<F4 ["); builder.Append(numArray13.Length); builder.Append("] "); builder.Append(str7); builder.Append(" >\n"); } break; case eSECS_FORMAT.U8: if (!data.IsEmpty) { ulong[] numArray14; if (!data.IsArray) { numArray14 = new ulong[] { (ulong)data.Value }; } else { numArray14 = (ulong[])data.Value; } string str8 = SecsItem2Str.GetU8Str(numArray14); builder.Append("<U8 ["); builder.Append(numArray14.Length); builder.Append("] "); builder.Append(str8); builder.Append(" >\n"); } break; case eSECS_FORMAT.U1: if (!data.IsEmpty) { byte[] buffer2; if (!data.IsArray) { buffer2 = new byte[] { (byte)data.Value }; } else { buffer2 = (byte[])data.Value; } string str9 = SecsItem2Str.GetU1Str(buffer2); builder.Append("<U1 ["); builder.Append(buffer2.Length); builder.Append("] "); builder.Append(str9); builder.Append(" >\n"); } break; case eSECS_FORMAT.U2: if (!data.IsEmpty) { ushort[] numArray15; if (!data.IsArray) { numArray15 = new ushort[] { (ushort)data.Value }; } else { numArray15 = (ushort[])data.Value; } string str10 = SecsItem2Str.GetU2Str(numArray15); builder.Append("<U2 ["); builder.Append(numArray15.Length); builder.Append("] "); builder.Append(str10); builder.Append(" >\n"); } break; case eSECS_FORMAT.U4: if (!data.IsEmpty) { uint[] numArray16; if (!data.IsArray) { numArray16 = new uint[] { (uint)data.Value }; } else { numArray16 = (uint[])data.Value; } string str11 = SecsItem2Str.GetU4Str(numArray16); builder.Append("<U4 ["); builder.Append(numArray16.Length); builder.Append("] "); builder.Append(str11); builder.Append(" >\n"); } break; } break; } } } return(builder.ToString()); }
public override XElement SECSItemToXElement(SECSItem root) { if (root == null) { return(null); } if (root.Format == eSECS_FORMAT.LIST) { XElement element = new XElement("L"); element.SetAttributeValue("Count", root.ItemCount.ToString(CultureInfo.InvariantCulture)); element.SetAttributeValue("Fixed", root.Fixed ? "True" : "False"); element.SetAttributeValue("ItemName", root.Name); for (int i = 1; i <= root.ItemCount; i++) { element.Add(this.SECSItemToXElement(root.Item(i))); } return(element); } XElement element2 = new XElement(SECSFormat2.Format2Str((int)root.Format)); element2.SetAttributeValue("Count", root.ItemCount.ToString(CultureInfo.InvariantCulture)); element2.SetAttributeValue("Fixed", root.Fixed ? "True" : "False"); element2.SetAttributeValue("ItemName", root.Name); if (root.IsEmpty) { element2.Value = ""; return(element2); } eSECS_FORMAT format = root.Format; if (format <= eSECS_FORMAT.I4) { switch (format) { case eSECS_FORMAT.BINARY: element2.Value = SecsItem2Str.GetBinaryStr(root.Value as byte[]); return(element2); case eSECS_FORMAT.BOOLEAN: if (!root.IsArray) { bool[] data = new bool[] { (bool)root.Value }; element2.Value = SecsItem2Str.GetBooleanStr(data); return(element2); } element2.Value = SecsItem2Str.GetBooleanStr(root.Value as bool[]); return(element2); case eSECS_FORMAT.ASCII: element2.Value = (string)root.Value; return(element2); case eSECS_FORMAT.JIS8: element2.Value = (string)root.Value; return(element2); case eSECS_FORMAT.CHAR2: element2.Value = (string)root.Value; return(element2); case (eSECS_FORMAT)19: case (eSECS_FORMAT)20: case (eSECS_FORMAT)21: case (eSECS_FORMAT)22: case (eSECS_FORMAT)23: case (eSECS_FORMAT)27: return(element2); case eSECS_FORMAT.I8: if (!root.IsArray) { long[] numArray9 = new long[] { (long)root.Value }; element2.Value = SecsItem2Str.GetI8Str(numArray9); return(element2); } element2.Value = SecsItem2Str.GetI8Str(root.Value as long[]); return(element2); case eSECS_FORMAT.I1: if (!root.IsArray) { sbyte[] numArray10 = new sbyte[] { (sbyte)root.Value }; element2.Value = SecsItem2Str.GetI1Str(numArray10); return(element2); } element2.Value = SecsItem2Str.GetI1Str(root.Value as sbyte[]); return(element2); case eSECS_FORMAT.I2: if (!root.IsArray) { short[] numArray11 = new short[] { (short)root.Value }; element2.Value = SecsItem2Str.GetI2Str(numArray11); return(element2); } element2.Value = SecsItem2Str.GetI2Str(root.Value as short[]); return(element2); case eSECS_FORMAT.I4: if (!root.IsArray) { int[] numArray12 = new int[] { (int)root.Value }; element2.Value = SecsItem2Str.GetI4Str(numArray12); return(element2); } element2.Value = SecsItem2Str.GetI4Str(root.Value as int[]); return(element2); } return(element2); } switch (format) { case eSECS_FORMAT.F8: { if (root.IsArray) { element2.Value = SecsItem2Str.GetF8Str(root.Value as double[]); return(element2); } double[] numArray13 = new double[] { (double)root.Value }; element2.Value = SecsItem2Str.GetF8Str(numArray13); return(element2); } case eSECS_FORMAT.F4: if (!root.IsArray) { float[] numArray14 = new float[] { (float)root.Value }; element2.Value = SecsItem2Str.GetF4Str(numArray14); return(element2); } element2.Value = SecsItem2Str.GetF4Str(root.Value as float[]); return(element2); case (eSECS_FORMAT)37: case (eSECS_FORMAT)38: case (eSECS_FORMAT)39: case (eSECS_FORMAT)43: return(element2); case eSECS_FORMAT.U8: if (!root.IsArray) { ulong[] numArray15 = new ulong[] { (ulong)root.Value }; element2.Value = SecsItem2Str.GetU8Str(numArray15); return(element2); } element2.Value = SecsItem2Str.GetU8Str(root.Value as ulong[]); return(element2); case eSECS_FORMAT.U1: if (!root.IsArray) { byte[] buffer = new byte[] { (byte)root.Value }; element2.Value = SecsItem2Str.GetU1Str(buffer); return(element2); } element2.Value = SecsItem2Str.GetU1Str(root.Value as byte[]); return(element2); case eSECS_FORMAT.U2: if (!root.IsArray) { ushort[] numArray16 = new ushort[] { (ushort)root.Value }; element2.Value = SecsItem2Str.GetU2Str(numArray16); return(element2); } element2.Value = SecsItem2Str.GetU2Str(root.Value as ushort[]); return(element2); case eSECS_FORMAT.U4: if (!root.IsArray) { uint[] numArray17 = new uint[] { (uint)root.Value }; element2.Value = SecsItem2Str.GetU4Str(numArray17); return(element2); } element2.Value = SecsItem2Str.GetU4Str(root.Value as uint[]); return(element2); } return(element2); }