private void BtnExportDsv_Click(object sender, RoutedEventArgs e) { string filePath = System.IO.Path.Combine( _thisRace.GetDataModel().GetDB().GetDBPathDirectory(), System.IO.Path.GetFileNameWithoutExtension(_thisRace.GetDataModel().GetDB().GetDBFileName()) + ".zip"); Microsoft.Win32.SaveFileDialog openFileDialog = new Microsoft.Win32.SaveFileDialog(); openFileDialog.FileName = System.IO.Path.GetFileName(filePath); openFileDialog.InitialDirectory = System.IO.Path.GetDirectoryName(filePath); openFileDialog.DefaultExt = ".zip"; openFileDialog.Filter = "DSV Results (.zip)|*.zip"; try { if (openFileDialog.ShowDialog() == true) { filePath = openFileDialog.FileName; DSVExport dsvExport = new DSVExport(); dsvExport.Export(filePath, _thisRace); } } catch (DSVExportException ex) { System.Windows.MessageBox.Show( "Datei " + System.IO.Path.GetFileName(filePath) + " konnte nicht gespeichert werden.\n\nFehlermeldung: " + ex.GetHumanReadableError(), "Fehler", System.Windows.MessageBoxButton.OK, MessageBoxImage.Exclamation); } catch (Exception ex) { System.Windows.MessageBox.Show( "Datei " + System.IO.Path.GetFileName(filePath) + " konnte nicht gespeichert werden.\n\n" + ex.Message, "Fehler", System.Windows.MessageBoxButton.OK, MessageBoxImage.Exclamation); } }
string exportToXML(Race race) { DSVExport dsvExport = new DSVExport(); MemoryStream xmlData = new MemoryStream(); dsvExport.ExportXML(xmlData, race); // Convert to string xmlData.Position = 0; StreamReader reader = new StreamReader(xmlData); return(reader.ReadToEnd()); }
public void Verify_guessLastAndFirstname() { string lastname, firstname; lastname = firstname = string.Empty; DSVExport.guessLastAndFirstname("Sven Flossmann", out lastname, out firstname); Assert.AreEqual("Sven", firstname); Assert.AreEqual("Flossmann", lastname); lastname = firstname = string.Empty; DSVExport.guessLastAndFirstname("S.Flossmann", out lastname, out firstname); Assert.AreEqual("S.", firstname); Assert.AreEqual("Flossmann", lastname); lastname = firstname = string.Empty; DSVExport.guessLastAndFirstname("Flossmann, Sven", out lastname, out firstname); Assert.AreEqual("Sven", firstname); Assert.AreEqual("Flossmann", lastname); lastname = firstname = string.Empty; DSVExport.guessLastAndFirstname("Flossmann", out lastname, out firstname); Assert.AreEqual(string.Empty, firstname); Assert.AreEqual("Flossmann", lastname); lastname = firstname = string.Empty; DSVExport.guessLastAndFirstname("Flossmann, Sven Theo", out lastname, out firstname); Assert.AreEqual("Sven Theo", firstname); Assert.AreEqual("Flossmann", lastname); lastname = firstname = string.Empty; DSVExport.guessLastAndFirstname("Sven Theo Flossmann", out lastname, out firstname); Assert.AreEqual("Sven Theo", firstname); Assert.AreEqual("Flossmann", lastname); lastname = firstname = string.Empty; DSVExport.guessLastAndFirstname("S. Flossmann / Z. Zweigelt", out lastname, out firstname); Assert.AreEqual(string.Empty, firstname); Assert.AreEqual("S. Flossmann / Z. Zweigelt", lastname); }
public void BasicExceptions_MandatoryFields() { var model = createTestDataModel1Race1Run(); DSVExport dsvExport = new DSVExport(); MemoryStream xmlData = null; var raceProps = new AdditionalRaceProperties(); model.GetRace(0).AdditionalProperties = raceProps; xmlData = new MemoryStream(); Assert.AreEqual("missing racedate", Assert.ThrowsException <DSVExportException>(() => dsvExport.ExportXML(xmlData, model.GetRace(0))).Message); raceProps.DateResultList = DateTime.Today; xmlData = new MemoryStream(); Assert.AreEqual("missing raceid", Assert.ThrowsException <DSVExportException>(() => dsvExport.ExportXML(xmlData, model.GetRace(0))).Message); model.GetRace(0).AdditionalProperties.RaceNumber = "1234"; xmlData = new MemoryStream(); Assert.AreEqual("missing raceorganizer", Assert.ThrowsException <DSVExportException>(() => dsvExport.ExportXML(xmlData, model.GetRace(0))).Message); model.GetRace(0).AdditionalProperties.Organizer = "WSV Glonn"; xmlData = new MemoryStream(); Assert.AreEqual("missing racename", Assert.ThrowsException <DSVExportException>(() => dsvExport.ExportXML(xmlData, model.GetRace(0))).Message); model.GetRace(0).AdditionalProperties.Description = "Test Race"; xmlData = new MemoryStream(); Assert.AreEqual("missing raceplace", Assert.ThrowsException <DSVExportException>(() => dsvExport.ExportXML(xmlData, model.GetRace(0))).Message); model.GetRace(0).AdditionalProperties.Location = "Test Location"; xmlData = new MemoryStream(); Assert.AreEqual("missing useddsvlist", Assert.ThrowsException <DSVExportException>(() => dsvExport.ExportXML(xmlData, model.GetRace(0))).Message); model.GetDB().StoreKeyValue("DSV_UsedDSVList", "123"); xmlData = new MemoryStream(); Assert.AreEqual("missing f-value", Assert.ThrowsException <DSVExportException>(() => dsvExport.ExportXML(xmlData, model.GetRace(0))).Message); model.GetRace(0).RaceConfiguration.ValueF = 720.0; xmlData = new MemoryStream(); Assert.AreEqual("wrong raceresultview", Assert.ThrowsException <DSVExportException>(() => dsvExport.ExportXML(xmlData, model.GetRace(0))).Message); var rvp = new DSVSchoolRaceResultViewProvider(); rvp.Init(model.GetRace(0), model); model.GetRace(0).SetResultViewProvider(rvp); xmlData = new MemoryStream(); Assert.AreEqual("missing racejury ChiefRace", Assert.ThrowsException <DSVExportException>(() => dsvExport.ExportXML(xmlData, model.GetRace(0))).Message); model.GetRace(0).AdditionalProperties.RaceManager = new AdditionalRaceProperties.Person { Name = "Race Manager", Club = "Club" }; xmlData = new MemoryStream(); Assert.AreEqual("missing racejury Referee", Assert.ThrowsException <DSVExportException>(() => dsvExport.ExportXML(xmlData, model.GetRace(0))).Message); model.GetRace(0).AdditionalProperties.RaceReferee = new AdditionalRaceProperties.Person { Name = "Race Referee", Club = "Club" }; xmlData = new MemoryStream(); Assert.AreEqual("missing racejury RepresentativeTrainer", Assert.ThrowsException <DSVExportException>(() => dsvExport.ExportXML(xmlData, model.GetRace(0))).Message); model.GetRace(0).AdditionalProperties.TrainerRepresentative = new AdditionalRaceProperties.Person { Name = "Trainer Rep", Club = "Club" }; xmlData = new MemoryStream(); Assert.AreEqual("missing coarsename", Assert.ThrowsException <DSVExportException>(() => dsvExport.ExportXML(xmlData, model.GetRace(0))).Message); raceProps.CoarseName = "Kurs 1"; xmlData = new MemoryStream(); Assert.AreEqual("missing number_of_gates", Assert.ThrowsException <DSVExportException>(() => dsvExport.ExportXML(xmlData, model.GetRace(0))).Message); raceProps.RaceRun1.Gates = 10; xmlData = new MemoryStream(); Assert.AreEqual("missing number_of_turninggates", Assert.ThrowsException <DSVExportException>(() => dsvExport.ExportXML(xmlData, model.GetRace(0))).Message); raceProps.RaceRun1.Turns = 9; xmlData = new MemoryStream(); Assert.AreEqual("missing startaltitude", Assert.ThrowsException <DSVExportException>(() => dsvExport.ExportXML(xmlData, model.GetRace(0))).Message); raceProps.StartHeight = 1000; xmlData = new MemoryStream(); Assert.AreEqual("missing finishaltitude", Assert.ThrowsException <DSVExportException>(() => dsvExport.ExportXML(xmlData, model.GetRace(0))).Message); raceProps.FinishHeight = 100; xmlData = new MemoryStream(); Assert.AreEqual("missing courselength", Assert.ThrowsException <DSVExportException>(() => dsvExport.ExportXML(xmlData, model.GetRace(0))).Message); raceProps.CoarseLength = 1000; xmlData = new MemoryStream(); Assert.AreEqual("missing coursesetter", Assert.ThrowsException <DSVExportException>(() => dsvExport.ExportXML(xmlData, model.GetRace(0))).Message); raceProps.RaceRun1.CoarseSetter = new AdditionalRaceProperties.Person { Name = "Sven Flossmann", Club = "WSV Glonn" }; xmlData = new MemoryStream(); Assert.AreEqual("missing forerunner", Assert.ThrowsException <DSVExportException>(() => dsvExport.ExportXML(xmlData, model.GetRace(0))).Message); raceProps.RaceRun1.Forerunner1 = new AdditionalRaceProperties.Person { Name = "Fore Runner", Club = "WSV Glonn" }; // No exception is allow to occur here xmlData = new MemoryStream(); dsvExport.ExportXML(xmlData, model.GetRace(0)); }