示例#1
0
        public static ServerData SdoDeserializeServerData(byte[] data)
        {
            ServerData serverData = new ServerData();

            int dataLength = data.Length;
            int position = 0;
            int markCount = IsMarkByte(data[position]);

            while (markCount < 0 || dataLength < position || data[position] == 0)
            {
                position++;
                markCount = IsMarkByte(data[position]);
            }

            position++;

            for (int i = 0; i < markCount; i++)
            {
                while (data[position] != i + 1 || dataLength < position || data[position] == 0)
                {
                    position++;
                }

                if (dataLength < position || data[position] == 0)
                    return serverData;

                position++;

                switch (i + 1)
                {
                    case 1:
                        serverData.Id = SdoDeserializeString(data, ref position);
                        break;
                    case 2:
                        serverData.Status = SdoDeserializeString(data, ref position);
                        break;
                    case 3:
                        serverData.Text = SdoDeserializeString(data, ref position);
                        break;
                }
            }

            return serverData;
        }
示例#2
0
        private void WriteServerData(ServerData data)
        {
            XmlWriter xmlWriter = new XmlTextWriter("serverdata.xml", Encoding.UTF8);

            xmlWriter.WriteStartDocument();
            xmlWriter.WriteStartElement("serverdata");
            xmlWriter.WriteStartElement("id");
            xmlWriter.WriteString(data.Id);
            xmlWriter.WriteEndElement();
            xmlWriter.WriteStartElement("status");
            xmlWriter.WriteString(data.Status);
            xmlWriter.WriteEndElement();
            xmlWriter.WriteStartElement("text");
            xmlWriter.WriteString(data.Text);
            xmlWriter.WriteEndElement();
            xmlWriter.WriteEndElement();

            xmlWriter.Flush();
            xmlWriter.Close();
        }
示例#3
0
        public void SendResponse(ClientData clientData, NetworkStream stream)
        {
            ServerData serverData = new ServerData
            {
                Id = clientData.Id
            };

            try
            {
                serverData.Text = Helper.ProcessClientData(clientData);
                serverData.Status = "Success";
            }
            catch (Exception ex)
            {
                serverData.Text = ex.Message;
                serverData.Status = "Error";
            }

            byte[] buffer = Helper.SdoSerializeServerData(serverData);

            stream.Write(buffer, 0, buffer.Length);
            stream.Flush();
        }
示例#4
0
        public static byte[] SdoSerializeServerData(ServerData serverData)
        {
            byte[][] data = new byte[3][];

            data[0] = SdoSerializeString(serverData.Id);
            data[1] = SdoSerializeString(serverData.Status);
            data[2] = SdoSerializeString(serverData.Text);

            byte[] bytes = new byte[data[0].Length + data[1].Length + data[2].Length + 4];
            bytes[0] = 0xFB;

            int index = 1;
            for (int i = 1; i < 4; i++)
            {
                byte[] d = data[i - 1];

                bytes[index] = (byte)i;
                index++;
                d.CopyTo(bytes, index);
                index += d.Length;
            }

            return bytes;
        }