//---------------------------------------------------
        public static CColumnDefinitionSNMP FromDefinition(IDefinition definition)
        {
            CColumnDefinitionSNMP col = new CColumnDefinitionSNMP();

            col.ColumnName = definition.Name;
            col.OID        = definition.GetNumericalForm();
            col.DataType   = typeof(string);
            return(col);
        }
Exemple #2
0
        //-----------------------------------
        public override CResultAErreur GetDatas(CEasyQuerySource source, params string[] strIdsColonnesSources)
        {
            CResultAErreur result  = CResultAErreur.True;
            List <string>  strCols = new List <string>();

            foreach (IColumnDefinition col in Columns)
            {
                CColumnDefinitionSNMP colSnmp = col as CColumnDefinitionSNMP;
                if (colSnmp != null)
                {
                    if (strIdsColonnesSources.Contains(colSnmp.Id))
                    {
                        strCols.Add(colSnmp.OIDString);
                    }
                }
            }
            DataTable table = source.GetTable(this, strCols.ToArray());

            if (table != null)
            {
                //Vérifie les types de colonnes, pour éviter les pbs de déclaration dans la mib (merci assentria)
                foreach (IColumnDefinition col in Columns)
                {
                    CColumnDefinitionSNMP colSnmp = col as CColumnDefinitionSNMP;
                    if (colSnmp != null)
                    {
                        DataColumn colDeTable = table.Columns[colSnmp.ColumnName];
                        if (colDeTable != null && colDeTable.DataType != col.DataType)
                        {
                            colSnmp.SnmpType = null;
                            colSnmp.DataType = colDeTable.DataType;
                        }
                    }
                }
            }
            object a = Columns;

            result.Data = table;
            return(result);
        }
        //-----------------------------------
        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);
        }
Exemple #4
0
        //---------------------------------------
        private DataTable GetTableScalars(CTableDefinitionSnmpOfScalar tableScalar, 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 { }
                }
            }

            List <Variable> lstVariables = new List <Variable>();

            if (lstCols.Count == 0)
            {
                foreach (IColumnDefinition col in tableScalar.Columns)
                {
                    CColumnDefinitionSNMP colSnmp = col as CColumnDefinitionSNMP;
                    if (colSnmp != null)
                    {
                        lstVariables.Add(new Variable(ObjectIdentifier.Convert(colSnmp.OIDString + ".0")));
                    }
                }
            }
            else
            {
                foreach (uint[] oid in lstCols)
                {
                    lstVariables.Add(new Variable(new ObjectIdentifier(ObjectIdentifier.Convert(oid) + ".0")));
                }
            }
            IList <Variable> lstRetour = new List <Variable>();

            if (tableScalar.RemplissageOptimise)
            {
                lstRetour = m_interrogateur.Get(lstVariables);
            }
            else
            {
                foreach (Variable v in lstVariables)
                {
                    object res = m_interrogateur.Get(v.Id.ToString());
                    if (res is ISnmpData)
                    {
                        Variable vTmp = new Variable(v.Id, res as ISnmpData);
                        lstRetour.Add(vTmp);
                    }
                }
            }


            DataTable table = new DataTable(tableScalar.TableName);
            Dictionary <DataColumn, string> valeurs = new Dictionary <DataColumn, string>();

            foreach (Variable var in lstRetour)
            {
                DataColumn        col     = new DataColumn();
                IColumnDefinition colSNMP = tableScalar.Columns.FirstOrDefault(
                    c => c is CColumnDefinitionSNMP &&
                    ((CColumnDefinitionSNMP)c).OIDString + ".0" == var.Id.ToString());
                if (colSNMP != null)
                {
                    col.ColumnName = colSNMP.ColumnName;
                }
                else
                {
                    col.ColumnName = var.Id.ToString();
                }
                col.DataType = colSNMP.DataType;
                if (!table.Columns.Contains(col.ColumnName))
                {
                    table.Columns.Add(col);
                }
                valeurs[col] = var.Data == null ? "":var.Data.ToString();
            }
            DataRow row = table.NewRow();

            foreach (KeyValuePair <DataColumn, string> kv in valeurs)
            {
                try
                {
                    row[kv.Key] = kv.Value;
                }
                catch { }
            }
            table.Rows.Add(row);
            return(table);
        }
Exemple #5
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;
            }
        }
Exemple #6
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);
        }