SweetLib/Docs/SweetLib.md
2018-04-06 21:57:55 +02:00

66 KiB

Contents #

SweetLib # =

BaseTypeExtensions # =

Namespace

SweetLib.Utils.Extensions

Summary

Defines extensions to some general classes.

AsBool(bytes) method # =

Summary

Converts a byte array into a Boolean type.

Returns

Converted value.

Parameters
Name Type Description
bytes System.Byte[] Byte array representation to convert.

AsBytes(value) method # =

Summary

Converts a Int16 value into a byte array.

Returns

Byte array representation of the value.

Parameters
Name Type Description
value System.Int16 Value to convert.

AsBytes(value) method # =

Summary

Converts a UInt16 value into a byte array.

Returns

Byte array representation of the value.

Parameters
Name Type Description
value System.UInt16 Value to convert.

AsBytes(value) method # =

Summary

Converts a Int32 value into a byte array.

Returns

Byte array representation of the value.

Parameters
Name Type Description
value System.Int32 Value to convert.

AsBytes(value) method # =

Summary

Converts a UInt32 value into a byte array.

Returns

Byte array representation of the value.

Parameters
Name Type Description
value System.UInt32 Value to convert.

AsBytes(value) method # =

Summary

Converts a Int64 value into a byte array.

Returns

Byte array representation of the value.

Parameters
Name Type Description
value System.Int64 Value to convert.

AsBytes(value) method # =

Summary

Converts a UInt64 value into a byte array.

Returns

Byte array representation of the value.

Parameters
Name Type Description
value System.UInt64 Value to convert.

AsBytes(value) method # =

Summary

Converts a Single value into a byte array.

Returns

Byte array representation of the value.

Parameters
Name Type Description
value System.Single Value to convert.

AsBytes(value) method # =

Summary

Converts a Double value into a byte array.

Returns

Byte array representation of the value.

Parameters
Name Type Description
value System.Double Value to convert.

AsBytes(value) method # =

Summary

Converts a Boolean value into a byte array.

Returns

Byte array representation of the value.

Parameters
Name Type Description
value System.Boolean Value to convert.

AsBytes(value) method # =

Summary

Converts a DateTime value into a byte array.

Returns

Byte array representation of the value.

Parameters
Name Type Description
value System.DateTime Value to convert.

AsBytes(value) method # =

Summary

Converts a String value into a byte array.

Returns

Byte array representation of the value.

Parameters
Name Type Description
value System.String Value to convert.
Remarks

Using UTF32Encoding for converting.

AsBytes(value) method # =

Summary

Converts a Char value into a byte array.

Returns

Byte array representation of the value.

Parameters
Name Type Description
value System.Char Value to convert.

AsChar(bytes) method # =

Summary

Converts a byte array into a Char type.

Returns

Converted value.

Parameters
Name Type Description
bytes System.Byte[] Byte array representation to convert.

AsDateTime(bytes) method # =

Summary

Converts a byte array into a DateTime type.

Returns

Converted value.

Parameters
Name Type Description
bytes System.Byte[] Byte array representation to convert.

AsDouble(bytes) method # =

Summary

Converts a byte array into a Double type.

Returns

Converted value.

Parameters
Name Type Description
bytes System.Byte[] Byte array representation to convert.

AsInt16(bytes) method # =

Summary

Converts a byte array into a Int16 type.

Returns

Converted value.

Parameters
Name Type Description
bytes System.Byte[] Byte array representation to convert.

AsInt32(bytes) method # =

Summary

Converts a byte array into a Int32 type.

Returns

Converted value.

Parameters
Name Type Description
bytes System.Byte[] Byte array representation to convert.

AsInt64(bytes) method # =

Summary

Converts a byte array into a Int64 type.

Returns

Converted value.

Parameters
Name Type Description
bytes System.Byte[] Byte array representation to convert.

AsSingle(bytes) method # =

Summary

Converts a byte array into a Single type.

Returns

Converted value.

Parameters
Name Type Description
bytes System.Byte[] Byte array representation to convert.

AsString(bytes) method # =

Summary

Converts a byte array into a String type.

Returns

Converted value.

Parameters
Name Type Description
bytes System.Byte[] Byte array representation to convert.
Remarks

Using UTF32Encoding for converting.

AsUInt16(bytes) method # =

Summary

Converts a byte array into a UInt16 type.

Returns

Converted value.

Parameters
Name Type Description
bytes System.Byte[] Byte array representation to convert.

AsUInt32(bytes) method # =

Summary

Converts a byte array into a UInt32 type.

Returns

Converted value.

Parameters
Name Type Description
bytes System.Byte[] Byte array representation to convert.

AsUInt64(bytes) method # =

Summary

Converts a byte array into a UInt64 type.

Returns

Converted value.

Parameters
Name Type Description
bytes System.Byte[] Byte array representation to convert.

DateTimeExtensions # =

Namespace

SweetLib.Utils.Extensions

Summary

Defines extensions to classes which are related to DateTime.

ToDateTime(timestamp) method # =

