From feb2c0abe5b0f8dff871f22004d7b7b033295a6f Mon Sep 17 00:00:00 2001 From: Lunastra Date: Sat, 11 Dec 2021 18:01:02 -0800 Subject: [PATCH 1/5] Create function to create folder in archive --- .../ArchiveController.cs | 25 +++++++++++++++---- Source Code/main/Controller.cs | 11 ++++++++ Source Code/main/main.csproj | 1 + 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.Archive/ArchiveController.cs b/Source Code/TeamHobby.HobbyProjectGenerator.Archive/ArchiveController.cs index e76171b..2661298 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator.Archive/ArchiveController.cs +++ b/Source Code/TeamHobby.HobbyProjectGenerator.Archive/ArchiveController.cs @@ -12,18 +12,33 @@ namespace TeamHobby.HobbyProjectGenerator.Archive _conn = dataSource; } - public IDataSource GetDataSource(){ - return _conn; - } // Create the folder where the compress file will be stored public bool CreateArchiveFolder(){ + string curPath = Directory.GetCurrentDirectory(); + //string temp = @ + string archiveFolder = curPath + "\\HobbyArhive"; + //Console.WriteLine("Creating a new folder at: {0}", archiveFolder); + if (!Directory.Exists(archiveFolder)) + { + Console.WriteLine("Creating a new folder at: {0}", archiveFolder); + Directory.CreateDirectory(archiveFolder); + } return true; } // Return the name of the new output file with Path - public string CreateOutFileName(){ - return "hello"; + public string CreateOutFileName() { + try { + string path = Directory.GetCurrentDirectory(); + Console.WriteLine("The current directory is {0}", path); + return path; + } + catch + { + Console.WriteLine("ArchiveCon: Creating a file name failed. "); + return ""; + } } // put everything toget here diff --git a/Source Code/main/Controller.cs b/Source Code/main/Controller.cs index 1932939..dfb67a9 100644 --- a/Source Code/main/Controller.cs +++ b/Source Code/main/Controller.cs @@ -1,6 +1,7 @@ using main; using System; using System.Data.Odbc; +using TeamHobby.HobbyProjectGenerator.Archive; using TeamHobby.HobbyProjectGenerator.DataAccess; @@ -67,6 +68,16 @@ namespace TeamHobby.HobbyProjectGenerator.Main // Closing the connection sqlDS.getConnection().Close(); + // Testing archive Manager + ArchiveController archive = new ArchiveController(datasource); + string curPath = archive.CreateOutFileName(); + + //Creating the folder Archive + Console.WriteLine("Creating a new folder ..."); + archive.CreateArchiveFolder(); + + + // 2.Inserting Data into the database: //string sqlWrite = "INSERT into log(lvname, catname, userop, logmessage) values " + // "('Info', 'View', 'Testing DAL stuffs', 'new DAL method tested');"; diff --git a/Source Code/main/main.csproj b/Source Code/main/main.csproj index 63f5952..8853c02 100644 --- a/Source Code/main/main.csproj +++ b/Source Code/main/main.csproj @@ -12,6 +12,7 @@ + From 9db6ab7db7c23dbb4fe67af8b696380921dde38a Mon Sep 17 00:00:00 2001 From: Lunastra Date: Sat, 11 Dec 2021 22:34:47 -0800 Subject: [PATCH 2/5] Create copy to file method --- .../ArchiveController.cs | 16 ++++++- .../Implementations/SqlDAO.cs | 42 ++++++++++++++++++- Source Code/main/Controller.cs | 15 ++++++- 3 files changed, 67 insertions(+), 6 deletions(-) diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.Archive/ArchiveController.cs b/Source Code/TeamHobby.HobbyProjectGenerator.Archive/ArchiveController.cs index 2661298..6fda930 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator.Archive/ArchiveController.cs +++ b/Source Code/TeamHobby.HobbyProjectGenerator.Archive/ArchiveController.cs @@ -17,7 +17,7 @@ namespace TeamHobby.HobbyProjectGenerator.Archive public bool CreateArchiveFolder(){ string curPath = Directory.GetCurrentDirectory(); //string temp = @ - string archiveFolder = curPath + "\\HobbyArhive"; + string archiveFolder = curPath + "\\HobbyArchive"; //Console.WriteLine("Creating a new folder at: {0}", archiveFolder); if (!Directory.Exists(archiveFolder)) { @@ -30,8 +30,14 @@ namespace TeamHobby.HobbyProjectGenerator.Archive // Return the name of the new output file with Path public string CreateOutFileName() { try { - string path = Directory.GetCurrentDirectory(); + string path = Directory.GetCurrentDirectory() + "\\HobbyArchive"; Console.WriteLine("The current directory is {0}", path); + string date = DateTime.Now.ToString("M_d_yyyy"); + string fileName = date + "_archive.csv"; + string filePath = System.IO.Path.Combine(path, fileName); + + Console.WriteLine("Date: {0}", date); + Console.WriteLine("Filepath: {0}", filePath); return path; } catch @@ -43,6 +49,12 @@ namespace TeamHobby.HobbyProjectGenerator.Archive // put everything toget here public bool Controller(){ + + // Create the folder for Archiving + CreateArchiveFolder(); + + // Create the file name for output + CreateOutFileName(); return true; } diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/Implementations/SqlDAO.cs b/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/Implementations/SqlDAO.cs index d68b6bf..c2ae271 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/Implementations/SqlDAO.cs +++ b/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/Implementations/SqlDAO.cs @@ -36,7 +36,7 @@ namespace TeamHobby.HobbyProjectGenerator.DataAccess return _conn; } - // Closing a connection here will cause a problem + // TODO: Closing a connection here will cause a problem // Make sure whoever called this need to close the connection until we can fixed it. public Object? ReadData(string cmd) { @@ -175,7 +175,45 @@ namespace TeamHobby.HobbyProjectGenerator.DataAccess // Copy the Sql data to the a text file public bool CopyToFile(string filePath){ - return true; + try + { + _conn.Open(); + // Conver backward slash in to forward slash + filePath = filePath.Replace("\\", "/"); + string sqlQuery = "SELECT 'LtimeStamp', 'logID', 'LvName', 'catName', 'userOP', 'logMessage' " + + "UNION ALL " + + "SELECT* FROM log " + + "WHERE DATEDIFF(CURRENT_TIMESTAMP, log.LtimeStamp) > 30 " + + "INTO OUTFILE '" + filePath + "'" + + "FIELDS ENCLOSED BY ''" + + "TERMINATED BY ',' " + + "LINES TERMINATED BY '\r\n';"; + + Console.WriteLine(sqlQuery); + + OdbcCommand command = new OdbcCommand(sqlQuery, _conn); + //command.Parameters.AddWithValue("@filePath", filePath); + //command.Prepare(); + + Console.WriteLine("Output to a file started. "); + command.ExecuteNonQuery(); + Console.WriteLine("Output to a file completed. "); + + + _conn.Close(); + return true; + + } + catch + { + _conn.Close(); + Console.WriteLine("Error when copying query to a file !!"); + throw; + } + finally + { + _conn.Close(); + } } public bool RemoveOutputFile(string filePath){ diff --git a/Source Code/main/Controller.cs b/Source Code/main/Controller.cs index dfb67a9..ed04cef 100644 --- a/Source Code/main/Controller.cs +++ b/Source Code/main/Controller.cs @@ -70,12 +70,23 @@ namespace TeamHobby.HobbyProjectGenerator.Main // Testing archive Manager ArchiveController archive = new ArchiveController(datasource); - string curPath = archive.CreateOutFileName(); //Creating the folder Archive Console.WriteLine("Creating a new folder ..."); archive.CreateArchiveFolder(); - + Console.WriteLine(""); + + // Creating a file name: + Console.WriteLine("Creating file name ... "); + string curPath = archive.CreateOutFileName(); + + string pathForward = @"C:\Users\Chunchunmaru\Documents\csulbFall2021\HobbyProject\Source Code\main\bin\Debug\net6.0\HobbyArchive"; + string pathTemp = "C:/Temp/oldlogs10.txt"; + string pathTempBack = @"C:\Temp\oldlogs10.txt"; + Console.WriteLine("----------------"); + + //Output SQL to a text file + sqlDS.CopyToFile(curPath); // 2.Inserting Data into the database: From 421637bda735f6e3eabecdd5f274f6324f64d258 Mon Sep 17 00:00:00 2001 From: Lunastra Date: Sat, 11 Dec 2021 22:59:17 -0800 Subject: [PATCH 3/5] Add a CreateOutFile method overload Changed the file path for the archive folder --- .../ArchiveController.cs | 39 +++++++++++++++++-- Source Code/main/Controller.cs | 12 +++--- 2 files changed, 43 insertions(+), 8 deletions(-) diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.Archive/ArchiveController.cs b/Source Code/TeamHobby.HobbyProjectGenerator.Archive/ArchiveController.cs index 6fda930..4ea6841 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator.Archive/ArchiveController.cs +++ b/Source Code/TeamHobby.HobbyProjectGenerator.Archive/ArchiveController.cs @@ -15,8 +15,18 @@ namespace TeamHobby.HobbyProjectGenerator.Archive // Create the folder where the compress file will be stored public bool CreateArchiveFolder(){ - string curPath = Directory.GetCurrentDirectory(); - //string temp = @ + //string curPath = Directory.GetCurrentDirectory(); + string curPath = @"C:\"; + + // Find the root drive of the program + string drive = Path.GetPathRoot(path: curPath); + // Check if Drive exists or not + if (!Directory.Exists(drive)) + { + Console.WriteLine("Drive {0} not found", drive); + return false; + } + string archiveFolder = curPath + "\\HobbyArchive"; //Console.WriteLine("Creating a new folder at: {0}", archiveFolder); if (!Directory.Exists(archiveFolder)) @@ -27,6 +37,7 @@ namespace TeamHobby.HobbyProjectGenerator.Archive return true; } + // Return the name of the new output file with Path public string CreateOutFileName() { try { @@ -38,7 +49,29 @@ namespace TeamHobby.HobbyProjectGenerator.Archive Console.WriteLine("Date: {0}", date); Console.WriteLine("Filepath: {0}", filePath); - return path; + return filePath; + } + catch + { + Console.WriteLine("ArchiveCon: Creating a file name failed. "); + return ""; + } + } + + // Method overload to take in a specific path + public string CreateOutFileName(string archivePath) + { + try + { + //string path = archivePath + "\\HobbyArchive"; + Console.WriteLine("The current directory is {0}", archivePath); + string date = DateTime.Now.ToString("M_d_yyyy"); + string fileName = date + "_archive.csv"; + string filePath = System.IO.Path.Combine(archivePath, fileName); + + Console.WriteLine("Date: {0}", date); + Console.WriteLine("Filepath: {0}", filePath); + return filePath; } catch { diff --git a/Source Code/main/Controller.cs b/Source Code/main/Controller.cs index ed04cef..c63324a 100644 --- a/Source Code/main/Controller.cs +++ b/Source Code/main/Controller.cs @@ -77,13 +77,15 @@ namespace TeamHobby.HobbyProjectGenerator.Main Console.WriteLine(""); // Creating a file name: + string filePath = @"C:\HobbyArchive"; Console.WriteLine("Creating file name ... "); - string curPath = archive.CreateOutFileName(); + //string curPath = archive.CreateOutFileName(); + string curPath = archive.CreateOutFileName(filePath); - string pathForward = @"C:\Users\Chunchunmaru\Documents\csulbFall2021\HobbyProject\Source Code\main\bin\Debug\net6.0\HobbyArchive"; - string pathTemp = "C:/Temp/oldlogs10.txt"; - string pathTempBack = @"C:\Temp\oldlogs10.txt"; - Console.WriteLine("----------------"); + //string pathForward = @"C:\Users\Chunchunmaru\Documents\csulbFall2021\HobbyProject\Source Code\main\bin\Debug\net6.0\HobbyArchive"; + //string pathTemp = "C:/Temp/oldlogs10.txt"; + //string pathTempBack = @"C:\Temp\oldlogs10.txt"; + //Console.WriteLine("----------------"); //Output SQL to a text file sqlDS.CopyToFile(curPath); From b89e4f69c4192b986419f2b8cf37e8533034e717 Mon Sep 17 00:00:00 2001 From: Lunastra Date: Sat, 11 Dec 2021 23:40:39 -0800 Subject: [PATCH 4/5] Process flowed testing for compress sequence --- .../ArchiveController.cs | 3 ++- .../Implementations/SqlDAO.cs | 17 +++++++++++++++-- Source Code/main/Controller.cs | 18 ++++++++++++++++-- 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.Archive/ArchiveController.cs b/Source Code/TeamHobby.HobbyProjectGenerator.Archive/ArchiveController.cs index 4ea6841..54ebad0 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator.Archive/ArchiveController.cs +++ b/Source Code/TeamHobby.HobbyProjectGenerator.Archive/ArchiveController.cs @@ -65,9 +65,10 @@ namespace TeamHobby.HobbyProjectGenerator.Archive { //string path = archivePath + "\\HobbyArchive"; Console.WriteLine("The current directory is {0}", archivePath); + //string date = DateTime.Now.ToString("M_d_yyyy_H:mm:ss"); string date = DateTime.Now.ToString("M_d_yyyy"); string fileName = date + "_archive.csv"; - string filePath = System.IO.Path.Combine(archivePath, fileName); + string filePath = Path.Combine(archivePath, fileName); Console.WriteLine("Date: {0}", date); Console.WriteLine("Filepath: {0}", filePath); diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/Implementations/SqlDAO.cs b/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/Implementations/SqlDAO.cs index c2ae271..1843b50 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/Implementations/SqlDAO.cs +++ b/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/Implementations/SqlDAO.cs @@ -217,13 +217,26 @@ namespace TeamHobby.HobbyProjectGenerator.DataAccess } public bool RemoveOutputFile(string filePath){ - return true; + try + { + if (File.Exists(filePath)) + { + Console.WriteLine("File at: {0} exist, proceed to remove.", filePath); + File.Delete(filePath); + return true; + } + return false; + } + catch { + Console.WriteLine("Removing file failed!!"); + return false; + } } // Remove data from the database, if failed, let the controller handle it. public bool RemoveEntries() { - string sqlCmd = "DELETE FROM log WHERE DATE_DIFF(current_timestamp, log.LtimeStamp) > 30"; + string sqlCmd = "DELETE FROM log WHERE DATEDIFF(current_timestamp, log.LtimeStamp) > 30"; try{ DeleteData(sqlCmd); diff --git a/Source Code/main/Controller.cs b/Source Code/main/Controller.cs index c63324a..6f6d0d8 100644 --- a/Source Code/main/Controller.cs +++ b/Source Code/main/Controller.cs @@ -78,18 +78,32 @@ namespace TeamHobby.HobbyProjectGenerator.Main // Creating a file name: string filePath = @"C:\HobbyArchive"; - Console.WriteLine("Creating file name ... "); + //Console.WriteLine("Creating file name ... "); //string curPath = archive.CreateOutFileName(); string curPath = archive.CreateOutFileName(filePath); //string pathForward = @"C:\Users\Chunchunmaru\Documents\csulbFall2021\HobbyProject\Source Code\main\bin\Debug\net6.0\HobbyArchive"; //string pathTemp = "C:/Temp/oldlogs10.txt"; //string pathTempBack = @"C:\Temp\oldlogs10.txt"; - //Console.WriteLine("----------------"); + Console.WriteLine("----------------"); //Output SQL to a text file sqlDS.CopyToFile(curPath); + // Compress the file + sqlDS.CompressFile(curPath); + + //Remove output file + sqlDS.RemoveOutputFile(curPath); + + // Remove entries fromt the database + sqlDS.RemoveEntries(); + + // Testing date time patters + //string date = DateTime.Now.ToString("d"); + //Console.WriteLine(date); + //Console.WriteLine(DateTime.Now.ToString("M_d_yyyy_H:mm:ss")); + // 2.Inserting Data into the database: //string sqlWrite = "INSERT into log(lvname, catname, userop, logmessage) values " + From 4e970f28b6b366062b3cd491a0af47f045d00e4b Mon Sep 17 00:00:00 2001 From: Lunastra Date: Sun, 12 Dec 2021 00:24:40 -0800 Subject: [PATCH 5/5] Rename to archiveManager Add the while loop and if statement --- .../ArchiveController.cs | 100 ----------- .../ArchiveManager.cs | 161 ++++++++++++++++++ Source Code/main/Controller.cs | 63 ++++--- 3 files changed, 196 insertions(+), 128 deletions(-) delete mode 100644 Source Code/TeamHobby.HobbyProjectGenerator.Archive/ArchiveController.cs create mode 100644 Source Code/TeamHobby.HobbyProjectGenerator.Archive/ArchiveManager.cs diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.Archive/ArchiveController.cs b/Source Code/TeamHobby.HobbyProjectGenerator.Archive/ArchiveController.cs deleted file mode 100644 index 54ebad0..0000000 --- a/Source Code/TeamHobby.HobbyProjectGenerator.Archive/ArchiveController.cs +++ /dev/null @@ -1,100 +0,0 @@ - -using TeamHobby.HobbyProjectGenerator.DataAccess; - -namespace TeamHobby.HobbyProjectGenerator.Archive -{ - public class ArchiveController - { - private IDataSource _conn; - - // Constructor to take in the connection. - public ArchiveController(IDataSource dataSource) { - _conn = dataSource; - } - - - // Create the folder where the compress file will be stored - public bool CreateArchiveFolder(){ - //string curPath = Directory.GetCurrentDirectory(); - string curPath = @"C:\"; - - // Find the root drive of the program - string drive = Path.GetPathRoot(path: curPath); - // Check if Drive exists or not - if (!Directory.Exists(drive)) - { - Console.WriteLine("Drive {0} not found", drive); - return false; - } - - string archiveFolder = curPath + "\\HobbyArchive"; - //Console.WriteLine("Creating a new folder at: {0}", archiveFolder); - if (!Directory.Exists(archiveFolder)) - { - Console.WriteLine("Creating a new folder at: {0}", archiveFolder); - Directory.CreateDirectory(archiveFolder); - } - return true; - } - - - // Return the name of the new output file with Path - public string CreateOutFileName() { - try { - string path = Directory.GetCurrentDirectory() + "\\HobbyArchive"; - Console.WriteLine("The current directory is {0}", path); - string date = DateTime.Now.ToString("M_d_yyyy"); - string fileName = date + "_archive.csv"; - string filePath = System.IO.Path.Combine(path, fileName); - - Console.WriteLine("Date: {0}", date); - Console.WriteLine("Filepath: {0}", filePath); - return filePath; - } - catch - { - Console.WriteLine("ArchiveCon: Creating a file name failed. "); - return ""; - } - } - - // Method overload to take in a specific path - public string CreateOutFileName(string archivePath) - { - try - { - //string path = archivePath + "\\HobbyArchive"; - Console.WriteLine("The current directory is {0}", archivePath); - //string date = DateTime.Now.ToString("M_d_yyyy_H:mm:ss"); - string date = DateTime.Now.ToString("M_d_yyyy"); - string fileName = date + "_archive.csv"; - string filePath = Path.Combine(archivePath, fileName); - - Console.WriteLine("Date: {0}", date); - Console.WriteLine("Filepath: {0}", filePath); - return filePath; - } - catch - { - Console.WriteLine("ArchiveCon: Creating a file name failed. "); - return ""; - } - } - - // put everything toget here - public bool Controller(){ - - // Create the folder for Archiving - CreateArchiveFolder(); - - // Create the file name for output - CreateOutFileName(); - return true; - } - - - - - - } -} \ No newline at end of file diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.Archive/ArchiveManager.cs b/Source Code/TeamHobby.HobbyProjectGenerator.Archive/ArchiveManager.cs new file mode 100644 index 0000000..256ce31 --- /dev/null +++ b/Source Code/TeamHobby.HobbyProjectGenerator.Archive/ArchiveManager.cs @@ -0,0 +1,161 @@ + +using TeamHobby.HobbyProjectGenerator.DataAccess; + +namespace TeamHobby.HobbyProjectGenerator.Archive +{ + public class ArchiveManager + { + private IDataSource _conn; + + // Constructor to take in the connection. + public ArchiveManager(IDataSource dataSource) { + _conn = dataSource; + } + + + // Create the folder where the compress file will be stored + public bool CreateArchiveFolder(){ + //string curPath = Directory.GetCurrentDirectory(); + string curPath = @"C:\"; + string folderName = "\\HobbyArchive"; + + // Find the root drive of the program + string drive = Path.GetPathRoot(path: curPath); + // Check if Drive exists or not + if (!Directory.Exists(drive)) + { + Console.WriteLine("Drive {0} not found", drive); + return false; + } + + string archiveFolder = curPath + folderName; + //Console.WriteLine("Creating a new folder at: {0}", archiveFolder); + if (!Directory.Exists(archiveFolder)) + { + Console.WriteLine("Creating a new folder at: {0}", archiveFolder); + Directory.CreateDirectory(archiveFolder); + } + return true; + } + + + // Return the name of the new output file with Path + public string CreateOutFileName() { + try { + // Creating a file name: + string path = @"C:\HobbyArchive"; + //string path = Directory.GetCurrentDirectory() + "\\HobbyArchive"; + Console.WriteLine("The current directory is {0}", path); + string date = DateTime.Now.ToString("M_d_yyyy"); + string fileName = date + "_archive.csv"; + string filePath = System.IO.Path.Combine(path, fileName); + + Console.WriteLine("Date: {0}", date); + Console.WriteLine("Filepath: {0}", filePath); + return filePath; + } + catch + { + Console.WriteLine("ArchiveCon: Creating a file name failed. "); + return ""; + } + } + + // Method overload to take in a specific path + public string CreateOutFileName(string archivePath) + { + try + { + //string path = archivePath + "\\HobbyArchive"; + Console.WriteLine("The current directory is {0}", archivePath); + //string date = DateTime.Now.ToString("M_d_yyyy_H:mm:ss"); + string date = DateTime.Now.ToString("M_d_yyyy"); + string fileName = date + "_archive.csv"; + string filePath = Path.Combine(archivePath, fileName); + + Console.WriteLine("Date: {0}", date); + Console.WriteLine("Filepath: {0}", filePath); + return filePath; + } + catch + { + Console.WriteLine("ArchiveCon: Creating a file name failed. "); + return ""; + } + } + + // put everything toget here + public bool Controller(){ + + SqlDAO sqlDS = null; + if (_conn.GetType() == typeof(SqlDAO)) + { + sqlDS = (SqlDAO)_conn; + + } + // TODO: Remember to add try catch block here to make sure it is completed. + + //Creating the folder Archive + Console.WriteLine("Creating a new folder ..."); + CreateArchiveFolder(); + Console.WriteLine("Creating a new folder completed ..."); + Console.WriteLine("----------------"); + Console.WriteLine(""); + + // Creating a file name: + string filePath = @"C:\HobbyArchive"; + //Console.WriteLine("Creating file name ... "); + //string curPath = archive.CreateOutFileName(); + Console.WriteLine("Creating Output file name ..."); + string curPath = CreateOutFileName(); + Console.WriteLine("Output file name created ..."); + Console.WriteLine("----------------"); + Console.WriteLine(""); + + //string pathForward = @"C:\Users\Chunchunmaru\Documents\csulbFall2021\HobbyProject\Source Code\main\bin\Debug\net6.0\HobbyArchive"; + //string pathTemp = "C:/Temp/oldlogs10.txt"; + //string pathTempBack = @"C:\Temp\oldlogs10.txt"; + + //Output SQL to a text file + Console.WriteLine("Copying to a text file ..."); + sqlDS.CopyToFile(curPath); + Console.WriteLine("Copying completed ..."); + Console.WriteLine("----------------"); + Console.WriteLine(""); + + // Compress the file + Console.WriteLine("Copressing the text file ..."); + sqlDS.CompressFile(curPath); + Console.WriteLine("Copression completed ..."); + Console.WriteLine("----------------"); + Console.WriteLine(""); + + //Remove output file + Console.WriteLine("Removing the text file ..."); + sqlDS.RemoveOutputFile(curPath); + Console.WriteLine("Text File removal completed ..."); + Console.WriteLine("----------------"); + Console.WriteLine(""); + + // Remove entries fromt the database + Console.WriteLine("Removing the text file ..."); + sqlDS.RemoveEntries(); + Console.WriteLine("Entries removal completed ..."); + Console.WriteLine("----------------"); + Console.WriteLine(""); + + // Testing date time patters + //string date = DateTime.Now.ToString("d"); + //Console.WriteLine(date); + //Console.WriteLine(DateTime.Now.ToString("M_d_yyyy_H:mm:ss")); + + return true; + + } + + + + + + } +} \ No newline at end of file diff --git a/Source Code/main/Controller.cs b/Source Code/main/Controller.cs index 6f6d0d8..0dee3c0 100644 --- a/Source Code/main/Controller.cs +++ b/Source Code/main/Controller.cs @@ -64,45 +64,55 @@ namespace TeamHobby.HobbyProjectGenerator.Main Console.WriteLine("Date={0} {1} {2} {3} {4} {5}", reader[0], reader[1], reader[2], reader[3], reader[4], reader[5]); } SqlDAO sqlDS = (SqlDAO)datasource; + Console.WriteLine(""); // Closing the connection sqlDS.getConnection().Close(); + // While loop to keep this running forever with UserManagement // Testing archive Manager - ArchiveController archive = new ArchiveController(datasource); + //while (true) + //{ + string currentDate = DateTime.Now.ToString("dd"); + string currentTime = DateTime.Now.ToString("T"); + Console.WriteLine("Current date: {0}, Current Time: {1}", currentDate, currentTime); + if (String.Equals(currentDate, "1") && String.Equals(currentTime, "00:00:00 AM")){ + ArchiveManager archive = new ArchiveManager(datasource); + archive.Controller(); + } + //} + + //Creating the folder Archive - Console.WriteLine("Creating a new folder ..."); - archive.CreateArchiveFolder(); - Console.WriteLine(""); + //Console.WriteLine("Creating a new folder ..."); + //archive.CreateArchiveFolder(); + //Console.WriteLine(""); - // Creating a file name: - string filePath = @"C:\HobbyArchive"; - //Console.WriteLine("Creating file name ... "); - //string curPath = archive.CreateOutFileName(); - string curPath = archive.CreateOutFileName(filePath); + //// Creating a file name: + //string filePath = @"C:\HobbyArchive"; + ////Console.WriteLine("Creating file name ... "); + ////string curPath = archive.CreateOutFileName(); + //string curPath = archive.CreateOutFileName(filePath); - //string pathForward = @"C:\Users\Chunchunmaru\Documents\csulbFall2021\HobbyProject\Source Code\main\bin\Debug\net6.0\HobbyArchive"; - //string pathTemp = "C:/Temp/oldlogs10.txt"; - //string pathTempBack = @"C:\Temp\oldlogs10.txt"; - Console.WriteLine("----------------"); + ////string pathForward = @"C:\Users\Chunchunmaru\Documents\csulbFall2021\HobbyProject\Source Code\main\bin\Debug\net6.0\HobbyArchive"; + ////string pathTemp = "C:/Temp/oldlogs10.txt"; + ////string pathTempBack = @"C:\Temp\oldlogs10.txt"; + //Console.WriteLine("----------------"); - //Output SQL to a text file - sqlDS.CopyToFile(curPath); + ////Output SQL to a text file + //sqlDS.CopyToFile(curPath); - // Compress the file - sqlDS.CompressFile(curPath); + //// Compress the file + //sqlDS.CompressFile(curPath); - //Remove output file - sqlDS.RemoveOutputFile(curPath); + ////Remove output file + //sqlDS.RemoveOutputFile(curPath); - // Remove entries fromt the database - sqlDS.RemoveEntries(); + //// Remove entries fromt the database + //sqlDS.RemoveEntries(); - // Testing date time patters - //string date = DateTime.Now.ToString("d"); - //Console.WriteLine(date); - //Console.WriteLine(DateTime.Now.ToString("M_d_yyyy_H:mm:ss")); + // 2.Inserting Data into the database: @@ -120,9 +130,6 @@ namespace TeamHobby.HobbyProjectGenerator.Main //Console.WriteLine("Writing completed. "); - - - /* ExampleDAO z = new ExampleDAO(); z.UserData("Tomato"); Console.Read();*/