Quick Search:

Mode

Context

Displaying 3 lines of context. None | Less | More | Full

Other Diffs

Ignore

Blank Lines Whitespace:

Diff

294
 
296
 
296
 
MainForm.cs
_>3737     ///
 3838     public class MainForm : System.Windows.Forms.Form
 3939     {
<> 40+        private enum OperationModes { Upload, CollectUpload, Collect };
  41+
4042         private MenuItem campaignMenuItem;
 4143         private MainMenu mainMenu1;
 4244         private MenuItem exitMenuItem;
     
 !
4547         private MenuItem menuCollectUpload;
 4648         private MenuItem menuUpload;
 4749 
<>48 -        //! Server url to send data
  50+        // Server url to send data
4951         private string _uploadServer = "";
 5052 
<>51 -        //! Timer delegate that points to the calling menu handler
 52 -        private Delegate _delegateMenus;
 53 -        //! Timer delegate for Status Textbox
  53+        // Timer delegate that points to the calling menu handler
  54+        //private Delegate _delegateMenus; // NMP: Waste
  55+
  56+        // Timer delegate for Status Textbox
5457         private Delegate _delegateStatusUpdate;
<>55 -        //! Timer delegate for Feedback Textbox
  58+        // Timer delegate for Feedback Textbox
5659         private Delegate _delegateFeedbackUpdate;
<>57 -        //! Timer delegate for Upload Textbox
  60+        // Timer delegate for Upload Textbox
5861         private Delegate _delegateUploadUpdate;
 5962                           
<>60 -        //! The main sensor manager that takes care of data collection and upload to server
  63+        // The main sensor manager that takes care of data collection and upload to server
6164         private SensorDataManager _sensorDataManager;
 6265 
 6366         private FeedbackManager _feedbackManager;
<>64 -        //! Points to procedure to thread
  67+        // Points to procedure to thread
6568         private TimerCallback _timerDelegate;
<>66 -        //! Variable for upload monitoring              
  69+        // Variable for upload monitoring              
6770         private System.Threading.Timer _uploadMonitorTimer;             
<>68 -        //! Check status of transmit and sensors every x milliseconds
 69 -        private const int UPLDMNTRINTRVL = 10000;                          
 70 -        //! Lock object used for controlling access to multithreaded function resources
  71+       
  72+        // Transmit and sensors monitor frequency (ms)
  73+        private const int uploadMonitorInterval = 10000;
  74+
  75+        private const int uploadInterval = 10000;
  76+       
  77+        // Lock object used for controlling access to multithreaded function resources
7178         private object _lock = new object();
 7279 
 7380         private bool _manualCapture = false;
     
 !
7683 
 7784         private string _campaignname = "";
 7885         private Boolean _uploadOnStart = false;
<> 86+        private Boolean _startOnLoad = false;
7987         private Boolean _debugModeOn = false;
 8088         private Boolean _killUploadMonitor = false;
 8189         private MenuItem menuConfig;
<> 90+       
8291         private Label label1;                          
<>83 -
8492         private Label status;
 8593         private Label upload;
 8694         private Panel loadingPanel;
     
 !
332340         /// <summary>
 333341         /// Timer function that displays status and error messages to screen
 334342         /// </summary>
<>335 -
336343         private void monitorUpload(Object o)
 337344         {
 338345             lock (_lock)
 339346             {
 340347                 Message msg;
<>341 -                bool error = false;
  348+                //bool error = false;
342349                 try
 343350                 {
 344351                     while (!_killUploadMonitor && (msg = DatabaseManager.MessageQueue.GetItem()) != null)
     
 !
347354                         if (msg.MType == MessageType.Error)
 348355                         {
 349356                             // critical system error
<>350 -                            error = true;   // stop the current operation if there are error messages
  357+                           // error = true;   // stop the current operation if there are error messages
351358 
 352359                             if (_debugModeOn)
 353360                                 Invoke(_delegateStatusUpdate, new Object[] { status, msg.ToString() });
     
 !
359366                         }
 360367                         else if (msg.MType == MessageType.Status)
 361368                         {
<>362 -                            Invoke(_delegateStatusUpdate, new Object[] { status, msg.ToString() });             // update the status textbox
  369+                            Invoke(_delegateStatusUpdate, new Object[] { status, msg.ToString() });
363370                         }
 364371                         else if (msg.MType == MessageType.Information)
 365372                         {
     
 !
369376                         else if (msg.MType == MessageType.UploadSuccess)
 370377                         {
 371378                             if (msg.Text.Length == 0)
<>372 -                                Invoke(_delegateUploadUpdate, new Object[] { upload, "" });                         // update the status textbox
  379+                                Invoke(_delegateUploadUpdate, new Object[] { upload, "" });                        
373380                             else
<>374 -                                Invoke(_delegateUploadUpdate, new Object[] { upload, msg.ToString() });             // update the status textbox
  381+                                Invoke(_delegateUploadUpdate, new Object[] { upload, msg.ToString() });            
375382                         }
 376383                         else if (msg.MType == MessageType.Feedback)
 377384                         {
 378385                             if (msg.Text.Length > 0)
<>379 -                                Invoke(_delegateFeedbackUpdate, new Object[] { status, msg.ToString() });             // display feedback in textbox
  386+                                // Display feedback in textbox
  387+                                Invoke(_delegateFeedbackUpdate, new Object[] { status, msg.ToString() });
380388                         }
 381389                         else if (msg.MType == MessageType.TaskComplete)
 382390                         {
<>383 -                            Invoke(_delegateUploadUpdate, new Object[] { status, msg.ToString() });                 // update the status textbox
 384 -                            Invoke(_delegateMenus, new Object[] { null, null });
  391+                            Invoke(_delegateUploadUpdate, new Object[] { status, msg.ToString() });
385392                         }
 386393                     }
 387394 
<>388 -                    if (error)
 389 -                        Invoke(_delegateMenus, new Object[] { null, null });
  395+                    //if (error)
  396+                    //    Invoke(_delegateMenus, new Object[] { null, null });
  397+                } catch {    
  398+                    // if there is an error at this point, it is most likely because the application is exiting and freeing resources, so don't bother showing it on screen
390399                 }
<>391 -                catch {     // if there is an error at this point, it is most likely because the application is exiting and freeing resources, so don't bother showing it on screen
 392 -               
 393 -                }
394400             }
 395401         }
 396402 
     
 !
469475             status.Height = Screen.PrimaryScreen.WorkingArea.Height;
 470476         }
 471477 