Summary

Converts an Unix timestamp into a DateTime.

Returns

Converted DateTime.

Parameters
Name Type Description
timestamp System.Double Unix timestamp to convert.

ToUnixTimeStamp(date) method # =

Summary

Converts a DateTime into an Unix timestamp.

Returns

Converted Unix timestamp.

Parameters
Name Type Description
date System.DateTime DateTime to convert into Unix timestamp.

ILogMemory # =

Namespace

SweetLib.Utils.Logger.Memory

Summary

Interface for a class to store and proceed LogMessage objects.

Archive(fullFileName) method # =

Summary

Saves all remembered LogMessage objects into a persistent file.

Parameters
Name Type Description
fullFileName System.String File name to store the LogMessage objects.

Forget(message) method # =

Summary

Removes a from the ILogMemory.

Parameters
Name Type Description
message SweetLib.Utils.Logger.Message.LogMessage LogMessage to be removed.
Remarks

This might not have any effect depending on the ILogMemory implementation.

Remember(message) method # =

Summary

Adds a into the ILogMemory.

Parameters
Name Type Description
message SweetLib.Utils.Logger.Message.LogMessage LogMessage to be stored.

IniFileStorer # =

Namespace

SweetLib.Classes.Storer

Summary

Implementation of an IStorer interface which stores the data inside an ini file.

#ctor(fileName) constructor # =

Summary

Creates a new instance of IniFileStorer with a specified file name.

Parameters
Name Type Description
fileName System.String The file name of the ini file.

FileName property # =

Summary

Ini file path.

IStorer # =

Namespace

SweetLib.Classes.Storer

Summary

Interface, which provides several methods to store simple data.

DeleteKey(section,key) method # =

Summary

Deletes a key inside a .

Parameters
Name Type Description
section System.String Represents the section in which the data is stored.
key System.String Represents the key to be deleted.

DeleteSection(section) method # =

Summary

Deletes a section with all its keys.

Parameters
Name Type Description
section System.String Represents the section to be deleted.

HasKey(section,key) method # =

Summary

Checks, if a key exists inside a section.

Returns

True, if is found inside .

Parameters
Name Type Description
section System.String Represents the section in which the data is stored.
key System.String Represents the key of the stored data.

ReadBool(section,key,defaultValue) method # =

Summary

Reads a bool value.

Returns

Value of the in .

Parameters
Name Type Description
section System.String Represents the section in which the data is stored.
key System.String Represents the key of the stored data.
defaultValue System.Boolean Default value, if this value does not exist.

ReadInteger(section,key,defaultValue) method # =

Summary

Reads an integer value.

Returns

Value of the in .

Parameters
Name Type Description
section System.String Represents the section in which the data is stored.
key System.String Represents the key of the stored data.
defaultValue System.Int32 Default value, if this value does not exist.

ReadString(section,key,defaultValue) method # =

Summary

Reads a string value.

Returns

Value of the in .

Parameters
Name Type Description
section System.String Represents the section in which the data is stored.
key System.String Represents the key of the stored data.
defaultValue System.String Default value, if this value does not exist.

WriteBool(section,key,value) method # =

Summary

Writes a bool value.

Parameters
Name Type Description
section System.String Represents the section in which the data is stored.
key System.String Represents the key of the stored data.
value System.Boolean Value to be stored.

WriteInteger(section,key,value) method # =

Summary

Writes an integer value.

Parameters
Name Type Description
section System.String Represents the section in which the data is stored.
key System.String Represents the key of the stored data.
value System.Int32 Value to be stored.

WriteString(section,key,value) method # =

Summary

Writes a string value.

Parameters
Name Type Description
section System.String Represents the section in which the data is stored.
key System.String Represents the key of the stored data.
value System.String Value to be stored.

Logger # =

Namespace

SweetLib.Utils.Logger

Summary

Global logger class providing several methods to log events by the application.

Remarks

As DefaultLogMemory a ArchivableConsoleLogMemory will be used. You can change this to any other implementation at any time while runtime. Default log levels are set as bitflags in GlobalLogLevel.

DefaultLogMemory property # =

Summary

The default ILogMemory which will be used for any logging action, if no custom ILogMemory is set as parameter.

GlobalLogLevel property # =

Summary

The global log level. Only messages with the set LogLevel will be procedered.

Debug(message) method # =

Summary

Will log a message with the Debug log level.

Parameters
Name Type Description
message System.String Message to log.

Error(message) method # =

Summary

Will log a message with the Error log level.

Parameters
Name Type Description
message System.String Message to log.

Info(message) method # =

Summary

Will log a message with the Info log level.

Parameters
Name Type Description
message System.String Message to log.

Log(logLevel,message) method # =

Summary

Will log a message into the global DefaultLogMemory.

Parameters
Name Type Description
logLevel SweetLib.Utils.Logger.LogLevel The log level of this message.
message System.String The message to log.

Log(logLevel,message,logMemory) method # =

Summary

Will log a message into the provided .

