Revised Logging LLD

Fixed entry point and added LogEntry class
This commit is contained in:
colincreasman 2021-12-13 11:36:10 -08:00
parent 99c3a7eb4a
commit 4f2f4c8fce
23 changed files with 328 additions and 41 deletions

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TeamHobby.HobbyProjectGenerator.Logging
{
public interface ILogger
{
bool Log(LogEntry log);
IList<string> GetAllLogs();
}
}

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TeamHobby.HobbyProjectGenerator.Logging.Contracts
{
public interface ILoggerFactory
{
ILogger CreateLogger()
{
}
}
}

View File

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TeamHobby.HobbyProjectGenerator.Logging
{
public class ConsoleLogger : ILogger
{
public IList<string> GetAllLogs()
{
throw new NotImplementedException();
}
public bool Log(string description)
{
throw new NotImplementedException();
}
}
}

View File

@ -0,0 +1,24 @@
using System;
namespace TeamHobby.HobbyProjectGenerator.Logging
{
public class DBLogger : ILogger
{
public DBLogger()
{
}
public IList<string> GetAllLogs()
{
throw new NotImplementedException();
}
public bool Log(LogEntry log)
{
throw new NotImplementedException();
}
}
}

View File

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TeamHobby.HobbyProjectGenerator.Logging.Contracts;
namespace TeamHobby.HobbyProjectGenerator.Logging.Implementations
{
public class DBLoggerFactory : ILoggerFactory
{
public DBLoggerFactory()
{
}
public ILogger CreateLogger()
{
return new DBLogger();
}
}
}

View File

@ -0,0 +1,18 @@
using System;
namespace TeamHobby.HobbyProjectGenerator.Logging
{
public class FileLogger : ILogger
{
public IList<string> GetAllLogs()
{
throw new NotImplementedException();
}
public bool Log(string description)
{
throw new NotImplementedException();
}
}
}

View File

@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
namespace TeamHobby.HobbyProjectGenerator.Logging
{
// implementation of ILogger that stores logs as they initialize
public class InMemoryLogger : ILogger
{
// make readonly to prevent it from being changed somewhere other than in the constructor
private readonly IList<string> _logStore;
public InMemoryLogger()
{
// list of current logs
_logStore = new List<string>();
}
public bool Log(string description)
{
try
{
// string interpolation to add UTC timestamp to log description
_logStore.Add($"{DateTime.UtcNow}-> {description}");
return true;
}
catch
{
return false;
}
}
public IList<string> GetAllLogs()
{
return _logStore;
}
}
}

View File

@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TeamHobby.HobbyProjectGenerator.Logging
{
public enum LogLevel
{
Info, Debug, Warning, Error
}
public enum LogCategory
{
View, Business, Server, Data, Datastore
}
// LogEntry is a record type with init properties for each field
// ensures that log entries are immutable after initialization
public record LogEntry
{
public LogLevel level { get; init; }
public LogCategory category { get; init; }
public string user { get; init; }
public string description { get; init; }
public DateTime timestamp { get; init; }
}
}

View File

@ -1,14 +0,0 @@
using System;
namespace TeamHobby.HobbyProjectGenerator.Logging
{
public class Logger
{
public static void PrintTest()
{
Console.WriteLine("testing");
}
}
}

View File

@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TeamHobby.HobbyProjectGenerator.DataAccess;
using TeamHobby.HobbyProjectGenerator.Logging.Contracts;
using TeamHobby.HobbyProjectGenerator.Logging.Implementations;
namespace TeamHobby.HobbyProjectGenerator.Logging
{
internal class LoggingController
{
private readonly IDataSource<string> _conn;
private readonly ILogger _logger;
private readonly ILoggerFactory _factory;
// private readonly LogEntry _logEntry;
// Both Constructors take an IDataSource arg to make logging extensible to future data sources
// first constructor has no additional args - defaults to using the DBFactiry implementation
public LoggingController(IDataSource<string> dataSource)
{
_conn = dataSource;
_factory = new DBLoggerFactory();
_logger = _factory.CreateLogger();
}
// second constructor takes an additional ILoggerFactory arg - allows for extensible logger types
public LoggingController(IDataSource<string> dataSource, ILoggerFactory factory)
{
_conn = dataSource;
_factory = factory;
_logger = _factory.CreateLogger();
}
public void Process()
{
_logger.Log();
}
}
}

