Ejemplo n.º 1
0
        /// <summary>
        /// Meldet sich als Verbraucher an eine Analyse an.
        /// </summary>
        /// <param name="analyser">Die Analyseeinheit.</param>
        public void RegisterPhase2(TSParser analyser)
        {
            // See if there is a well known table
            foreach (var tableType in typeof(WellKnownTable).Assembly.GetExportedTypes())
            {
                if (typeof(WellKnownTable).IsAssignableFrom(tableType))
                {
                    if (!tableType.IsAbstract)
                    {
                        if (WellKnownTable.GetWellKnownStream(tableType) == PID)
                        {
                            // Remember
                            SubItems[6].Text = tableType.Name;

                            // Create consumer
                            var parser = TableParser.Create(CountTable, tableType);

                            // Connect
                            analyser.SetFilter(PID, true, parser.AddPayload);

                            // Done
                            break;
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            string ConnectionString =
                "Data Source=USER-PC;" +
                "Initial Catalog= master;" +
                "Integrated Security = true;";

            //TableParser par = new TableParser(new Person());
            //    par.ShowProperties();
            //    par.ShowTypes();
            //    Console.WriteLine(par.CreateTableQuery());
            //    par.CreateTable(ConnectionString);
            //    Console.WriteLine("-----------------------------------------------------------");
            TableParser par1 = new TableParser(new PC());

            //par1.ShowProperties();
            //par1.ShowTypes();
            // Console.WriteLine(par1.CreateTableQuery());
            // par1.CreateTable(ConnectionString);
            Console.WriteLine("-----------------------------------------------------------");
            PC pc = new PC {
                Mark = "ASUS", Model = "LDP 1234", Price = 24999
            };
            PC pc1 = new PC {
                Mark = "ACER", Model = "ABC 1234", Price = 19800
            };
            PC pc2 = new PC {
                Mark = "HP", Model = "zzz 1234", Price = 12340
            };

            //Console.WriteLine(par1.InsertInTableQuery(pc));
            //par1.InsertInTable(ConnectionString,pc);
            par1.InsertInTable(ConnectionString, pc1);
            par1.InsertInTable(ConnectionString, pc2);
        }
Ejemplo n.º 3
0
        public void TestParserShouldAllowTableArgs()
        {
            TableParser parser = new TableParser();
            Table       table  = parser.LoadTable("|TableWithArgs|someArg|\n|field1|field2|\n|1.74|73|\n\n");

            Assert.AreEqual("someArg", table.GetTableArgAt(0));
        }
Ejemplo n.º 4
0
        public void FormatHtmlTableTest()
        {
            string md = @"
<table>
<tbody>
<tr>    <td>Column1</td>     <td>Column2</td>     <td>Column3</td> </tr>
<tr>
    <td>Column1 Row 1</td><td>Column2 Row 1</td><td>Column3 Row 1</td>
</tr>
<tr>    <td>Column1 Row 2</td>
    <td>Column2 Row 2</td><td>Column3 Row 2</td>
</tr>
<tr>
    <td>Column1 Row 3</td>
    <td>Column2 Row 3</td>
    <td>Column3 Row 3</td>
</tr></tbody></table></html>
";

            var parser = new TableParser();
            var niceMd = parser.FormatMarkdownTable(md);

            Console.WriteLine(niceMd);
            Assert.IsTrue(niceMd.Contains("		<td>Column3 Row 3</td>"), "Pipe is not formatted as expected");
        }
        public void HasNotAlignmentRows()
        {
            var grid = new Grid();

            grid.AddRow(new GridRow(new[] { new GridCell("a") }));
            grid.AddRow(new GridRow(new[] { new GridCell("-"), new GridCell(":-a") }));
            var table = new TableParser().Parse(grid);

            Assert.NotNull(table);
            Assert.Equal(2, table.Rows.Count);

            Assert.NotNull(table.Rows[0]);
            Assert.Single(table.Rows[0]);
            Assert.NotNull(table.Rows[0][0]);
            Assert.Equal("a", table.Rows[0][0].Value);
            Assert.Equal(Alignment.Undefined, table.Rows[0][0].Alignment);

            Assert.NotNull(table.Rows[1]);
            Assert.Equal(2, table.Rows[1].Count);

            Assert.NotNull(table.Rows[1][0]);
            Assert.Equal("-", table.Rows[1][0].Value);
            Assert.Equal(Alignment.Undefined, table.Rows[1][0].Alignment);

            Assert.NotNull(table.Rows[1][1]);
            Assert.Equal(":-a", table.Rows[1][1].Value);
            Assert.Equal(Alignment.Undefined, table.Rows[1][1].Alignment);
        }
Ejemplo n.º 6
0
        public void ToStringTable()
        {
            var els = "Extra really long string";

            var l1 = CA.ToList <string>("A", els, "", "");
            var l2 = CA.ToList <string>("B", "", els, "");

            //List<List<string>> ls = new List<List<string>>();
            //ls.Add(l1);
            //ls.Add(l2);

            var headers = TestData.listABCD;

            var list = new List <string>();

            list.AddRange(l1);
            list.AddRange(l2);

            var td = CA.OneDimensionArrayToTwoDirection(list.ToArray(), 4);

            //string[,] t = new string[]

            //cl.CmdTableTest();
            //CmdTableTests.CmdTable2Tests();

            var s = TableParser.ToStringTable(td);

            Console.WriteLine(s);
        }
Ejemplo n.º 7
0
    public IList <T> ToListOf <T>()
    {
        var result      = new List <T>();
        var theClass    = typeof(T);
        var tableParser = new TableParser(table);

        tableParser.Parse();
        IObjectCreationStrategy <T> objectCreationStrategy = null;

        if (theClass.HasAParameterlessPublicCtor())
        {
            objectCreationStrategy = new ObjectCtreationParameterlessCtorStrategy <T>(tableParser, culture);
        }
        else
        {
            objectCreationStrategy = new ObjectCreationCtorStrategy <T>(tableParser, culture);
        }

        foreach (var row in tableParser.Rows)
        {
            var obj = objectCreationStrategy.CreateObjectFromRow(row);
            if (obj != null)
            {
                result.Add(obj);
            }
        }

        return(result);
    }
Ejemplo n.º 8
0
        public void ParseMarkdownGridTableToDataTest()
        {
            string md = @"
+------------------------------------------+----------------+------------+
| Header 1                                 | Header 2       | Header 3   |
+==========================================+================+============+
| Column 1                                 | Column 2 Text  | Column 3   |
+------------------------------------------+----------------+------------+
| Column 4                                 | Column 5 Text  | Column 5.5 |
| and a bottle of Russian rum              |                |            |
| with broken glass                        |                |            |
+------------------------------------------+----------------+------------+
| Column 6                                 | Column 7 Text  | Column 8   |
+------------------------------------------+----------------+------------+
| Column 9                                 | Column 10 Text | Column 11  |
| ho ho and a bottle of rum                |                |            |
+------------------------------------------+----------------+------------+
";

            var parser = new TableParser();
            var data   = parser.ParseMarkdownToData(md);

            Console.WriteLine(data.Count);
            Console.WriteLine(parser.ToGridTableMarkdown(data));

            Assert.IsTrue(data.Count == 5, "Table should have returned 5 rows");
            Assert.IsTrue(data[2][0].Text.Contains("\nand a bottle of"));
        }
Ejemplo n.º 9
0
    public List <T> LoadTable <T>() where T : class, new()
    {
        DataTable table    = Data[typeof(T).Name];
        int       rowCount = table.Rows.Count;
        //使用首行创建TableParser,将这张表和一个数据类型绑定
        DataRow         firstRow    = table.Rows[0];
        TableParser <T> classParser = TableParser <T> .Create(firstRow);

        List <T> result = new List <T>();

        //读取其他行的信息到数据中
        for (int i = 1; i < rowCount; i++)
        {
            //
            if (classParser.Parse(table.Rows[i]) == null)
            {
                Log.Warning("第{0}行解析失败", i);
                continue;
            }
            //添加转换后的实例到列表并输出显示
            result.Add(classParser.Parse(table.Rows[i]));
            PrintResult <T>(result[i - 1]);
        }
        return(result);
    }
Ejemplo n.º 10
0
        public void CsvTableParserFromFileTest()
        {
            var parser    = new TableParser();
            var tableData = parser.ParseCsvFileToData(@"c:\temp\Names.csv", ",");

            Console.WriteLine(parser.ToGridTableMarkdown(tableData));
        }
Ejemplo n.º 11
0
 public ParseTableTest()
 {
     ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
     _excelExtensionsProvider    = new ExcelExtensions.Providers.Extensions();
     _parserProvider             = new Parser();
     _tableParser = new TableParser <ParseTableTestBaseModel>(_excelExtensionsProvider, _parserProvider);
 }
Ejemplo n.º 12
0
        public void TestParserFromFile()
        {
            TableParser parser = new TableParser();
            Dictionary <string, List <Table> > tables = parser.LoadTablesFromFile("../../TableParserTestContents.txt");

            Assert.AreEqual(1, tables.Count);
            Assert.AreEqual(3, tables["ImcTable"][0].RowsCount());
        }
Ejemplo n.º 13
0
        public void TestTokenizer()
        {
            TableParser parser = new TableParser();
            Table       table  = parser.LoadTable("|ImcTable|\n|altura|peso|imc|\n|1.74|73|24.11|\n|1.63|62|23.33|\n|1.52|51|22.07|");

            Assert.AreEqual(3, table.RowsCount());
            Assert.AreEqual(3, table.FieldsCount());
        }
Ejemplo n.º 14
0
        public void NextTokenShouldBeKey()
        {
            var parser = new TableParser();

            parser.ParseLine(0, "table", TokenType.Table).Single();

            Assert.AreEqual(TokenType.Key, parser.NextExpectedToken);
        }
Ejemplo n.º 15
0
        public void WordStartingWithTableIsNotRecognised()
        {
            var output = new TableParser().ParseLine(0, "  tabletest ", TokenType.Table).Single();

            var expectedOutput = new ParsedSpan(0, TokenType.Parameter, 2, "tabletest", Errors.Invalid);

            AreEqual(expectedOutput, output);
        }
Ejemplo n.º 16
0
        public void TableWithTabIsRecognised()
        {
            var output = new TableParser().ParseLine(0, " table\t", TokenType.Table).Single();

            var expectedOutput = new ParsedSpan(0, TokenType.Table, 1, "table", string.Format(Errors.ExpectsParam, "Table"));

            AreEqual(expectedOutput, output);
        }
        public void TestParseNullProcess()
        {
            var root         = new XElement(this.documentRoot);
            var startElement = TraverseUtils.TagElement(root, "Table");
            var parser       = new TableParser();

            parser.Parse(null, startElement);
        }
Ejemplo n.º 18
0
        private static void BuildDocumentation(string content, List <string> matches, string schemaName)
        {
            PGSchema schema = SchemaProcessor.GetSchema(schemaName);

            content = content.Replace("[DBName]", Program.Database.ToUpperInvariant());
            content = content.Replace("[SchemaName]", schemaName);

            content = SequenceParser.Parse(content, matches, SequenceProcessor.GetSequences(schemaName));
            content = TableParser.Parse(content, matches, schema.Tables);
            content = ViewParser.Parse(content, matches, schema.Views);
            content = SequenceParser.Parse(content, matches, schema.Sequences);
            content = MaterializedViewParser.Parse(content, matches, schema.MaterializedViews);
            content = FunctionParser.Parse(content, matches, schema.Functions);
            content = FunctionParser.ParseTriggers(content, matches, schema.TriggerFunctions);
            content = TypeParser.Parse(content, matches, schema.Types);

            foreach (PgTable table in schema.Tables)
            {
                Console.WriteLine("Generating documentation for table \"{0}\".", table.Name);
                TableRunner.Run(table);
            }


            foreach (PgFunction function in schema.Functions)
            {
                Console.WriteLine("Generating documentation for function \"{0}\".", function.Name);
                FunctionRunner.Run(function);
            }

            foreach (PgFunction function in schema.TriggerFunctions)
            {
                Console.WriteLine("Generating documentation for trigger function \"{0}\".", function.Name);
                FunctionRunner.Run(function);
            }

            foreach (PgMaterializedView materializedView in schema.MaterializedViews)
            {
                Console.WriteLine("Generating documentation for materialized view \"{0}\".", materializedView.Name);
                MaterializedViewRunner.Run(materializedView);
            }

            foreach (PgView view in schema.Views)
            {
                Console.WriteLine("Generating documentation for view \"{0}\".", view.Name);
                ViewRunner.Run(view);
            }
            foreach (PgType type in schema.Types)
            {
                Console.WriteLine("Generating documentation for type \"{0}\".", type.Name);
                TypeRunner.Run(type);
            }

            string targetPath = System.IO.Path.Combine(OutputPath, schemaName + ".html");

            FileHelper.WriteFile(content, targetPath);
        }
Ejemplo n.º 19
0
        public void ThenTheStorageHasTheFollowingEntries(Table table)
        {
            var tableParser = new TableParser();

            tableParser.InjectValues.From(_storage).To(table).Inject();
            foreach (var row in table.Rows)
            {
                StringAssert.AreEqualIgnoringCase(row[ColumnNames.Value], _storage[row[ColumnNames.Field]]);
            }
        }
Ejemplo n.º 20
0
    public virtual void ReLoad(string table, bool fileMode = false)
    {
        mItemArray = TableParser.Parse <T>(table, fileMode).ToList();

        // build the key-value map.
        for (int i = 0; i < mItemArray.Count; i++)
        {
            mKeyItemMap[mItemArray[i].Key()] = i;
        }
    }
Ejemplo n.º 21
0
    public virtual void ReLoad()
    {
        mItemArray = TableParser.Parse <T>(TableName(), true).ToList();

        // build the key-value map.
        for (int i = 0; i < mItemArray.Count; i++)
        {
            mKeyItemMap[mItemArray[i].Key()] = i;
        }
    }
Ejemplo n.º 22
0
    public virtual void ReLoad()
    {
        mItemArray = TableParser.Parse <T>(TableName());

        // build the key-value map.
        for (int i = 0; i < mItemArray.Length; i++)
        {
            mKeyItemMap[mItemArray[i].Key()] = i;
        }
    }
Ejemplo n.º 23
0
        public void ColumnInfoTest()
        {
            var data = GetTableData();

            var parser  = new TableParser();
            var colInfo = parser.GetColumnInfo(data);

            Assert.IsNotNull(colInfo);
            Console.WriteLine(JsonSerializationUtils.Serialize(colInfo));
        }
Ejemplo n.º 24
0
        public bool Recognize(TableParser _parser)
        {
            Stack <int>    States  = new Stack <int>();
            Stack <Symbol> Symbols = new Stack <Symbol>();
            Stack <Symbol> String  = new Stack <Symbol>();
            Stack <Symbol> Action  = new Stack <Symbol>();


            return(true);
        }
Ejemplo n.º 25
0
        public void DataToTableHtmlTest()
        {
            var data = GetTableData();

            var    parser = new TableParser();
            string html   = parser.ToTableHtml(data);

            Console.WriteLine(html);

            Assert.IsTrue(html.Contains("<td>Column 5 Text</td>"));
        }
Ejemplo n.º 26
0
        public void DataToMarkdownGridTableTest()
        {
            var data = GetTableData();

            var    parser = new TableParser();
            string html   = parser.ToGridTableMarkdown(data);

            Console.WriteLine(html);

            Assert.IsTrue(html.Contains("| ho ho and"));
        }
Ejemplo n.º 27
0
    // constructor.
    public void ReadFromFile(string Path)
    {
        // load from excel txt file.
        mItemArray = TableParser.Parse <T>(Path, TableType());

        // build the key-value map.
        for (int i = 0; i < mItemArray.Length; i++)
        {
            mKeyItemMap[mItemArray[i].Key()] = i;
        }
    }
Ejemplo n.º 28
0
    // constructor.
    internal TableManager()
    {
        // load from excel txt file.
        mItemArray = TableParser.Parse <T>(TableName());

        // build the key-value map.
        for (int i = 0; i < mItemArray.Length; i++)
        {
            mKeyItemMap[mItemArray[i].Key()] = i;
        }
    }
Ejemplo n.º 29
0
        public void TestContent(string tableName, string[] expectedColumns)
        {
            var path = TestContext.CurrentContext.TestDirectory + "../../../../resources/" + tableName;
            var ts   = new TableStatistics();

            ts.Read(path);
            var p   = new TableParser();
            var res = p.Read(ts, path);

            CollectionAssert.AreEqual(expectedColumns, res.Tables[0].Rows[0].Cells.Select(x => x.Value.Trim()).ToArray());
        }
        public void TestParseMissingEndTableTag()
        {
            var processorMock = new TagProcessorMock <TableProcessor>();
            var parser        = new TableParser();

            var root = new XElement(this.documentRoot);

            TraverseUtils.TagElement(root, "EndTable").Remove();
            var startElement = TraverseUtils.TagElement(root, "Table");

            parser.Parse(processorMock, startElement);
        }
Ejemplo n.º 31
0
 public WebExtractor()
 {
     _parser = new TableParser();
 }