Exemplo n.º 1
0
        //---------------------------------------
        private DataTable GetTableSnmp(CTableDefinitionSNMP tableSNMP, params string[] strIdsColonnesSource)
        {
            List <uint[]> lstCols = new List <uint[]>();

            if (strIdsColonnesSource != null)
            {
                foreach (string strIdCol in strIdsColonnesSource)
                {
                    try
                    {
                        lstCols.Add(ObjectIdentifier.Convert(strIdCol));
                    }
                    catch { }
                }
            }
            DataTable table = m_interrogateur.GetTable(tableSNMP.OID, lstCols.ToArray());

            if (table != null)
            {
                foreach (DataColumn col in table.Columns)
                {
                    IColumnDefinition colSNMP = tableSNMP.Columns.FirstOrDefault(
                        c => c is CColumnDefinitionSNMP &&
                        ((CColumnDefinitionSNMP)c).OIDString == col.ColumnName);
                    if (colSNMP != null)
                    {
                        col.ColumnName = colSNMP.ColumnName;
                    }
                }
                return(table);
            }
            return(null);
        }
Exemplo n.º 2
0
 //-----------------------------------
 private static void FillListeTables(
     CEasyQuerySource laBase,
     IDefinition definition,
     List <ITableDefinition> lstToFill,
     CEasyQuerySourceFolder folderRacine)
 {
     foreach (IDefinition children in definition.Children)
     {
         if (children.Type == DefinitionType.Table)
         {
             CTableDefinitionSNMP table = FromDefinition(laBase, children, folderRacine);
             if (table != null)
             {
                 lstToFill.Add(table);
                 laBase.AddTable(table);
             }
         }
         else if (children.Type == DefinitionType.OidValueAssignment || children.Type == DefinitionType.Scalar)
         {
             CEasyQuerySourceFolder folder = folderRacine.GetSubFolderWithCreate(children.Name);
             if (folder != null && children.GetNumericalForm().Length > 0)
             {
                 folder.SetExtendedProperty(c_strExtendedPropertyOID, ObjectIdentifier.Convert(children.GetNumericalForm()));
             }
             if (children.Type == DefinitionType.Scalar)
             {
                 folder.SetExtendedProperty(c_strExtendedPropertyValue, new CValeurExtendedProprieteFolderSnmpScalar(ObjectIdentifier.Convert(children.GetNumericalForm())));
                 folder.ImageKey = CValeurExtendedProprieteFolderSnmpScalar.c_strImageScalar;
             }
             FillListeTables(laBase, children, lstToFill, folder);
         }
     }
 }
Exemplo n.º 3
0
        public System.Data.DataTable GetData(ITableDefinition tableDefinition)
        {
            DataTable            result    = null;
            CTableDefinitionSNMP tableSNMP = tableDefinition as CTableDefinitionSNMP;

            if (tableSNMP != null)
            {
                result = Messenger.ReadTable(VersionCode.V2,
                                             new IPEndPoint(IPAddress.Parse(m_strIp), m_nPort),
                                             new OctetString(m_strCommunaute),
                                             new ObjectIdentifier(tableSNMP.OID),
                                             1000);
                if (result != null)
                {
                    foreach (DataColumn col in result.Columns)
                    {
                        IColumnDefinition colSNMP = tableDefinition.Columns.FirstOrDefault(
                            c => c is CColumnDefinitionSNMP &&
                            ((CColumnDefinitionSNMP)c).OIDString == col.ColumnName);
                        if (colSNMP != null)
                        {
                            col.ColumnName = colSNMP.ColumnName;
                        }
                    }
                }
            }
            return(result);
        }
Exemplo n.º 4
0
        //---------------------------------------
        public DataTable GetData(ITableDefinition tableDefinition, params string[] strIdsColonnesSource)
        {
            CTableDefinitionSNMP tableSNMP = tableDefinition as CTableDefinitionSNMP;

            if (tableSNMP != null && m_interrogateur != null)
            {
                return(GetTableSnmp(tableSNMP, strIdsColonnesSource));
            }

            CTableDefinitionSnmpOfScalar tableScalars = tableDefinition as CTableDefinitionSnmpOfScalar;

            if (tableScalars != null && m_interrogateur != null)
            {
                return(GetTableScalars(tableScalars, strIdsColonnesSource));
            }

            return(null);
        }
Exemplo n.º 5
0
        //-----------------------------------
        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)
                        {
                            CColumnDefinitionSNMP newCol = new CColumnDefinitionSNMP();
                            newCol.ColumnName = col.Name;
                            newCol.OID        = col.GetNumericalForm();
                            newCol.DataType   = typeof(string);
                            table.AddColumn(newCol);
                        }
                    }
                }
            }
            return(table);
        }
Exemplo n.º 6
0
        //---------------------------------------
        private DataTable GetTableSnmp(CTableDefinitionSNMP tableSNMP, params string[] strIdsColonnesSource)
        {
            DateTime      dt      = DateTime.Now;
            List <uint[]> lstCols = new List <uint[]>();

            if (strIdsColonnesSource != null)
            {
                foreach (string strIdCol in strIdsColonnesSource)
                {
                    try
                    {
                        lstCols.Add(ObjectIdentifier.Convert(strIdCol));
                    }
                    catch { }
                }
            }
            DataTable table = m_agent.GetTable(tableSNMP.OID, lstCols.ToArray());

            if (table != null)
            {
                foreach (DataColumn col in table.Columns)
                {
                    IColumnDefinition colSNMP = tableSNMP.Columns.FirstOrDefault(
                        c => c is CColumnDefinitionSNMP &&
                        ((CColumnDefinitionSNMP)c).OIDString == col.ColumnName);
                    if (colSNMP != null)
                    {
                        col.ColumnName = colSNMP.ColumnName;
                    }
                }
                TimeSpan sp = DateTime.Now - dt;
                System.Console.WriteLine("Get snmp table :" + sp.TotalMilliseconds.ToString());
                return(table);
            }
            return(null);
        }
Exemplo n.º 7
0
        //-----------------------------------
        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;
            }
        }
Exemplo n.º 8
0
        //-----------------------------------
        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);
        }