Ejemplo n.º 1
0
        //-----------------------------------------------------------
        public IDataRoomServer GetServer()
        {
            CDataHotelClient client = new CDataHotelClient();

            client.Init(m_strPollingHotelURL);
            return(client.GetRoomServer());
        }
Ejemplo n.º 2
0
        //-------------------------------------------------------------
        public static CResultAErreur InitUsagePolling(string strHotelURL)
        {
            CResultAErreur result = CResultAErreur.True;

            try
            {
                m_strHotelURL = strHotelURL;
                CDataHotelClient hotelClient = new CDataHotelClient();
                hotelClient.Init(strHotelURL);
                CMemoryDb db = hotelClient.GetRoomServer().GetConfig();
                if (db == null)
                {
                    return(result);
                }
                CDataHotel hotel = new CDataHotel(db);
                if (!hotel.ReadIfExist(new CFiltreMemoryDb("1=1")))
                {
                    hotel.CreateNew();
                    hotel.Label = "Timos hotel";
                }
                CDataHotelTable table = new CDataHotelTable(db);
                if (!table.ReadIfExist(new CFiltreMemoryDb(CDataHotelTable.c_champId + "=@1", c_LicenceUsagePollingTableId)))
                {
                    table.CreateNew(c_LicenceUsagePollingTableId);
                    table.TableName = c_LicenceUsagePollingTable;
                    table.Hotel     = hotel;
                }
                bool bFieldExists = false;
                foreach (CDataHotelField field in table.Fields)
                {
                    if (field.Id == c_LicenceUsagePollingNbUsedFieldId)
                    {
                        bFieldExists = true;
                        break;
                    }
                }
                if (!bFieldExists)
                {
                    CDataHotelField field = new CDataHotelField(db);
                    field.CreateNew(c_LicenceUsagePollingNbUsedFieldId);
                    field.FieldName  = c_LicenceUsagePollingNbUsedField;
                    field.HotelTable = table;
                }
                hotelClient.GetRoomServer().UpdateConfig(db);

                if (m_timer == null)
                {
                    m_timer          = new Timer(5 * 60 * 1000);
                    m_timer.Elapsed += m_timer_Elapsed;
                    m_timer.Start();
                }
            }
            catch (Exception e)
            {
                result.EmpileErreur(new CErreurException(e));
            }
            return(result);
        }
Ejemplo n.º 3
0
        //----------------------------------------------------------------------
        internal CResultAErreur DoPoll(
            CDataHotelClient client,
            CAgentSnmpPourSupervision agent)
        {
            CResultAErreur result = CResultAErreur.True;

            if (m_formulePolling != null)
            {
                try
                {
                    CContexteEvaluationExpression ctx = new CContexteEvaluationExpression(agent);
                    result = m_formulePolling.Eval(ctx);
                    if (!result || result.Data == null)
                    {
                        result.EmpileErreur("Error while polling " + HotelTable + "." + HotelField);
                        return(result);
                    }
                    double?fVal = result.Data as double?;
                    if (fVal == null)
                    {
                        fVal = result.Data as Int32?;
                        if (fVal == null)
                        {
                            fVal = Convert.ToDouble(result.Data);
                        }
                    }
                    if (fVal != null)
                    {
                        client.GetRoomServer().SendData(
                            HotelTable,
                            HotelField,
                            EntityId,
                            DateTime.Now,
                            fVal.Value);
                    }
                }
                catch (Exception e)
                {
                    result.EmpileErreur(new CErreurException(e));
                    result.EmpileErreur("Error while polling " + HotelTable + "." + HotelField);
                    return(result);
                }
            }
            return(result);
        }