<>472 -        //! Close sensors and any transmit monitors
  478+        // Close sensors and any transmit monitors
473479         private void MainForm_Closed(object sender, System.EventArgs e)
 474480         {
<>475 -            if (_uploadMonitorTimer != null)
 476 -            {
 477 -                _killUploadMonitor = true;
 478 -                _uploadMonitorTimer.Dispose();
 479 -            }          
 480 -            _sensorDataManager.CloseSensors();
  481+            closeSensors();
481482         }
 482483 
 483484         //! Start upload monitor thread
     
 !
487488             _killUploadMonitor = false;
 488489             AutoResetEvent autoEvent = new AutoResetEvent(false);
 489490             _timerDelegate = new TimerCallback(monitorUpload);
<>490 -            _uploadMonitorTimer = new System.Threading.Timer(_timerDelegate, autoEvent, 0, UPLDMNTRINTRVL);
  491+            _uploadMonitorTimer = new System.Threading.Timer(_timerDelegate, autoEvent, 0, uploadMonitorInterval);
  492+        }
491493 
<> 494+        private void uploadData() { }
  495+
  496+        private void collectData() { }
  497+
  498+        private void closeSensors(){
  499+            if (_uploadMonitorTimer != null)
  500+            {
  501+                _killUploadMonitor = true;
  502+                _uploadMonitorTimer.Dispose();
  503+            }
  504+            _sensorDataManager.CloseSensors();
492505         }
 493506 
<>494 -        //! Collect data and store locally
  507+        private OperationModes _operationMode;
  508+
  509+        // Set mode of operation (upload, collect or collect_upload)
  510+        // Modes are mutually exclusive
  511+        private OperationModes Mode
  512+        {
  513+            set
  514+            {
  515+                _operationMode = value;
  516+
  517+                // Interrupt sensors and monitor while changing mode
  518+                closeSensors();
  519+
  520+                bool activityOn = false;
  521+
  522+                switch (_operationMode)
  523+                {
  524+                    case OperationModes.Upload:
  525+                        menuCollect.Checked = false;
  526+                        menuCollectUpload.Checked = false;
  527+
  528+                        activityOn = menuUpload.Checked = !menuUpload.Checked;
  529+
  530+                        if(activityOn)
  531+                            _sensorDataManager.UploadOnly();
  532+
  533+                        break;
  534+                    case OperationModes.Collect:
  535+                        menuUpload.Checked = false;
  536+                        menuCollectUpload.Checked = false;
  537+
  538+                        activityOn = menuCollect.Checked = !menuCollect.Checked;
  539+
  540+                        if(activityOn)
  541+                            _sensorDataManager.Collect(false);
  542+
  543+                        break;
  544+                    case OperationModes.CollectUpload:
  545+                        menuUpload.Checked = false;
  546+                        menuCollect.Checked = false;
  547+
  548+                        activityOn = menuCollectUpload.Checked = !menuCollectUpload.Checked;
  549+
  550+                        if (activityOn && _manualCapture == false)
  551+                            _sensorDataManager.Collect(true);
  552+
  553+                        break;
  554+                }
  555+
  556+                if (activityOn)
  557+                    startMonitor();
  558+            }
  559+        }
  560+
  561+        // Collect data and store locally
