From e13c5006c8e26c71d15e2cd073a9af8231fa170c Mon Sep 17 00:00:00 2001 From: Serraniel Date: Sun, 16 Apr 2017 18:07:30 +0200 Subject: [PATCH] Doc Texts Fixed Version number --- SweetLib.Demo.Console/Program.cs | 7 +++ .../Properties/AssemblyInfo.cs | 4 +- .../Exception/RegistryStorerException.cs | 14 ++++- SweetLib/Classes/Storer/IStorer.cs | 57 +++++++++++++++++++ SweetLib/Classes/Storer/IniFileStorer.cs | 14 ++++- SweetLib/Classes/Storer/RegistryStorer.cs | 35 +++++++++--- SweetLib/Properties/AssemblyInfo.cs | 4 +- SweetLib/Utils/Logger/Logger.cs | 55 +++++++++++++++++- SweetLib/Utils/Logger/Memory/ILogMemory.cs | 16 ++++++ SweetLib/Utils/Logger/Message/LogMessage.cs | 35 +++++++++++- .../Logger/Message/LogMessageFormatter.cs | 24 +++++++- 11 files changed, 247 insertions(+), 18 deletions(-) diff --git a/SweetLib.Demo.Console/Program.cs b/SweetLib.Demo.Console/Program.cs index 6da4911..b7e4391 100644 --- a/SweetLib.Demo.Console/Program.cs +++ b/SweetLib.Demo.Console/Program.cs @@ -1,9 +1,12 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; +using SweetLib.Classes.Storer; using SweetLib.Utils.Logger; +using SweetLib.Utils.Logger.Message; namespace SweetLib.Demo.Console { @@ -21,6 +24,10 @@ namespace SweetLib.Demo.Console Logger.Error("Error :("); System.Console.ReadLine(); + + var f = Path.GetTempFileName(); + var ini = new IniFileStorer(f); + System.Console.WriteLine(ini.ReadString("sec","key")); } } } diff --git a/SweetLib.Demo.Console/Properties/AssemblyInfo.cs b/SweetLib.Demo.Console/Properties/AssemblyInfo.cs index 2dae91b..561580b 100644 --- a/SweetLib.Demo.Console/Properties/AssemblyInfo.cs +++ b/SweetLib.Demo.Console/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern // übernehmen, indem Sie "*" eingeben: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.19.0")] -[assembly: AssemblyFileVersion("1.0.19.0")] +[assembly: AssemblyVersion("1.0.21.0")] +[assembly: AssemblyFileVersion("1.0.21.0")] diff --git a/SweetLib/Classes/Exception/RegistryStorerException.cs b/SweetLib/Classes/Exception/RegistryStorerException.cs index c2cf14c..aed90c9 100644 --- a/SweetLib/Classes/Exception/RegistryStorerException.cs +++ b/SweetLib/Classes/Exception/RegistryStorerException.cs @@ -1,9 +1,21 @@ -namespace SweetLib.Classes.Exception +using SweetLib.Classes.Storer; + +namespace SweetLib.Classes.Exception { + /// + /// Exception thrown by . + /// public class RegistryStorerException : System.Exception { + /// + /// Creates a new . + /// public RegistryStorerException(){} + /// + /// Creates a new . + /// + /// Exception message. public RegistryStorerException(string message):base(message) {} } } diff --git a/SweetLib/Classes/Storer/IStorer.cs b/SweetLib/Classes/Storer/IStorer.cs index f1c0505..0c5f258 100644 --- a/SweetLib/Classes/Storer/IStorer.cs +++ b/SweetLib/Classes/Storer/IStorer.cs @@ -1,23 +1,80 @@ namespace SweetLib.Classes.Storer { + /// + /// Interface, which provides several methods to store simple data. + /// public interface IStorer { + /// + /// Reads a string value. + /// + /// Represents the section in which the data is stored. + /// Represents the key of the stored data. + /// Default value, if this value does not exist. + /// Value of the in . string ReadString(string section, string key, string defaultValue = ""); + /// + /// Reads an integer value. + /// + /// Represents the section in which the data is stored. + /// Represents the key of the stored data. + /// Default value, if this value does not exist. + /// Value of the in . int ReadInteger(string section, string key, int defaultValue = 0); + /// + /// Reads a bool value. + /// + /// Represents the section in which the data is stored. + /// Represents the key of the stored data. + /// Default value, if this value does not exist. + /// Value of the in . bool ReadBool(string section, string key, bool defaultValue = false); + /// + /// Checks, if a key exists inside a section. + /// + /// Represents the section in which the data is stored. + /// Represents the key of the stored data. + /// True, if is found inside . bool HasKey(string section, string key); + /// + /// Writes a string value. + /// + /// Represents the section in which the data is stored. + /// Represents the key of the stored data. + /// Value to be stored. void WriteString(string section, string key, string value); + /// + /// Writes an integer value. + /// + /// Represents the section in which the data is stored. + /// Represents the key of the stored data. + /// Value to be stored. void WriteInteger(string section, string key, int value); + /// + /// Writes a bool value. + /// + /// Represents the section in which the data is stored. + /// Represents the key of the stored data. + /// Value to be stored. void WriteBool(string section, string key, bool value); + /// + /// Deletes a key inside a . + /// + /// Represents the section in which the data is stored. + /// Represents the key to be deleted. void DeleteKey(string section, string key); + /// + /// Deletes a section with all its keys. + /// + /// Represents the section to be deleted. void DeleteSection(string section); } } diff --git a/SweetLib/Classes/Storer/IniFileStorer.cs b/SweetLib/Classes/Storer/IniFileStorer.cs index f913813..c0e77ff 100644 --- a/SweetLib/Classes/Storer/IniFileStorer.cs +++ b/SweetLib/Classes/Storer/IniFileStorer.cs @@ -3,16 +3,26 @@ using System.Text; namespace SweetLib.Classes.Storer { + /// + /// Implementation of an interface which stores the data inside an ini file. + /// public class IniFileStorer : IStorer { + /// + /// Ini file path. + /// public string FileName { get; } [DllImport("kernel32", CharSet = CharSet.Unicode)] - static extern long WritePrivateProfileString(string Section, string Key, string Value, string FilePath); + private static extern long WritePrivateProfileString(string section, string key, string value, string filePath); [DllImport("kernel32", CharSet = CharSet.Unicode)] - static extern int GetPrivateProfileString(string Section, string Key, string Default, StringBuilder RetVal, int Size, string FilePath); + private static extern int GetPrivateProfileString(string section, string key, string defaultValue, StringBuilder value, int size, string filePath); + /// + /// Creates a new instance of with a specified file name. + /// + /// The file name of the ini file. public IniFileStorer(string fileName) { FileName = fileName; diff --git a/SweetLib/Classes/Storer/RegistryStorer.cs b/SweetLib/Classes/Storer/RegistryStorer.cs index 8803232..a04aac2 100644 --- a/SweetLib/Classes/Storer/RegistryStorer.cs +++ b/SweetLib/Classes/Storer/RegistryStorer.cs @@ -3,24 +3,45 @@ using SweetLib.Classes.Exception; namespace SweetLib.Classes.Storer { + /// + /// Implementation of an interface which stores the data inside the registry. + /// + /// + /// Sections will be interpreted as subkeys on registry level. + /// public class RegistryStorer : IStorer { - public RegistryKey BaseRegistryKey { get; } + /// + /// The base registry key in which will be operated. + /// + public RegistryKey OperatingRegistryKey { get; } + /// + /// Creates a new instance of with a specified application name. + /// + /// The applications base name. This will be used as name for a sub key inside the software key below the base key. + /// + /// This will use current user as the base key. + /// public RegistryStorer(string appName) : this(Registry.CurrentUser, appName) { } + /// + /// Creates a new instance of with a specified application name. + /// + /// Provide a key of , e.G. Registry.CurrentUser. + /// The applications base name. This will be used as name for a sub key inside the software key below the base key. public RegistryStorer(RegistryKey baseRegistryKey, string appName) { baseRegistryKey = baseRegistryKey.CreateSubKey("SOFTWARE"); - BaseRegistryKey = baseRegistryKey?.CreateSubKey(appName); + OperatingRegistryKey = baseRegistryKey?.CreateSubKey(appName); - if (BaseRegistryKey == null) + if (OperatingRegistryKey == null) throw new RegistryStorerException("Unable to create registriy key."); } public string ReadString(string section, string key, string defaultValue = "") { - var localRegKey = BaseRegistryKey.OpenSubKey(section); + var localRegKey = OperatingRegistryKey.OpenSubKey(section); return (string)localRegKey?.GetValue(key.ToUpper()); } @@ -45,7 +66,7 @@ namespace SweetLib.Classes.Storer public void WriteString(string section, string key, string value) { - var localRegKey = BaseRegistryKey.CreateSubKey(section); + var localRegKey = OperatingRegistryKey.CreateSubKey(section); localRegKey?.SetValue(key.ToUpper(), value); } @@ -61,13 +82,13 @@ namespace SweetLib.Classes.Storer public void DeleteKey(string section, string key) { - var localRegKey = BaseRegistryKey.CreateSubKey(section); + var localRegKey = OperatingRegistryKey.CreateSubKey(section); localRegKey?.DeleteValue(key); } public void DeleteSection(string section) { - BaseRegistryKey.DeleteSubKey(section); + OperatingRegistryKey.DeleteSubKey(section); } } } diff --git a/SweetLib/Properties/AssemblyInfo.cs b/SweetLib/Properties/AssemblyInfo.cs index 430144b..cdc736e 100644 --- a/SweetLib/Properties/AssemblyInfo.cs +++ b/SweetLib/Properties/AssemblyInfo.cs @@ -31,5 +31,5 @@ using System.Runtime.InteropServices; // Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern // übernehmen, indem Sie "*" eingeben: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.21.0")] -[assembly: AssemblyFileVersion("1.0.21.0")] +[assembly: AssemblyVersion("0.1.23.0")] +[assembly: AssemblyFileVersion("0.1.23.0")] diff --git a/SweetLib/Utils/Logger/Logger.cs b/SweetLib/Utils/Logger/Logger.cs index a6ea578..daa682d 100644 --- a/SweetLib/Utils/Logger/Logger.cs +++ b/SweetLib/Utils/Logger/Logger.cs @@ -4,6 +4,9 @@ using SweetLib.Utils.Logger.Message; namespace SweetLib.Utils.Logger { + /// + /// Enum which contains the several log levels. + /// [Flags] public enum LogLevel { @@ -14,25 +17,55 @@ namespace SweetLib.Utils.Logger Warn = 1 << 3, Error = 1 << 4, - All = Int32.MaxValue, + All = Int32.MaxValue, }; + /// + /// Global logger class providing several methods to log events by the application. + /// + /// + /// As a will be used. You can change this to any other implementation at any time while runtime. + /// Default log levels are set as bitflags in . + /// public static class Logger { + /// + /// The global log level. Only messages with the set will be procedered. + /// public static LogLevel GlobalLogLevel { get; set; } = LogLevel.Info | LogLevel.Warn | LogLevel.Error; + /// + /// The default which will be used for any logging action, if no custom is set as parameter. + /// public static ILogMemory DefaultLogMemory = new ArchivableConsoleLogMemory(); + /// + /// Will log a message into the global . + /// + /// The log level of this message. + /// The message to log. public static void Log(LogLevel logLevel, string message) { Log(logLevel, message, DefaultLogMemory); } + /// + /// Will log a message into the provided . + /// + /// The log level of this message. + /// /// The message to log. + /// The to store the into. public static void Log(LogLevel logLevel, string message, ILogMemory logMemory) { Log(new LogMessage(logLevel, message), logMemory); } + /// + /// Will log a message into the provided . + /// + /// A object to store. + /// The to store the into. + /// In general use cases you should either use one of the or methods which will generate a call to this method. public static void Log(LogMessage message, ILogMemory logMemory) { if (message == null) @@ -47,26 +80,46 @@ namespace SweetLib.Utils.Logger logMemory.Remember(message); } + /// + /// Will log a message with the log level. + /// + /// Message to log. public static void Trace(string message) { Log(LogLevel.Trace, message); } + /// + /// Will log a message with the log level. + /// + /// Message to log. public static void Debug(string message) { Log(LogLevel.Debug, message); } + /// + /// Will log a message with the log level. + /// + /// Message to log. public static void Info(string message) { Log(LogLevel.Info, message); } + /// + /// Will log a message with the log level. + /// + /// Message to log. public static void Warn(string message) { Log(LogLevel.Warn, message); } + /// + /// Will log a message with the log level. + /// + /// Message to log. public static void Error(string message) { Log(LogLevel.Error, message); diff --git a/SweetLib/Utils/Logger/Memory/ILogMemory.cs b/SweetLib/Utils/Logger/Memory/ILogMemory.cs index 96aef66..4f59112 100644 --- a/SweetLib/Utils/Logger/Memory/ILogMemory.cs +++ b/SweetLib/Utils/Logger/Memory/ILogMemory.cs @@ -2,12 +2,28 @@ namespace SweetLib.Utils.Logger.Memory { + /// + /// Interface for a class to store and proceed objects. + /// public interface ILogMemory { + /// + /// Adds a into the . + /// + /// to be stored. void Remember(LogMessage message); + /// + /// Removes a from the . + /// + /// to be removed. + /// This might not have any effect depending on the implementation. void Forget(LogMessage message); + /// + /// Saves all remembered objects into a persistent file. + /// + /// File name to store the objects. void Archive(string fullFileName); } } diff --git a/SweetLib/Utils/Logger/Message/LogMessage.cs b/SweetLib/Utils/Logger/Message/LogMessage.cs index 7c840e6..978dc17 100644 --- a/SweetLib/Utils/Logger/Message/LogMessage.cs +++ b/SweetLib/Utils/Logger/Message/LogMessage.cs @@ -3,16 +3,39 @@ using System.Globalization; namespace SweetLib.Utils.Logger.Message { + /// + /// contains all event log data which should be logged in as a single log message. + /// public class LogMessage : IFormattable { + /// + /// The of this event log. + /// public LogLevel LogLevel { get; } + /// + /// The message of this event log. + /// public string Message { get; } + /// + /// The date and time of this event log. + /// public DateTime LogDateTime { get; } + /// + /// Creates a new instance. will be the . + /// + /// The log level of this event log. + /// The message of this event log. public LogMessage(LogLevel logLevel, string message) : this(logLevel, message, DateTime.Now) { } + /// + /// Creates a new instance. + /// + /// The log level of this event log. + /// The message of this event log. + /// The of this event log. public LogMessage(LogLevel logLevel, string message, DateTime logDateTime) { if (message == null) @@ -26,12 +49,22 @@ namespace SweetLib.Utils.Logger.Message LogDateTime = logDateTime; } + /// + /// Generates a formatted of this event log. will be used to format this event log. + /// + /// A formated of this event log. public override string ToString() { return ToString(LogMessageFormatter.DefaultFormatString, CultureInfo.CurrentCulture); } - public string ToString(string format, IFormatProvider formatProvider) + /// + /// Generates a formatted of this event log with a given format. + /// + /// The format to be used. See for more format information. + /// Optional, an interface to be used while formatting if needed. + /// A formated of this event log. + public string ToString(string format, IFormatProvider formatProvider = null) { return LogMessageFormatter.Instance.Format(format, this, formatProvider); } diff --git a/SweetLib/Utils/Logger/Message/LogMessageFormatter.cs b/SweetLib/Utils/Logger/Message/LogMessageFormatter.cs index 2c0187c..85befa7 100644 --- a/SweetLib/Utils/Logger/Message/LogMessageFormatter.cs +++ b/SweetLib/Utils/Logger/Message/LogMessageFormatter.cs @@ -3,6 +3,10 @@ using System.Globalization; namespace SweetLib.Utils.Logger.Message { + /// + /// A which is used to format objects. + /// + /// This class implements a singleton pattern. public class LogMessageFormatter : ICustomFormatter { @@ -10,10 +14,16 @@ namespace SweetLib.Utils.Logger.Message private static object Locker { get; } = new object(); - public static LogMessageFormatter FormatterInstance { get; set; } + /// + /// Accesses the global instance of the . + /// + private static LogMessageFormatter FormatterInstance { get; set; } public static string DefaultFormatString { get; set; } = $"[{CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern} - {CultureInfo.CurrentCulture.DateTimeFormat.LongTimePattern}] (LL): V"; + /// + /// The default format string which is used to format objects, if no custom format string is provided. + /// public static LogMessageFormatter Instance { get @@ -32,10 +42,20 @@ namespace SweetLib.Utils.Logger.Message } } + /// + /// Formats a object. + /// + /// The format string. If , will be used. + /// The object to be formatted. + /// Optional, an interface to be used while formatting if needed. + /// A formatted of the . + /// + /// If is not a object, it will either be returned the formatted string implemented by the type of , if is implemented by it, or the result." + /// public string Format(string format, object arg, IFormatProvider formatProvider) { if (format == null) - throw new ArgumentNullException(nameof(format)); + format = DefaultFormatString; if (arg == null) throw new ArgumentNullException(nameof(arg));