Ejemplo n.º 4
0
        //----------------------------------------------------------
        private void AssureListeTables()
        {
            if (m_listeTables == null)
            {
                CDataHotelClient client = new CDataHotelClient(m_strIp, m_nPort);
                try
                {
                    DataSet ds = client.GetRoomServer().GetDataSetModele();
                    if (ds != null)
                    {
                        m_listeTables = new List <ITableDefinition>();
                        foreach (DataTable table in ds.Tables)
                        {
                            string strTableId = table.ExtendedProperties[CDataHotelTable.c_extPropTableId] as string;
                            if (strTableId != null)
                            {
                                CTableDefinitionDataHotel tableDef = new CTableDefinitionDataHotel(strTableId, table.TableName);
                                tableDef.AddColumn(new CColonneDefinitionHotelEntiteId("Data entity id"));
                                tableDef.AddColumn(new CColonneDefinitionHotelDate("Data date"));

                                foreach (DataColumn col in table.Columns)
                                {
                                    string strColId = col.ExtendedProperties[CDataHotelField.c_extPropColumnId] as string;
                                    if (strColId != null)
                                    {
                                        CColonneDefinitionDataHotel colHotel = new CColonneDefinitionDataHotel(strColId, col.ColumnName);
                                        tableDef.AddColumn(colHotel);
                                    }
                                }
                                m_listeTables.Add(tableDef);

                                CTableDefinitionEntitiesDataHotel tableE = new CTableDefinitionEntitiesDataHotel(strTableId, table.TableName);
                                m_listeTables.Add(tableE);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                }
            }
        }
Ejemplo n.º 5
0
        //----------------------------------------------------------
        public DataTable GetData(CTableDefinitionEntitiesDataHotel table, DateTime dataStart, DateTime dataEnd)
        {
            CDataHotelClient client = new CDataHotelClient(m_strIp, m_nPort);

            try
            {
                IEnumerable <string> lstIds      = client.GetRoomServer().GetEntities(table.Id, dataStart, dataEnd);
                DataTable            tableRetour = GetTableEntitiesVide(table);
                tableRetour.BeginLoadData();
                foreach (string strId in lstIds)
                {
                    DataRow row = tableRetour.NewRow();
                    row[CTableDefinitionEntitiesDataHotel.c_strNomEntityId] = strId;
                    tableRetour.Rows.Add(row);
                }
                return(tableRetour);
            }
            catch
            {
            }
            return(null);
        }
Ejemplo n.º 6
0
        //------------------------------------------------------------
        public void DoPoll()
        {
            //Vérifie la connexion à l'hotel
            CDataHotelClient client = new CDataHotelClient(HotelIp, HotelPort);

            if (client.SafePing())
            {
                //Extrait tous les OID à lire
                HashSet <string> strOids = new HashSet <string>();
                foreach (CSnmpHotelPolledData data in PolledDatas)
                {
                    data.ExtractOids(strOids);
                }
                IList <Variable>            lstVars    = Agent.ReadSnmp(strOids.ToArray());
                Dictionary <string, object> dicValeurs = new Dictionary <string, object>();
                foreach (Variable v in lstVars)
                {
                    string strOID = v.Id.ToString();
                    dicValeurs[strOID] = v.Data;
                }

                try
                {
                    CAgentSnmpPourSupervision agent = Agent;
                    agent.SetCacheOID(dicValeurs);

                    //C'est parti
                    foreach (CSnmpHotelPolledData data in PolledDatas)
                    {
                        data.DoPoll(client, agent);
                    }
                }
                finally
                {
                    Agent.SetCacheOID(null);
                }
            }
        }
Ejemplo n.º 7
0
        /// //////////////////////////////////////////
        public override CResultAErreur MyEval(CContexteEvaluationExpression ctx, object[] valeursParametres)
        {
            CResultAErreur result = CResultAErreur.True;

            try
            {
                CDataHotelClient client = new CDataHotelClient(
                    (string)valeursParametres[0],
                    (int)valeursParametres[1]);
                result = client.GetRoomServer().SendData(
                    (string)valeursParametres[2],
                    (string)valeursParametres[3],
                    (string)valeursParametres[4],
                    (DateTime)valeursParametres[5],
                    Convert.ToDouble(valeursParametres[6]));
                result.Data = result.Result;
            }
            catch
            {
                result.EmpileErreur(I.T("Error during the evaluation of the function 'SetBigData'|20018"));
                return(result);
            }
            return(result);
        }
Ejemplo n.º 8
0
        /// ///////////////////////////////////////////////////////////
        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);
        }
Ejemplo n.º 9
0
        //----------------------------------------------------------
        public DataTable GetData(CTableDefinitionDataHotel tableHotel, CDataHotelQuery query)
        {
            DataTable tableResult = null;

            try
            {
                CDataHotelClient client = new CDataHotelClient(m_strIp, m_nPort);
                //Convertit les ids de colonne en id de colonne DataHotel;
                List <string> lstIds = new List <string>();
                Dictionary <string, IColumnDefinition> dicIdToColDef = new Dictionary <string, IColumnDefinition>();

                //remarque sur le code :
                //au début, les CColonneDefinitionDataHotel avaient un id qui leur était propre
                //au lieu de prendre l'id de la colonne de DataHotel, du coup,
                //il fallait faire une conversion des IdCol -> IdHotel.
                //Cette notion a été corrigée, mais pour compatiblité, on continue à
                //convertir.
                foreach (string strIdCol in query.ChampsId)
                {
                    IColumnDefinition           col    = tableHotel.GetColumn(strIdCol);
                    CColonneDefinitionDataHotel colHot = col as CColonneDefinitionDataHotel;
                    if (colHot != null)
                    {
                        lstIds.Add(colHot.HotelColumnId);
                        dicIdToColDef[colHot.HotelColumnId] = col;
                        if (query.Filtre != null)
                        {
                            query.Filtre.ReplaceColumnId(strIdCol, colHot.HotelColumnId);
                        }
                    }
                    if (col is CColonneDefinitionHotelDate)
                    {
                        dicIdToColDef[CDataHotelTable.c_nomChampTableDate] = col;
                    }
                    if (col is CColonneDefinitionHotelEntiteId)
                    {
                        dicIdToColDef[CDataHotelTable.c_nomChampTableEntiteId] = col;
                    }
                }
                query.ChampsId = lstIds;
                CResultAErreurType <CDataTableFastSerialize> res = client.GetRoomServer().GetData(query);
                if (res && res.Data != null)
                {
                    tableResult = res.DataType;
                    foreach (DataColumn col in tableResult.Columns)
                    {
                        IColumnDefinition colDef = null;
                        if (dicIdToColDef.TryGetValue(col.ColumnName, out colDef))
                        {
                            col.ExtendedProperties[CODEQBase.c_extPropColonneId] = col.ColumnName;
                            col.ColumnName = colDef.ColumnName;
                        }
                    }
                }

                return(tableResult);
            }
            catch (Exception ex)
            {
            }
            return(null);
        }
Ejemplo n.º 10
0
        static void m_timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            if (m_bIsPolling)
            {
                return;
            }
            try
            {
                m_bIsPolling = true;

                IGestionnaireSessionsTimos gestionnaire   = (IGestionnaireSessionsTimos)C2iFactory.GetNewObject(typeof(IGestionnaireSessionsTimos));
                Dictionary <string, int?>  dicNbParProfil = new Dictionary <string, int?>();
                Dictionary <string, int?>  dicNbParUser   = new Dictionary <string, int?>();
                foreach (int nId in gestionnaire.GetListeIdSessionsConnectees())
                {
                    CSessionClientSurServeurTimos sessionSurServeur = gestionnaire.GetSessionClientSurServeur(nId) as CSessionClientSurServeurTimos;
                    if (sessionSurServeur != null && sessionSurServeur.UserLicence != null)
                    {
                        string strKeyUserLicence = sessionSurServeur.UserLicence.IdLys + " " + sessionSurServeur.UserLicence.ToString();
                        string strIdUtilisateur  = sessionSurServeur.KeyUtilisateur != null ? sessionSurServeur.KeyUtilisateur.StringValue : "";
                        int?   nVal = null;
                        try
                        {
                            if (sessionSurServeur.SessionClient.IsConnected)
                            {
                                if (!dicNbParProfil.TryGetValue(strKeyUserLicence, out nVal))
                                {
                                    nVal = 0;
                                }
                                nVal++;
                                dicNbParProfil[strKeyUserLicence] = nVal;
                                if (strIdUtilisateur.Length > 0)
                                {
                                    if (!dicNbParUser.TryGetValue(strIdUtilisateur, out nVal))
                                    {
                                        nVal = 0;
                                    }
                                    nVal++;
                                    dicNbParUser[strIdUtilisateur] = nVal;
                                }
                            }
                        }
                        catch { }
                    }
                }
                CDataHotelClient hotelClient = new CDataHotelClient();
                hotelClient.Init(m_strHotelURL);
                foreach (KeyValuePair <string, int?> kv in dicNbParProfil)
                {
                    string strIdEtt = kv.Key;
                    if (strIdEtt.Length == 0)
                    {
                        strIdEtt = "Empty";
                    }
                    hotelClient.StoreDataToSend(c_LicenceUsagePollingTableId, c_LicenceUsagePollingNbUsedFieldId,
                                                kv.Key, DateTime.Now, kv.Value.Value);
                }
                foreach (KeyValuePair <string, int?> kv in dicNbParUser)
                {
                    string strIdEtt = kv.Key;
                    if (strIdEtt.Length == 0)
                    {
                        strIdEtt = "Empty";
                    }
                    hotelClient.StoreDataToSend(c_LicenceUsagePollingTableId, c_LicenceUsagePollingNbUsedFieldId,
                                                kv.Key, DateTime.Now, kv.Value.Value);
                }
                hotelClient.FlushData();
            }
            catch { }
            finally{
                m_bIsPolling = false;
            }
        }