diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.Archive/ArchiveController.cs b/Source Code/TeamHobby.HobbyProjectGenerator.Archive/ArchiveController.cs new file mode 100644 index 0000000..9e39fb8 --- /dev/null +++ b/Source Code/TeamHobby.HobbyProjectGenerator.Archive/ArchiveController.cs @@ -0,0 +1,7 @@ +namespace TeamHobby.HobbyProjectGenerator.Archive +{ + public class ArchiveController + { + + } +} \ No newline at end of file diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.Archive/Contracts/IDataSource.cs b/Source Code/TeamHobby.HobbyProjectGenerator.Archive/Contracts/IDataSource.cs new file mode 100644 index 0000000..f173ba6 --- /dev/null +++ b/Source Code/TeamHobby.HobbyProjectGenerator.Archive/Contracts/IDataSource.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +//namespace TeamHobby.HobbyProjectGenerator.Archive.Contracts +namespace TeamHobby.HobbyProjectGenerator.Archive +{ + public interface IDataSource + { + // Method for reading data, return 0 for sucessful operation + Object ReadData(string cmd); + + // Method for Writing data to a data source + bool WriteData(string cmd); + + //Method for deleteing data from a data source, 0 for successful + bool DeleteData(); + + // Method for updating data from a data source, 0 for sucessful + bool UpdateData(); + } +} diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.Archive/Contracts/IRelationArchivable.cs b/Source Code/TeamHobby.HobbyProjectGenerator.Archive/Contracts/IRelationArchivable.cs new file mode 100644 index 0000000..96cabb9 --- /dev/null +++ b/Source Code/TeamHobby.HobbyProjectGenerator.Archive/Contracts/IRelationArchivable.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TeamHobby.HobbyProjectGenerator.Archive +{ + public interface IRelationArchivable + { + bool CreateArchived(string fileName); + } +} diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.Archive/Implementations/SQLSource.cs b/Source Code/TeamHobby.HobbyProjectGenerator.Archive/Implementations/SQLSource.cs new file mode 100644 index 0000000..ab5b34a --- /dev/null +++ b/Source Code/TeamHobby.HobbyProjectGenerator.Archive/Implementations/SQLSource.cs @@ -0,0 +1,96 @@ +using System; +using System.Collections.Generic; +using System.Data.SqlClient; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.IO.Compression; + + +namespace TeamHobby.HobbyProjectGenerator.Archive +{ + public class SQLSource : IDataSource, IRelationArchivable + { + //private SqlConnection conn; + + //public SQLSource(string info) + //{ + // conn = new SqlConnection(info); + //} + + public bool DeleteData() + { + throw new NotImplementedException(); + } + + public Object ReadData(string cmd) + { + try + { + // conn.open(); + // conn.Execute(); + Console.WriteLine("Access a SQL database"); + Console.WriteLine("Select * from archive"); + + // while (myReader) + // Print to console + // conn.close(); + return null; + } + catch (Exception e) + { + Console.WriteLine(e.Message); + return null; + } + } + + public bool UpdateData() + { + throw new NotImplementedException(); + } + + public bool WriteData(string cmd) + { + throw new NotImplementedException(); + } + + // Method to archive data + public bool CreateArchived(string fileName) + { + throw new NotImplementedException(); + } + + public bool CompressFile(string fileName) + { + try + { + // Get the stream of the original file + using FileStream origFile = File.Open(fileName, FileMode.Open); + + + // Get the attribute of the file + FileAttributes atrribute = File.GetAttributes(fileName); + + // Check to see if the file is hidden or already compressed before compressing the file. + if (atrribute != FileAttributes.Hidden && atrribute != FileAttributes.Compressed) + { + using FileStream outputFile = File.Create(fileName + ".gz"); + + using GZipStream compressor = new GZipStream(outputFile, CompressionMode.Compress); + origFile.CopyTo(compressor); + + return true; + } + + return true; + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + return false; + } + } + + } +} diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.Archive/RelationalDataSourceFactory.cs b/Source Code/TeamHobby.HobbyProjectGenerator.Archive/RelationalDataSourceFactory.cs new file mode 100644 index 0000000..08f602a --- /dev/null +++ b/Source Code/TeamHobby.HobbyProjectGenerator.Archive/RelationalDataSourceFactory.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TeamHobby.HobbyProjectGenerator.Archive; + +namespace TeamHobby.HobbyProjectGenerator.Archive +{ + public class RelationalDataSourceFactory + { + // Mehthod to create a specific data source suitable to the need + public IDataSource? getDataSource(string name) + { + try + { + if (String.Equals(name, "SQL", StringComparison.OrdinalIgnoreCase)) + { + return new SQLSource(); + } + else + { + return null; + } + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + return null; + } + } + } +} diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.Archive/TeamHobby.HobbyProjectGenerator.Archive.csproj b/Source Code/TeamHobby.HobbyProjectGenerator.Archive/TeamHobby.HobbyProjectGenerator.Archive.csproj new file mode 100644 index 0000000..ac029dc --- /dev/null +++ b/Source Code/TeamHobby.HobbyProjectGenerator.Archive/TeamHobby.HobbyProjectGenerator.Archive.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/Source Code/TeamHobby.HobbyProjectGenerator/TeamHobby.HobbyProjectGenerator.sln b/Source Code/TeamHobby.HobbyProjectGenerator/TeamHobby.HobbyProjectGenerator.sln deleted file mode 100644 index 367f50c..0000000 --- a/Source Code/TeamHobby.HobbyProjectGenerator/TeamHobby.HobbyProjectGenerator.sln +++ /dev/null @@ -1,49 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.0.31919.166 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.HobbyProjectGenerator", "TeamHobby.HobbyProjectGenerator.csproj", "{C75B6909-FD9E-4382-94B6-7CA2CE371C9A}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.UserManagement.Tests", "..\TeamHobby.UserManagement.Tests\TeamHobby.UserManagement.Tests.csproj", "{5C5A44B4-EC3C-44F2-8F39-F917F8ED932F}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.HobbyProjectGenerator.DAL", "..\TeamHobby.HobbyProjectGenerator.DAL\TeamHobby.HobbyProjectGenerator.DAL.csproj", "{DCB0E160-1F6D-406E-8633-489CD564479B}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.HobbyProjectGenerator.Models", "..\TeamHobby.HobbyProjectGenerator.Models\TeamHobby.HobbyProjectGenerator.Models.csproj", "{75DED6C2-D404-4E71-A58B-0F616DB5C062}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TeamHobby.HobbyProjectGenerator.Main", "..\TeamHobby.HobbyProjectGenerator.Main\TeamHobby.HobbyProjectGenerator.Main.csproj", "{1D3E043F-A6EC-46D8-87ED-4164D095B83A}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {C75B6909-FD9E-4382-94B6-7CA2CE371C9A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {C75B6909-FD9E-4382-94B6-7CA2CE371C9A}.Debug|Any CPU.Build.0 = Debug|Any CPU - {C75B6909-FD9E-4382-94B6-7CA2CE371C9A}.Release|Any CPU.ActiveCfg = Release|Any CPU - {C75B6909-FD9E-4382-94B6-7CA2CE371C9A}.Release|Any CPU.Build.0 = Release|Any CPU - {5C5A44B4-EC3C-44F2-8F39-F917F8ED932F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {5C5A44B4-EC3C-44F2-8F39-F917F8ED932F}.Debug|Any CPU.Build.0 = Debug|Any CPU - {5C5A44B4-EC3C-44F2-8F39-F917F8ED932F}.Release|Any CPU.ActiveCfg = Release|Any CPU - {5C5A44B4-EC3C-44F2-8F39-F917F8ED932F}.Release|Any CPU.Build.0 = Release|Any CPU - {DCB0E160-1F6D-406E-8633-489CD564479B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {DCB0E160-1F6D-406E-8633-489CD564479B}.Debug|Any CPU.Build.0 = Debug|Any CPU - {DCB0E160-1F6D-406E-8633-489CD564479B}.Release|Any CPU.ActiveCfg = Release|Any CPU - {DCB0E160-1F6D-406E-8633-489CD564479B}.Release|Any CPU.Build.0 = Release|Any CPU - {75DED6C2-D404-4E71-A58B-0F616DB5C062}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {75DED6C2-D404-4E71-A58B-0F616DB5C062}.Debug|Any CPU.Build.0 = Debug|Any CPU - {75DED6C2-D404-4E71-A58B-0F616DB5C062}.Release|Any CPU.ActiveCfg = Release|Any CPU - {75DED6C2-D404-4E71-A58B-0F616DB5C062}.Release|Any CPU.Build.0 = Release|Any CPU - {1D3E043F-A6EC-46D8-87ED-4164D095B83A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {1D3E043F-A6EC-46D8-87ED-4164D095B83A}.Debug|Any CPU.Build.0 = Debug|Any CPU - {1D3E043F-A6EC-46D8-87ED-4164D095B83A}.Release|Any CPU.ActiveCfg = Release|Any CPU - {1D3E043F-A6EC-46D8-87ED-4164D095B83A}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {B2517200-A9F9-468C-B0EB-280FF9B9FBC9} - EndGlobalSection -EndGlobal diff --git a/Source Code/TeamHobby.Main/HobbyMain.cs b/Source Code/TeamHobby.Main/HobbyMain.cs new file mode 100644 index 0000000..6d30a27 --- /dev/null +++ b/Source Code/TeamHobby.Main/HobbyMain.cs @@ -0,0 +1,62 @@ +// See https://aka.ms/new-console-template for more information +using System.Data.SqlClient; +using System.IO.Compression; +using TeamHobby.HobbyProjectGenerator.Archive; + +public class HobbyMain +{ + static void Main(string[] args) + { + Console.WriteLine("Hello World!"); + + // Testing Compressing a file + string fileName = @"C:\Users\Chunchunmaru\Documents\csulbFall2021\HobbyProject\Source Code\TeamHobby.Main\archiving2.txt"; + //string fileName = @"arhiving2.txt"; + FileInfo fileInfo = new FileInfo(fileName); + + Console.WriteLine("File Name: {0}", fileInfo.FullName); + + //Console.WriteLine("Starting file compression: "); + //Compress(fileInfo); + //Console.WriteLine("Ending compression"); + //SqlConnection myconn = new SqlConnection(); + + + //IDataSource dataSource = new SQLSource(); + + SQLSource sqlSource = new SQLSource(); + bool res = sqlSource.CompressFile(fileName); + //bool res = CompressFile(fileName); + Console.WriteLine(res); + + + } + + + public static void Compress(FileInfo fi) + { + // Get the stream of the source file. + using (FileStream inFile = fi.OpenRead()) + { + // Prevent compressing hidden and + // already compressed files. + if ((File.GetAttributes(fi.FullName) & FileAttributes.Hidden) != FileAttributes.Hidden & fi.Extension != ".gz") + { + // Create the compressed file. + using (FileStream outFile = + File.Create(fi.FullName + ".gz")) + { + using (GZipStream Compress = new GZipStream(outFile, CompressionMode.Compress)) + { + // Copy the source file into + // the compression stream. + inFile.CopyTo(Compress); + + Console.WriteLine("Compressed {0} from {1} to {2} bytes.", + fi.Name, fi.Length.ToString(), outFile.Length.ToString()); + } + } + } + } + } +} diff --git a/Source Code/TeamHobby.Main/TeamHobby.Main.csproj b/Source Code/TeamHobby.Main/TeamHobby.Main.csproj new file mode 100644 index 0000000..00d7d1d --- /dev/null +++ b/Source Code/TeamHobby.Main/TeamHobby.Main.csproj @@ -0,0 +1,19 @@ + + + + Exe + net6.0 + enable + enable + HobbyMain + + + + + + + + + + + diff --git a/Source Code/TeamHobby.Main/archiving2.txt b/Source Code/TeamHobby.Main/archiving2.txt new file mode 100644 index 0000000..a2ba694 --- /dev/null +++ b/Source Code/TeamHobby.Main/archiving2.txt @@ -0,0 +1,46 @@ +title Use Case: Archiving + +participant ArchiveController.cs +participant DataConnection +participant DataSourceFactory +participant SQLSource +participant MariaDB + +activate ArchiveController.cs +activate DataConnection +ArchiveController.cs ->DataConnection:static DataConnection getDataConnection() +DataConnection -->ArchiveController.cs:return DataConnection +deactivate DataConnection + +activate DataSourceFactory +ArchiveController.cs ->DataSourceFactory: new DataSourceFactory() +DataSourceFactory ->DataSourceFactory:DataSourceFactory()\nconstructor +ArchiveController.cs <-- DataSourceFactory:return DataSourceFactory +deactivate DataSourceFactory + +activate SQLSource +ArchiveController.cs->SQLSource: IDataSource DataSourceFact.GetDataSource(String sourceName, string info) +SQLSource->SQLSource: SQLSource(string info)\nconstructor +SQLSource --> ArchiveController.cs :return SQLSource + +loop #lightblue while true +alt #lightgreen date == 1 +ArchiveController.cs ->ArchiveController.cs: string fileName = string CreateFileName( ) +ArchiveController.cs -> SQLSource: int Compress(string fileName) +activate MariaDB + +SQLSource -> MariaDB: int createArchive(string fileLocation) +MariaDB -->SQLSource:return 0 + +SQLSource ->MariaDB: int RemoveEntries() +MariaDB-->SQLSource:return 0 +end + + +deactivate MariaDB + +SQLSource-->ArchiveController.cs:return 0 +end + +deactivate ArchiveController.cs +deactivate SQLSource \ No newline at end of file diff --git a/doc/LowLevel/archiving2.txt b/doc/LowLevel/archiving2.txt new file mode 100644 index 0000000..a2ba694 --- /dev/null +++ b/doc/LowLevel/archiving2.txt @@ -0,0 +1,46 @@ +title Use Case: Archiving + +participant ArchiveController.cs +participant DataConnection +participant DataSourceFactory +participant SQLSource +participant MariaDB + +activate ArchiveController.cs +activate DataConnection +ArchiveController.cs ->DataConnection:static DataConnection getDataConnection() +DataConnection -->ArchiveController.cs:return DataConnection +deactivate DataConnection + +activate DataSourceFactory +ArchiveController.cs ->DataSourceFactory: new DataSourceFactory() +DataSourceFactory ->DataSourceFactory:DataSourceFactory()\nconstructor +ArchiveController.cs <-- DataSourceFactory:return DataSourceFactory +deactivate DataSourceFactory + +activate SQLSource +ArchiveController.cs->SQLSource: IDataSource DataSourceFact.GetDataSource(String sourceName, string info) +SQLSource->SQLSource: SQLSource(string info)\nconstructor +SQLSource --> ArchiveController.cs :return SQLSource + +loop #lightblue while true +alt #lightgreen date == 1 +ArchiveController.cs ->ArchiveController.cs: string fileName = string CreateFileName( ) +ArchiveController.cs -> SQLSource: int Compress(string fileName) +activate MariaDB + +SQLSource -> MariaDB: int createArchive(string fileLocation) +MariaDB -->SQLSource:return 0 + +SQLSource ->MariaDB: int RemoveEntries() +MariaDB-->SQLSource:return 0 +end + + +deactivate MariaDB + +SQLSource-->ArchiveController.cs:return 0 +end + +deactivate ArchiveController.cs +deactivate SQLSource \ No newline at end of file