public void Test1() { const string test = @"someObjectName ::= TEXTUAL-CONVENTION STATUS current DESCRIPTION ""A multi line description"" SYNTAX INTEGER { first(0), second(100) }"; Lexer lexer = new Lexer(); StringReader reader = new StringReader(test); lexer.Parse(reader); string name = lexer.NextSymbol.ToString(); lexer.NextSymbol.Expect(Symbol.Assign); lexer.NextSymbol.Expect(Symbol.TextualConvention); var tc = new TextualConvention(string.Empty, name, lexer); Assert.AreEqual(name, tc.Name); Assert.IsNull(tc.Reference); Assert.AreEqual(typeof(IntegerType), tc.Syntax.GetType()); Assert.AreEqual(Status.current, tc.Status); Assert.IsNull(tc.DisplayHint); Assert.AreEqual("A multi line\n description", tc.Description); }
//----------------------------------- private static void FillListeTables( CEasyQuerySource laBase, IDefinition definition, List <ITableDefinition> lstToFill, CEasyQuerySourceFolder folderRacine) { CTableDefinitionSnmpOfScalar tableScalars = null; if (definition.Entity != null) { tableScalars = new CTableDefinitionSnmpOfScalar(); tableScalars.OIDRacine = definition.GetNumericalForm(); tableScalars.TableName = folderRacine.Name + "_Scalars"; tableScalars.FolderId = folderRacine.Id; } foreach (IDefinition children in definition.Children) { if (children.Type == DefinitionType.Table) { CTableDefinitionSNMP table = FromDefinition(laBase, children, folderRacine); if (table != null) { lstToFill.Add(table); laBase.AddTableUniquementPourObjetConnexion(table); } } else if (children.Type == DefinitionType.OidValueAssignment) { CEasyQuerySourceFolder folder = folderRacine.GetSubFolderWithCreate(children.Name); FillListeTables(laBase, children, lstToFill, folder); } else if (children.Type == DefinitionType.Scalar) { if (children.Type == DefinitionType.Scalar && tableScalars != null) { CColumnDefinitionSNMP colSnmp = new CColumnDefinitionSNMP(); colSnmp.ColumnName = children.Name; colSnmp.OID = children.GetNumericalForm(); Type tp = typeof(string); ObjectType objType = children.Entity as ObjectType; if (objType != null) { TextualConvention conv = objType.Syntax as TextualConvention; if (conv != null) { tp = ((AbstractTypeAssignment)conv.Syntax).GetTypeDotNet(); } else { AbstractTypeAssignment abs = objType.Syntax as AbstractTypeAssignment; if (abs != null) { tp = abs.GetTypeDotNet(); } } } switch (objType.Access) { case MaxAccess.accessibleForNotify: case MaxAccess.readOnly: colSnmp.IsReadOnly = true; break; case MaxAccess.readWrite: case MaxAccess.readCreate: colSnmp.IsReadOnly = false; break; } colSnmp.DataType = tp; tableScalars.AddColumn(colSnmp); } } } if (tableScalars != null && tableScalars.Columns.Count() > 0) { laBase.AddTableUniquementPourObjetConnexion(tableScalars); tableScalars.Base = laBase; } }
//----------------------------------- public static CTableDefinitionSNMP FromDefinition( CEasyQuerySource laBase, IDefinition def, CEasyQuerySourceFolder folder ) { CTableDefinitionSNMP table = null; if (def.Type == DefinitionType.Table) { table = new CTableDefinitionSNMP(laBase); table.TableName = def.Name; table.OID = def.GetNumericalForm(); if (folder != null) { table.FolderId = folder.Id; } if (def.Children.Count() == 1) { CColumnDefinitionSimple colIndex = new CColumnDefinitionSimple("Index", typeof(string)); table.AddColumn(colIndex); IDefinition entry = def.Children.ElementAt(0); foreach (IDefinition col in entry.Children) { if (col.Type == DefinitionType.Column) { ObjectType objType = col.Entity as ObjectType; if (objType != null && objType.Access != MaxAccess.notAccessible) { CColumnDefinitionSNMP newCol = new CColumnDefinitionSNMP(); newCol.ColumnName = col.Name; newCol.Description = col.Description; newCol.OID = col.GetNumericalForm(); TextualConvention conv = objType.Syntax as TextualConvention; if (conv != null) { newCol.SnmpType = conv.Syntax as AbstractTypeAssignment; } else { newCol.SnmpType = objType.Syntax as AbstractTypeAssignment; } if (newCol.SnmpType == null) { newCol.DataType = typeof(string); newCol.IsReadOnly = true; } switch (objType.Access) { case MaxAccess.accessibleForNotify: case MaxAccess.readOnly: newCol.IsReadOnly = true; break; case MaxAccess.readWrite: case MaxAccess.readCreate: newCol.IsReadOnly = false; break; } table.AddColumn(newCol); } } } } } return(table); }