/// ///////////////////////////////////////////////////////////
        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);
        }
Example #2
0
        public static CResultAErreur Init(
            string strEventJournalName,
            string strEventJournalTexte,
            IIndicateurProgression indicateurProgress)
        {
            CResultAErreur result = CResultAErreur.True;

            try
            {
                int nValeurIndicateur = 0;
                C2iEventLog.Init(strEventJournalName, strEventJournalTexte, NiveauBavardage.VraiPiplette);
                CConteneurIndicateurProgression indicateur = CConteneurIndicateurProgression.GetConteneur(indicateurProgress);
                if (indicateur != null)
                {
                    indicateur.PushSegment(0, 13);
                }


                CTraducteur.ReadFichier("");

                #region Configuration du remoting

                indicateur.SetValue(nValeurIndicateur++);

                AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);

                C2iSponsor.EnableSecurite();
                #endregion

                #region Configuration de l'allocateur d'objets
                Dictionary <string, MarshalByRefObject> dicLocalSingleton = new Dictionary <string, MarshalByRefObject>();
                dicLocalSingleton["sc2i.multitiers.client.IGestionnaireSessions"] = new CGestionnaireSessionSagexProSolo();
                C2iFactory.InitEnLocal(new C2iObjetServeurFactory(), dicLocalSingleton);

                indicateur.SetValue(nValeurIndicateur++);

                CSessionClient session = CSessionClient.CreateInstance();
                result = session.OpenSession(new CAuthentificationSessionServer(), "SagexProSolo", ETypeApplicationCliente.Service);
                if (!result)
                {
                    result.EmpileErreur(I.T("Opening session error|30010"));
                    return(result);
                }


                CSc2iDataServer.AddDefinitionConnexion(
                    new CDefinitionConnexionDataSource(
                        c_droitsDataSource,
                        typeof(CGestionnaireDroitsUtilisateurs),
                        ""));

                CSc2iDataServer.SetIdConnexionForClasse(typeof(CDroitUtilisateurServeur), c_droitsDataSource);
                #endregion

                #region Configuration de la base de données
                indicateur.SetValue(nValeurIndicateur++);

                Type typeConnexion = typeof(CAccess97DatabaseConnexion);

                //Récuperation du type de connection

                CSc2iDataServer.Init(
                    new CDefinitionConnexionDataSource(
                        c_mainDataSource,
                        typeConnexion,
                        "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\"C:\\Documents and Settings\\GENERIC\\Mes documents\\BASEVIDE2000.MDB\"",
                        ""));
                #endregion

                #region Ajout des références DLL
                indicateur.SetValue(nValeurIndicateur++);
                AppDomain.CurrentDomain.Load("sc2i.data.client");
                AppDomain.CurrentDomain.Load("sc2i.data.serveur");
                AppDomain.CurrentDomain.Load("sc2i.data.dynamic");
                AppDomain.CurrentDomain.Load("sc2i.data.dynamic.loader");
                AppDomain.CurrentDomain.Load("sc2i.process");
                AppDomain.CurrentDomain.Load("sc2i.process.serveur");
                AppDomain.CurrentDomain.Load("sc2i.expression");
                AppDomain.CurrentDomain.Load("sc2i.Formulaire");
                AppDomain.CurrentDomain.Load("futurocom.vectordb.data");
                AppDomain.CurrentDomain.Load("futurocom.vectordb.data.server");
                AppDomain.CurrentDomain.Load("futurocomapp.data");
                AppDomain.CurrentDomain.Load("futurocomapp.data.server");
                AppDomain.CurrentDomain.Load("sagexpro.data");
                AppDomain.CurrentDomain.Load("sagexpro.data.serveur");


                foreach (Assembly ass in AppDomain.CurrentDomain.GetAssemblies())
                {
                    CContexteDonnee.AddAssembly(ass);
                }
                #endregion

                #region Teste la connexion
                indicateur.SetValue(nValeurIndicateur++);
                IDatabaseConnexion cnx = CSc2iDataServer.GetInstance().GetDatabaseConnexion(session.IdSession, c_mainDataSource);

                //Attend la connexion pendant au max 5 minutes pour que ça démarre
                DateTime dtStartAttente = DateTime.Now;
                TimeSpan delaiAttente   = DateTime.Now - dtStartAttente;
                result = cnx.IsConnexionValide();
                while (!result && delaiAttente.TotalSeconds < 5 * 60)
                {
                    C2iEventLog.WriteErreur(result.MessageErreur);
                    delaiAttente = DateTime.Now - dtStartAttente;
                    C2iEventLog.WriteErreur(I.T("Connection not availiable(@1)|30014", delaiAttente.TotalSeconds.ToString() + " s)") +
                                            Environment.NewLine);
                    string messageErreur = I.T("The connection with the database could not have been established. Verify the connection string and check if the database has been started|30015");
                    C2iEventLog.WriteErreur(messageErreur);

                    result.EmpileErreur(messageErreur);
                    return(result);
                }

                if (typeof(CSqlDatabaseConnexion).IsAssignableFrom(typeConnexion))
                {
                    cnx.RunStatement("SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED");
                }

                #endregion


                //Initialisation des classes autoexecutables
                CAutoexecuteurClasses.RunAutoexecs();

                //Initialisation du serveur de documents GED
                //Initialise les restrictions standards

                #region Vérifie que les champs des tables font bien moins de 25 cars
                indicateur.SetValue(nValeurIndicateur++);

                DateTime dt = DateTime.Now;

                foreach (Type tp in CContexteDonnee.GetAllTypes())
                {
                    CStructureTable structure = CStructureTable.GetStructure(tp);
                    if (structure.NomTable.Length > 25)
                    {
                        result.EmpileErreur("Table " + structure.NomTable + " (" + tp.ToString() + ")=" + structure.NomTable.Length + "cars");
                    }
                    if (structure.NomTable.ToUpper() != structure.NomTable)
                    {
                        result.EmpileErreur(I.T("Table name @1 must be uppercase|30018", structure.NomTable));
                    }
                    foreach (CInfoChampTable champ in structure.Champs)
                    {
                        if (champ.NomChamp.Length > 25)
                        {
                            result.EmpileErreur("Table " + structure.NomTable + " (" + tp.ToString() + ")\t champ " + champ.NomChamp + "=" + champ.NomChamp.Length + "cars");
                        }
                        if (champ.NomChamp.ToUpper() != champ.NomChamp)
                        {
                            result.EmpileErreur(I.T("The name of the field '@1' of the field '@2' must be uppercase|30019", champ.NomChamp, structure.NomTable));
                        }
                    }
                }
                TimeSpan sp = DateTime.Now - dt;
                Console.WriteLine(I.T("Table name verification |30020") + sp.TotalMilliseconds);
                if (!result)
                {
                    return(result);
                }
                #endregion

                #region Mise à jour de la structure de la base
                indicateur.SetValue(nValeurIndicateur++);

                CUpdaterDataBase updaterDataBase = CUpdaterDataBase.GetInstance(cnx, new CSagexproStructureBase());

                //S'assure que la gestion des éléments est initialisé dans les licences
                //CLicenceCheckElementNb.GetInstance();

                result = updaterDataBase.UpdateStructureBase(indicateur);
                if (!result)
                {
                    return(result);
                }


                #endregion


                //Restrictions sur applications


                //Initialisation du serveur de documents GED

                //Initialisation de la base d'utilisateurs AD
                //CAdBase.Init(CfuturocomappServeurRegistre.RacineAd,"","");

                //Initialise les fournisseurs de services
                //CSessionClientSurServeur.RegisterFournisseur( new CFournisseurFiltresForSynchronisation() );

                CGestionnaireEvenements.Init();



                if (!result)
                {
                    return(result);
                }

                //CGestionnaireObjetsAttachesASession.OnAttacheObjet += new LinkObjectEventHandler(CGestionnaireObjetsAttachesASession_OnAttacheObjet);
            }
            catch (Exception e)
            {
                result.EmpileErreur(new CErreurException(e));
            }
            return(result);
        }