Example #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            Stopwatch st = Stopwatch.StartNew();

            for (int i = 0; i < 1; i++)
            {
                st.Restart();
                MessageData md = new MessageData();
                MessageItem mi;

                mi = new MessageItem("", 3);
                md.AppendItem(mi);
                {
                    mi = new MessageItem(HComEnums.ItemFormat.I4, "DATAID", (int)2);
                    md.AppendItem(mi);
                    mi = new MessageItem(HComEnums.ItemFormat.I4, "CEID", (int)1920);
                    md.AppendItem(mi);
                    mi = new MessageItem("RPTIDCOUNT", 2);
                    md.AppendItem(mi);
                    {
                        mi = new MessageItem("RPTIDLIST", 2);
                        md.AppendItem(mi);
                        {
                            mi = new MessageItem(HComEnums.ItemFormat.U2, "RPTID", (ushort)222);
                            md.AppendItem(mi);
                            mi = new MessageItem("VCOUNT", 2);
                            md.AppendItem(mi);
                            {
                                mi = new MessageItem(HComEnums.ItemFormat.A, "VCOUNT", "0");
                                md.AppendItem(mi);
                                mi = new MessageItem(HComEnums.ItemFormat.A, "VCOUNT", "op1");
                                md.AppendItem(mi);
                            }
                        }

                        mi = new MessageItem("RPTIDLIST", 2);
                        md.AppendItem(mi);
                        {
                            mi = new MessageItem(HComEnums.ItemFormat.U2, "RPTID", (ushort)333);
                            md.AppendItem(mi);
                            mi = new MessageItem("VCOUNT", 2);
                            md.AppendItem(mi);
                            {
                                mi = new MessageItem(HComEnums.ItemFormat.A, "VCOUNT", "abcd");
                                md.AppendItem(mi);
                                mi = new MessageItem(HComEnums.ItemFormat.A, "VCOUNT", "op2");
                                md.AppendItem(mi);
                            }
                        }
                    }
                }

                XmlTextWriter writer = new XmlTextWriter(Console.Out);
                writer.Formatting = Formatting.None;
                XmlDocument xmldoc = md.GetLog(writer);
                Console.WriteLine();
                Console.WriteLine(xmldoc.InnerXml);
                Console.WriteLine("Get Byte to XML------");
                Console.WriteLine(md.GetData());

                MessageData mdRecv = new MessageData();
                mdRecv.SetData(md.GetData());
                mdRecv.GetLog(writer);
                Console.WriteLine();

                st.Stop();
                Console.WriteLine("Time Elapsed {0:000}:{1:000}", i, st.ElapsedMilliseconds);
            }
        }
Example #2
0
        private void AppendXML(MessageItem mi)
        {
            //build data to xml to used for log and process logic.

            try
            {
                XmlElement newNode = doc.CreateElement(mi.type.ToString());
                ////Alias
                if (!string.IsNullOrWhiteSpace(mi.name))
                {
                    XmlAttribute newAttributeAlias = doc.CreateAttribute("n");
                    newAttributeAlias.Value = mi.name;
                    newNode.Attributes.Append(newAttributeAlias);
                }

                ////Length
                XmlAttribute newAttributeLen = doc.CreateAttribute("l");
                switch (mi.type)
                {
                case HComEnums.ItemFormat.A: newAttributeLen.Value = ((string)mi.value).Length.ToString(); newNode.InnerText = (string)mi.value; break;

                case HComEnums.ItemFormat.B: newAttributeLen.Value = sizeof(byte).ToString(); newNode.InnerText = ((byte)mi.value).ToString(); break;

                case HComEnums.ItemFormat.Bool: newAttributeLen.Value = sizeof(bool).ToString(); newNode.InnerText = ((bool)mi.value).ToString(); break;

                case HComEnums.ItemFormat.F4: newAttributeLen.Value = sizeof(float).ToString(); newNode.InnerText = ((float)mi.value).ToString(); break;

                case HComEnums.ItemFormat.F8: newAttributeLen.Value = sizeof(double).ToString(); newNode.InnerText = ((double)mi.value).ToString(); break;

                case HComEnums.ItemFormat.I1: newAttributeLen.Value = sizeof(sbyte).ToString(); newNode.InnerText = ((sbyte)mi.value).ToString(); break;

                case HComEnums.ItemFormat.I2: newAttributeLen.Value = sizeof(short).ToString(); newNode.InnerText = ((short)mi.value).ToString(); break;

                case HComEnums.ItemFormat.I4: newAttributeLen.Value = sizeof(int).ToString(); newNode.InnerText = ((int)mi.value).ToString(); break;

                case HComEnums.ItemFormat.I8: newAttributeLen.Value = sizeof(long).ToString(); newNode.InnerText = ((long)mi.value).ToString(); break;

                case HComEnums.ItemFormat.JIS: newAttributeLen.Value = ((string)mi.value).Length.ToString(); newNode.InnerText = (string)mi.value; break;

                case HComEnums.ItemFormat.L: newAttributeLen.Value = mi.len.ToString(); break;

                case HComEnums.ItemFormat.U1: newAttributeLen.Value = sizeof(byte).ToString(); newNode.InnerText = ((byte)mi.value).ToString(); break;

                case HComEnums.ItemFormat.U2: newAttributeLen.Value = sizeof(ushort).ToString(); newNode.InnerText = ((ushort)mi.value).ToString(); break;

                case HComEnums.ItemFormat.U4: newAttributeLen.Value = sizeof(uint).ToString(); newNode.InnerText = ((uint)mi.value).ToString(); break;

                case HComEnums.ItemFormat.U8: newAttributeLen.Value = sizeof(ulong).ToString(); newNode.InnerText = ((ulong)mi.value).ToString(); break;

                case HComEnums.ItemFormat.W: newAttributeLen.Value = sizeof(ushort).ToString(); newNode.InnerText = ((ushort)mi.value).ToString(); break;
                }
                newNode.Attributes.Append(newAttributeLen);

                XmlNode previousNode = FindPreviousList(lastAddedNode);
                if (previousNode != null)
                {
                    previousNode.AppendChild(newNode);
                }
                else
                {
                    if (doc.HasChildNodes)
                    {
                        throw new Exception("List Unmatched.");
                    }
                    doc.AppendChild(newNode);
                }

                lastAddedNode = newNode;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }