Beispiel #1
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();
        }
Beispiel #2
0
        public static IPListNode test2(IPListNode dict, string key)
        {
            IPListNode node = dict[key];

            if (node == null)
            {
                return(null);
            }

            return(test2(node, key));
        }
Beispiel #3
0
        /**
         * @ 设置节点的 Tag 属性
         * @ node 要设置的节点
         * @ token 当前要处理的json 对象
         * */
        private void SetNodeTag(IPListNode node, JToken token)
        {
            // 如果上级是数组不用设置 tag 的
            if (token.Parent.Type == JTokenType.Array)
            {
                return;
            }

            JProperty jproperty = (JProperty)token.Parent;

            node.Tag = jproperty.Name;
        }
Beispiel #4
0
        static void TestNormalXml()
        {
            XmlDict xd = new XmlDict();

            xd.Load("ms-persist.xml");
            string     v1 = xd["recipename"].Value.ToString();
            IPListNode l3 = xd["ingredlist"]["listitem 3"];
            string     v2 = l3.ToXmlString();

            Console.WriteLine("{0},{1},{2}", l3.Tag, l3.Order, l3.Value);
            int count = xd.Items.Count;

            Console.WriteLine(v1);
            Console.WriteLine(count);
        }
Beispiel #5
0
        /**
         * @ 转换JToken对象到IPListNode
         * */
        protected IPListNode SwitchJToken(JToken token)
        {
            IPListNode node = null;

            switch (token.Type)
            {
            case JTokenType.Array:
                node = new PListArray();
                SetNodeTag(node, token);
                node.ReaderJson(token);
                break;

            case JTokenType.Object:
                node = new PListDict();
                SetNodeTag(node, token);
                node.ReaderJson(token);
                break;

            default:
                node = new PListDict();
                if (token.Type == JTokenType.Property)
                {
                    JProperty  jproperty    = (JProperty)token;
                    IPListNode childrenNode = null;
                    if (jproperty.Value.Type == JTokenType.Array)
                    {
                        childrenNode = new PListArray();
                    }
                    else
                    {
                        childrenNode = new PListDict();
                    }

                    childrenNode.Tag = jproperty.Name;
                    ((PListDict)node).Add(childrenNode.Tag, childrenNode);
                    childrenNode.ReaderJson(jproperty.Value);
                }
                else
                {
                    // 如果上级是数组不用设置 tag 的
                    SetNodeTag(node, token);
                    JValue jValue = (JValue)token;
                    node.Value = jValue.Value;
                }
                break;
            }
            return(node);
        }
Beispiel #6
0
        /**
         * @ 将json字符串反序列化为plist对象
         * */
        public virtual IPListNode FromJson(string json)
        {
            IPListNode node  = null;
            JToken     token = JsonConvert.DeserializeObject <JToken>(json);

            if (token.Type == JTokenType.Array)
            {
                node = new PListArray();
            }
            else if (token.Type == JTokenType.Object)
            {
                node = new PListDict();
            }

            node.ReaderJson(token);

            return(node);
        }
Beispiel #7
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;
            }
        }