Ejemplo n.º 1
0
        private void InitProcess()
        {
            //Configure Enterprise Model Library
            EnterpriseModel.Net.LibConfig.Instance.Config = new CooperAtkins.NotificationClient.Generic.DataAccess
                                                            .EnterpriseModelConfig(ConfigurationManager.ConnectionStrings["SqlConnectionString"].ConnectionString);

            EnterpriseModelConfig config = new EnterpriseModelConfig(ConfigurationManager.ConnectionStrings["SqlConnectionString"].ConnectionString);

            bool connectionOpened = false;
            int  lastAttemptMins  = 5 * 1000;

            while (!connectionOpened)
            {
                EnterpriseModel.Net.DataAccess dataAccess = null;
                try
                {
                    dataAccess = config.GetDbGateway();
                    dataAccess.Initialize();
                    dataAccess.Connection.Open();
                    connectionOpened = true;
                    dataAccess.Connection.Close();
                }
                catch
                {
                    LogBook.Write("Unable to open database connection, SqlConnectionString:" + "");
                    LogBook.Write("Attempting to connect after:" + (lastAttemptMins / 1000).ToString() + " Seconds");
                    Thread.Sleep(lastAttemptMins);
                    lastAttemptMins += lastAttemptMins;
                }
                finally
                {
                    if (dataAccess != null)
                    {
                        dataAccess.Dispose();
                    }
                }
            }

            target = new AlarmInitializer();

            try
            {
                //target.SetServerTime();
            }
            catch
            {
            }

            /* if user restarts the service, this operation will resumes previously lost notification*/
            target.ResumeNotificationProcess();

            button1_Click(null, null);

            UDPListener();
        }
Ejemplo n.º 2
0
        private void StartService()
        {
            if (connString.ToStr() == string.Empty)
            {
                connString = ConfigurationManager.ConnectionStrings["SqlConnectionString"].ConnectionString;
            }
            connString = connString.Remove(0, connString.IndexOf(";") + 1);
            connString = connString.Replace("MultipleActiveResultSets=true;", "");

            EnterpriseModelConfig config = new EnterpriseModelConfig(connString);

            bool connectionOpened = false;
            int  lastAttemptMins  = 30 * 1000;

            while (!connectionOpened)
            {
                DataAccess dataAccess = null;
                try
                {
                    dataAccess = config.GetDbGateway();
                    dataAccess.Initialize();
                    dataAccess.Connection.Open();
                    connectionOpened = true;
                    initializeProcess.isDBConnected = true;
                    dataAccess.Connection.Close();
                }
                catch
                {
                    LogBook.Write("Unable to open database connection, SqlConnectionString:" + connString);
                    LogBook.Write("Attempting to connect after:" + (lastAttemptMins / 1000).ToString() + " Seconds");
                    Thread.Sleep(lastAttemptMins);
                    lastAttemptMins += lastAttemptMins;
                }
            }

            /* if the the process type is not a sub process */
            if (_args != null && _args.Length == 0)
            {
                initializeProcess.InitProcess(_args);
            }


            if (initializeProcess.DefaultConnectionString.ToStr() != string.Empty)
            {
                connString = initializeProcess.DefaultConnectionString;
            }

            config = new EnterpriseModelConfig(connString);

            EnterpriseModel.Net.LibConfig.Instance.Config = config;

            if (DBName.ToStr() == string.Empty)
            {
                DBName = initializeProcess.firstDBName;
            }

            if (DBName.ToStr() == string.Empty)
            {
                DBName = "Intelliware";
            }

            //Program.
            //Check if the old notification service is running
            LogBook.SetAppName(DBName);

            string logPath = GetRegValue("LogFilePath", Common.TEMP_TRAK_REG_KEY).ToStr();

            /*in case if it returns empty*/
            if (logPath.Trim() == string.Empty)
            {
                //logPath = @"C:\log.txt";
                logPath = @"C:\Program Files (x86)\TempTrak\LogFiles";
            }

            if (OUID == 0)
            {
                logPath = logPath + @"\IWNotify.log";
            }
            else
            {
                logPath = logPath + @"\IWNotify-" + OUID + ".log";
            }

            LogBook.SetLogFilePath(logPath);
            LogBook.Write("LogPath: " + logPath);

            /* LogBook.Write("Checking the Old version is running");
             * string serviceName = "Intelli-Ware Notification Service";
             * //set the time out for the service to stop
             * int timeoutMilliseconds = 500;
             *
             * ServiceController service = new ServiceController(serviceName);
             *
             * try
             * {
             *
             *   System.TimeSpan timeout = System.TimeSpan.FromMilliseconds(timeoutMilliseconds);
             *   //if the service is running stop the service, else write a log to know the service status
             *   if (service.Status == ServiceControllerStatus.Running)
             *   {
             *       LogBook.Write("Old version is running");
             *       service.Stop();
             *       service.WaitForStatus(ServiceControllerStatus.Stopped, timeout);
             *       LogBook.Write("Old version is stopped");
             *   }
             *   else
             *   { LogBook.Write("Old version is not running"); }
             * }
             * catch (Exception ex)
             * {
             *   //log the error if an error occurs while stopping the old notification service
             *   LogBook.Write("Exception occurred while checking the old service status.");
             *   LogBook.Write(ex.StackTrace);
             * }
             * finally { service.Dispose(); }
             */
            LogBook.Write("New Service Starting....");
            InitProcess();
        }