///<summary>Gets one EServiceSignalHQ from the serviceshq db located on SERVER184. Returns null in case of failure.</summary> public static EServiceMetrics GetEServiceMetricsFromSignalHQ() { if (RemotingClient.RemotingRole == RemotingRole.ClientWeb) { return(Meth.GetObject <EServiceMetrics>(MethodBase.GetCurrentMethod())); } EServiceMetrics eServiceMetric = new EServiceMetrics(); if (PrefC.ContainsKey("ServicesHqDoNotConnect") && PrefC.GetBool(PrefName.ServicesHqDoNotConnect)) { eServiceMetric.ErrorMessage = "Not allowed to connect to the serviceshq database."; return(eServiceMetric); } string dbPassword; if (!CDT.Class1.Decrypt(PrefC.GetString(PrefName.ServicesHqMySqpPasswordObf), out dbPassword)) { eServiceMetric.ErrorMessage = "Unable to decrypt serviceshq password"; return(eServiceMetric); } try { DataAction.Run(() => { //See EServiceSignalHQs.GetEServiceMetrics() for details. string command = @"SELECT 0 EServiceSignalNum, h.* FROM eservicesignalhq h WHERE h.ReasonCode=1024 AND h.ReasonCategory=1 AND h.ServiceCode=2 AND h.RegistrationKeyNum=-1 ORDER BY h.SigDateTime DESC LIMIT 1" ; EServiceSignal eServiceSignal = Crud.EServiceSignalCrud.SelectOne(command); if (eServiceSignal != null) { using (XmlReader reader = XmlReader.Create(new System.IO.StringReader(eServiceSignal.Tag))) { eServiceMetric = (EServiceMetrics) new XmlSerializer(typeof(EServiceMetrics)).Deserialize(reader); } eServiceMetric.IsValid = true; } }, PrefC.GetString(PrefName.ServicesHqServer), PrefC.GetString(PrefName.ServicesHqDatabase), PrefC.GetString(PrefName.ServicesHqMySqlUser), dbPassword, "", "", DatabaseType.MySql); } catch (Exception ex) { eServiceMetric.ErrorMessage = ex.Message; } return(eServiceMetric); }
///<summary>Get metrics from serviceshq.</summary> public static EServiceMetrics CalculateMetrics(float accountBalanceEuro) { //No remoting role check, No call to database. DateTime dateTimeStart = DateTime.Today; DateTime dateTimeEnd = dateTimeStart.AddDays(1); List <string> websitesDown = PrefC.GetRaw("BroadcasterWebsitesToMonitor").Split(',') .Select(x => WebSiteIsAvailable(x)).ToList(); websitesDown.RemoveAll(x => string.IsNullOrEmpty(x.Trim())); EServiceMetrics ret = new EServiceMetrics() { Timestamp = DateTime.Now, AccountBalanceEuro = accountBalanceEuro, IsBroadcasterHeartbeatOk = GetIsBroadcasterHeartbeatOk(), WebsitesDown = string.Join("; ", websitesDown), IsValid = true, }; return(ret); }
///<summary>Gets one EServiceSignalHQ from the serviceshq db located on SERVER184. Returns null in case of failure.</summary> public static EServiceMetrics GetEServiceMetricsFromSignalHQ() { if (RemotingClient.RemotingRole == RemotingRole.ClientWeb) { return(Meth.GetObject <EServiceMetrics>(MethodBase.GetCurrentMethod())); } //Create an ODThread so that we can safely change the database connection settings without affecting the calling method's connection. ODThread odThread = new ODThread(new ODThread.WorkerDelegate((ODThread o) => { //Always set the thread static database connection variables to set the serviceshq db conn. new DataConnection().SetDbT("server184", "serviceshq", "root", "", "", "", DatabaseType.MySql, true); //See EServiceSignalHQs.GetEServiceMetrics() for details. string command = @"SELECT 0 EServiceSignalNum, h.* FROM eservicesignalhq h WHERE h.ReasonCode=1024 AND h.ReasonCategory=1 AND h.ServiceCode=2 AND h.RegistrationKeyNum=-1 ORDER BY h.SigDateTime DESC LIMIT 1" ; EServiceSignal eServiceSignal = Crud.EServiceSignalCrud.SelectOne(command); EServiceMetrics eServiceMetric = new EServiceMetrics(); if (eServiceSignal != null) { using (XmlReader reader = XmlReader.Create(new System.IO.StringReader(eServiceSignal.Tag))) { eServiceMetric = (EServiceMetrics) new XmlSerializer(typeof(EServiceMetrics)).Deserialize(reader); } eServiceMetric.IsValid = true; } o.Tag = eServiceMetric; })); odThread.AddExceptionHandler(new ODThread.ExceptionDelegate((Exception e) => { })); //Do nothing odThread.Name = "eServiceMetricsThread"; odThread.Start(true); if (!odThread.Join(2000)) //Give this thread up to 2 seconds to complete. { return(null); } EServiceMetrics retVal = (EServiceMetrics)odThread.Tag; return(retVal); }