示例#1
0
            public static void ConvertTable(
                Stream inStream,
                Stream outStream,
                ReadMTableItem readItem,
                WriteMTableItem writeItem,
                GetMTableItemSize getItemSize)
            {
                var list = ReadTable(inStream, readItem);

                WriteTable(outStream, list, writeItem, getItemSize);
            }
示例#2
0
            private static Node ReadMTable(Stream stream, ReadMTableItem readItem)
            {
                var root = new Node();

                using (var parser = new TextFieldParser(stream))
                {
                    parser.SetDelimiters(",");
                    parser.ReadLine();

                    while (!parser.EndOfData)
                    {
                        var fields   = parser.ReadFields();
                        var curLevel = root;

                        int i = 0;
                        for (i = 0; i < 10 && fields[i] != ":"; i++)
                        {
                            if (fields[i] == "")
                            {
                                continue;
                            }

                            string key = fields[i];
                            Node   child;
                            if (curLevel.Children == null)
                            {
                                curLevel.Children = new List <Node>();
                            }
                            var children = (List <Node>)curLevel.Children;
                            if (children.Count == 0 || key != children[children.Count - 1].Name)
                            {
                                child      = new Node();
                                child.Name = key;
                                children.Add(child);
                                curLevel = child;
                            }
                            else
                            {
                                curLevel = children[children.Count - 1];
                            }
                        }

                        for (i++; i < fields.Length && fields[i] == ""; i++)
                        {
                        }

                        curLevel.Children = readItem(fields, i);
                    }
                }
                return(root);
            }
示例#3
0
            private static List <Node> ReadTable(Stream stream, ReadMTableItem readItem)
            {
                var list = new List <Node>();

                using (var parser = new TextFieldParser(stream))
                {
                    parser.SetDelimiters(",");
                    parser.ReadLine();              // Skip the header

                    while (!parser.EndOfData)
                    {
                        var fields = parser.ReadFields();
                        var key    = fields[0];
                        var node   = new Node();
                        node.Name  = key;
                        node.Child = readItem(fields, 1);
                        list.Add(node);
                    }
                }
                return(list);
            }