Exemplo n.º 1
0
        public static IBaseBlock[] Create(Section[] sections)
        {
            TextBlock b = new TextBlock();

            foreach (var section in sections)
            {
                if (section.NoData)// header section
                {
                    var list = section.Sections;
                    for (int i = 0, l = list.Count; i < l; i++)
                    {
                        var sub = list[i];
                        var t   = new Tag(sub.BlockId, i);
                        if (TextBlockParser.ParseHeader(t, sub.Data))
                        {
                            b.List.Add(t);
                        }
                        else
                        {
                            return(new[] { new InvalidBlock(BLOCK_ID, sections)
                                           .AddMessage(string.Format("Invalid header block {0}.", sub.BlockId)) });
                        }
                    }
                }
                else
                {
                    if (TextBlockParser.IsDataBlock(section))
                    {
                        string errorMessage; IList <Tag> tags;
                        if (TextBlockParser.Parse(section.Data, out errorMessage, out tags))
                        {
                            foreach (var t in tags)
                            {
                                b.List.Add(t);
                            }
                        }
                        else
                        {
                            return(new[] {
                                new InvalidBlock(BLOCK_ID, sections).AddMessage(errorMessage)
                            });
                        }
                    }
                    else
                    {
                        return(new[] { new InvalidBlock(BLOCK_ID, sections)
                                       .AddMessage("Invalid data block.") });
                    }
                }
            }
            return(new[] { b });
        }
Exemplo n.º 2
0
        public static IBaseBlock[] Create(Section[] sections)
        {
            var b = new TrailerBlock();

            for (int i = 0, l = sections.Length; i < l; i++)
            {
                var headers = sections[i].Sections;
                for (int j = 0, jl = headers.Count; j < jl; j++)
                {
                    var header = headers[j];
                    var t      = new Tag(header.BlockId, j);
                    if (TextBlockParser.ParseHeader(t, header.Data))
                    {
                        b.List.Add(t);
                    }
                    else
                    {
                        return(new[] { new InvalidBlock(BLOCK_ID, sections)
                                       .AddMessage(string.Format("Invalid header block {0}.", header.BlockId)) });
                    }
                }
            }
            return(new[] { b });
        }