495562         private void menuCollect_Click(object sender, EventArgs e)
 496563         {
<>497 -            if (menuUpload.Checked)
  564+            this.Mode = OperationModes.Collect;
  565+            /*if (menuUpload.Checked)
498566                 menuUpload_Click(null, null);
 499567             else if (menuCollectUpload.Checked)
 500568                 menuCollectUpload_Click(null, null);
 501569 
 502570             if (!menuCollect.Checked)
 503571             {
 504572                 _delegateMenus = new DelegateMenus(menuCollect_Click);
<> 573+               
505574                 _sensorDataManager.Collect(false);
 506575 
 507576                 startMonitor();
 508577             }
 509578             else
 510579             {
<>511 -                MainForm_Closed(null, null);
  580+                closeSensors();
512581             }
 513582 
<>514 -            menuCollect.Checked = !menuCollect.Checked;
  583+            menuCollect.Checked = !menuCollect.Checked;*/
515584         }
 516585 
 517586         //! Collect data and upload to server
 518587         public void menuCollectUpload_Click(object sender, EventArgs e)
 519588         {
<>520 -            if (menuUpload.Checked)
  589+            this.Mode = OperationModes.CollectUpload;
  590+            /*if (menuUpload.Checked)
521591                 menuUpload_Click(null, null);
 522592             else if (menuCollect.Checked)
 523593                 menuCollect_Click(null, null);
     
 !
533603             }
 534604             else
 535605             {
<>536 -                MainForm_Closed(null, null);
  606+                closeSensors();
537607             }
 538608 
<>539 -            menuCollectUpload.Checked = !menuCollectUpload.Checked;
  609+            menuCollectUpload.Checked = !menuCollectUpload.Checked;*/
540610         }
 541611 
<>542 -        //! Reads the configuration xml file for campaignr
  612+
  613+        // Upload to server
  614+        private void menuUpload_Click(object sender, EventArgs e)
  615+        {
  616+            this.Mode = OperationModes.Upload;
  617+            /*if (menuCollectUpload.Checked)
  618+                menuCollectUpload_Click(null, null);
  619+            else if (menuCollect.Checked)
  620+                menuCollect_Click(null, null);
  621+
  622+            if (!menuUpload.Checked)
  623+            {
  624+                _delegateMenus = new DelegateMenus(menuUpload_Click);
  625+                _sensorDataManager.UploadOnly();
  626+
  627+                startMonitor();
  628+            }
  629+            else
  630+            {
  631+                closeSensors();
  632+            }
  633+
  634+            menuUpload.Checked = !menuUpload.Checked;*/
  635+        }
  636+
  637+        // Reads the configuration xml file for campaignr
