Beispiel #1
0
        static string GetDatabaseParms()
        {
            string DatabaseSource = "";
            string InitialCatalog = "";
            string MachineName    = "";

            MbcsUtils.Parameters parms = null;
            parms = new MbcsUtils.Parameters(appPath + LOCAL_USER_DIRECTORY + "\\" + MBCSCENTRAL_CONFIG);
            parms.getConfigs();
            object obj = null;

            parms.getItem("databaseSource", ref obj);
            DatabaseSource = (string)obj; //  + ",1433";
            parms.getItem("initialCatalog", ref obj);
            InitialCatalog = (string)obj;
            parms.getItem("MachineName", ref obj);
            MachineName = (string)(obj == null || ((string)obj).Contains("*") ? "" : (string)obj + "\\");
            if (DatabaseSource == null || InitialCatalog == null || DatabaseSource.Trim() == "" || InitialCatalog.Trim() == "")
            {
                return(null);
            }
            if (MachineName != null && !MachineName.Trim().Equals(""))
            {
                DatabaseSource = MachineName + DatabaseSource;
            }
            return(SqlBaseConnectionString.Replace("<source>", DatabaseSource).
                   Replace("<catalog>", InitialCatalog).
                   Replace("<user>", DB_USER_NAME).
                   Replace("<password>", DB_PASSWORD));
        }