View File

@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<OutputType>Library</OutputType>
<PlatformTarget>AnyCPU</PlatformTarget>
<Platforms>AnyCPU;x86</Platforms>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<Optimize>True</Optimize>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x86'">
<Optimize>True</Optimize>
</PropertyGroup>
</Project>

View File

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
@ -6,4 +6,9 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\TeamHobby.HobbyProjectGenerator.Archive\TeamHobby.HobbyProjectGenerator.Archive.csproj" />
<ProjectReference Include="..\TeamHobby.HobbyProjectGenerator.DataAccess\TeamHobby.HobbyProjectGenerator.DataAccess.csproj" />
</ItemGroup>
</Project>

View File

@ -13,7 +13,7 @@ namespace TeamHobby.HobbyProjectGenerator.UserManagement
public string IsInputValid(string checkUN, string checkPWD)
{
// Create bool variables to check if username and password are valid
bool ValidUN = checkUN.All(un=>Char.IsLetterOrDigit(un) || un=='@'
bool ValidUN = checkUN.All(un => Char.IsLetterOrDigit(un) || un == '@'
|| un == '.' || un == ',' || un == '!');
bool ValidPwd = checkPWD.All(Char.IsLetterOrDigit);
@ -34,7 +34,7 @@ namespace TeamHobby.HobbyProjectGenerator.UserManagement
return "Invalid Password\n";
}
else if (checkUN.Length <= 15 && checkUN.Length > 0
|| ValidUN is true && checkPWD.Length <= 18
|| ValidUN is true && checkPWD.Length <= 18
&& checkPWD.Length > 0 || ValidPwd is true)
{
return "Username and password is valid.\n";
@ -105,22 +105,22 @@ namespace TeamHobby.HobbyProjectGenerator.UserManagement
{
}*/
/*conPsswrd = false;
}
else
{
Console.WriteLine("Passwords did not match, please try again.");
}
}
return true;
}*/
/*conPsswrd = false;
}
else
{
Console.WriteLine("Passwords did not match, please try again.");
}
}
return true;
}*/
public void AccountController()
{
// Create objects
//UserAccount user = new UserAccount();
UiPrint ui = new UiPrint();
bool foo = true;
while (foo == true)

View File

@ -19,7 +19,7 @@ namespace TeamHobby.HobbyProjectGenerator.UserManagement
Password = pwd;
Time = TimeStamp;
}
public string username { get { return UserName; } }
public string username { get { return UserName; } }
public string password { get { return Password; } }
// New User Credentials
@ -37,6 +37,6 @@ namespace TeamHobby.HobbyProjectGenerator.UserManagement
public string NewUserName { get { return newusername; } }
public string NewPassword { get { return newpassword; } }
public string NewEmail { get { return newemail; } }
public DateTime Newtime { get { return newtime;} }
public DateTime Newtime { get { return newtime; } }
}
}

View File