543638         private void readXMLConfig(string xmlcfgfilename)
 544639         {
 545640             try
     
 !
557652                 {
 558653                     _campaignname = se.Attributes["name"];
 559654 
<>560 -                    // TODO: Send the info to the upload manager of choice
  655+                    // TODO: Flush the database if requested
561656                     if (se.Attribute("flushDatabase") != null && se.Attribute("flushDatabase") == "true")
 562657                         flushDatabase = true;
 563658 
 564659                     this.Text = "Campaignr - "+ _campaignname;
 565660 
<> 661+                    // Whether or not to start uploading data on start
566662                     _uploadOnStart = System.Convert.ToBoolean(se.Attributes["uploadOnStart"]);
<> 663+
567664                     _debugModeOn = System.Convert.ToBoolean(se.Attributes["debug"]);
 568665 
 569666                     if (!_debugModeOn)
     
 !
573670 
 574671                     SimpleElements elements = se.ChildElements;
 575672 
<>576 -                    SimpleElement automatic = elements.Item("automatic"); // TODO: Support manual capture!
  673+                    SimpleElement automatic = elements.Item("automatic");
577674 
 578675                     if (automatic==null)
 579676                     {
     
 !
586683                         DatabaseManager.MessageQueue.PostItem(new Message("Configuration file missing automatic or manual section", MessageType.Error));
 587684                         return;
 588685                     }
<>589 -                   
  686+
  687+                    // Whether or not to start collecting data on start
  688+                    _startOnLoad = System.Convert.ToBoolean(se.Attributes["startOnLoad"]) && !_manualCapture;
  689+
590690                     progressBar1.Value += 10;
 591691                     int step = (int)Math.Floor(20 / automatic.ChildElements.Count);
 592692 
     
 !
9881088             return sensor;
 9891089         }
 9901090 
<>991 -        //! Upload to server
 992 -        private void menuUpload_Click(object sender, EventArgs e)
 993 -        {
 994 -            if (menuCollectUpload.Checked)
 995 -                menuCollectUpload_Click(null, null);
 996 -            else if (menuCollect.Checked)
 997 -                menuCollect_Click(null, null);
 998 -
 999 -            if (!menuUpload.Checked)
 1000 -            {
 1001 -                _delegateMenus = new DelegateMenus(menuUpload_Click);
 1002 -                _sensorDataManager.UploadOnly();
 1003 -                startMonitor();
 1004 -            }
 1005 -            else
 1006 -            {
 1007 -                MainForm_Closed(null, null);
 1008 -            }
 1009 -
 1010 -            menuUpload.Checked = !menuUpload.Checked;
 1011 -        }
 1012 -
10131091         private void loadConfiguration(object sender, EventArgs e)
 10141092         {
 10151093             string fileToLoad = "";
     
 !
11251203             _uploadManager.Server = _uploadServer;
 11261204             // _uploadManager.Port = _uploadPort;
 11271205 
<>1128 -            // Must be called after
 1129 -            if (menuCollectUpload.Checked)
 1130 -                menuCollectUpload_Click(null, null);
 1131 -            else if (menuCollect.Checked)
 1132 -                menuCollect_Click(null, null);
 1133 -            else if (menuUpload.Checked)
 1134 -                menuUpload_Click(null, null);
 1135 -
11361206             if (_manualCapture == false)
 11371207             {
<>1138 -                _sensorDataManager.CollectInterval = 10000; // Default is 10 sec
  1208+                _sensorDataManager.CollectInterval = uploadInterval;
11391209             }
 11401210             else
 11411211             {
<>1142 -                // Setup event handler for center button
  1212+                // Setup data capture event handler for center button
11431213                 this.KeyPress += new KeyPressEventHandler(MainForm_KeyPress);
 11441214             }
 11451215 
<>1146 -            if (_uploadOnStart)
 1147 -            { // the configuration expects the upload to start immediately
  1216+            if (_startOnLoad && _uploadOnStart)
  1217+            {
  1218+                this.Mode = OperationModes.CollectUpload;
  1219+            }
  1220+            else if (_startOnLoad)
  1221+            {
  1222+                this.Mode = OperationModes.Collect;
  1223+            }
  1224+            else if (_uploadOnStart)
  1225+            {
  1226+                if (_manualCapture)
  1227+                {
  1228+                    // The configuration expects the upload to start immediately
  1229+                    _uploadManager.StartUpload();
  1230+                    startMonitor();
  1231+                }
  1232+                else
  1233+                    this.Mode = OperationModes.Upload;
  1234+            }
  1235+
  1236+            /*if (_uploadOnStart)
  1237+            {
  1238+                // The configuration expects the upload to start immediately
11481239                 _uploadManager.StartUpload();
 11491240                 startMonitor();
 11501241             }
 11511242             else
 11521243             {
 11531244                 _killUploadMonitor = false;
<>1154 -                monitorUpload(null); // update the screen in case a session has not started
 1155 -            }
11561245 
<> 1246+                // Update the screen in case a session has not started
  1247+                monitorUpload(null);
  1248+            }*/
  1249+
<_11571250             progressBar1.Value = 100;
 11581251 
 11591252             loadingPanel.Visible = false;
Atlassian FishEye, Subversion, CVS & Perforce analysis. (Version:1.5.4 Build:build-307 2008-07-31 ) - Administration - Page generated 2009-11-24 01:27 -0800