Exemplo n.º 1
0
        /**
         * @ 将IPListNode对象转换为JSON字符串
         * */
        public override void WriterJson(TextWriter writer)
        {
            writer.Write(Utilities.JSON_BRACKET_LEFT);
            int len = Count;

            for (int i = 0; i < len; i++)
            {
                var           item      = this[i];
                NodeValueType valueType = GetValueType(item.Value);
                string        keyName   = valueType.ToString().ToLower();

                if (valueType == (valueType & (NodeValueType.DICT | NodeValueType.ARRAY)))
                {
                    IPListNode node = (IPListNode)item;
                    node.WriterJson(writer);
                    string comma = Utilities.IsWriterComma(len, i, 1);
                    writer.Write(comma);
                }
                else
                {
                    FormatJson(writer, "", item);
                    string comma = Utilities.IsWriterComma(len, i, 1);
                    writer.Write(comma);
                }
            }
            writer.Write(Utilities.JSON_BRACKET_RIGHT);
        }
Exemplo n.º 2
0
        /**
         * @ 格式化值的输出
         * @ ht LdfHashtable对象
         * */
        protected virtual void FormatXml(XmlWriter writer, IPListNode ht)
        {
            string        result    = string.Empty;
            NodeValueType valueType = GetValueType(ht.Value);
            string        keyString = valueType.ToString().ToLower();

            writer.WriteStartElement(keyString);
            switch (valueType)
            {
            case NodeValueType.DATA:
                writer.WriteString(Convert.ToBase64String(ht.Value as byte[]));
                break;

            case NodeValueType.DATE:
                string plistDate = ht.Value.ObjToDateTime().ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss.ffffffZ");
                writer.WriteString(plistDate);
                break;

            //case "key":
            case NodeValueType.REAL:
            case NodeValueType.STRING:
            case NodeValueType.INTEGER:
                writer.WriteString(ht.Value.ToString());
                break;
            }
            writer.WriteEndElement();
        }
Exemplo n.º 3
0
        /**
         * @ 实现 IPListNode 接口
         * */
        public override void WriterXml(XmlWriter writer)
        {
            foreach (var item in properties)
            {
                NodeValueType valueType = GetValueType(item.Value);
                string        keyName   = valueType.ToString().ToLower();

                if (valueType == (valueType & (NodeValueType.DICT | NodeValueType.ARRAY)))
                {
                    writer.WriteStartElement(keyName);
                    IPListNode node = (IPListNode)item;
                    node.WriterXml(writer);
                    writer.WriteEndElement();
                }
                else
                {
                    FormatXml(writer, item);
                }
            }
        }
Exemplo n.º 4
0
        /**
         * @ 格式化值的输出
         * @ ht LdfHashtable对象
         * */
        protected virtual void FormatJson(TextWriter writer, string key, IPListNode ht)
        {
            string        result    = string.Empty;
            NodeValueType valueType = GetValueType(ht.Value);

            if (key.IsNotNullOrEmpty())
            {
                writer.Write(string.Format("{0}{1}{0}{2}", Utilities.JSON_QUOTES, key, Utilities.JSON_COLON));
            }
            string keyString = valueType.ToString().ToLower();

            switch (valueType)
            {
            case NodeValueType.DATA:
                string data = Convert.ToBase64String(ht.Value as byte[]);
                FormatJson(writer, data);
                break;

            case NodeValueType.DATE:
                long unixDate = ht.Value.ObjToLong();
                FormatJson(writer, unixDate);
                break;

            //case "key":
            case NodeValueType.STRING:
                FormatJson(writer, ht.Value);
                break;

            case NodeValueType.REAL:
            case NodeValueType.INTEGER:
                writer.Write(ht.Value);
                break;

            case NodeValueType.TRUE:
            case NodeValueType.FALSE:
                writer.Write(ht.Value.ObjToInt());
                break;
            }
        }