public static Assembly LoadAssembly(String fileName)
        {
            String eventHandlerPath = ConfigurationReader.GetAppSetting("eventhandlerbinaypath").ToString();

            if (!eventHandlerPath.EndsWith("/", StringComparison.CurrentCulture))
            {
                eventHandlerPath = eventHandlerPath + "/";
            }

            Logger.Debug("Loading assembly: " + eventHandlerPath + fileName);

            return(Assembly.LoadFile(eventHandlerPath + fileName));
        }
        public static Int32 Start()
        {
            Int32 maxEventWorkerThreads = Convert.ToInt32(ConfigurationReader.GetAppSetting("maxeventworkers"));

            connectionManager = new ConnectionManager("reportingwritemgr", maxEventWorkerThreads);

            TuDbConnection conn;

            try
            {
                conn = connectionManager.GetConnection();
            }
            catch (Exception ex)
            {
                Logger.Debug("Error connecting to reporting database: " + ex.Message);
                return(1);
            }

            List <Thread> threads = new List <Thread>();
            Dictionary <UInt64, EventQueue>    eventQueues     = new Dictionary <UInt64, EventQueue>();
            List <SupportedEventProcessor>     supportedEvents = new List <SupportedEventProcessor>();
            SupportedEventProcessorDataAdapter supportedEventProcessorDataAdapter = new SupportedEventProcessorDataAdapter(conn);


            try
            {
                supportedEvents = supportedEventProcessorDataAdapter.GetAll();

                foreach (SupportedEventProcessor e in supportedEvents)
                {
                    eventsQueueManager.DefineEvent(e.EventId);
                }

                //  Spawn worker threads

                foreach (SupportedEventProcessor eventProcessorInfo in supportedEvents)
                {
                    //      Logger.Debug("Starting next thread");

                    Thread t = new Thread(new ParameterizedThreadStart(ReportingServiceMain.Worker));

                    t.Start(eventProcessorInfo);

                    threads.Add(t);

                    Thread.Sleep(1000);
                }

                //   Logger.Debug(String.Format("Worker {0}: Releasing connection {1}", threadId, dbConnection.PoolId));

                connectionManager.Release(conn);

                Thread.Sleep(2000);
            }
            catch (Exception ex)
            {
                Logger.Debug(String.Format("Error starting threads: {0}", ex.Message));
                Thread.Sleep(5000);
            }

            foreach (Thread t in threads)
            {
                t.Join();
            }

            return(0);
        }