public int ExportUpdatePeriod = 24; // En heures

        public void InitTimos()
        {
            CResultAErreur result = CResultAErreur.True;

            string strServeurUrl = TimosServerURL;
            int    nTcpChannel   = 0;
            string strBindTo     = "";

            string strRadiuServerUrl = RadiusServerURL;
            uint   nRadiusPort       = (uint)RadiusServerPort;
            string strSharedKey      = RadiusSharedKey;

            int nUpdatePeriod = ExportUpdatePeriod;

            try
            {
                AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);

                AuthenticationService.Init(strRadiuServerUrl, nRadiusPort, strSharedKey);

                result = CSC2iMultitiersClient.Init(nTcpChannel, strServeurUrl, 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);

                C2iSponsor.EnableSecurite();

                /*TcpChannel channel = new TcpChannel();
                 * ChannelServices.RegisterChannel(channel, false);*/

                if (!result)
                {
                    result.EmpileErreur("Erreur lors de l'initialisation");
                }

                // Configuration des Schedulers
                // ATTENTION : Dans le cas de plusieurs serveurs (load balancing par exemple) il faut locker le traitement dans la commande appelée
                ScheduleCommand.RunEvery(1, PeriodUnit.Hour, "TimosWebApp/ExportService.TraiteListeExports", new Dictionary <string, object>(), new DateTime(2021, 06, 01, 01, 00, 00), null);

                /*/ DEBUG ONLY
                 * ScheduleCommand.RunEvery(1, PeriodUnit.Minute, "TimosWebApp/ExportService.UpdateAllExports", new Dictionary<string, object>(), null, null);
                 * //*/
            }
            catch (Exception e)
            {
                result.EmpileErreur(e.Message);
            }
        }
        /// ///////////////////////////////////////////////////////////
        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);
        }
Exemple #3
0
        static void Main(string[] args)
        {
            CResultAErreur result        = CResultAErreur.True;
            string         strServeurUrl = "tcp://127.0.0.1:8160";
            int            nTcpChannel   = 0;
            string         strBindTo     = "";

            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);

                result = CSC2iMultitiersClient.Init(nTcpChannel, strServeurUrl, 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);

                C2iSponsor.EnableSecurite();

                if (result)
                {
                    /*CSessionClient session = CSessionClient.CreateInstance();
                     *
                     * CAuthentificationSessionTimosLoginPwd authParams = new CAuthentificationSessionTimosLoginPwd(
                     *  "youcef",
                     *  "minutes",
                     *  new CParametresLicence(new List<string>(), new List<string>()));
                     *
                     * //result = session.OpenSession(authParams, "Console de test", ETypeApplicationCliente.Windows);/
                     * result = session.OpenSession(new CAuthentificationSessionProcess(), "Console de test", ETypeApplicationCliente.Process);
                     *
                     * if (!result)
                     * {
                     *  result.EmpileErreur("Erreur lors de l'authentification");
                     *  Console.WriteLine("Erreur lors de l'authentification");
                     *  Console.ReadKey();
                     *  return;
                     * }
                     *
                     * /*
                     * string strLogin = "******";
                     * string strPassCrypte = C2iCrypto.Crypte("minutes");
                     *
                     * CContexteDonnee contexte = new CContexteDonnee(session.IdSession, true, false);
                     * CDonneesActeurUtilisateur utilisateurTimos = new CDonneesActeurUtilisateur(contexte);
                     * if (utilisateurTimos.ReadIfExists(new CFiltreData(CDonneesActeurUtilisateur.c_champLogin + "=@1 and " +
                     *      CDonneesActeurUtilisateur.c_champPassword + "=@2",
                     *      strLogin, strPassCrypte)))
                     * {
                     *  result.Data = utilisateurTimos;
                     *  Console.WriteLine("Utilisateur " + strLogin + " connecté");
                     *  Console.ReadKey();
                     *  return;
                     * }*/

                    ITimosServiceForAspectize serviceClientAspectize = (ITimosServiceForAspectize)C2iFactory.GetNewObject(typeof(ITimosServiceForAspectize));
                    string strNomGestionnaire = serviceClientAspectize.GetType().ToString();
                    result = serviceClientAspectize.OpenSession("youcef", "minutes");
                    if (result)
                    {
                        Console.WriteLine("Key utilisateur connecté = " + (string)result.Data);
                        Console.ReadKey();
                    }

                    Console.WriteLine("Nom du gestionnaire : " + strNomGestionnaire);
                    Console.ReadKey();
                }
            }
            catch (Exception e)
            {
                result.EmpileErreur(e.Message);
                Console.WriteLine(e.Message);
                Console.WriteLine("Erreur. Pressez n'importe quelle touche pour quitter");
                Console.ReadKey();
            }
        }