/// <summary>
        /// Service logic method
        /// </summary>
        /// <param name="arg"></param>
        private void DoWork(object arg)
        {
            for (; ; )
            {
                if (iVantageImportStop.WaitOne(10000))
                    return;

                try
                {
                    EmployeeModel employeeModel = new EmployeeModel();
                    employeeModel.ServiceWork();
                }
                catch (Exception ex)
                {
                    Logger.Write(string.Format("An error has ocurred while running the IVantage Import Service!\n{0}\n{1}", ex.Message, ex.StackTrace));

                    SettingsModel settings = new SettingsModel();
                    EmailModel emailModel = new EmailModel();
                    StringBuilder mailError = new StringBuilder();
                    mailError.AppendLine(string.Format("An error has ocurred while running the IVantage Import Service!\n{0}\n{1}", ex.Message, ex.StackTrace));
                    //MailUtility.SendMail(settings.GetITEmailOnError(), "", "", mailError.ToString(), "IVantage Import Service - Error occured on Employee Information", false, null);
                    emailModel.SaveEmailList(settings.GetITEmailOnError(), "IVantage Import Service - Error occured on Employee Information", mailError.ToString(), "System", (int)Globals.Security.SystemEmployeeID);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Service Method that will start the import process of IVantage data
        /// </summary>
        /// <returns>True if process ran OK, False if there was an error</returns>
        public bool ServiceWork()
        {
            SettingsModel settings = new SettingsModel();
            EmailModel emailModel = new EmailModel();

            try
            {
                UpdateDivisions();
            }
            catch (Exception ex)
            {
                Logger.Write(string.Format("An error has ocurred while trying to import the Division information!\n{0}\n{1}", ex.InnerException, ex.StackTrace));

                StringBuilder mailError = new StringBuilder();
                mailError.AppendLine(string.Format("An Error Ocurred when importing the Division Information!\n{0}\n{1}", ex.InnerException, ex.StackTrace));
                //MailUtility.SendMail(settings.GetITEmailOnError(), "", "", mailError.ToString(), "IVantage Import Service - Error occured on Division Information", false, null);
                emailModel.SaveEmailList(settings.GetITEmailOnError(), "IVantage Import Service - Error occured on Division Information", mailError.ToString(), "System", (int)Globals.Security.SystemEmployeeID);

                return false;
            }

            try
            {
                UpdateEmployees();
            }
            catch (Exception ex)
            {
                Logger.Write(string.Format("An error has ocurred while trying to import the Employee information!\n{0}\n{1}", ex.InnerException, ex.StackTrace));

                StringBuilder mailError = new StringBuilder();
                mailError.AppendLine(string.Format("An Error Ocurred when importing the Employee Information!\n{0}\n{1}", ex.InnerException, ex.StackTrace));
                //MailUtility.SendMail(settings.GetITEmailOnError(), "", "", mailError.ToString(), "IVantage Import Service - Error occured on Employee Information", false, null);
                emailModel.SaveEmailList(settings.GetITEmailOnError(), "IVantage Import Service - Error occured on Employee Information", mailError.ToString(), "System", (int)Globals.Security.SystemEmployeeID);

                return false;
            }

            try
            {
                UpdateEmergencyContacts();
            }
            catch (Exception ex)
            {
                Logger.Write(string.Format("An error has ocurred while trying to import the Emergency Contact information!\n{0}\n{1}", ex.InnerException, ex.StackTrace));

                StringBuilder mailError = new StringBuilder();
                mailError.AppendLine(string.Format("An Error Ocurred when importing the Emergency Contact Information!\n{0}\n{1}", ex.InnerException, ex.StackTrace));
                //MailUtility.SendMail(settings.GetITEmailOnError(), "", "", mailError.ToString(), "IVantage Import Service - Error occured on Emergency Contact Information", false, null);
                emailModel.SaveEmailList(settings.GetITEmailOnError(), "IVantage Import Service - Error occured on Emergency Contact Information", mailError.ToString(), "System", (int)Globals.Security.SystemEmployeeID);

                return false;
            }

            return true;
        }