Ejemplo n.º 1
0
 /// <summary>
 /// Attempts to terminate the application.
 /// </summary>
 /// <returns>Null if the operation succeeds, or a <see cref="SerializedException"/>
 /// encapsulating the error that occured if the operation fails.</returns>
 public void Terminate(ref SerializedException sx)
 {
     try
     {
         //System.Windows.Forms.Application.Exit();
         Client.Instance().MustTerminate = true;
     }
     catch (Exception e)
     {
         sx = new SerializedException(e.GetType().ToString(), e.Message, e.StackTrace);
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Handles the SessionEnding events, allowing the client to terminate if the system
 /// is shutting down but not be affected if the user is simply logging off.
 /// </summary>
 /// <param name="sender">The object related to the event.</param>
 /// <param name="e">The arguments related to the event.</param>
 private static void SystemEvents_SessionEnding(object sender, SessionEndingEventArgs e)
 {
     try
     {
         if (e.Reason == SessionEndReasons.SystemShutdown)
         {
             Client client = Client.Instance();
             client.mustTerminate = true;
             e.Cancel             = false;
         }
     }
     catch
     {}
 }
Ejemplo n.º 3
0
 static void Main(string [] args)
 {
     //Attach the default Exception handlers
     AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(UnhandledExceptionHandler);
     Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(ApplicationThreadExceptionHandler);
     try
     {
         if (CheckForRunningInstances(false))
         {
             //there is another instance of the application running so this one must exit
             return;
         }
         Client client = Client.Instance();
         //set the time scheduler to control the automatic start/stop of the crawling
         if (client.globals.Settings.EnableScheduler)
         {
             client.startScheduler              = new AlarmTimer();
             client.startScheduler.AlarmTime    = DateTime.Parse(client.globals.Settings.StartTime.ToShortTimeString());
             client.startScheduler.OnAlarmBell += new EventHandler(startScheduler_OnAlarmBell);
             client.startScheduler.Enabled      = true;
             client.startScheduler.Start();
             client.stopScheduler              = new AlarmTimer();
             client.stopScheduler.AlarmTime    = DateTime.Parse(client.globals.Settings.StopTime.ToShortTimeString());
             client.stopScheduler.OnAlarmBell += new EventHandler(stopScheduler_OnAlarmBell);
             client.stopScheduler.Enabled      = true;
             client.stopScheduler.Start();
             if ((DateTime.Now > client.startScheduler.AlarmTime) && (DateTime.Now < client.stopScheduler.AlarmTime))
             {
                 client.startScheduler.AlarmTime.AddDays(1);
                 client.stopScheduler.AlarmTime.AddDays(1);
                 client.crawler = Crawler.Instance();
                 if (client.globals.Client_Info.UserID != 0)
                 {
                     client.crawler.Start();
                 }
             }
         }
         else
         {
             client.crawler = Crawler.Instance();
             if (client.globals.Client_Info.UserID != 0)
             {
                 client.crawler.Start();
             }
         }
         //Attach the System Shutdown detection observer
         //SystemEvents.SessionEnding += new SessionEndingEventHandler(SystemEvents_SessionEnding);
         //Allow the control of the client through Remoting
         RemotingConfiguration.Configure(client.globals.AppPath + "CrawlWave.Client.exe.config", true);
         while (!client.mustTerminate)
         {
             //Wait until it's time to exit
             Thread.Sleep(Backoff.DefaultBackoff);
             if (Environment.HasShutdownStarted)
             {
                 break;
             }
         }
     }
     catch (Exception e)
     {
         MessageBox.Show("CrawlWave Client failed to start:\n" + e.Message, "CrawlWave Client", MessageBoxButtons.OK, MessageBoxIcon.Error);
         return;
     }
 }