コード例 #1
0
 private void onTimerElapsed(object sender, System.Timers.ElapsedEventArgs e)
 {
     //Event handler for self timed operation
     try {
         if (this.mStartup)
         {
             //Set startup condition- create utility service
             this.mStartup        = false;
             this.mTimer.Interval = getTimerInterval();
             initServices();
         }
         if (!this.mShutdown)
         {
             //Run the service
             for (int i = 0; i < this.mSvcs.Length; i++)
             {
                 FileMgr svc = this.mSvcs[i];
                 svc.Execute();
             }
             for (int j = 0; j < this.mFTPSvcs.Length; j++)
             {
                 FTPMgr ftp = this.mFTPSvcs[j];
                 ftp.Execute();
             }
         }
         else
         {
             //Shutdown condition
             this.mTimer.Enabled = false;
         }
     }
     catch (ApplicationException ex) { throw ex; }
     catch (Exception ex) { reportError(new ApplicationException("Unexpected error in timer interval operations.", ex), false, true); }
 }
コード例 #2
0
 protected override void OnStart(string[] args)
 {
     //Set things in motion so your service can do its work
     try {
         //Timed or one shot
         if (this.mUseTimer)
         {
             this.mStartup        = true;
             this.mTimer.Interval = 100;
             this.mTimer.Enabled  = true;
         }
         else
         {
             initServices();
             for (int i = 0; i < this.mSvcs.Length; i++)
             {
                 FileMgr svc = this.mSvcs[i];
                 svc.Execute();
             }
             for (int j = 0; j < this.mFTPSvcs.Length; j++)
             {
                 FTPMgr ftp = this.mFTPSvcs[j];
                 ftp.Execute();
             }
         }
     }
     catch (Exception ex) { reportError(new ApplicationException("Unexpected error in OnStart.", ex), false, true); }
 }
コード例 #3
0
        private void initServices()
        {
            //Create service instances based upon the configuration file
            try {
                //Read configuration from app.config
                IDictionary oDict = (IDictionary)ConfigurationManager.GetSection("dirs");
                if (oDict != null)
                {
                    int dirs = Convert.ToInt32(oDict["count"]);
                    this.mSvcs = new FileMgr[dirs];
                    for (int i = 1; i <= dirs; i++)
                    {
                        oDict = (IDictionary)ConfigurationManager.GetSection("dir" + i.ToString());
                        string  src     = oDict["src"].ToString();
                        string  pattern = oDict["pattern"].ToString();
                        string  dest    = oDict["dest"].ToString();
                        string  suffix  = oDict["suffix"].ToString();
                        FileMgr oSvc    = new FileMgr(src, pattern, dest, suffix);
                        this.mSvcs[i - 1] = oSvc;
                    }
                }

                oDict = (IDictionary)ConfigurationManager.GetSection("ftps");
                if (oDict != null)
                {
                    int ftps = Convert.ToInt32(oDict["count"]);
                    this.mFTPSvcs = new FTPMgr[ftps];
                    for (int i = 1; i <= ftps; i++)
                    {
                        oDict = (IDictionary)ConfigurationManager.GetSection("ftp" + i.ToString());
                        string server   = oDict["server"].ToString();
                        string path     = oDict["path"].ToString();
                        string pattern  = oDict["pattern"].ToString();
                        string userid   = oDict["userid"].ToString();
                        string password = oDict["password"].ToString();
                        string prefix   = oDict["prefix"].ToString();
                        string suffix   = oDict["suffix"].ToString();
                        FTPMgr ftp      = new FTPMgr(server, path, pattern, userid, password, prefix, suffix);
                        this.mFTPSvcs[i - 1] = ftp;
                    }
                }
            }
            catch (ApplicationException ex) { throw ex; }
            catch (Exception ex) { reportError(new ApplicationException("Unexpected error in initializing services.", ex), false, true); }
        }