public CResultAErreur RecalculeParametresHotelPolling() { //Trouve le setup system List <CSnmpHotelPollingSetup> lstSetups = ParametresHotelPollingList; CSnmpHotelPollingSetup setup = null; foreach (CSnmpHotelPollingSetup s in lstSetups) { if (s.Id.StartsWith(CSnmpHotelPollingSetup.c_IdPollingSystem)) { setup = s; break; } } if (setup == null) { CMemoryDb db = new CMemoryDb(); setup = new CSnmpHotelPollingSetup(db); setup.CreateNew(); setup.Id = CSnmpHotelPollingSetup.c_IdPollingSystem + sc2i.common.CUniqueIdentifier.GetNew(); setup.Libelle = "System"; setup.HotelPort = CSnmpPollingHotelClient.HotelPollingServerPort; lstSetups.Add(setup); } if (setup.HotelPort == 0) { setup.HotelPort = CSnmpPollingHotelClient.HotelPollingServerPort; } if (setup.HotelIp == null || setup.HotelIp.Length == 0) { setup.HotelIp = CSnmpPollingHotelClient.HotelPollingServerIp; } CListeSnmpHotelPolledData lstPolled = setup.PolledDatas; lstPolled.Clear(); CResultAErreur result = CResultAErreur.True; foreach (CEntiteSnmp entite in EntitesSnmp) { CResultAErreurType <IEnumerable <CSnmpHotelPolledData> > res = entite.GetSnmpHotelPolledData(); if (!res) { result.EmpileErreur(res.Erreur); result.EmpileErreur(I.T("Error in entity @1|20259", entite.Libelle)); } else if (res.DataType is IEnumerable <CSnmpHotelPolledData> ) { foreach (CSnmpHotelPolledData data in res.DataType) { lstPolled.Add(data); } } } setup.PolledDatas = lstPolled; CommitParametresHotelPolling(); return(result); }
//--------------------------------------------- /// ///////////////////////////////////////////// public CAgentSnmpPourSupervision GetAgentPourSupervision(CMemoryDb database, bool bAvecEntites) { if (database == null) { database = CMemoryDbPourSupervision.GetMemoryDb(ContexteDonnee); } CAgentSnmpPourSupervision agent = new CAgentSnmpPourSupervision(database); if (!agent.ReadIfExist(Id.ToString(), false)) { agent.CreateNew(Id.ToString()); } else if (!agent.IsToRead()) { return(agent); } agent.Row[CMemoryDb.c_champIsToRead] = false; CTypeAgentPourSupervision typeAgent = TypeAgent.GetTypeAgentPourSupervision(database); agent.TypeAgent = typeAgent; agent.Ip = SnmpIp; agent.Timeout = Timeout; agent.SnmpPort = SnmpPort; agent.SnmpVersion = SnmpVersion; agent.Communaute = SnmpCommunaute; agent.TrapsIpString = TrapsIpsString; foreach (CSnmpPollingSetup setup in ParametresPolling) { CSnmpPollingSetup newSetup = database.ImporteObjet(setup, true, false) as CSnmpPollingSetup; newSetup.Agent = agent; } foreach (CSnmpHotelPollingSetup setup in ParametresHotelPolling) { CSnmpHotelPollingSetup newSetup = database.ImporteObjet(setup, true, false) as CSnmpHotelPollingSetup; newSetup.Agent = agent; } if (bAvecEntites) { foreach (CEntiteSnmp entite in EntitesSnmp) { if (entite.EntiteSnmpParente == null) { CTypeEntiteSnmpPourSupervision typeEntite = typeAgent.TypesEntites.FirstOrDefault(te => te.Id == entite.TypeEntiteSnmp.Id.ToString()); if (typeEntite != null) { CEntiteSnmpPourSupervision ett = entite.GetEntitePourSupervision(typeEntite); if (ett != null) { ett.AgentSnmp = agent; } } } } } return(agent); }
//-------------------------------------------------- public void Init(CSnmpHotelPollingSetup pollingSetup, CAgentSnmpPourSupervision agent) { m_agent = agent; m_setup = pollingSetup; m_txtLibelle.Text = pollingSetup.Libelle; m_txtFrequence.UnitValue = new CValeurUnite(m_setup.FrequenceMinutes, CClasseUniteTemps.c_idMIN); m_txtIP.Text = pollingSetup.HotelIp; m_txtNumPort.IntValue = pollingSetup.HotelPort; m_extModeEdition.ModeEdition = !pollingSetup.Id.StartsWith(CSnmpHotelPollingSetup.c_IdPollingSystem); m_controleItem.LockEdition = !m_extModeEdition.ModeEdition; FillListeChamps(); }
public static bool EditeSetup(CSnmpHotelPollingSetup setup, CAgentSnmpPourSupervision agent) { using (CFormEditeHotelPollingSetup frm = new CFormEditeHotelPollingSetup()) { frm.m_panelSetup.Init( setup, agent); if (frm.ShowDialog() == DialogResult.OK) { return(true); } return(false); } }
/// ///////////////////////////////////////////////////////// public void RemoveParametreHotelPolling(CSnmpHotelPollingSetup parametre) { ParametresHotelPollingList.Remove(parametre); CommitParametresHotelPolling(); }
/// ///////////////////////////////////////////////////////// public void AddParametreHotelPolling(CSnmpHotelPollingSetup parametre) { ParametresHotelPollingList.Add(parametre); CommitParametresHotelPolling(); }
//------------------------------------------------------------------ private static void m_timerPolling_Elapsed(object sender, ElapsedEventArgs e) { if (m_bIsPolling) { return; } m_bIsPolling = true; if (!m_bDemandeInterruption) { lock (typeof(CLockerPollingList)) { DateTime dtPoll = DateTime.Now.AddSeconds(-2); DateTime dtDebug = DateTime.Now; int nNbPooled = 0; List <CDonneeCumuleeTransportable> lstDonnees = new List <CDonneeCumuleeTransportable>(); if (m_configuration == null || m_configuration.DataBase == null) { return; } IEnumerable <CInfoPolling> lstToPoll = m_pollingList.GetElementsAPoller(DateTime.Now); if (lstToPoll.Count() > 0) { CServiceMediation.GetDefaultInstance().Trace.Write("Poll " + lstToPoll.Count() + " elements", ALTRACE.POLLING); } foreach (CInfoPolling info in lstToPoll) { if (m_bDemandeInterruption) { break; } /*CSnmpPollingSetup setup = new CSnmpPollingSetup(m_configuration.DataBase); * if (setup.ReadIfExist(info.IdPollingSetup)) * { * CDonneeCumuleeTransportable donnee = setup.GetDonneeTransportable(); * if (donnee != null) * { * lstDonnees.Add(donnee); * info.LastPollDate = dtPoll; * info.NextPollDate = dtPoll.AddMinutes(setup.FrequenceMinutes); * nNbPooled++; * } * } * else*/ { CSnmpHotelPollingSetup hotelSetup = new CSnmpHotelPollingSetup(m_configuration.DataBase); if (hotelSetup.ReadIfExist(info.IdHotelPollingSetup)) { hotelSetup.DoPoll(); info.LastPollDate = dtPoll; info.NextPollDate = dtPoll.AddMilliseconds(hotelSetup.FrequenceMinutes); nNbPooled++; } else { m_pollingList.RemoveElement(info); } } } if (nNbPooled > 0) { TimeSpan sp = DateTime.Now - dtDebug; Console.WriteLine("Pool1 " + nNbPooled + " : " + sp.TotalMilliseconds.ToString()); } CSnmpConnexion.DefaultInstance.SendDonneesPooled(lstDonnees); if (nNbPooled > 0) { TimeSpan sp = DateTime.Now - dtDebug; Console.WriteLine("Pool2 " + nNbPooled + " : " + sp.TotalMilliseconds.ToString()); } } } m_bIsPolling = false; m_bDemandeInterruption = false; }