//-----------------------------------------------------------
        public CResultAErreur WriteSnmpValue()
        {
            CResultAErreur result = CResultAErreur.True;
            CEntiteSnmp    entite = ElementAChamps as CEntiteSnmp;

            if (entite != null)
            {
                return(entite.SendToSnmp(false, ChampCustom.Id));
            }
            return(result);
        }
        //-----------------------------------------------------------
        public CResultAErreur UpdateSnmpValue()
        {
            CResultAErreur result = CResultAErreur.True;
            CEntiteSnmp    entite = ElementAChamps as CEntiteSnmp;

            if (entite != null)
            {
                return(entite.ReadChampSnmp(ChampCustom.Id));
            }
            return(result);
        }
        //----------------------------------------------------------------------
        public CResultAErreur UpdateValeurs(CContexteDonnee contexteDeBasePasEnEdition, IIndicateurProgression indicateurProgression)
        {
            if (Count == 0)
            {
                return(CResultAErreur.True);
            }
            CConteneurIndicateurProgression progress = CConteneurIndicateurProgression.GetConteneur(indicateurProgression);
            CResultAErreur result = CResultAErreur.True;
            //Lecture entite par entité pour optimiser la lecture
            Dictionary <CEntiteSnmp, HashSet <CChampCustom> > lstChamps = new Dictionary <CEntiteSnmp, HashSet <CChampCustom> >();

            progress.SetBornesSegment(0, Count);
            foreach (CCoupleEntiteSnmp_Champ couple in this)
            {
                HashSet <CChampCustom> set = null;
                if (!lstChamps.TryGetValue(couple.Entite, out set))
                {
                    set = new HashSet <CChampCustom>();
                    lstChamps[couple.Entite] = set;
                }
                set.Add(couple.ChampCustom);
            }

            CSessionClient session = CSousSessionClient.GetNewSousSession(this[0].Entite.ContexteDonnee.IdSession);

            session.OpenSession(new CAuthentificationSessionSousSession(this[0].Entite.ContexteDonnee.IdSession),
                                "SNMP", ETypeApplicationCliente.Service);
            using (CContexteDonnee ctxModif = new CContexteDonnee(session.IdSession, true, false))
            {
                int nIndex = 1;
                foreach (KeyValuePair <CEntiteSnmp, HashSet <CChampCustom> > kv in lstChamps)
                {
                    CEntiteSnmp        entite       = kv.Key.GetObjetInContexte(ctxModif) as CEntiteSnmp;
                    CInterrogateurSnmp dynamicAgent = new CInterrogateurSnmp();
                    dynamicAgent.Connexion = entite.AgentSnmp.GetNewSnmpConnexion();
                    CEntiteSnmpPourSupervision ettSup = null;
                    foreach (CChampCustom champ in kv.Value)
                    {
                        int nIdChamp = champ.Id;
                        if (entite.ReadChampSnmp(nIdChamp, dynamicAgent, ref ettSup))
                        {
                            entite.CopieValeurSnmpDansValeurChamp(nIdChamp);
                        }
                        progress.SetValue(nIndex++);
                    }
                }
                progress.SetValue(Count);
                ctxModif.SaveAll(true);
                System.Threading.Thread.Sleep(2000);
                session.CloseSession();
            }
            return(result);
        }
Beispiel #4
0
        /// /////////////////////////////////////////////
        private CResultAErreur MapEntitesFromSNMP(CAgentSnmpPourSupervision agent)
        {
            CResultAErreur      result      = CResultAErreur.True;
            HashSet <int>       entitesVues = new HashSet <int>();
            CListeObjetsDonnees lstEntites  = EntitesSnmp;

            foreach (CEntiteSnmpPourSupervision entiteFromSnmp in agent.Entites)
            {
                CEntiteSnmp entite = new CEntiteSnmp(ContexteDonnee);
                lstEntites.Filtre = new CFiltreData(CEntiteSnmp.c_champIndex + "=@1 and " +
                                                    CTypeEntiteSnmp.c_champId + "=@2",
                                                    entiteFromSnmp.Index,
                                                    entiteFromSnmp.TypeEntite.Id);
                if (lstEntites.Count == 0)
                {
                    entite = new CEntiteSnmp(ContexteDonnee);
                    entite.CreateNewInCurrentContexte();
                    entite.AgentSnmp = this;
                }
                else
                {
                    entite = lstEntites[0] as CEntiteSnmp;
                }
                result = entite.FillFromSnmp(entiteFromSnmp);
                if (!result)
                {
                    return(result);
                }
                entitesVues.Add(entite.Id);
            }
            foreach (CEntiteSnmp entite in EntitesSnmp)
            {
                entite.IsFromSnmp = entitesVues.Contains(entite.Id);
            }
            return(result);
        }
 //----------------------------------------------------------------------
 public void AddChamp(CEntiteSnmp entite, CChampCustom champ)
 {
     Add(new CCoupleEntiteSnmp_Champ(entite, champ));
 }
 //----------------------------------------------------------------------
 public CCoupleEntiteSnmp_Champ(CEntiteSnmp entite, CChampCustom champ)
 {
     m_entite      = entite;
     m_champCustom = champ;
 }