Example #1
0
        ///<summary>Wrapper method to call the passed-in func in a seperate thread connected to the reporting server.
        ///This method should only be used for SELECT, with the exception DashboardAR. Using this for create/update/delete may cause duplicates.
        ///The return type of this function is whatever the return type of the method you passed in is.
        ///Throws an exception if anything went wrong executing func within the thread.</summary>
        ///<param name="doRunOnReportServer">If this false, the func will run against the currently connected server.</param>
        public static T RunFuncOnReportServer <T>(Func <T> func, bool doRunOnReportServer = true)
        {
            if (!doRunOnReportServer)
            {
                return(func());
            }
            Exception ex             = null;
            ODThread  threadGetTable = new ODThread(new ODThread.WorkerDelegate((ODThread o) => {
                DataAction.Run(() => { o.Tag = func(); }                    //set the tag to the func's output.
                               , ConnectionNames.DentalOfficeReportServer); //run on the report server. if not set up, automatically runs on the current server.
            }));

            threadGetTable.AddExceptionHandler(new ODThread.ExceptionDelegate((Exception e) => {
                ex = e;
            }));
            threadGetTable.Name = "ReportComplexGetTableThread";
            threadGetTable.Start(true);
            threadGetTable.Join(Timeout.Infinite);
            //Now that we are back on the main thread, it is now safe to throw exceptions.
            if (ex != null)
            {
                ExceptionDispatchInfo.Capture(ex.InnerException ?? ex).Throw();              //This preserves the stack trace of the InnerException.
            }
            return((T)threadGetTable.Tag);
        }
Example #2
0
 ///<summary>Adds a PrefCache for the given database connection. Used by UnitTestsWeb.</summary>
 public static void AddCache(ConnectionNames connName)
 {
     DataAction.Run(() => {
         PrefCache cache = new PrefCache();
         if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
         {
             DataTable table = GetTableFromCache(false);
             cache.FillCacheFromTable(table);
         }
         else
         {
             cache.GetTableFromCache(true);
         }
         _dictCachesForDbs[connName] = cache;
     }, connName);
 }
Example #3
0
        ///<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);
        }