Beispiel #2
0
        protected override void OnStart(string[] args)
        {
            // Add code here to start your service. This method should set things
            // in motion so your service can do its work.

            Thread.Sleep(30000);
            appPath = System.AppDomain.CurrentDomain.BaseDirectory;
            if (!appPath.EndsWith("\\"))
            {
                appPath += "\\";
            }

            GlobalShared.user = new MbcsCentral.Accounts();
            //GlobalShared.user.setName("Service");
            GlobalShared.logFileName     = "MbcsListener.log";
            GlobalShared.Log             = MbcsUtils.LogClass.instance;
            GlobalShared.Log.logFileName = appPath + GlobalShared.logFileName;

            GlobalShared.Log.Log((int)LogClass.logType.Config, "***********************************", false);
            GlobalShared.Log.Log((int)LogClass.logType.Config, "Starting up. appPath=" + appPath, false);
            GlobalShared.Log.Log((int)LogClass.logType.Config, "***********************************", false);

            // Setup connectionstrings and paths
            GlobalShared.Log.Log((int)LogClass.logType.Config, "Setting up connectionstrings and paths", false);
            MbcsUtils.Parameters configs = new MbcsUtils.Parameters(appPath + "MbcsListener.config");
            try
            {
                configs.getConfigs();
            }
            catch (System.Exception ex)
            {
                GlobalShared.Log.Log((int)LogClass.logType.Config, "Error getting configs. There may be a duplicate name. Cannot continue. " + ex.Message, false);
                return;
            }
            object obj = null;

            configs.getItem(GlobalShared.smtpConfigs[(int)GlobalShared.smtpItem.MbcsListenerPath], ref obj);
            MbcsListenerPath = (string)obj;
            string connectionString = GetDatabaseParms();

            GlobalShared.Log.Log((int)LogClass.logType.Config, "   MbcsListenerPath=" + MbcsListenerPath, false);
            string oldString = "dbSource";
            string newString = "WinTRM.accdb";

            //pmPath = GetSetting(AppName:="Winpm", Section:="Options", Key:="DefaultDataBase", Default:="c:\\pmsys\\winpm.mdb")
            GlobalShared.Log.Log((int)LogClass.logType.Config, "   pmPath=" + GlobalShared.pmPath, false);
            connectionString = connectionString.Replace(oldString, MbcsListenerPath + newString);
            GlobalShared.CN  = new SqlConnection(connectionString);
            GlobalShared.Log.Log((int)LogClass.logType.Config, "   CN=" + connectionString, false);
            // Setup MAIL directories
            GlobalShared.mailDir    = MbcsListenerPath + GlobalShared.mailDir;
            GlobalShared.mailInDir  = GlobalShared.mailDir + GlobalShared.mailInDir;
            GlobalShared.mailOutDir = GlobalShared.mailDir + GlobalShared.mailOutDir;
            GlobalShared.Log.Log((int)LogClass.logType.Config, "   mailDir=" + GlobalShared.mailDir, false);
            GlobalShared.Log.Log((int)LogClass.logType.Config, "   mailInDir=" + GlobalShared.mailInDir, false);
            GlobalShared.Log.Log((int)LogClass.logType.Config, "   mailOutdir=" + GlobalShared.mailOutDir, false);

            GlobalShared.Log.Log((int)LogClass.logType.Config, "Retrieving SMTP configuration.", false);
            string fldr = string.Format("{0}\\{1}\\{2}\\{3}", Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), "MBCS", "Wintrm", "MbcsListener.config");

            //If Not IsNothing(configs) Then
            //DictUtils.getItem(configs, smtpConfigs(smtpItem.ListenSleepTime), RETRIEVE_MAIL_INTERVAL)
            //DictUtils.getItem(configs, smtpConfigs(smtpItem.ReadOutlook), readOutlook)
            //DictUtils.getItem(configs, smtpConfigs(smtpItem.ReadSmtp), readSmtp)
            //DictUtils.getItem(configs, smtpConfigs(smtpItem.AuthenticationReceive), authenticationType)
            //DictUtils.getItem(configs, smtpConfigs(smtpItem.UserName), Username)
            //DictUtils.getItem(configs, smtpConfigs(smtpItem.Password), Password)
            //DictUtils.getItem(configs, smtpConfigs(smtpItem.IncomingHost), Host)
            //DictUtils.getItem(configs, smtpConfigs(smtpItem.IncomingPort), Port)
            //DictUtils.getItem(configs, smtpConfigs(smtpItem.EmailAddress), Email)
            //DictUtils.getItem(configs, smtpConfigs(smtpItem.UseInSSL), SSL)
            //DictUtils.getItem(configs, smtpConfigs(smtpItem.UseInTSL), TSL)
            //End If

            GlobalShared.Log.Log((int)LogClass.logType.Config, "   Username="******"   Password="******"   Host=" + Host, false);
            GlobalShared.Log.Log((int)LogClass.logType.Config, "   Port=" + Port, false);
            GlobalShared.Log.Log((int)LogClass.logType.Config, "   Email=" + Email, false);
            GlobalShared.Log.Log((int)LogClass.logType.Config, "   SSL=" + SSL, false);
            GlobalShared.Log.Log((int)LogClass.logType.Config, "   TSL=" + TSL, false);
            GlobalShared.Log.Log((int)LogClass.logType.Config, "   Authentication=" + authenticationType, false);
            GlobalShared.Log.Log((int)LogClass.logType.Config, "   RETRIEVE_MAIL_INTERVAL=" + RETRIEVE_MAIL_INTERVAL, false);
            GlobalShared.Log.Log((int)LogClass.logType.Config, "   ReadSmtp=" + readSmtp, false);
            GlobalShared.Log.Log((int)LogClass.logType.Config, "   ReadOutlook=" + readOutlook, false);

            //If Username.Trim = "" Or Host.Trim = "" Or Port <= 0 Or Email.Trim = "" Then
            //Log.Log((int)LogClass.logType.ErrorCondition, "No Username found. Email configuration needs to be setup. Exiting")
            //End If

            obj = "HELLO";
            TimerCallback tcb = this.listen;

            GlobalShared.Log.Log((int)LogClass.logType.Config, "Setting up Timer", false);
            try {
                myTimer = new System.Threading.Timer(tcb, obj, DELAY, RETRIEVE_MAIL_INTERVAL);
            } catch (System.IO.FileNotFoundException ex) {
                GlobalShared.Log.Log((int)LogClass.logType.ErrorCondition, ex.Message, false);
            } catch (System.Exception ex) {
                GlobalShared.Log.Log((int)LogClass.logType.ErrorCondition, ex.Message, false);
            }
            GlobalShared.Log.Log((int)LogClass.logType.Config, "Ready to listen for messages", false);

            //End If
        }