public void updateWindowStatus() { Debug.WriteLine("main_window: updating status"); testStatusLabel.Text = "Test stage: " + LuckyMe.testStageString(); LuckyMeLib.HaggleStatus status = LuckyMeLib.getHaggleStatus(); switch (status) { case LuckyMeLib.HaggleStatus.HAGGLE_DAEMON_CRASHED: haggleStatusLabel.Text = "Haggle has crashed"; break; case LuckyMeLib.HaggleStatus.HAGGLE_DAEMON_ERROR: haggleStatusLabel.Text = "Haggle status error..."; break; case LuckyMeLib.HaggleStatus.HAGGLE_DAEMON_NOT_RUNNING: haggleStatusLabel.Text = "Haggle is not running"; break; case LuckyMeLib.HaggleStatus.HAGGLE_DAEMON_RUNNING: haggleStatusLabel.Text = "Haggle is running"; break; } updateLockStatus(); if (LuckyMeLib.isLuckyMeRunning()) { if (LuckyMeLib.isTestRunning()) { luckyMeStatusLabel.Text = "LuckyMe and test is running"; } else { luckyMeStatusLabel.Text = "LuckyMe is running, but not test"; } Debug.WriteLine("main_window: LuckyMe is running"); } else { luckyMeStatusLabel.Text = "LuckyMe is not running"; Debug.WriteLine("main_window: LuckyMe is not running"); } numDataObjectsGenLabel.Text = LuckyMe.getNumDataObjectsGenerated() + " data objects generated"; this.Refresh(); }
/* * This function can be called for two reasons: * 1) Normal operation: save the data base and move the old files aside. * 2) Abort test: delete all data. * * 2) is only called in response to "abort test". This is necessary if * the user accidentally started haggle before starting luckyGUI, or * something. */ private static bool archiveHaggleFiles(bool saveFiles) { if (LuckyMeLib.isTestRunning()) { Debug.WriteLine("archiveHaggleFiles(): Test is still running..."); return(false); } int i; // 2) store haggle folder on SD card: // FIXME: "\Application Data\" should be "%APPDATA%" string sourcedir = "\\Carte de Stockage\\Haggle"; string source2dir = "\\Application Data\\Haggle"; // FIXME: "\Storage Card\" should probably be something like "%STORAGECARD%" string archivedirbase = "\\Carte de Stockage\\Haggle-Backup"; if (System.IO.Directory.Exists(source2dir)) { string[] file = System.IO.Directory.GetFiles(source2dir); for (i = 0; i < file.Length; i++) { try { if (saveFiles && System.IO.Directory.Exists(sourcedir)) { string dstfile = sourcedir + "\\" + System.IO.Path.GetFileName(file[i]); Debug.WriteLine("Copy: " + file[i] + " to " + dstfile); System.IO.File.Copy(file[i], dstfile, true); } // Delete all files that are not libhaggle.txt (because it's open) and // startup.do, because we want it to stay put. if (!(System.IO.Path.GetFileName(file[i]).Equals("libhaggle.txt") || System.IO.Path.GetFileName(file[i]).Equals("startup.do") || System.IO.Path.GetFileName(file[i]).Equals("config.xml"))) { Debug.WriteLine("Delete: " + file[i]); System.IO.File.Delete(file[i]); } } catch (Exception e) { System.Diagnostics.Debug.WriteLine("Error: " + e); return(false); } } } string archivedir; i = 0; do { archivedir = archivedirbase + "-" + i; i++; } while (System.IO.Directory.Exists(archivedir)); try { if (saveFiles) { if (System.IO.Directory.Exists(sourcedir)) { Debug.WriteLine("Move: " + sourcedir + " to " + archivedir); System.IO.Directory.Move(sourcedir, archivedir); } } else { if (System.IO.Directory.Exists(source2dir)) { string[] file = System.IO.Directory.GetFiles(source2dir); for (i = 0; i < file.Length; i++) { if (!(System.IO.Path.GetFileName(file[i]).Equals("libhaggle.txt") || System.IO.Path.GetFileName(file[i]).Equals("startup.do") || System.IO.Path.GetFileName(file[i]).Equals("config.xml"))) { Debug.WriteLine("Delete: " + file[i]); System.IO.File.Delete(file[i]); } } } if (System.IO.Directory.Exists(sourcedir)) { string[] file = System.IO.Directory.GetFiles(sourcedir); for (i = 0; i < file.Length; i++) { Debug.WriteLine("Delete: " + file[i]); System.IO.File.Delete(file[i]); } } } } catch (Exception) { System.Diagnostics.Debug.WriteLine("Could not move " + sourcedir); } return(true); }
public static bool stopTest() { bool retval = true; // be optimistic :) if (testStage != TestStage.RUNNING) { Debug.WriteLine("Cannot stop test since test stage=" + testStageString()); return(false); } mCallTimer.Change(System.Threading.Timeout.Infinite, System.Threading.Timeout.Infinite); setTestStage(TestStage.STOPPING); if (LuckyMeLib.isLuckyMeRunning()) { if (LuckyMeLib.isHaggleRunning()) { int res = LuckyMeLib.stopLuckyMe(1); Debug.WriteLine("stopLuckyMe() returned " + res); if (res < 0) { Debug.WriteLine("stopTest(): stopLuckyMe failed"); if (LuckyMeLib.isTestRunning()) { setTestStage(TestStage.RUNNING); } else { // Set not running although test stop failed setTestStage(TestStage.NOT_RUNNING); return(true); } return(false); } setTestStage(TestStage.STOPPING); } else { Debug.WriteLine("stopTest(): Haggle was not running"); int res = LuckyMeLib.stopLuckyMe(0); // Haggle was not running so we cannot expect a shutdown callback // -> set NOT_RUNNING immediately setTestStage(TestStage.NOT_RUNNING); } } else { if (LuckyMeLib.isHaggleRunning()) { int res = LuckyMeLib.stopHaggle(); if (res == 1) { Debug.WriteLine("stopTest(): Haggle stopped"); } else if (res == -1) { Debug.WriteLine("stopTest(): Could not stop Haggle, no Haggle handle"); } else { Debug.WriteLine("stopTest(): Could not stop Haggle, not running"); } } setTestStage(TestStage.NOT_RUNNING); } return(retval); }
public static bool startTest() { if (testStage != TestStage.NOT_RUNNING) { return(false); } // Reset counters numDataObjectsGenerated = 0; setTestStage(TestStage.STARTING); if (!startHaggle()) { setTestStage(TestStage.NOT_RUNNING); return(false); } // Start LuckyMe thread if (!LuckyMeLib.isLuckyMeRunning()) { int res = LuckyMeLib.startLuckyMe(); if (res < 0) { Debug.WriteLine("Error: Could not start LuckyMe!"); setTestStage(TestStage.NOT_RUNNING); return(false); } // Check again that LuckyMe and the Haggle event loop is running if (!LuckyMeLib.isLuckyMeRunning()) { Debug.WriteLine("Error: LuckyMe not running after start!"); setTestStage(TestStage.NOT_RUNNING); return(false); } } else { Debug.WriteLine("LuckyMe already running"); } Thread.Sleep(2000); if (!LuckyMeLib.isTestRunning()) { Debug.WriteLine("Starting LuckyMe test loop"); int res = LuckyMeLib.startTest(); if (res < 0) { Debug.WriteLine("Error: Could not start LuckyMe test loop!"); setTestStage(TestStage.NOT_RUNNING); LuckyMeLib.stopHaggle(); return(false); } } else { Debug.WriteLine("LuckyMe test already running"); } setTestStage(TestStage.RUNNING); return(true); }