/// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main()
        {
#if DEBUG
            WeiService service = new WeiService();
            service.Start();
#else
            ServiceBase[] ServicesToRun;
            ServicesToRun = new ServiceBase[]
            {
                new WeiService()
            };
            ServiceBase.Run(ServicesToRun);
#endif
        }
예제 #2
0
 protected override void OnStop()
 {
     Console.WriteLine("in stop");
     stopInterfaces();
     for (int i = 0; i < 10; i++)
     {
         if (WeiService.isAnyInterfaceRunning())
         {
             Thread.Sleep(5000);
         }
     }
     if (serviceHost != null)
     {
         serviceHost.Close();
         serviceHost = null;
     }
 }
예제 #3
0
        protected override void OnStart(string[] args)
        {
            Assembly assembly = Assembly.GetExecutingAssembly();
            String   fileName = assembly.Location + ".config";

            if (!File.Exists(fileName))
            {
                throw new Exception("Missing configuration file. Expecting file @" + fileName);
            }

            LogUtil.logInfo("Starting Wei Service");
            try
            {
                _dbUtils          = EnterpriseLibraryContainer.Current.GetInstance <DBUtil>();
                _interfaceManager = EnterpriseLibraryContainer.Current.GetInstance <InterfaceManager>();
                _requestManager   = new RequestManager(_dbUtils);
                _interfaceManager.initailize(this);

                if (serviceHost != null)
                {
                    serviceHost.Close();
                }

                // Create a ServiceHost for the CalculatorService type and
                // provide the base address.
                serviceHost = new ServiceHost(typeof(WeiMonitoring));

                // Open the ServiceHostBase to create listeners and start
                // listening for messages.

                serviceHost.Open();
                instance = this;
                LogUtil.logInfo("Started Wei Service");
            }
            catch (AddressAlreadyInUseException e)
            {
                LogUtil.log("Service address is already in use", e);
            }
            catch (Exception e)
            {
                LogUtil.log("Error Starting Wei Service", e);
                throw (e);
            }
        }
        public void initailize(WeiService service)
        {
            LogUtil.logDebug("Starting initailize in InterfaceManager");
            DbCommand cmd = _weidb.GetStoredProcCommand("Wei_getInterfaces");

            using (IDataReader dataReader = _weidb.ExecuteReader(cmd))
            {
                LogUtil.logDebug("Executed getInterfaces");
                while (dataReader.Read())
                {
                    LogUtil.logDebug("Has data from getInterfaces");
                    try
                    {
                        int interfaceId = (int)dataReader["id"];

                        LogUtil.logInfo("Starting Interface:" + dataReader["name"] + " with interface id " + interfaceId + " DriverType:" + dataReader["drivername"].ToString() + " HandlerType: " + dataReader["handlername"].ToString());

                        IHandler handler = createHandlerIfReqd(dataReader["handlername"].ToString(), dataReader["handlerdll"].ToString(), dataReader["handlertype"].ToString());
                        IDriver  driver  = createDriver(dataReader["drivername"].ToString(), dataReader["driverdll"].ToString(), dataReader["drivertype"].ToString());

                        if (handler == null || driver == null)
                        {
                            LogUtil.logInfo("Skipping Interface:" + dataReader["name"] + " with interface id " + interfaceId + " DriverType:" + dataReader["drivername"].ToString() + " HandlerType: " + dataReader["handlername"].ToString() + ". Handler=" + handler + " and driver=" + driver);
                            continue;
                        }
                        driver.initialize(interfaceId, dataReader["config"].ToString(), service.RequestManager, service.DBUtil);

                        interfaces.Add(interfaceId, new Interface(interfaceId, (string)dataReader["name"], handler, driver, dataReader["fileformat"].ToString()));

                        driver.start();

                        LogUtil.logInfo("Started Interface:" + dataReader["name"]);
                    }
                    catch (Exception e)
                    {
                        LogUtil.log("Error starting the interface", e);
                    }
                }
                LogUtil.logDebug("Exiting initialize in InterfaceManager");
            }
        }
        private bool shutdown(bool force)
        {
            WeiService.stopInterfaces();
            for (int i = 0; i < 10; i++)
            {
                if (WeiService.isAnyInterfaceRunning())
                {
                    Thread.Sleep(5000);
                }
                else
                {
                    WeiService.instance.Stop();
                    return(true);
                }
            }

            if (force)
            {
                WeiService.instance.Stop();
                return(true);
            }

            return(false);
        }