Parameters
Name Type Description
logLevel SweetLib.Utils.Logger.LogLevel The log level of this message.
message System.String The message to log.
logMemory SweetLib.Utils.Logger.Memory.ILogMemory The ILogMemory to store the into.

Log(message,logMemory) method # =

Summary

Will log a message into the provided .

Parameters
Name Type Description
message SweetLib.Utils.Logger.Message.LogMessage A LogMessage object to store.
logMemory SweetLib.Utils.Logger.Memory.ILogMemory The ILogMemory to store the into.
Remarks

In general use cases you should either use one of the Log or Log methods which will generate a call to this method.

Trace(message) method # =

Summary

Will log a message with the Trace log level.

Parameters
Name Type Description
message System.String Message to log.

Warn(message) method # =

Summary

Will log a message with the Warn log level.

Parameters
Name Type Description
message System.String Message to log.

LogLevel # =

Namespace

SweetLib.Utils.Logger

Summary

Enum which contains the several log levels.

LogMessage # =

Namespace

SweetLib.Utils.Logger.Message

Summary

LogMessage contains all event log data which should be logged in as a single log message.

#ctor(logLevel,message) constructor # =

Summary

Creates a new LogMessage instance. Now will be the LogDateTime.

Parameters
Name Type Description
logLevel SweetLib.Utils.Logger.LogLevel The log level of this event log.
message System.String The message of this event log.

#ctor(logLevel,message,logDateTime) constructor # =

Summary

Creates a new LogMessage instance.

Parameters
Name Type Description
logLevel SweetLib.Utils.Logger.LogLevel The log level of this event log.
message System.String The message of this event log.
logDateTime System.DateTime The DateTime of this event log.

LogDateTime property # =

Summary

The date and time of this event log.

LogLevel property # =

Summary

The LogLevel of this event log.

Message property # =

Summary

The message of this event log.

ToString() method # =

Summary

Generates a formatted String of this event log. DefaultFormatString will be used to format this event log.

Returns

A formated String of this event log.

Parameters

This method has no parameters.

ToString(format,formatProvider) method # =

Summary

Generates a formatted String of this event log with a given format.

Returns

A formated String of this event log.

Parameters
Name Type Description
format System.String The format to be used. See LogMessageFormatter for more format information.
formatProvider System.IFormatProvider Optional, an IFormatProvider interface to be used while formatting if needed.

LogMessageFormatter # =

Namespace

SweetLib.Utils.Logger.Message

Summary

A ICustomFormatter which is used to format LogMessage objects.

Remarks

This class implements a singleton pattern.

FormatterInstance property # =

Summary

Accesses the global instance of the LogMessageFormatter.

Instance property # =

Summary

The default format string which is used to format LogMessage objects, if no custom format string is provided.

Format(format,arg,formatProvider) method # =

Summary

Formats a LogMessage object.

Returns

A formatted String of the LogMessage.

Parameters
Name Type Description
format System.String The format string. If , DefaultFormatString will be used.
arg System.Object The LogMessage object to be formatted.
formatProvider System.IFormatProvider Optional, an IFormatProvider interface to be used while formatting if needed.
Remarks

If is not a LogMessage object, it will either be returned the formatted string implemented by the type of , if IFormattable is implemented by it, or the result."

RegistryStorer # =

Namespace

SweetLib.Classes.Storer

Summary

Implementation of an IStorer interface which stores the data inside the registry.

Remarks

Sections will be interpreted as subkeys on registry level.

#ctor(appName) constructor # =

Summary

Creates a new instance of RegistryStorer with a specified application name.

Parameters
Name Type Description
appName System.String The applications base name. This will be used as name for a sub key inside the software key below the base key.
Remarks

This will use current user as the base key.

#ctor(baseRegistryKey,appName) constructor # =

Summary

Creates a new instance of RegistryStorer with a specified application name.

Parameters
Name Type Description
baseRegistryKey Microsoft.Win32.RegistryKey Provide a key of Registry, e.G. .
appName System.String The applications base name. This will be used as name for a sub key inside the software key below the base key.

OperatingRegistryKey property # =

Summary

The base registry key in which will be operated.

RegistryStorerException # =

Namespace

SweetLib.Classes.Exceptions

Summary

Exception thrown by RegistryStorer.

#ctor() constructor # =

Summary

Creates a new RegistryStorerException.

Parameters

This constructor has no parameters.

#ctor(message) constructor # =

Summary

Creates a new RegistryStorerException.

Parameters
Name Type Description
message System.String Exception message.

SweetUtils # =

Namespace

SweetLib.Utils

Summary

A generic class containing useful methods.

LegalizeFilename(fileName) method # =

Summary

Legalizes a file name with the DefaultFileNameReplaceChar character.

Returns

Legalized file name.

Parameters
Name Type Description
fileName System.String File name to legalize.

LegalizeFilename(fileName,replaceChar) method # =

Summary

Legalizes a file name by a given replace character.

Returns

Legalized file name.

Parameters
Name Type Description
fileName System.String File name to legalize.
replaceChar System.Char Character to be used as replace character.