//----------------------------------------------------------------------- public IDonneeSynchronisationMediation GetDonneesPourSynchro(int nIdProxy, int nIdLastSyncSessionConnue) { if (m_synchroniseurServiceMediation != null) { try { return(m_synchroniseurServiceMediation.GetUpdatesForProxy(nIdProxy, nIdLastSyncSessionConnue)); } catch (Exception e) { Console.WriteLine(e.ToString()); } } //Demande au proxy précédent d'aller chercher les données foreach (CSnmpProxy proxy in CSnmpProxyConfiguration.GetInstance().GetProxiesPrecedents()) { try { ISnmpConnexion connexion = proxy.GetConnexion(); return(connexion.GetDonneesPourSynchro(nIdProxy, nIdLastSyncSessionConnue)); } catch { } } return(null); }
//-------------------------------------------------------------------------- public CResultAErreur CreateUpdateObjet(object objet) { CResultAErreur result = CResultAErreur.True; if (!IsMySelf()) { ISnmpConnexion cnxDisttante = GetConnexionDistante(); if (cnxDisttante != null) { return(cnxDisttante.CreateUpdateObjet(objet)); } result.EmpileErreur(I.T("Can not reach host @1|20009", EndPoint.Address.ToString())); return(result); } if (objet is CSnmpProxyConfiguration) { CSnmpProxyConfiguration.SetDefaultInstance((CSnmpProxyConfiguration)objet); } if (objet is CValiseEntiteDeMemoryDb) { objet = ((CValiseEntiteDeMemoryDb)objet).Entite; } if (objet is CEntiteDeMemoryDb) { result = CServiceMediation.GetDefaultInstance().Configuration.UpdateEntite(objet as sc2i.common.memorydb.CEntiteDeMemoryDb); } return(result); }
//----------------------------------------------------------------------- public CResultAErreur SendDonneesPooled(List <CDonneeCumuleeTransportable> lstDonnees) { if (m_synchroniseurServiceMediation != null) { try { return(m_synchroniseurServiceMediation.SendDonneesPooled(lstDonnees)); } catch (Exception e) { Console.WriteLine(e.ToString()); } } //Demande au proxy précédent d'aller chercher les données foreach (CSnmpProxy proxy in CSnmpProxyConfiguration.GetInstance().GetProxiesPrecedents()) { try { ISnmpConnexion connexion = proxy.GetConnexion(); return(connexion.SendDonneesPooled(lstDonnees)); } catch { } } return(null); }
//---------------------------------------------------------------------- /// <summary> /// Retourne une Configuration SNMP à envoyer au Proxy en cours /// </summary> /// <returns></returns> public CSnmpProxyConfiguration GetConfiguration() { CSnmpProxyConfiguration configuration = new CSnmpProxyConfiguration(); configuration.IdProxyConfiguré = Id; configuration.FrequencePollingMinutes = FrequencePollingMinutes; List <CSnmpProxy> listeProxyConfigures = new List <CSnmpProxy>(); // Ajouter les Proxy distants (Next) et leurs plages IP gérées foreach (CLienDeProxy lienProxy in LiensDeProxyDestination) { if (lienProxy.ProxyDestination != null) { HashSet <CPlageIP> hPlages = new HashSet <CPlageIP>(); hPlages.Add(new CPlageIP(lienProxy.ProxyDestination.AdresseIp, 0)); CSnmpProxy proxyAAjouterALaConfig = lienProxy.ProxyDestination.GetTypePourSupervision(configuration.Database); if (proxyAAjouterALaConfig != null) { foreach (CPlageIP plage in lienProxy.PlagesIP) { hPlages.Add(plage); } lienProxy.ProxyDestination.FillHashSetPlagesGerees(hPlages); foreach (CPlageIP plage in hPlages) { proxyAAjouterALaConfig.AddPlage(plage); } listeProxyConfigures.Add(proxyAAjouterALaConfig); } } } // Ajoute les proxies Sources (Prev) à la configuration foreach (CLienDeProxy lienPrev in LiensDeProxySource) { if (lienPrev.ProxySource != null) { CSnmpProxy proxyAAjouterALaConfig = lienPrev.ProxySource.GetTypePourSupervision(configuration.Database); proxyAAjouterALaConfig.IsProxyPrev = true; listeProxyConfigures.Add(proxyAAjouterALaConfig); // En tant que Proxy Source (Précédent) } } return(configuration); }
//---------------------------------------------------------------------------------- public void DoOperationAsynchrone(IOperationSynchronisation operation, int nIdSession) { CSnmpProxyInDb proxy = new CSnmpProxyInDb(CContexteDonneeSysteme.GetInstance()); if (proxy.ReadIfExists(Int32.Parse(operation.IdElementASynchroniser))) { CSnmpProxyConfiguration configurationAEnvoyer = proxy.GetConfiguration(); if (configurationAEnvoyer != null) { CAppeleurFonctionAvecDelai.CallFonctionAvecDelai( GetConnexion(), "CreateUpdateObjet", 1, configurationAEnvoyer); } } }
//-------------------------------------------------------------------- public void RedescendAlarmes(CMemoryDb dbContenantLesAlarmesARedescendre) { CServiceMediation.GetDefaultInstance().RedescendAlarmes(dbContenantLesAlarmesARedescendre); foreach (CSnmpProxy proxy in CSnmpProxyConfiguration.GetInstance().ListeProxySuivants) { try { ISnmpConnexion connexion = proxy.GetConnexion(); RedescendAlarmesDelegate del = new RedescendAlarmesDelegate(RedescendAlarmeAsync); del.BeginInvoke(connexion, dbContenantLesAlarmesARedescendre, null, null); } catch { } } }
protected override void OnStart(string[] args) { try { C2iEventLog.Init("Timos", NiveauBavardage.VraiPiplette); RemotingConfiguration.Configure(AppDomain.CurrentDomain.BaseDirectory + "\\serviceMediation.remoting.config", false); RemotingConfiguration.CustomErrorsMode = CustomErrorsModes.On; CAutoexecuteurClasses.RunAllAutoexecs(); CSnmpProxyConfiguration.GetInstance().MiseAJour(true); CServiceMediation.GetDefaultInstance().Configuration.MettreAJour(true, true); } catch (Exception e) { C2iEventLog.WriteErreur(e.Message); throw e; } }
//--------------------------------------------------- public void SetConfigurationDeSnmpProxy(CSnmpProxyConfiguration config) { if (IsMySelf()) { if (config != null) { CSnmpProxyConfiguration.SetDefaultInstance(config); } } else { ISnmpConnexion cnx = GetConnexionDistante(); if (cnx != null) { cnx.SetConfigurationDeSnmpProxy(config); } } }
//--------------------------------------------------- public CSnmpProxyConfiguration GetConfigurationDeSnmpProxy(int nIdProxy) { if (m_fournisseurDeConfiguration != null) { return(m_fournisseurDeConfiguration.GetConfigurationDeProxy(nIdProxy)); } foreach (CSnmpProxy proxy in CSnmpProxyConfiguration.GetInstance().GetProxiesPrecedents()) { try { ISnmpConnexion connexion = proxy.GetConnexion(); return(connexion.GetConfigurationDeSnmpProxy(nIdProxy)); } catch { } } return(null); }
//-------------------------------------------------------------------- public CResultAErreurType <CMappageIdsAlarmes> RemonteAlarmes(CMemoryDb dbContenantLesAlarmesARemonter) { CResultAErreurType <CMappageIdsAlarmes> result = new CResultAErreurType <CMappageIdsAlarmes>(); if (m_traiteurAlarme != null) { return(m_traiteurAlarme.Traite(dbContenantLesAlarmesARemonter)); } else { foreach (CSnmpProxy proxy in CSnmpProxyConfiguration.GetInstance().GetProxiesPrecedents()) { ISnmpConnexion connexion = proxy.GetConnexion(); return(connexion.RemonteAlarmes(dbContenantLesAlarmesARemonter)); } } result.EmpileErreur(I.T("Can not manage alarms")); return(result); }
//--------------------------------------------------- public void NotifyProxyNecessiteMAJ( int nIdProxy, bool bConfigProxy, bool bServiceMediation, bool bFullSync) { if (IsMySelf()) { StringBuilder bl = new StringBuilder(); bl.Append("Proxy setup update requiered "); bl.Append("proxy setup="); bl.Append(bConfigProxy); bl.Append(", mediation setup="); bl.Append(bServiceMediation); bl.Append(", Full update="); bl.Append(bFullSync); CServiceMediation.GetDefaultInstance().Trace.Write(bl.ToString(), ALTRACE.DEBUG, ALTRACE.POLLING, ALTRACE.TRACE); CSnmpProxyConfiguration.GetInstance().IdProxyConfiguré = nIdProxy; if (bConfigProxy) { CSnmpProxyConfiguration.GetInstance().MiseAJour(false); } if (bServiceMediation) { CServiceMediation.GetDefaultInstance().Configuration.MettreAJour(bFullSync, true); } } else { ISnmpConnexion cnxDisttante = GetConnexionDistante(); if (cnxDisttante != null) { cnxDisttante.NotifyProxyNecessiteMAJ(nIdProxy, bConfigProxy, bServiceMediation, bFullSync); } } }
//-------------------------------------------------------------------- public void UpdateAgentIpFromMediation(string strAgentId, string strNewIp, bool bUpdateTimosDb) { if (m_traiteurAlarme != null) { m_traiteurAlarme.UpdateAgentIpFromMediation(strAgentId, strNewIp, bUpdateTimosDb); } else { CServiceMediation service = CServiceMediation.GetDefaultInstance(); if (service != null && service.Configuration != null && service.Configuration.DataBase != null) { CAgentSnmpPourSupervision agent = service.Configuration.DataBase.GetEntite <CAgentSnmpPourSupervision>(strAgentId); if (agent != null) { agent.Ip = strNewIp; } } foreach (CSnmpProxy proxy in CSnmpProxyConfiguration.GetInstance().GetProxiesPrecedents()) { ISnmpConnexion cnx = proxy.GetConnexion(); cnx.UpdateAgentIpFromMediation(strAgentId, strNewIp, bUpdateTimosDb); } } }
private void m_btnConfiguration_Click(object sender, EventArgs e) { CSnmpProxyConfiguration config = CSnmpProxyConfiguration.GetInstance(); if (config != null) { StringBuilder sBuilder = new StringBuilder(); sBuilder.AppendLine("My SNMP Configuration is :"); foreach (CSnmpProxy proxy in config.ListeProxy) { sBuilder.Append("\t"); sBuilder.AppendLine(proxy.NomProxy); foreach (CPlageIP plage in proxy.PlagesIP) { sBuilder.Append("\t\t"); sBuilder.AppendLine(plage.ModeleIpString + "/" + plage.Mask.ToString()); } } MessageBox.Show(sBuilder.ToString()); } }
/// /////////////////////////////////////////////////////////// public static CResultAErreur InitClientTimos( string strServeurUrl, int nTcpChannel, string strBindTo, IIndicateurProgression indicateurProgression) { CResultAErreur result = CResultAErreur.True; try { AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal); //SUPPRIMé journal d'évenements: sur les postes clients qui ne sont pas autorisés //à créer un journal d'évenements, ça bloque, et comme ce n'est pas //très important sur un poste client, il n'y a plus //de journal d'évenements TIMOS sur les postes clients. //C2iEventLog.Init("", "Client Timos", NiveauBavardage.VraiPiplette); m_strUrlServeurMain = strServeurUrl; m_nPortServeur = nTcpChannel; result = CSC2iMultitiersClient.Init(m_nPortServeur, m_strUrlServeurMain, strBindTo); LifetimeServices.LeaseTime = new TimeSpan(0, 5, 0); LifetimeServices.LeaseManagerPollTime = new TimeSpan(0, 5, 0); LifetimeServices.SponsorshipTimeout = new TimeSpan(0, 3, 0); LifetimeServices.RenewOnCallTime = new TimeSpan(0, 8, 0); /*LifetimeServices.LeaseTime = new TimeSpan(0, 0, 3); * LifetimeServices.LeaseManagerPollTime = new TimeSpan(0, 0, 10); * LifetimeServices.SponsorshipTimeout = new TimeSpan(0, 0, 10); * LifetimeServices.RenewOnCallTime = new TimeSpan(0, 0, 5);*/ /*if ( !result ) * { * //On ne parvient pas à contacter le serveur primaire, s'adresse au serveur secondaire * result = CSC2iMultitiersClient.Init ( * m_nPortServeur, * m_strUrlServeurSecondaire); * if ( result ) * CSessionClient.AfterOpenSession += new SessionEventHandler(AfterOpenSessionModeDeconnecte); * } * else * { * if ( bAvecSynchronisation && m_strUrlServeurSecondaire != "") * { * //On a contacté le serveur primaire, tente une synchronisation * result = SynchroniseSecondaireToMain( indicateurProgression ); * if ( !result ) * return result; * CSessionClient.BeforeClosingSession += new SessionEventHandler(BeforeCloseSessionModeConnecte); * } * }*/ if (!result) { return(result); } C2iSponsor.EnableSecurite(); // System.Runtime.Remoting.RemotingConfiguration.Configure (strFichierConfig); // sc2i.multitiers.client.C2iFactory.InitFromFile(strFichierConfig); AppDomain.CurrentDomain.Load("sc2i.data.client"); AppDomain.CurrentDomain.Load("sc2i.data.dynamic"); AppDomain.CurrentDomain.Load("timos.data"); AppDomain.CurrentDomain.Load("sc2i.process"); AppDomain.CurrentDomain.Load("sc2i.documents"); AppDomain.CurrentDomain.Load("futurocom.sig"); AppDomain.CurrentDomain.Load("data.hotel.client"); #region Chargement des plugins CGestionnairePlugins.InitPlugins(AppDomain.CurrentDomain.BaseDirectory, "plg"); // Initialilsation des plugins à partir de TIMOS_REGISTRY CDataBaseRegistrePourClient registre = new CDataBaseRegistrePourClient(0); string strFUT_CLT = registre.GetValeurString("FUT_CLT", ""); if (strFUT_CLT.Trim() != string.Empty) { List <string> listPluginFiles = new List <string>(); foreach (string strNomPlg in strFUT_CLT.Split(';')) { string strTmp = AppDomain.CurrentDomain.BaseDirectory + strNomPlg; if (File.Exists(strTmp)) { listPluginFiles.Add(strTmp); } } CGestionnairePlugins.LoadPlugins(listPluginFiles.ToArray()); } #endregion foreach (Assembly ass in AppDomain.CurrentDomain.GetAssemblies()) { CContexteDonnee.AddAssembly(ass); } AppDomain.CurrentDomain.AssemblyLoad += new AssemblyLoadEventHandler(OnLoadAssembly); CGestionnaireObjetsAttachesASession.OnAttacheObjet += new LinkObjectEventHandler(OnAttacheObjectASession); CAutoexecuteurClasses.RunAllAutoexecs(); CVersionDonneesObjet.EnableJournalisation = true; // Création d'une Configuration SNMP par défaut // Redirige tout vers le Serveur Timos (entant que Proxy par défaut) CSnmpProxyConfiguration configurationDefaut = new CSnmpProxyConfiguration(); CPlageIP plageToutes = new CPlageIP("255.255.255.255", 32); CSnmpProxy proxyDefaut = new CSnmpProxy(configurationDefaut.Database); proxyDefaut.CreateNew(); string strIp = strServeurUrl.Substring(strServeurUrl.IndexOf("//") + 2); string strPort = strIp.Substring(strIp.IndexOf(':') + 1); strIp = strIp.Substring(0, strIp.IndexOf(':')); try { proxyDefaut.AdresseIP = new IP(strIp).ToIPAddress(); } catch { try { IPHostEntry entry = Dns.GetHostEntry(strIp); if (entry != null) { foreach (IPAddress adr in entry.AddressList) { //Cherche une IP V4 dans les paramètres string strIpTest = adr.ToString(); Regex ex = new Regex(@"\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b"); if (ex.IsMatch(strIpTest)) { proxyDefaut.AdresseIP = adr; break; } } } } catch { } } proxyDefaut.Port = Int32.Parse(strPort); proxyDefaut.AddPlage(plageToutes); CDataHotelClient.InitForUseProxy(m_strUrlServeurMain); CSnmpProxyConfiguration.SetDefaultInstance(configurationDefaut); CSnmpConnexion.ToutPasserParDesProxies = true; } catch (ReflectionTypeLoadException loadex) { result.EmpileErreur(new CErreurException(loadex)); StringBuilder bl = new StringBuilder(); foreach (Exception exSub in loadex.LoaderExceptions) { bl.AppendLine(exSub.Message); FileNotFoundException exFileNotFound = exSub as FileNotFoundException; if (exFileNotFound != null && !string.IsNullOrEmpty(exFileNotFound.FusionLog)) { bl.AppendLine("Not found : " + exFileNotFound.FusionLog); } } result.EmpileErreur(bl.ToString()); } catch (Exception e) { StringBuilder bl = new StringBuilder(); ReflectionTypeLoadException lex = e as System.Reflection.ReflectionTypeLoadException; if (lex != null) { foreach (Exception ee in lex.LoaderExceptions) { bl.Append(ee.Message.ToString()); bl.Append("\r\n"); } } else { bl.Append(e.Message.ToString()); } result.EmpileErreur(bl.ToString()); } return(result); }
private void Form1_Load(object sender, EventArgs e) { CSnmpProxyConfiguration.GetInstance().MiseAJour(true); CServiceMediation.GetDefaultInstance().Configuration.MettreAJour(true, true); }