Exemplo n.º 1
0
        public void InitFromColonneSource(IColumnDeEasyQuery colonne, CODEQBase objetDeQuery)
        {
            m_colonneSource = colonne;

            CEasyQuery query = objetDeQuery.Query;

            if (query != null)
            {
                //cherche la source
                ITableDefinition  tableDef = null;
                IColumnDefinition colDef   = null;
                IsReadOnly  = true;
                Description = "";
                if (query.FindSource(colonne, objetDeQuery, out tableDef, out colDef))
                {
                    CColumnDefinitionSNMP colSnmp = colDef as CColumnDefinitionSNMP;
                    if (colSnmp != null)
                    {
                        if (tableDef is CTableDefinitionSNMP ||
                            tableDef is CTableDefinitionSnmpOfScalar)
                        {
                            Description = colSnmp.Description;
                            IsReadOnly  = colSnmp.IsReadOnly;
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        public bool SetSnmpValueForField(int nIdChampCustom, object value)
        {
            ITableDefinition  table = null;
            IColumnDefinition col   = null;

            CResultAErreurType <IObjetDeEasyQuery> resObj = TypeEntiteSnmp.FindSourceObjetInQuery();

            if (!resObj || resObj.DataType == null)
            {
                return(false);
            }

            IObjetDeEasyQuery objetSource = resObj.DataType;
            CEasyQuery        query       = objetSource.Query;
            IEnumerable <CChampEntiteFromQueryToChampCustom> lstChamps = TypeEntiteSnmp.ChampsFromQuery;
            CChampEntiteFromQueryToChampCustom champ = null;

            foreach (CChampEntiteFromQueryToChampCustom champTest in lstChamps)
            {
                if (champTest.IdChampCustom != null &&
                    champTest.IdChampCustom == nIdChampCustom)
                {
                    champ = champTest;
                    break;
                }
            }
            if (champ == null)
            {
                return(false);
            }

            if (query.FindSource(champ.Champ.ColonneSource, objetSource,
                                 out table,
                                 out col))
            {
                CEntiteSnmpPourSupervision ettPourSup = null;
                CColumnDefinitionSNMP      colSnmp    = col as CColumnDefinitionSNMP;

                if (colSnmp != null && !colSnmp.IsReadOnly)
                {
                    ISnmpData snmpVal = AbstractTypeAssignment.GetSnmpFromDotNet(colSnmp.SnmpType, value);
                    if (snmpVal == null && value != null)
                    {
                        snmpVal = new OctetString(value.ToString());
                    }
                    if (snmpVal != null)
                    {
                        string strIndex = Index;
                        if (champ.Champ.FormuleIndex != null)
                        {
                            if (ettPourSup == null)
                            {
                                ettPourSup = GetEntitePourSupervision(TypeEntiteSnmp.GetTypeEntitePourSupervision(null, false));
                            }
                            CContexteEvaluationExpression ctx = new CContexteEvaluationExpression(ettPourSup);
                            CResultAErreur restTmp            = champ.Champ.FormuleIndex.Eval(ctx);
                            if (restTmp && restTmp.Data != null)
                            {
                                strIndex = restTmp.Data.ToString();
                            }
                        }
                        if (!strIndex.StartsWith("."))
                        {
                            strIndex = "." + strIndex;
                        }
                        try
                        {
                            CInterrogateurSnmp agent = new CInterrogateurSnmp();
                            agent.Connexion.Version  = AgentSnmp.SnmpVersion;
                            agent.ConnexionIp        = AgentSnmp.SnmpIp;
                            agent.ConnexionPort      = AgentSnmp.SnmpPort;
                            agent.ConnexionCommunity = AgentSnmp.SnmpCommunaute;
                            CResultAErreur resTmp = agent.Set(colSnmp.OIDString + strIndex, snmpVal);
                            if (resTmp)
                            {
                                return(true);
                            }
                        }
                        catch
                        {
                        }
                    }
                }
            }
            return(false);
        }
Exemplo n.º 3
0
        //-----------------------------------------------------------------------
        //Si idsChampsAMettreAJour est vide, il faut tout mettre à jour
        public CResultAErreur SendToSnmp(bool bOnlyModifiés, params int[] idsChampsAMettreAJour)
        {
            CResultAErreur result = CResultAErreur.True;

            if (TypeEntiteSnmp == null)
            {
                return(result);
            }
            if (TypeEntiteSnmp.ReadOnly)
            {
                result.EmpileErreur(I.T("This is a readonly entity|20127"));
                return(result);
            }
            IEnumerable <CChampEntiteFromQueryToChampCustom> lstChamps = TypeEntiteSnmp.ChampsFromQuery;
            Dictionary <string, object>            lstValeurs          = new Dictionary <string, object>();
            CResultAErreurType <IObjetDeEasyQuery> resObj = TypeEntiteSnmp.FindSourceObjetInQuery( );

            if (!resObj || resObj.DataType == null)
            {
                result.EmpileErreur(resObj.Erreur);
                return(result);
            }

            IObjetDeEasyQuery objetSource = resObj.DataType;
            CEasyQuery        query       = objetSource.Query;

            Dictionary <string, string> dicOIDStringToChamp = new Dictionary <string, string>();
            CEntiteSnmpPourSupervision  ettPourSup          = null;

            foreach (CChampEntiteFromQueryToChampCustom champ in lstChamps)
            {
                if (champ.IdChampCustom != null && (idsChampsAMettreAJour.Length == 0 ||
                                                    idsChampsAMettreAJour.Contains(champ.IdChampCustom.Value)))
                {
                    CRelationElementAChamp_ChampCustom rel = CUtilElementAChamps.GetRelationToChamp(this, champ.IdChampCustom.Value);
                    if (rel != null && (bOnlyModifiés && (rel.Row.RowState == DataRowState.Added || rel.Row.RowState == DataRowState.Modified) ||
                                        !bOnlyModifiés))
                    {
                        object valeur = rel.Valeur;

                        ITableDefinition  table = null;
                        IColumnDefinition col   = null;
                        if (query.FindSource(champ.Champ.ColonneSource, objetSource,
                                             out table,
                                             out col))
                        {
                            CColumnDefinitionSNMP colSnmp = col as CColumnDefinitionSNMP;

                            if (colSnmp != null && !champ.Champ.IsReadOnly)
                            {
                                ISnmpData snmpVal = AbstractTypeAssignment.GetSnmpFromDotNet(colSnmp.SnmpType, valeur);
                                if (snmpVal == null && valeur != null)
                                {
                                    snmpVal = new OctetString(valeur.ToString());
                                }
                                if (snmpVal != null)
                                {
                                    string strIndex = Index;
                                    if (champ.Champ.FormuleIndex != null)
                                    {
                                        if (ettPourSup == null)
                                        {
                                            ettPourSup = GetEntitePourSupervision(TypeEntiteSnmp.GetTypeEntitePourSupervision(null, false));
                                        }
                                        CContexteEvaluationExpression ctx = new CContexteEvaluationExpression(ettPourSup);
                                        CResultAErreur restTmp            = champ.Champ.FormuleIndex.Eval(ctx);
                                        if (restTmp && restTmp.Data != null)
                                        {
                                            strIndex = restTmp.Data.ToString();
                                        }
                                    }
                                    if (!strIndex.StartsWith("."))
                                    {
                                        strIndex = "." + strIndex;
                                    }
                                    lstValeurs[colSnmp.OIDString + strIndex]          = snmpVal;
                                    dicOIDStringToChamp[colSnmp.OIDString + strIndex] = champ.ChampCustom.Nom;
                                }
                            }
                        }
                    }
                }
            }
            if (lstValeurs.Count > 0)
            {
                CInterrogateurSnmp agent = new CInterrogateurSnmp();
                agent.Connexion.Version  = AgentSnmp.SnmpVersion;
                agent.ConnexionIp        = AgentSnmp.SnmpIp;
                agent.ConnexionPort      = AgentSnmp.SnmpPort;
                agent.ConnexionCommunity = AgentSnmp.SnmpCommunaute;
                foreach (KeyValuePair <string, object> kv in lstValeurs)
                {
                    try
                    {
                        CResultAErreur resTmp = agent.Set(kv.Key, kv.Value);

                        if (!resTmp)
                        {
                            string strChamp = null;
                            if (dicOIDStringToChamp.TryGetValue(kv.Key, out strChamp))
                            {
                                result.EmpileErreur(new CErreurValidation(I.T("Entity @1 (@2), Field @3 : |20105", Libelle, Index, strChamp) + resTmp.Erreur.ToString(), resTmp.IsAvertissement));
                            }
                            else
                            {
                                result.EmpileErreur(resTmp.Erreur);
                            }
                            if (!result.IsAvertissement)
                            {
                                return(result);
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        result.EmpileErreur(new CErreurException(e));
                    }
                }
            }
            return(result);
        }