/// <summary> /// Main runtime loop used to collect and send data off too the computer /// </summary> private void Start() { ThreadManager manager = new ThreadManager(SaveContainer.Load()); Logger.Logger logs = new Logger.Logger(); logs.RemoveOldLogs(DateTime.Today.AddMonths(-1)); string command = ""; while ((command = Console.ReadLine()) != "e") { if (command == "t") { manager.CaptureImageSet(CameraRequest.SendTestImage); } else if (command == "s") { Console.WriteLine(manager.SavePath); Console.Write("new save path: "); manager.SavePath = Console.ReadLine(); } else { manager.CaptureImageSet(); } } Console.WriteLine("Quitting"); }
public void SaveandLoadNormally() { SaveContainer.Data data = CreateDummyData(12); string fileLocation = @"C:\scanimage\testFile.test"; //ensure that the file doesn't already exist if (File.Exists(fileLocation)) { File.Delete(fileLocation); } SaveContainer.Conf = data; SaveContainer.Save(fileLocation); Assert.IsTrue(File.Exists(fileLocation)); //check that the loaded file is identicle SaveContainer.Conf = new SaveContainer.Data().Default(); SaveContainer.Data loadData = SaveContainer.Load(fileLocation); File.Delete(fileLocation); Assert.IsTrue(loadData.CameraCount == data.CameraCount); for (int i = 0; i < loadData.CameraCount; i++) { Assert.IsTrue(data.Cameras[i].Address == loadData.Cameras[i].Address); Assert.IsTrue(data.Cameras[i].Id == loadData.Cameras[i].Id); Assert.IsTrue(data.Cameras[i].Port == loadData.Cameras[i].Port); Assert.IsTrue(data.Cameras[i].CamFileIdentity == loadData.Cameras[i].CamFileIdentity); } }
public void TestLoadException() { Exception ex = null; //Invalid Data Exception when the path isn't valid try { SaveContainer.Load("thisfileDoesn'tExitstAndIfItDoesThenThisWillFailSoDon'tHaveFileWithThisName2232.yep"); } catch (Exception e) { Assert.IsTrue(e is InvalidDataException); ex = e; } Assert.IsTrue(ex != null); ex = null; //Other exception for when there is another issue try { SaveContainer.Load(@"C:\scanimage\adminOnly.txt"); } catch (Exception e) { Assert.IsFalse(e is InvalidDataException); ex = e; } Assert.IsNotNull(ex); }
public void InvalidLoad() { string save = Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + "testSave"; SaveContainer.CustomSaveDirectory = save; try { if (File.Exists(save)) { File.Delete(save); } SaveContainer.Data config = SaveContainer.Load(); Assert.True(config.Equals(new SaveContainer.Data().Default())); } catch (Exception) { Assert.Fail("Shouldn't throw an error"); } finally { if (File.Exists(save)) { File.Delete(save); } } }
public void AlternateSave() { #region initialise SaveContainer.CustomSaveDirectory = SaveContainer.DefaultSaveDirectory; SaveContainer.Data testCase = new SaveContainer.Data { Cameras = new[] { new CameraConfiguration() { Address = 3556734, CamFileIdentity = "test1", Id = 67, Port = 3165 }, new CameraConfiguration() { Address = 7489, CamFileIdentity = "test1WE", Id = 562, Port = 673 } } }; #endregion try { SaveContainer.Conf = testCase; SaveContainer.Save(); Assert.IsTrue(File.Exists(SaveContainer.CustomSaveDirectory)); SaveContainer.Load(); File.Delete(SaveContainer.CustomSaveDirectory); Assert.IsTrue(SaveContainer.Conf.Equals(testCase)); } catch (Exception e) { Assert.Fail("Shouldn't throw an error, " + e.Message); } finally { if (File.Exists(SaveContainer.DefaultSaveDirectory)) { File.Delete(SaveContainer.DefaultSaveDirectory); } } }
public void StandardLoadSave() { SaveContainer.CustomSaveDirectory = null; SaveContainer.Conf = new SaveContainer.Data().Default(); try { SaveContainer.Save(); Assert.IsTrue(File.Exists(SaveContainer.DefaultSaveDirectory)); SaveContainer.Load(); File.Delete(SaveContainer.DefaultSaveDirectory); } catch (Exception e) { Assert.Fail("Shouldn't throw an error, " + e.Message); } finally { if (File.Exists(SaveContainer.DefaultSaveDirectory)) { File.Delete(SaveContainer.DefaultSaveDirectory); } } }