@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace TeamHobby.HobbyProjectGenerator.Implementations
{
public class InMemoryUserService
public class InMemoryUserService
{
// Make it readonly so it can't be changed
private readonly IList<string> _logstore;

View File

@ -1,6 +1,6 @@
namespace TeamHobby.HobbyProjectGenerator
{
public class User_Authentication
public class User_Authentication
{
public IList<string> GetAllUsers()
{

View File

@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace TeamHobby.HobbyProjectGenerator.Implementations
{
public class User_Manager
public class User_Manager
{
public IList<string> GetAllUsers()
{

View File

@ -17,49 +17,96 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.Main", "..\TeamHo
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.HobbyProjectGenerator.DataAccess", "..\TeamHobby.HobbyProjectGenerator.DataAccess\TeamHobby.HobbyProjectGenerator.DataAccess.csproj", "{AA48A66C-FA36-4AF9-A782-CEC22838EB8F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TeamHobby.HobbyProjectGenerator.Logging", "..\TeamHobby.HobbyProjectGenerator.Logging\TeamHobby.HobbyProjectGenerator.Logging.csproj", "{C0494115-838E-43A3-8896-133E5D1E874A}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.HobbyProjectGenerator.Logging", "..\TeamHobby.HobbyProjectGenerator.Logging\TeamHobby.HobbyProjectGenerator.Logging.csproj", "{C0494115-838E-43A3-8896-133E5D1E874A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.HobbyProjectGenerator.UserManagement", "..\TeamHobby.HobbyProjectGenerator.UserManagement\TeamHobby.HobbyProjectGenerator.UserManagement.csproj", "{2E7193B8-86B6-48DA-9671-CD84615A5F5D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.HobbyProjectGenerator.Logging.Tests", "..\TeamHobby.HobbyProjectGenerator.Logging.Tests\TeamHobby.HobbyProjectGenerator.Logging.Tests.csproj", "{CA8D11CF-807C-4C90-A529-0371F73518F6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x86 = Release|x86
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}.Debug|x86.ActiveCfg = Debug|Any CPU
{C75B6909-FD9E-4382-94B6-7CA2CE371C9A}.Debug|x86.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
{C75B6909-FD9E-4382-94B6-7CA2CE371C9A}.Release|x86.ActiveCfg = Release|Any CPU
{C75B6909-FD9E-4382-94B6-7CA2CE371C9A}.Release|x86.Build.0 = Release|Any CPU
{5C5A44B4-EC3C-44F2-8F39-F917F8ED932F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5C5A44B4-EC3C-44F2-8F39-F917F8ED932F}.Debug|x86.ActiveCfg = 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
{5C5A44B4-EC3C-44F2-8F39-F917F8ED932F}.Release|x86.ActiveCfg = Release|Any CPU
{5C5A44B4-EC3C-44F2-8F39-F917F8ED932F}.Release|x86.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}.Debug|x86.ActiveCfg = Debug|Any CPU
{75DED6C2-D404-4E71-A58B-0F616DB5C062}.Debug|x86.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
{75DED6C2-D404-4E71-A58B-0F616DB5C062}.Release|x86.ActiveCfg = Release|Any CPU
{75DED6C2-D404-4E71-A58B-0F616DB5C062}.Release|x86.Build.0 = Release|Any CPU
{30C7EBF3-3957-46E5-86C1-C13356841ECA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{30C7EBF3-3957-46E5-86C1-C13356841ECA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{30C7EBF3-3957-46E5-86C1-C13356841ECA}.Debug|x86.ActiveCfg = Debug|Any CPU
{30C7EBF3-3957-46E5-86C1-C13356841ECA}.Debug|x86.Build.0 = Debug|Any CPU
{30C7EBF3-3957-46E5-86C1-C13356841ECA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{30C7EBF3-3957-46E5-86C1-C13356841ECA}.Release|Any CPU.Build.0 = Release|Any CPU
{30C7EBF3-3957-46E5-86C1-C13356841ECA}.Release|x86.ActiveCfg = Release|Any CPU
{30C7EBF3-3957-46E5-86C1-C13356841ECA}.Release|x86.Build.0 = Release|Any CPU
{B88ED0D9-72E2-4245-BD8F-856FF42E500C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B88ED0D9-72E2-4245-BD8F-856FF42E500C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B88ED0D9-72E2-4245-BD8F-856FF42E500C}.Debug|x86.ActiveCfg = Debug|Any CPU
{B88ED0D9-72E2-4245-BD8F-856FF42E500C}.Debug|x86.Build.0 = Debug|Any CPU
{B88ED0D9-72E2-4245-BD8F-856FF42E500C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B88ED0D9-72E2-4245-BD8F-856FF42E500C}.Release|Any CPU.Build.0 = Release|Any CPU
{B88ED0D9-72E2-4245-BD8F-856FF42E500C}.Release|x86.ActiveCfg = Release|Any CPU
{B88ED0D9-72E2-4245-BD8F-856FF42E500C}.Release|x86.Build.0 = Release|Any CPU
{ED126EFB-B337-42F9-BE4B-65A5AE90503B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{ED126EFB-B337-42F9-BE4B-65A5AE90503B}.Debug|x86.ActiveCfg = Debug|Any CPU
{ED126EFB-B337-42F9-BE4B-65A5AE90503B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{ED126EFB-B337-42F9-BE4B-65A5AE90503B}.Release|Any CPU.Build.0 = Release|Any CPU
{ED126EFB-B337-42F9-BE4B-65A5AE90503B}.Release|x86.ActiveCfg = Release|Any CPU
{ED126EFB-B337-42F9-BE4B-65A5AE90503B}.Release|x86.Build.0 = Release|Any CPU
{AA48A66C-FA36-4AF9-A782-CEC22838EB8F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AA48A66C-FA36-4AF9-A782-CEC22838EB8F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AA48A66C-FA36-4AF9-A782-CEC22838EB8F}.Debug|x86.ActiveCfg = Debug|x86
{AA48A66C-FA36-4AF9-A782-CEC22838EB8F}.Debug|x86.Build.0 = Debug|x86
{AA48A66C-FA36-4AF9-A782-CEC22838EB8F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AA48A66C-FA36-4AF9-A782-CEC22838EB8F}.Release|Any CPU.Build.0 = Release|Any CPU
{AA48A66C-FA36-4AF9-A782-CEC22838EB8F}.Release|x86.ActiveCfg = Release|Any CPU
{AA48A66C-FA36-4AF9-A782-CEC22838EB8F}.Release|x86.Build.0 = Release|Any CPU
{C0494115-838E-43A3-8896-133E5D1E874A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C0494115-838E-43A3-8896-133E5D1E874A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C0494115-838E-43A3-8896-133E5D1E874A}.Debug|x86.ActiveCfg = Debug|Any CPU
{C0494115-838E-43A3-8896-133E5D1E874A}.Debug|x86.Build.0 = Debug|Any CPU
{C0494115-838E-43A3-8896-133E5D1E874A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C0494115-838E-43A3-8896-133E5D1E874A}.Release|Any CPU.Build.0 = Release|Any CPU
{C0494115-838E-43A3-8896-133E5D1E874A}.Release|x86.ActiveCfg = Release|Any CPU
{C0494115-838E-43A3-8896-133E5D1E874A}.Release|x86.Build.0 = Release|Any CPU
{2E7193B8-86B6-48DA-9671-CD84615A5F5D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2E7193B8-86B6-48DA-9671-CD84615A5F5D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2E7193B8-86B6-48DA-9671-CD84615A5F5D}.Debug|x86.ActiveCfg = Debug|Any CPU
{2E7193B8-86B6-48DA-9671-CD84615A5F5D}.Debug|x86.Build.0 = Debug|Any CPU
{2E7193B8-86B6-48DA-9671-CD84615A5F5D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2E7193B8-86B6-48DA-9671-CD84615A5F5D}.Release|Any CPU.Build.0 = Release|Any CPU
{2E7193B8-86B6-48DA-9671-CD84615A5F5D}.Release|x86.ActiveCfg = Release|Any CPU
{2E7193B8-86B6-48DA-9671-CD84615A5F5D}.Release|x86.Build.0 = Release|Any CPU
{CA8D11CF-807C-4C90-A529-0371F73518F6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CA8D11CF-807C-4C90-A529-0371F73518F6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CA8D11CF-807C-4C90-A529-0371F73518F6}.Debug|x86.ActiveCfg = Debug|x86
{CA8D11CF-807C-4C90-A529-0371F73518F6}.Debug|x86.Build.0 = Debug|x86
{CA8D11CF-807C-4C90-A529-0371F73518F6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CA8D11CF-807C-4C90-A529-0371F73518F6}.Release|Any CPU.Build.0 = Release|Any CPU
{CA8D11CF-807C-4C90-A529-0371F73518F6}.Release|x86.ActiveCfg = Release|Any CPU
{CA8D11CF-807C-4C90-A529-0371F73518F6}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -128,7 +128,7 @@ public class HobbyMain
Console.WriteLine("Read the database");
while (reader.Read())
{
Console.WriteLine("Date={0} {1} {2} {3} {4} {5}", reader[0], reader[1], reader[2], reader[3],reader[4], reader[5]);
Console.WriteLine("Date={0} {1} {2} {3} {4} {5}", reader[0], reader[1], reader[2], reader[3], reader[4], reader[5]);
//Console.WriteLine("Col A: {0} ", reader[0]);
//Console.WriteLine("Column: " + reader.FieldCount);
//Console.WriteLine("Column={1}", reader[1]);

View File

@ -1,7 +1,9 @@
public class MasterController{
public static void main(string[] args){
public class MasterController
{
public static void main(string[] args)
{
//The main Controller of the program, It will run all services here
@ -13,12 +15,14 @@ public class MasterController{
int userInput = 0;
while (userInput != -1) {
while (userInput != -1)
{
// Print the menu
//
if (userInput == 1){
if (userInput == 1)
{
// 1. User Managment goes here
}

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 330 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 274 KiB