Exemplo n.º 1
0
        /// <summary>
        /// 在外节点上移除内节点
        /// </summary>
        /// <param name="parent">外节点</param>
        /// <param name="name">要移除内节点名称</param>
        //public static void Remove(this PiaNode parent, string name)
        //{
        //    //读取原本节点
        //    foreach (var nt in parent.ChildNodes)
        //    {
        //        if (nt.NodeName == name)
        //        {
        //            parent.ChildNodes.Remove(nt);
        //            break;
        //        }
        //    }
        //}

        /// <summary>
        /// 移除纸张
        /// </summary>
        /// <param name="parent">外节点</param>
        /// <param name="name">要移除内节点名称</param>
        public static void RemoveChildNodes(this PiaNode parent, string[] name)
        {
            //读取原本节点
            var pia = new List <PiaNode>();

            foreach (var nt in parent.ChildNodes)
            {
                foreach (var va in nt.Values)
                {
                    //string tem = va.Key;
                    if (va.Key == "name_str" && name.Contains(va.Value) /*name.Contains(va.Value)*/)
                    {
                        pia.Add(nt);
                        break;
                    }
                }
            }
            if (pia.Count != 0)
            {
                foreach (var item in pia)
                {
                    parent.ChildNodes.Remove(item);
                }
            }
        }
Exemplo n.º 2
0
 internal PlotStyle(PiaNode baseNode)
 {
     NodeName = baseNode.NodeName;
     Parent   = baseNode.Parent;
     Owner    = baseNode.Owner;
     Values   = baseNode.Values;
 }
Exemplo n.º 3
0
        /// <summary>
        /// 反序列化解压节点,加入InnerData的方法
        /// </summary>
        /// <param name="parent">文件主体</param>
        /// <param name="nodeString">注释</param>
        public static void DeserializeNode(this PiaNode parent, string nodeString)
        {
            if (parent == null && !(parent is PiaFile))
            {
                throw new ArgumentNullException("parent"); //参数空异常
            }
            if (nodeString == null)
            {
                throw new ArgumentNullException("nodeString"); //参数空异常
            }
            var dataLines = nodeString.Split
                                (new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);//删除空条目

            for (int i = 0; i < dataLines.Length; i++)
            {
                var curLine = dataLines[i];
                if (curLine.Contains('='))//有等号就获取属性
                {
                    var value = DeserializeValue(curLine);

                    if (!parent.Values.ContainsKey(value.Key))
                    {
                        parent.Values.Add(value.Key, value.Value);
                    }
                    else
                    {
                        parent.Values[value.Key] = value.Value;
                    }
                }
                else if (curLine.Contains('{'))// "meta{"
                {
                    var nodeBuilder = GetNodeInnerData(dataLines, i, out int n);

                    //添加内部数据
                    var childNode = new PiaNode(nodeBuilder)
                    {
                        NodeName = curLine.Trim().TrimEnd('{'), //名称
                        Parent   = parent,                      //来源
                        Owner    = parent.Owner                 //拥有者
                    };

                    parent.ChildNodes.Add(childNode); //每一个大括号内是一组

                    i = n - 1;
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// 在节点上添加新节点
        /// </summary>
        /// <param name="parent">数据节点</param>
        /// <param name="nodeString">要添加的信息</param>
        public static PiaNode Add(this PiaNode parent, string name, string nodeString = null)
        {
            var childNode = new PiaNode
            {
                NodeName = name,        //名称
                Parent   = parent,      //来源
                Owner    = parent.Owner //拥有者
            };

            if (!string.IsNullOrEmpty(nodeString))
            {
                //添加内部数据
                var getNodeInnerData = GetNodeInnerData(nodeString);
                childNode.DeserializeNode(getNodeInnerData); //加入InnerData的方法
            }
            parent.ChildNodes.Add(childNode);
            return(childNode);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 序列化节点(压缩)
        /// </summary>
        /// <param name="node">节点</param>
        /// <param name="level">节点数</param>
        /// <returns></returns>
        internal static string SerializeNode(this PiaNode node, int level = 0)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            var nodeBuilder = new StringBuilder();
            var whiteSpace  = new string(' ', level);

            foreach (var value in node.Values)
            {
                nodeBuilder.AppendFormat("{0}{1}\n", whiteSpace, SerializeValue(value));
            }

            foreach (var child in node.ChildNodes)
            {
                nodeBuilder.AppendFormat("{0}{1}{2}\n", whiteSpace, child.NodeName, "{");
                nodeBuilder.Append(SerializeNode(child, level + 1));
                nodeBuilder.AppendFormat("{0}{1}\n", whiteSpace, "}");
            }

            return(nodeBuilder.ToString());
        }