/// <summary> /// BackupDatabaseToYmlGZ /// </summary> public string BackupDatabaseToYmlGZ() { string Base64EncodedBackup; TImportExportWebConnector.ExportAllTables(out Base64EncodedBackup); return(Base64EncodedBackup); }
public void TestImportCSV2() { TVerificationResultCollection VerificationResult = null; string doc = String.Empty; using (StreamReader sr = new StreamReader("../../demodata/partners/samplefilepartnerimport2.csv")) { doc = sr.ReadToEnd(); } PartnerImportExportTDS MainDS = TImportExportWebConnector.ImportFromCSVFileReturnDataSet(doc, "dMy", ",", out VerificationResult); if (VerificationResult != null) { Assert.IsFalse(VerificationResult.HasCriticalErrors, "there was an error importing the csv file"); } foreach (PFamilyRow f in MainDS.PFamily.Rows) { Console.WriteLine("Family name : " + f.FamilyName); } // we are currently ignoring UNIT and ORGANISATION partners, only importing the 7 FAMILY partners. // due to the strange format of the file, each row is imported as a separate partner, ending up with 27 invalid partners Assert.AreEqual(7, MainDS.PPartner.Rows.Count); }
public void TestImportCSV() { XmlDocument doc = TCsv2Xml.ParseCSVFile2Xml("../../demodata/partners/samplePartnerImport.csv", ";"); TVerificationResultCollection VerificationResult = null; PartnerImportExportTDS MainDS = TImportExportWebConnector.ImportFromCSVFile(TXMLParser.XmlToString(doc), "DMY", out VerificationResult); if (VerificationResult != null) { Assert.IsFalse(VerificationResult.HasCriticalErrors, "there was an error importing the csv file"); } // there should be 2 partners imported Assert.AreEqual(2, MainDS.PPartner.Rows.Count); }
private static bool DumpYmlGz(string YmlFile) { string YmlGZData = TImportExportWebConnector.ExportAllTables(); YmlFile = Path.GetFullPath(YmlFile); FileStream fs = new FileStream(YmlFile, FileMode.Create); byte[] buffer = Convert.FromBase64String(YmlGZData); fs.Write(buffer, 0, buffer.Length); fs.Close(); TLogging.Log("backup has been written to " + YmlFile); return(true); }
public void TestImportCSVUnknownColumn() { TVerificationResultCollection VerificationResult = null; string doc = String.Empty; using (StreamReader sr = new StreamReader("../../csharp/ICT/Testing/lib/MPartner/SampleData/samplePartnerImport_unknown_column.csv")) { doc = sr.ReadToEnd(); } TImportExportWebConnector.ImportFromCSVFileReturnDataSet(doc, "DMY", ";", out VerificationResult); Assert.IsNotNull(VerificationResult, "Expected to get errors"); Assert.AreEqual(1, VerificationResult.Count, "there should be one error"); Assert.AreEqual("Unknown Column(s): Test2", VerificationResult[0].ResultText, "VerificationResult message"); }
public void TestImportCSV_Dates_MDY() { TVerificationResultCollection VerificationResult = null; string doc = String.Empty; using (StreamReader sr = new StreamReader("../../csharp/ICT/Testing/lib/MPartner/SampleData/samplePartnerImport_dates_mdy.csv")) { doc = sr.ReadToEnd(); } PartnerImportExportTDS MainDS = TImportExportWebConnector.ImportFromCSVFileReturnDataSet(doc, "mdy", ";", out VerificationResult); if (VerificationResult != null) { if (VerificationResult.HasCriticalErrors) { Assert.AreEqual(String.Empty, VerificationResult.BuildVerificationResultString(), "there was an error importing the csv file"); } } // there should be 2 partners imported (2 x family) Assert.AreEqual(2, MainDS.PPartner.Rows.Count); Assert.AreEqual(2, MainDS.PFamily.Rows.Count); Assert.AreEqual(new DateTime(1979, 8, 19), MainDS.PFamily[0].DateOfBirth, "date of birth is wrong!"); // Now try with the wrong date format VerificationResult = null; MainDS = TImportExportWebConnector.ImportFromCSVFileReturnDataSet(doc, "dmy", ";", out VerificationResult); Assert.IsNotNull(VerificationResult, "Expected to get errors"); int numErrors = 0; for (int i = 0; i < VerificationResult.Count; i++) { if (VerificationResult[i].ResultSeverity != TResultSeverity.Resv_Status) { numErrors++; } } Assert.AreEqual(2, numErrors, "Wrong number of errors"); }
public void TestImportCSVWithoutName() { TVerificationResultCollection VerificationResult = null; string doc = String.Empty; using (StreamReader sr = new StreamReader("../../csharp/ICT/Testing/lib/MPartner/SampleData/samplePartnerImport_invalid.csv")) { doc = sr.ReadToEnd(); } TImportExportWebConnector.ImportFromCSVFileReturnDataSet(doc, "DMY", ";", out VerificationResult); Assert.IsNotNull(VerificationResult, "Expected to get errors"); Assert.AreEqual(2, VerificationResult.Count, "there should be two errors"); Assert.AreEqual("Missing Firstname or family name in line 2", VerificationResult[0].ResultText, "VerificationResult message"); Assert.AreEqual("We need either a valid address, phone number, email address or IBAN in line 4", VerificationResult[1].ResultText, "VerificationResult message"); }
public void TestImportCSV_Dates_MDY() { TVerificationResultCollection VerificationResult = null; string doc = String.Empty; using (StreamReader sr = new StreamReader("../../demodata/partners/samplePartnerImport_dates_mdy.csv")) { doc = sr.ReadToEnd(); } PartnerImportExportTDS MainDS = TImportExportWebConnector.ImportFromCSVFileReturnDataSet(doc, "mdy", ";", out VerificationResult); if (VerificationResult != null) { Assert.IsFalse(VerificationResult.HasCriticalErrors, "there was an error importing the csv file"); } // there should be 4 partners imported (2 x family + 2 x person) Assert.AreEqual(4, MainDS.PPartner.Rows.Count); Assert.AreEqual(2, MainDS.PmPassportDetails.Rows.Count); Assert.AreEqual(((PmPassportDetailsRow)MainDS.PmPassportDetails.Rows[0]).DateOfIssue, new DateTime(2016, 5, 22), "passport date of issue is wrong!"); // Now try with the wrong date format VerificationResult = null; MainDS = TImportExportWebConnector.ImportFromCSVFileReturnDataSet(doc, "dmy", ";", out VerificationResult); Assert.IsNotNull(VerificationResult, "Expected to get errors"); int numErrors = 0; for (int i = 0; i < VerificationResult.Count; i++) { if (VerificationResult[i].ResultSeverity != TResultSeverity.Resv_Status) { numErrors++; } } Assert.AreEqual(5, numErrors, "Wrong number of errors"); }
public void TestImportCSV() { TVerificationResultCollection VerificationResult = null; string doc = String.Empty; using (StreamReader sr = new StreamReader("../../demodata/partners/samplePartnerImport.csv")) { doc = sr.ReadToEnd(); } PartnerImportExportTDS MainDS = TImportExportWebConnector.ImportFromCSVFileReturnDataSet(doc, "DMY", ";", out VerificationResult); if (VerificationResult != null) { Assert.IsFalse(VerificationResult.HasCriticalErrors, "there was an error importing the csv file"); } // there should be 2 partners imported Assert.AreEqual(2, MainDS.PPartner.Rows.Count); }
private static bool LoadYmlGz(string YmlFile) { string restoreFile = Path.GetFullPath(YmlFile); if (!File.Exists(restoreFile) || !restoreFile.EndsWith(".yml.gz")) { Console.WriteLine("invalid filename or no read permission for " + restoreFile + ", please try again"); return(false); } string YmlGZData = string.Empty; try { FileStream fs = new FileStream(restoreFile, FileMode.Open, FileAccess.Read); byte[] buffer = new byte[fs.Length]; fs.Read(buffer, 0, buffer.Length); fs.Close(); YmlGZData = Convert.ToBase64String(buffer); } catch (Exception e) { TLogging.Log("cannot open file " + restoreFile); TLogging.Log(e.ToString()); return(false); } if (TImportExportWebConnector.ResetDatabase(YmlGZData)) { TLogging.Log("backup has been restored from " + restoreFile); } else { TLogging.Log("there have been problems with the restore"); return(false); } return(true); }
public void TestImportCSV2() { XmlDocument doc = TCsv2Xml.ParseCSVFile2Xml("../../demodata/partners/samplefilepartnerimport2.csv", ","); TVerificationResultCollection VerificationResult = null; Console.WriteLine(TXMLParser.XmlToString(doc)); PartnerImportExportTDS MainDS = TImportExportWebConnector.ImportFromCSVFile(TXMLParser.XmlToString(doc), "dMy", out VerificationResult); if (VerificationResult != null) { Assert.IsFalse(VerificationResult.HasCriticalErrors, "there was an error importing the csv file"); } foreach (PFamilyRow f in MainDS.PFamily.Rows) { Console.WriteLine("Family name : " + f.FamilyName); } // we are currently ignoring UNIT and ORGANISATION partners, only importing the 7 FAMILY partners. // due to the strange format of the file, each row is imported as a separate partner, ending up with 27 invalid partners Assert.AreEqual(7, MainDS.PPartner.Rows.Count); }
public void TestImportCSV_Dates_DMY() { XmlDocument doc = TCsv2Xml.ParseCSVFile2Xml("../../demodata/partners/samplePartnerImport_dates_dmy.csv", ";"); TVerificationResultCollection VerificationResult = null; PartnerImportExportTDS MainDS = TImportExportWebConnector.ImportFromCSVFile(TXMLParser.XmlToString(doc), "dmy", out VerificationResult); if (VerificationResult != null) { Assert.IsFalse(VerificationResult.HasCriticalErrors, "there was an error importing the csv file"); } // there should be 4 partners imported (2 x family + 2 x person) Assert.AreEqual(4, MainDS.PPartner.Rows.Count, "Wrong number of partners"); Assert.AreEqual(2, MainDS.PmPassportDetails.Rows.Count, "Wrong number of persons"); Assert.AreEqual(((PmPassportDetailsRow)MainDS.PmPassportDetails.Rows[0]).DateOfIssue, new DateTime(2016, 4, 22), "passport date of issue is wrong!"); // Now try with the wrong date format VerificationResult = null; MainDS = TImportExportWebConnector.ImportFromCSVFile(TXMLParser.XmlToString(doc), "mdy", out VerificationResult); Assert.IsNotNull(VerificationResult, "Expected to get errors"); int numErrors = 0; for (int i = 0; i < VerificationResult.Count; i++) { if (VerificationResult[i].ResultSeverity != TResultSeverity.Resv_Status) { numErrors++; } } Assert.AreEqual(5, numErrors, "Wrong number of errors"); }
private void RunMenu() { bool ReadLineLoopEnd = false; bool EntryParsedOK = false; System.Int16 ClientID = 0; System.Int16 ClientTaskPriority = 1; do { string ServerCommand = (Console.ReadLine()); if (ServerCommand.Length > 0) { ServerCommand = ServerCommand.Substring(0, 1); switch (Convert.ToChar(ServerCommand)) { case 'm': case 'M': Console.WriteLine(Environment.NewLine + "-> Available commands <-"); Console.WriteLine(" c: list connected Clients / C: list disconnected Clients"); Console.WriteLine(" d: disconnect a certain Client"); if (TLogging.DebugLevel > 0) { Console.WriteLine(" l: load AppDomain for a fake Client (for debugging purposes only!)"); } Console.WriteLine(" p: perform timed server processing manually now"); Console.WriteLine(" q: queue a Client Task for a certain Client"); Console.WriteLine(" s: Server Status"); if (TLogging.DebugLevel > 0) { Console.WriteLine(" y: show Server memory"); Console.WriteLine(" g: perform Server garbage collection (for debugging purposes only!)"); } Console.WriteLine(" e: export the database to yml.gz"); Console.WriteLine(" i: import a yml.gz, which will overwrite the database"); #if DEBUG Console.WriteLine(" r: Mark all Cached Tables for Refreshing"); #endif Console.WriteLine(" o: controlled Server shutdown (gets all connected clients to disconnect)"); Console.WriteLine(" u: unconditional Server shutdown (forces 'hard' disconnection of all Clients!)"); WriteServerPrompt(); // list connected Clients break; case 'c': Console.WriteLine(Environment.NewLine + "-> Connected Clients <-"); Console.WriteLine(TheServerManager.FormatClientList(false)); WriteServerPrompt(); // list disconnected Clients break; case 'C': Console.WriteLine(Environment.NewLine + "-> Disconnected Clients <-"); Console.WriteLine(TheServerManager.FormatClientList(true)); WriteServerPrompt(); // disconnect a certain Client break; case 'd': case 'D': Console.WriteLine(Environment.NewLine + "-> Disconnect a certain Client <-"); if (TheServerManager.ClientList.Count > 0) { Console.WriteLine(TheServerManager.FormatClientList(false)); Console.Write(" Enter ClientID: "); string ConsoleInput = Console.ReadLine(); try { ClientID = System.Int16.Parse(ConsoleInput); String CantDisconnectReason; if (TheServerManager.DisconnectClient(ClientID, out CantDisconnectReason)) { TLogging.Log("Client #" + ClientID.ToString() + ": disconnection will take place shortly."); } else { TLogging.Log( "Client #" + ClientID.ToString() + " could not be disconnected on admin request. Reason: " + CantDisconnectReason); } } catch (System.FormatException) { Console.WriteLine(" Entered ClientID is not numeric!"); } catch (Exception exp) { TLogging.Log( Environment.NewLine + "Exception occured while trying to disconnect a Client on admin request:" + Environment.NewLine + exp.ToString()); } } else { Console.WriteLine(" * no Clients connected *"); } WriteServerPrompt(); // load AppDomain for a fake Client (for debugging purposes only!) break; case 'e': case 'E': string YmlGZData = TImportExportWebConnector.ExportAllTables(); Console.Write(" Please enter filename of yml.gz file: "); string backupFile = Path.GetFullPath(Console.ReadLine()); if (!backupFile.EndsWith(".yml.gz")) { Console.WriteLine("filename has to end with .yml.gz. Please try again"); } else { FileStream fs = new FileStream(backupFile, FileMode.Create); byte[] buffer = Convert.FromBase64String(YmlGZData); fs.Write(buffer, 0, buffer.Length); fs.Close(); TLogging.Log("backup has been written to " + backupFile); } WriteServerPrompt(); break; case 'i': case 'I': Console.WriteLine(Environment.NewLine + "-> DELETING YOUR DATABASE <-"); Console.Write(" Enter YES to import the new database (anything else to leave command): "); if (Console.ReadLine() == "YES") { Console.Write(" Please enter filename of yml.gz file: "); string restoreFile = Path.GetFullPath(Console.ReadLine()); if (!File.Exists(restoreFile) || !restoreFile.EndsWith(".yml.gz")) { Console.WriteLine("invalid filename, please try again"); } else { FileStream fsRead = new FileStream(restoreFile, FileMode.Open); byte[] bufferRead = new byte[fsRead.Length]; fsRead.Read(bufferRead, 0, bufferRead.Length); fsRead.Close(); YmlGZData = Convert.ToBase64String(bufferRead); if (TImportExportWebConnector.ResetDatabase(YmlGZData)) { TLogging.Log("backup has been restored from " + restoreFile); } else { TLogging.Log("there have been problems with the restore"); } } WriteServerPrompt(); } else { Console.WriteLine(" Reset of database cancelled!"); WriteServerPrompt(); } break; case 'r': case 'R': Console.WriteLine(Environment.NewLine + "-> Marking all Cached Tables for Refreshing... <-"); TheServerManager.RefreshAllCachedTables(); WriteServerPrompt(); break; case 'p': case 'P': string resp = ""; Console.WriteLine(" Server Timed Processing Status: " + "runs daily at " + TheServerManager.TimedProcessingDailyStartTime24Hrs + "."); Console.WriteLine(" Partner Reminders: " + (TheServerManager.TimedProcessingJobEnabled("TProcessPartnerReminders") ? "On" : "Off")); Console.WriteLine(" Automatic Intranet Export: " + (TheServerManager.TimedProcessingJobEnabled("TProcessAutomatedIntranetExport") ? "On" : "Off")); Console.WriteLine(" Data Checks: " + (TheServerManager.TimedProcessingJobEnabled("TProcessDataChecks") ? "On" : "Off")); Console.WriteLine(" SMTP Server used for sending e-mails: " + TheServerManager.SMTPServer); if (TheServerManager.TimedProcessingJobEnabled("TProcessPartnerReminders")) { Console.WriteLine(""); Console.WriteLine("Do you want to run Reminder Processing now?"); Console.Write("Type YES to continue, anything else to skip:"); resp = Console.ReadLine(); if (resp == "YES") { TheServerManager.PerformTimedProcessingNow("TProcessPartnerReminders"); } } if (TheServerManager.TimedProcessingJobEnabled("TProcessAutomatedIntranetExport")) { Console.WriteLine(""); Console.WriteLine("Do you want to run Intranet Export Processing now?"); Console.Write("Type YES to continue, anything else to skip:"); resp = Console.ReadLine(); if (resp == "YES") { TheServerManager.PerformTimedProcessingNow("TProcessAutomatedIntranetExport"); } } if (TheServerManager.TimedProcessingJobEnabled("TProcessDataChecks")) { Console.WriteLine(""); Console.WriteLine("Do you want to run Data Checks Processing now?"); Console.Write("Type YES to continue, anything else to skip:"); resp = Console.ReadLine(); if (resp == "YES") { TheServerManager.PerformTimedProcessingNow("TProcessDataChecks"); } } WriteServerPrompt(); break; case 's': case 'S': Console.WriteLine(Environment.NewLine + "-> Server Status <-"); Console.WriteLine(); DisplayPetraServerInformation(TheServerManager); WriteServerPrompt(); break; case 'q': case 'Q': Console.WriteLine(Environment.NewLine + "-> Queue a Client Task for a certain Client <-"); if (TheServerManager.ClientList.Count > 0) { Console.WriteLine(TheServerManager.FormatClientList(false)); ReadClientID: Console.Write(" Enter ClientID: "); string ConsoleInput = Console.ReadLine(); try { ClientID = System.Int16.Parse(ConsoleInput); EntryParsedOK = true; } catch (System.FormatException) { Console.WriteLine(" Entered ClientID is not numeric!"); EntryParsedOK = false; } if (!EntryParsedOK) { goto ReadClientID; } Console.Write(" Enter Client Task Group: "); string ClientTaskGroup = Console.ReadLine(); Console.Write(" Enter Client Task Code: "); string ClientTaskCode = Console.ReadLine(); ReadClientTaskPriority: Console.Write(" Enter Client Task Priority: "); ConsoleInput = Console.ReadLine(); try { ClientTaskPriority = System.Int16.Parse(ConsoleInput); EntryParsedOK = true; } catch (System.FormatException) { Console.WriteLine(" Entered Client Task Priority is not numeric!"); EntryParsedOK = false; } if (!EntryParsedOK) { goto ReadClientTaskPriority; } try { if (TheServerManager.QueueClientTask(ClientID, ClientTaskGroup, ClientTaskCode, ClientTaskPriority)) { TLogging.Log("Client Task queued for Client #" + ClientID.ToString() + " on admin request."); } else { TLogging.Log( "Client Task for Client #" + ClientID.ToString() + " could not be queued on admin request."); } } catch (Exception exp) { TLogging.Log( Environment.NewLine + "Exception occured while queueing a Client Task on admin request:" + Environment.NewLine + exp.ToString()); } } else { Console.WriteLine(" * no Clients connected *"); } WriteServerPrompt(); // show Server memory break; case 'y': case 'Y': Console.WriteLine("Server memory: " + TheServerManager.ServerInfoMemory.ToString()); WriteServerPrompt(); // perform Server garbage collection break; case 'g': case 'G': Console.WriteLine("GarbageCollection performed. Server memory: " + TheServerManager.PerformGC().ToString()); WriteServerPrompt(); // unconditional Server shutdown break; case 'o': case 'O': Console.WriteLine(Environment.NewLine + "-> CONTROLLED SHUTDOWN (gets all connected clients to disconnect) <-"); Console.Write(" Enter YES to perform controlled shutdown (anything else to leave command): "); if (Console.ReadLine() == "YES") { if (!TheServerManager.StopServerControlled(false)) { Console.WriteLine(" Shutdown cancelled!"); WriteServerPrompt(); } } else { Console.WriteLine(" Shutdown cancelled!"); WriteServerPrompt(); } break; case 'u': case 'U': Console.WriteLine(Environment.NewLine + "-> UNCONDITIONAL SHUTDOWN (force disconnection of all Clients) <-"); Console.Write(" Enter YES to perform UNCONDITIONAL shutdown (anything else to leave command): "); if (Console.ReadLine() == "YES") { TheServerManager.StopServer(); ReadLineLoopEnd = true; } else { Console.WriteLine(" Shutdown cancelled!"); WriteServerPrompt(); } break; default: Console.WriteLine( Environment.NewLine + "-> Unrecognised command '" + ServerCommand + "' <- (Press 'm' for menu)"); WriteServerPrompt(); break; } // case Convert.ToChar( ServerCommand ) } else { WriteServerPrompt(); } } while (!(ReadLineLoopEnd == true)); }
/// <summary> /// RestoreDatabaseFromYmlGZ /// </summary> public bool RestoreDatabaseFromYmlGZ(string AYmlGzData) { return(TImportExportWebConnector.ResetDatabase(AYmlGzData)); }
/// <summary> /// BackupDatabaseToYmlGZ /// </summary> public string BackupDatabaseToYmlGZ() { return(TImportExportWebConnector.ExportAllTables()); }