From a07923d2142e2fa289943d8753be7d2da68c5c2d Mon Sep 17 00:00:00 2001 From: "chris.watts90@outlook.com" Date: Wed, 24 May 2017 22:34:40 +0100 Subject: [PATCH] create nlogLogger project. create UdpNotifier project. implemented IPluginPathProvider and IConfigFilePathProvider, IContainerHelper and INotifierManager. --- .../Interfaces/IConfigFilePathProvider.cs | 13 + RaceLapTimer/Interfaces/IContainerHelper.cs | 15 + RaceLapTimer/Interfaces/ILoggerService.cs | 33 + RaceLapTimer/Interfaces/INotifierManager.cs | 14 + RaceLapTimer/Interfaces/INotifierProvider.cs | 18 + .../Interfaces/INotifierProviderFactory.cs | 14 + .../Interfaces/IPluginPathProvider.cs | 13 + RaceLapTimer/Interfaces/Interfaces.csproj | 8 + .../Interfaces/NotificationEventArgs.cs | 12 + RaceLapTimer/NLogLogger/NLogConfig.xml | 11 + RaceLapTimer/NLogLogger/NLogLogger.csproj | 76 + .../NLogLogger/NLogLogger.csproj.user | 6 + RaceLapTimer/NLogLogger/NLogLoggingService.cs | 119 + RaceLapTimer/NLogLogger/NLogSchema/NLog.xsd | 2966 +++++++++++++++++ .../NLogLogger/Properties/AssemblyInfo.cs | 36 + RaceLapTimer/NLogLogger/packages.config | 4 + RaceLapTimer/RaceLapTimer.sln | 20 + RaceLapTimer/RaceLapTimer/App.config | 8 + .../AuthenticationBootstrapper.cs | 36 +- .../RaceLapTimer/ConfigFilePathProvider.cs | 22 + .../RaceLapTimer/Configs/NinjectConfig.xml | 4 + .../Notifications/ContainerHelper.cs | 38 + .../Notifications/NotificationManager.cs | 112 + .../RaceLapTimer/PluginPathProvider.cs | 18 + .../RaceLapTimer/Plugins/placeholder.txt | 1 + RaceLapTimer/RaceLapTimer/RaceLapTimer.csproj | 26 + RaceLapTimer/RaceLapTimer/packages.config | 4 + RaceLapTimer/RaceLapTimerHost/App.config | 8 + .../RaceLapTimerHost/RaceLapTimerHost.csproj | 12 + .../UdpNotifier/Properties/AssemblyInfo.cs | 36 + RaceLapTimer/UdpNotifier/UdpNotifier.csproj | 61 + .../UdpNotifier/UdpNotifierProvider.cs | 63 + .../UdpNotifier/UdpNotifierProviderFactory.cs | 28 + 33 files changed, 3846 insertions(+), 9 deletions(-) create mode 100644 RaceLapTimer/Interfaces/IConfigFilePathProvider.cs create mode 100644 RaceLapTimer/Interfaces/IContainerHelper.cs create mode 100644 RaceLapTimer/Interfaces/ILoggerService.cs create mode 100644 RaceLapTimer/Interfaces/INotifierManager.cs create mode 100644 RaceLapTimer/Interfaces/INotifierProvider.cs create mode 100644 RaceLapTimer/Interfaces/INotifierProviderFactory.cs create mode 100644 RaceLapTimer/Interfaces/IPluginPathProvider.cs create mode 100644 RaceLapTimer/Interfaces/NotificationEventArgs.cs create mode 100644 RaceLapTimer/NLogLogger/NLogConfig.xml create mode 100644 RaceLapTimer/NLogLogger/NLogLogger.csproj create mode 100644 RaceLapTimer/NLogLogger/NLogLogger.csproj.user create mode 100644 RaceLapTimer/NLogLogger/NLogLoggingService.cs create mode 100644 RaceLapTimer/NLogLogger/NLogSchema/NLog.xsd create mode 100644 RaceLapTimer/NLogLogger/Properties/AssemblyInfo.cs create mode 100644 RaceLapTimer/NLogLogger/packages.config create mode 100644 RaceLapTimer/RaceLapTimer/ConfigFilePathProvider.cs create mode 100644 RaceLapTimer/RaceLapTimer/Configs/NinjectConfig.xml create mode 100644 RaceLapTimer/RaceLapTimer/Extensions/Notifications/ContainerHelper.cs create mode 100644 RaceLapTimer/RaceLapTimer/Extensions/Notifications/NotificationManager.cs create mode 100644 RaceLapTimer/RaceLapTimer/PluginPathProvider.cs create mode 100644 RaceLapTimer/RaceLapTimer/Plugins/placeholder.txt create mode 100644 RaceLapTimer/UdpNotifier/Properties/AssemblyInfo.cs create mode 100644 RaceLapTimer/UdpNotifier/UdpNotifier.csproj create mode 100644 RaceLapTimer/UdpNotifier/UdpNotifierProvider.cs create mode 100644 RaceLapTimer/UdpNotifier/UdpNotifierProviderFactory.cs diff --git a/RaceLapTimer/Interfaces/IConfigFilePathProvider.cs b/RaceLapTimer/Interfaces/IConfigFilePathProvider.cs new file mode 100644 index 0000000..927be83 --- /dev/null +++ b/RaceLapTimer/Interfaces/IConfigFilePathProvider.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Interfaces +{ + public interface IConfigFilePathProvider + { + string GetPath { get; } + } +} diff --git a/RaceLapTimer/Interfaces/IContainerHelper.cs b/RaceLapTimer/Interfaces/IContainerHelper.cs new file mode 100644 index 0000000..f04cff1 --- /dev/null +++ b/RaceLapTimer/Interfaces/IContainerHelper.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Interfaces +{ + public interface IContainerHelper + { + T Get(); + IEnumerable GetAll(); + void RegisterType(Type typeToBindTo, Type typeBeingBound, string uniqueName); + } +} diff --git a/RaceLapTimer/Interfaces/ILoggerService.cs b/RaceLapTimer/Interfaces/ILoggerService.cs new file mode 100644 index 0000000..6fab832 --- /dev/null +++ b/RaceLapTimer/Interfaces/ILoggerService.cs @@ -0,0 +1,33 @@ +using System; + +namespace Interfaces +{ + public interface ILoggerService + { + bool IsDebugEnabled { get; } + bool IsErrorEnabled { get; } + bool IsFatalEnabled { get; } + bool IsInfoEnabled { get; } + bool IsTraceEnabled { get; } + bool IsWarnEnabled { get; } + + void Debug(Exception exception); + void Debug(string format, params object[] args); + void Debug(Exception exception, string format, params object[] args); + void Error(Exception exception); + void Error(string format, params object[] args); + void Error(Exception exception, string format, params object[] args); + void Fatal(Exception exception); + void Fatal(string format, params object[] args); + void Fatal(Exception exception, string format, params object[] args); + void Info(Exception exception); + void Info(string format, params object[] args); + void Info(Exception exception, string format, params object[] args); + void Trace(Exception exception); + void Trace(string format, params object[] args); + void Trace(Exception exception, string format, params object[] args); + void Warn(Exception exception); + void Warn(string format, params object[] args); + void Warn(Exception exception, string format, params object[] args); + } +} diff --git a/RaceLapTimer/Interfaces/INotifierManager.cs b/RaceLapTimer/Interfaces/INotifierManager.cs new file mode 100644 index 0000000..07c728d --- /dev/null +++ b/RaceLapTimer/Interfaces/INotifierManager.cs @@ -0,0 +1,14 @@ +using System.Collections.Generic; + +namespace Interfaces +{ + public interface INotifierManager + { + List GetAvailableNotifiers(); + void NotifyRaceStarted(NotificationEventArgs args); + void NotifyRaceStarting(NotificationEventArgs args); + void NotifyRaceLapEvent(NotificationEventArgs args, Pilot pilot); + void NotifyRaceWinner(NotificationEventArgs args, Pilot pilot); + void NotifyRaceFinished(NotificationEventArgs args); + } +} diff --git a/RaceLapTimer/Interfaces/INotifierProvider.cs b/RaceLapTimer/Interfaces/INotifierProvider.cs new file mode 100644 index 0000000..502f025 --- /dev/null +++ b/RaceLapTimer/Interfaces/INotifierProvider.cs @@ -0,0 +1,18 @@ +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Interfaces +{ + public interface INotifierProvider + { + string GetDisplayName(); + string GetNotifierType(); + void NotifyRaceStarted(NotificationEventArgs args); + void NotifyRaceStarting(NotificationEventArgs args); + void NotifyRaceLapEvent(NotificationEventArgs args, Pilot pilot); + void NotifyRaceWinner(NotificationEventArgs args, Pilot pilot); + void NotifyRaceFinished(NotificationEventArgs args); + } +} diff --git a/RaceLapTimer/Interfaces/INotifierProviderFactory.cs b/RaceLapTimer/Interfaces/INotifierProviderFactory.cs new file mode 100644 index 0000000..8f4ef4a --- /dev/null +++ b/RaceLapTimer/Interfaces/INotifierProviderFactory.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Interfaces +{ + public interface INotifierProviderFactory + { + INotifierProvider CreateProvider(); + string GetType(); + } +} diff --git a/RaceLapTimer/Interfaces/IPluginPathProvider.cs b/RaceLapTimer/Interfaces/IPluginPathProvider.cs new file mode 100644 index 0000000..0c73726 --- /dev/null +++ b/RaceLapTimer/Interfaces/IPluginPathProvider.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Interfaces +{ + public interface IPluginPathProvider + { + string GetPluginPath { get; } + } +} diff --git a/RaceLapTimer/Interfaces/Interfaces.csproj b/RaceLapTimer/Interfaces/Interfaces.csproj index 1b7e18a..cff9079 100644 --- a/RaceLapTimer/Interfaces/Interfaces.csproj +++ b/RaceLapTimer/Interfaces/Interfaces.csproj @@ -40,8 +40,16 @@ + + + + + + + + diff --git a/RaceLapTimer/Interfaces/NotificationEventArgs.cs b/RaceLapTimer/Interfaces/NotificationEventArgs.cs new file mode 100644 index 0000000..239a423 --- /dev/null +++ b/RaceLapTimer/Interfaces/NotificationEventArgs.cs @@ -0,0 +1,12 @@ +using System; + +namespace Interfaces +{ + public class NotificationEventArgs + { + public DateTime RaceStartTime { get; set; } + public int PilotCount { get; set; } + public int MaxLaps { get; set; } + public int LapNumber { get; set; } + } +} \ No newline at end of file diff --git a/RaceLapTimer/NLogLogger/NLogConfig.xml b/RaceLapTimer/NLogLogger/NLogConfig.xml new file mode 100644 index 0000000..ce611d8 --- /dev/null +++ b/RaceLapTimer/NLogLogger/NLogConfig.xml @@ -0,0 +1,11 @@ + + + + + + + + + \ No newline at end of file diff --git a/RaceLapTimer/NLogLogger/NLogLogger.csproj b/RaceLapTimer/NLogLogger/NLogLogger.csproj new file mode 100644 index 0000000..e5b89a2 --- /dev/null +++ b/RaceLapTimer/NLogLogger/NLogLogger.csproj @@ -0,0 +1,76 @@ + + + + + Debug + AnyCPU + {9A93A12F-7591-406A-A4F3-41AA8299C4B4} + Library + Properties + NLogLogger + NLogLogger + v4.5.2 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\NLog.4.4.9\lib\net45\NLog.dll + True + + + + + + + + + + + + + + + + + {5c6dcc59-19f3-46ad-a479-926610f36257} + Interfaces + + + + + Designer + + + + + + Always + + + + + + \ No newline at end of file diff --git a/RaceLapTimer/NLogLogger/NLogLogger.csproj.user b/RaceLapTimer/NLogLogger/NLogLogger.csproj.user new file mode 100644 index 0000000..ca1d04b --- /dev/null +++ b/RaceLapTimer/NLogLogger/NLogLogger.csproj.user @@ -0,0 +1,6 @@ + + + + ProjectFiles + + \ No newline at end of file diff --git a/RaceLapTimer/NLogLogger/NLogLoggingService.cs b/RaceLapTimer/NLogLogger/NLogLoggingService.cs new file mode 100644 index 0000000..4c9eeac --- /dev/null +++ b/RaceLapTimer/NLogLogger/NLogLoggingService.cs @@ -0,0 +1,119 @@ +using System; +using System.IO; +using System.Reflection; +using Interfaces; +using NLog; +using NLog.Config; + +namespace NLogLogger +{ + public class NLogLoggingService : ILoggerService + { + private readonly NLog.Logger _logger; + public NLogLoggingService(IConfigFilePathProvider configFileFolder) + { + var cfgFilePath = Path.Combine(configFileFolder.GetPath, "NLogConfig.xml"); + LogManager.Configuration = new XmlLoggingConfiguration(cfgFilePath); + var loggerName = Assembly.GetEntryAssembly().GetName().Name; + _logger = LogManager.GetLogger(loggerName); + //_logger = LogManager.GetLogger(""); + } + + public bool IsDebugEnabled { get { return _logger.IsDebugEnabled; } } + public bool IsErrorEnabled { get { return _logger.IsErrorEnabled; } } + public bool IsFatalEnabled { get { return _logger.IsFatalEnabled; } } + public bool IsInfoEnabled { get { return _logger.IsInfoEnabled; } } + public bool IsTraceEnabled { get { return _logger.IsTraceEnabled; } } + public bool IsWarnEnabled { get { return _logger.IsWarnEnabled; } } + + public void Debug(Exception exception) + { + _logger.Debug(exception); + } + + public void Debug(string format, params object[] args) + { + _logger.Debug(format, args); + } + + public void Debug(Exception exception, string format, params object[] args) + { + _logger.Debug(exception, format, args); + } + + public void Error(Exception exception) + { + _logger.Error(exception); + } + + public void Error(string format, params object[] args) + { + _logger.Error(format, args); + } + + public void Error(Exception exception, string format, params object[] args) + { + _logger.Error(exception, format, args); + } + + public void Fatal(Exception exception) + { + _logger.Error(exception); + } + + public void Fatal(string format, params object[] args) + { + _logger.Fatal(format, args); + } + + public void Fatal(Exception exception, string format, params object[] args) + { + _logger.Error(exception, format, args); + } + + public void Info(Exception exception) + { + _logger.Info(exception); + } + + public void Info(string format, params object[] args) + { + _logger.Info(format, args); + } + + public void Info(Exception exception, string format, params object[] args) + { + _logger.Error(exception, format, args); + } + + public void Trace(Exception exception) + { + _logger.Trace(exception); + } + + public void Trace(string format, params object[] args) + { + _logger.Trace(format, args); + } + + public void Trace(Exception exception, string format, params object[] args) + { + _logger.Error(exception, format, args); + } + + public void Warn(Exception exception) + { + _logger.Warn(exception); + } + + public void Warn(string format, params object[] args) + { + _logger.Warn(format, args); + } + + public void Warn(Exception exception, string format, params object[] args) + { + _logger.Error(exception, format, args); + } + } +} diff --git a/RaceLapTimer/NLogLogger/NLogSchema/NLog.xsd b/RaceLapTimer/NLogLogger/NLogSchema/NLog.xsd new file mode 100644 index 0000000..74c38a5 --- /dev/null +++ b/RaceLapTimer/NLogLogger/NLogSchema/NLog.xsd @@ -0,0 +1,2966 @@ + + + + + + + + + + + + + + + Watch config file for changes and reload automatically. + + + + + Print internal NLog messages to the console. Default value is: false + + + + + Print internal NLog messages to the console error output. Default value is: false + + + + + Write internal NLog messages to the specified file. + + + + + Log level threshold for internal log messages. Default value is: Info. + + + + + Global log level threshold for application log messages. Messages below this level won't be logged.. + + + + + Throw an exception when there is an internal error. Default value is: false. + + + + + Throw an exception when there is a configuration error. If not set, determined by throwExceptions. + + + + + Gets or sets a value indicating whether Variables should be kept on configuration reload. Default value is: false. + + + + + Write internal NLog messages to the System.Diagnostics.Trace. Default value is: false. + + + + + Write timestamps for internal NLog messages. Default value is: true. + + + + + Use InvariantCulture as default culture instead of CurrentCulture. Default value is: false. + + + + + + + + + + + + + + Make all targets within this section asynchronous (creates additional threads but the calling thread isn't blocked by any target writes). + + + + + + + + + + + + + + + + + Prefix for targets/layout renderers/filters/conditions loaded from this assembly. + + + + + Load NLog extensions from the specified file (*.dll) + + + + + Load NLog extensions from the specified assembly. Assembly name should be fully qualified. + + + + + + + + + + Name of the logger. May include '*' character which acts like a wildcard. Allowed forms are: *, Name, *Name, Name* and *Name* + + + + + Comma separated list of levels that this rule matches. + + + + + Minimum level that this rule matches. + + + + + Maximum level that this rule matches. + + + + + Level that this rule matches. + + + + + Comma separated list of target names. + + + + + Ignore further rules if this one matches. + + + + + Enable or disable logging rule. Disabled rules are ignored. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the file to be included. You could use * wildcard. The name is relative to the name of the current config file. + + + + + Ignore any errors in the include file. + + + + + + + Variable name. + + + + + Variable value. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Number of log events that should be processed in a batch by the lazy writer thread. + + + + + Limit of full s to write before yielding into Performance is better when writing many small batches, than writing a single large batch + + + + + Action to be taken when the lazy writer thread request queue count exceeds the set limit. + + + + + Limit on the number of requests in the lazy writer thread request queue. + + + + + Time in milliseconds to sleep between batches. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Condition expression. Log events who meet this condition will cause a flush on the wrapped target. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Number of log events to be buffered. + + + + + Timeout (in milliseconds) after which the contents of buffer will be flushed if there's no write in the specified period of time. Use -1 to disable timed flushes. + + + + + Indicates whether to use sliding timeout. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Encoding to be used. + + + + + Instance of that is used to format log messages. + + + + + End of line value if a newline is appended at the end of log message . + + + + + Maximum message size in bytes. + + + + + Indicates whether to append newline at the end of log message. + + + + + Action that should be taken if the will be more connections than . + + + + + Action that should be taken if the message is larger than maxMessageSize. + + + + + Maximum current connections. 0 = no maximum. + + + + + Indicates whether to keep connection open whenever possible. + + + + + Size of the connection cache (number of connections which are kept alive). + + + + + Network address. + + + + + Maximum queue size. + + + + + Indicates whether to include dictionary contents. + + + + + Indicates whether to include source info (file name and line number) in the information sent over the network. + + + + + Indicates whether to include NLog-specific extensions to log4j schema. + + + + + Indicates whether to include stack contents. + + + + + Indicates whether to include call site (class and method name) in the information sent over the network. + + + + + AppInfo field. By default it's the friendly name of the current AppDomain. + + + + + NDC item separator. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + + + + + + Layout that should be use to calcuate the value for the parameter. + + + + + Viewer parameter name. + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Text to be rendered. + + + + + Header. + + + + + Footer. + + + + + Indicates whether to use default row highlighting rules. + + + + + Indicates whether to auto-check if the console is available. - Disables console writing if Environment.UserInteractive = False (Windows Service) - Disables console writing if Console Standard Input is not available (Non-Console-App) + + + + + The encoding for writing messages to the . + + + + + Indicates whether the error stream (stderr) should be used instead of the output stream (stdout). + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Condition that must be met in order to set the specified foreground and background color. + + + + + Background color. + + + + + Foreground color. + + + + + + + + + + + + + + + + Indicates whether to ignore case when comparing texts. + + + + + Regular expression to be matched. You must specify either text or regex. + + + + + Text to be matched. You must specify either text or regex. + + + + + Indicates whether to match whole words only. + + + + + Compile the ? This can improve the performance, but at the costs of more memory usage. If false, the Regex Cache is used. + + + + + Background color. + + + + + Foreground color. + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Text to be rendered. + + + + + Header. + + + + + Footer. + + + + + Indicates whether to send the log messages to the standard error instead of the standard output. + + + + + Indicates whether to auto-check if the console is available - Disables console writing if Environment.UserInteractive = False (Windows Service) - Disables console writing if Console Standard Input is not available (Non-Console-App) + + + + + The encoding for writing messages to the . + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Obsolete - value will be ignored! The logging code always runs outside of transaction. Gets or sets a value indicating whether to use database transactions. Some data providers require this. + + + + + Database user name. If the ConnectionString is not provided this value will be used to construct the "User ID=" part of the connection string. + + + + + Name of the database provider. + + + + + Database password. If the ConnectionString is not provided this value will be used to construct the "Password=" part of the connection string. + + + + + Indicates whether to keep the database connection open between the log events. + + + + + Database name. If the ConnectionString is not provided this value will be used to construct the "Database=" part of the connection string. + + + + + Name of the connection string (as specified in <connectionStrings> configuration section. + + + + + Connection string. When provided, it overrides the values specified in DBHost, DBUserName, DBPassword, DBDatabase. + + + + + Database host name. If the ConnectionString is not provided this value will be used to construct the "Server=" part of the connection string. + + + + + Connection string using for installation and uninstallation. If not provided, regular ConnectionString is being used. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + Text of the SQL command to be run on each log level. + + + + + Type of the SQL command to be run on each log level. + + + + + + + + + + + + + + + + + + + + + + + Type of the command. + + + + + Connection string to run the command against. If not provided, connection string from the target is used. + + + + + Indicates whether to ignore failures. + + + + + Command text. + + + + + + + + + + + + + + Layout that should be use to calcuate the value for the parameter. + + + + + Database parameter name. + + + + + Database parameter precision. + + + + + Database parameter scale. + + + + + Database parameter size. + + + + + + + + + + + + + + + + Name of the target. + + + + + Text to be rendered. + + + + + Header. + + + + + Footer. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + Name of the target. + + + + + Layout used to format log messages. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Layout used to format log messages. + + + + + Layout that renders event Category. + + + + + Layout that renders event ID. + + + + + Name of the Event Log to write to. This can be System, Application or any user-defined name. + + + + + Name of the machine on which Event Log service is running. + + + + + Value to be used as the event Source. + + + + + Action to take if the message is larger than the option. + + + + + Optional entrytype. When not set, or when not convertable to then determined by + + + + + Message length limit to write to the Event Log. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Indicates whether to return to the first target after any successful write. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Text to be rendered. + + + + + Header. + + + + + Footer. + + + + + File encoding. + + + + + Line ending mode. + + + + + Way file archives are numbered. + + + + + Name of the file to be used for an archive. + + + + + Indicates whether to automatically archive log files every time the specified time passes. + + + + + Size in bytes above which log files will be automatically archived. Warning: combining this with isn't supported. We cannot create multiple archive files, if they should have the same name. Choose: + + + + + Indicates whether to compress archive files into the zip archive format. + + + + + Maximum number of archive files that should be kept. + + + + + Gets or set a value indicating whether a managed file stream is forced, instead of using the native implementation. + + + + + Is the an absolute or relative path? + + + + + Cleanup invalid values in a filename, e.g. slashes in a filename. If set to true, this can impact the performance of massive writes. If set to false, nothing gets written when the filename is wrong. + + + + + Whether or not this target should just discard all data that its asked to write. Mostly used for when testing NLog Stack except final write + + + + + Is the an absolute or relative path? + + + + + Value indicationg whether file creation calls should be synchronized by a system global mutex. + + + + + Indicates whether the footer should be written only when the file is archived. + + + + + Name of the file to write to. + + + + + Value specifying the date format to use when archiving files. + + + + + Indicates whether to archive old log file on startup. + + + + + Indicates whether to create directories if they do not exist. + + + + + Indicates whether to enable log file(s) to be deleted. + + + + + File attributes (Windows only). + + + + + Indicates whether to delete old log file on startup. + + + + + Indicates whether to replace file contents on each write instead of appending log message at the end. + + + + + Indicates whether concurrent writes to the log file by multiple processes on the same host. + + + + + Indicates whether to keep log file open instead of opening and closing it on each logging event. + + + + + Maximum number of log filenames that should be stored as existing. + + + + + Indicates whether concurrent writes to the log file by multiple processes on different network hosts. + + + + + Number of files to be kept open. Setting this to a higher value may improve performance in a situation where a single File target is writing to many files (such as splitting by level or by logger). + + + + + Maximum number of seconds that files are kept open. If this number is negative the files are not automatically closed after a period of inactivity. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + Log file buffer size in bytes. + + + + + Indicates whether to automatically flush the file buffers after each log message. + + + + + Delay in milliseconds to wait before attempting to write to the file again. + + + + + Number of times the write is appended on the file before NLog discards the log message. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Condition expression. Log events who meet this condition will be forwarded to the wrapped target. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Windows domain name to change context to. + + + + + Required impersonation level. + + + + + Type of the logon provider. + + + + + Logon Type. + + + + + User account password. + + + + + Indicates whether to revert to the credentials of the process instead of impersonating another user. + + + + + Username to change context to. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Interval in which messages will be written up to the number of messages. + + + + + Maximum allowed number of messages written per . + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Endpoint address. + + + + + Name of the endpoint configuration in WCF configuration file. + + + + + Indicates whether to use a WCF service contract that is one way (fire and forget) or two way (request-reply) + + + + + Client ID. + + + + + Indicates whether to include per-event properties in the payload sent to the server. + + + + + Indicates whether to use binary message encoding. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + Layout that should be use to calculate the value for the parameter. + + + + + Name of the parameter. + + + + + Type of the parameter. + + + + + Type of the parameter. Obsolete alias for + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Text to be rendered. + + + + + Header. + + + + + Footer. + + + + + Indicates whether to send message as HTML instead of plain text. + + + + + Encoding to be used for sending e-mail. + + + + + Indicates whether to add new lines between log entries. + + + + + CC email addresses separated by semicolons (e.g. john@domain.com;jane@domain.com). + + + + + Recipients' email addresses separated by semicolons (e.g. john@domain.com;jane@domain.com). + + + + + BCC email addresses separated by semicolons (e.g. john@domain.com;jane@domain.com). + + + + + Mail message body (repeated for each log message send in one mail). + + + + + Mail subject. + + + + + Sender's email address (e.g. joe@domain.com). + + + + + Indicates the SMTP client timeout. + + + + + Priority used for sending mails. + + + + + Indicates whether NewLine characters in the body should be replaced with tags. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + SMTP Server to be used for sending. + + + + + SMTP Authentication mode. + + + + + Username used to connect to SMTP server (used when SmtpAuthentication is set to "basic"). + + + + + Password used to authenticate against SMTP server (used when SmtpAuthentication is set to "basic"). + + + + + Indicates whether SSL (secure sockets layer) should be used when communicating with SMTP server. + + + + + Port number that SMTP Server is listening on. + + + + + Indicates whether the default Settings from System.Net.MailSettings should be used. + + + + + Folder where applications save mail messages to be processed by the local SMTP server. + + + + + Specifies how outgoing email messages will be handled. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Layout used to format log messages. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Layout used to format log messages. + + + + + Encoding to be used when writing text to the queue. + + + + + Indicates whether to use the XML format when serializing message. This will also disable creating queues. + + + + + Indicates whether to check if a queue exists before writing to it. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + Indicates whether to create the queue if it doesn't exists. + + + + + Label to associate with each message. + + + + + Name of the queue to write to. + + + + + Indicates whether to use recoverable messages (with guaranteed delivery). + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Class name. + + + + + Method name. The method must be public and static. Use the AssemblyQualifiedName , https://msdn.microsoft.com/en-us/library/system.type.assemblyqualifiedname(v=vs.110).aspx e.g. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Layout used to format log messages. + + + + + Encoding to be used. + + + + + End of line value if a newline is appended at the end of log message . + + + + + Maximum message size in bytes. + + + + + Indicates whether to append newline at the end of log message. + + + + + Action that should be taken if the will be more connections than . + + + + + Action that should be taken if the message is larger than maxMessageSize. + + + + + Network address. + + + + + Size of the connection cache (number of connections which are kept alive). + + + + + Indicates whether to keep connection open whenever possible. + + + + + Maximum current connections. 0 = no maximum. + + + + + Maximum queue size. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Encoding to be used. + + + + + Instance of that is used to format log messages. + + + + + End of line value if a newline is appended at the end of log message . + + + + + Maximum message size in bytes. + + + + + Indicates whether to append newline at the end of log message. + + + + + Action that should be taken if the will be more connections than . + + + + + Action that should be taken if the message is larger than maxMessageSize. + + + + + Maximum current connections. 0 = no maximum. + + + + + Indicates whether to keep connection open whenever possible. + + + + + Size of the connection cache (number of connections which are kept alive). + + + + + Network address. + + + + + Maximum queue size. + + + + + Indicates whether to include dictionary contents. + + + + + Indicates whether to include source info (file name and line number) in the information sent over the network. + + + + + Indicates whether to include NLog-specific extensions to log4j schema. + + + + + Indicates whether to include stack contents. + + + + + Indicates whether to include call site (class and method name) in the information sent over the network. + + + + + AppInfo field. By default it's the friendly name of the current AppDomain. + + + + + NDC item separator. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + Name of the target. + + + + + Layout used to format log messages. + + + + + Indicates whether to perform layout calculation. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + Name of the target. + + + + + Layout used to format log messages. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Indicates whether performance counter should be automatically created. + + + + + Name of the performance counter category. + + + + + Counter help text. + + + + + Name of the performance counter. + + + + + Performance counter type. + + + + + The value by which to increment the counter. + + + + + Performance counter instance name. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Default filter to be applied when no specific rule matches. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + Condition to be tested. + + + + + Resulting filter to be applied when the condition matches. + + + + + + + + + + + + + Name of the target. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + Name of the target. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + Number of times to repeat each log message. + + + + + + + + + + + + + + + + + Name of the target. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + Number of retries that should be attempted on the wrapped target in case of a failure. + + + + + Time to wait between retries in milliseconds. + + + + + + + + + + + + + + + Name of the target. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + Name of the target. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + Name of the target. + + + + + Layout used to format log messages. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Should we include the BOM (Byte-order-mark) for UTF? Influences the property. This will only work for UTF-8. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + Encoding. + + + + + Value whether escaping be done according to the old NLog style (Very non-standard) + + + + + Value whether escaping be done according to Rfc3986 (Supports Internationalized Resource Identifiers - IRIs) + + + + + Web service method name. Only used with Soap. + + + + + Web service namespace. Only used with Soap. + + + + + Protocol to be used when calling web service. + + + + + Web service URL. + + + + + Name of the root XML element, if POST of XML document chosen. If so, this property must not be null. (see and ). + + + + + (optional) root namespace of the XML document, if POST of XML document chosen. (see and ). + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Footer layout. + + + + + Header layout. + + + + + Body layout (can be repeated multiple times). + + + + + Custom column delimiter value (valid when ColumnDelimiter is set to 'Custom'). + + + + + Column delimiter. + + + + + Quote Character. + + + + + Quoting mode. + + + + + Indicates whether CVS should include header. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Layout of the column. + + + + + Name of the column. + + + + + + + + + + + + + + + + List of property names to exclude when is true + + + + + Option to include all properties from the log events + + + + + Option to render the empty object value {} + + + + + Option to suppress the extra spaces in the output json + + + + + + + + + + + + + + Determines wether or not this attribute will be Json encoded. + + + + + Layout that will be rendered as the attribute's value. + + + + + Name of the attribute. + + + + + + + + + + + + + + Footer layout. + + + + + Header layout. + + + + + Body layout (can be repeated multiple times). + + + + + + + + + + + + + + + + + + + + + Layout text. + + + + + + + + + + + + + + + Action to be taken when filter matches. + + + + + Condition expression. + + + + + + + + + + + + + + + + + + + + + + + + + + Action to be taken when filter matches. + + + + + Indicates whether to ignore case when comparing strings. + + + + + Layout to be used to filter log messages. + + + + + Substring to be matched. + + + + + + + + + + + + + + + + + Action to be taken when filter matches. + + + + + String to compare the layout to. + + + + + Indicates whether to ignore case when comparing strings. + + + + + Layout to be used to filter log messages. + + + + + + + + + + + + + + + + + Action to be taken when filter matches. + + + + + Indicates whether to ignore case when comparing strings. + + + + + Layout to be used to filter log messages. + + + + + Substring to be matched. + + + + + + + + + + + + + + + + + Action to be taken when filter matches. + + + + + String to compare the layout to. + + + + + Indicates whether to ignore case when comparing strings. + + + + + Layout to be used to filter log messages. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RaceLapTimer/NLogLogger/Properties/AssemblyInfo.cs b/RaceLapTimer/NLogLogger/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..432b8f6 --- /dev/null +++ b/RaceLapTimer/NLogLogger/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("NLogLogger")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("NLogLogger")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("9a93a12f-7591-406a-a4f3-41aa8299c4b4")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/RaceLapTimer/NLogLogger/packages.config b/RaceLapTimer/NLogLogger/packages.config new file mode 100644 index 0000000..ff180ba --- /dev/null +++ b/RaceLapTimer/NLogLogger/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/RaceLapTimer/RaceLapTimer.sln b/RaceLapTimer/RaceLapTimer.sln index b6633e1..a1a9182 100644 --- a/RaceLapTimer/RaceLapTimer.sln +++ b/RaceLapTimer/RaceLapTimer.sln @@ -11,6 +11,14 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Interfaces", "Interfaces\In EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Helpers.Encryption", "Helpers.Encrytion\Helpers.Encryption.csproj", "{BC7DEA8B-5029-459A-AA54-EA81EB390F87}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NLogLogger", "NLogLogger\NLogLogger.csproj", "{9A93A12F-7591-406A-A4F3-41AA8299C4B4}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Notifiers", "Notifiers", "{CDAC76D5-5EC6-4357-A27C-0095BF98FDDF}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UdpNotifier", "UdpNotifier\UdpNotifier.csproj", "{734097B0-A764-40AD-957A-43FE4F085B65}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Logger", "Logger", "{36BDEE78-985C-4AF5-A39B-3BE89FAEB281}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -33,8 +41,20 @@ Global {BC7DEA8B-5029-459A-AA54-EA81EB390F87}.Debug|Any CPU.Build.0 = Debug|Any CPU {BC7DEA8B-5029-459A-AA54-EA81EB390F87}.Release|Any CPU.ActiveCfg = Release|Any CPU {BC7DEA8B-5029-459A-AA54-EA81EB390F87}.Release|Any CPU.Build.0 = Release|Any CPU + {9A93A12F-7591-406A-A4F3-41AA8299C4B4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9A93A12F-7591-406A-A4F3-41AA8299C4B4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9A93A12F-7591-406A-A4F3-41AA8299C4B4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9A93A12F-7591-406A-A4F3-41AA8299C4B4}.Release|Any CPU.Build.0 = Release|Any CPU + {734097B0-A764-40AD-957A-43FE4F085B65}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {734097B0-A764-40AD-957A-43FE4F085B65}.Debug|Any CPU.Build.0 = Debug|Any CPU + {734097B0-A764-40AD-957A-43FE4F085B65}.Release|Any CPU.ActiveCfg = Release|Any CPU + {734097B0-A764-40AD-957A-43FE4F085B65}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {9A93A12F-7591-406A-A4F3-41AA8299C4B4} = {36BDEE78-985C-4AF5-A39B-3BE89FAEB281} + {734097B0-A764-40AD-957A-43FE4F085B65} = {CDAC76D5-5EC6-4357-A27C-0095BF98FDDF} + EndGlobalSection EndGlobal diff --git a/RaceLapTimer/RaceLapTimer/App.config b/RaceLapTimer/RaceLapTimer/App.config index 93999eb..f714102 100644 --- a/RaceLapTimer/RaceLapTimer/App.config +++ b/RaceLapTimer/RaceLapTimer/App.config @@ -23,6 +23,14 @@ + + + + + + + + \ No newline at end of file diff --git a/RaceLapTimer/RaceLapTimer/AuthenticationBootstrapper.cs b/RaceLapTimer/RaceLapTimer/AuthenticationBootstrapper.cs index 003312c..bdb1778 100644 --- a/RaceLapTimer/RaceLapTimer/AuthenticationBootstrapper.cs +++ b/RaceLapTimer/RaceLapTimer/AuthenticationBootstrapper.cs @@ -1,35 +1,53 @@ -using Interfaces; +using System.Diagnostics; +using System.IO; +using Interfaces; using Nancy; using Nancy.Authentication.Forms; using Nancy.Bootstrapper; +using Nancy.Bootstrappers.Ninject; using Nancy.Conventions; using Nancy.Diagnostics; using Nancy.TinyIoc; +using Ninject; using RaceLapTimer.ApiControllers; +using RaceLapTimer.Extensions.Notifications; namespace RaceLapTimer { - public class FormsAuthBootstrapper : DefaultNancyBootstrapper + public class FormsAuthBootstrapper : NinjectNancyBootstrapper { - protected override void ConfigureApplicationContainer(TinyIoCContainer container) + protected override void ConfigureApplicationContainer(IKernel container) { // We don't call "base" here to prevent auto-discovery of // types/dependencies + // Configure things for a wider purpose, non-requestcontroller based. + container.Bind().To(); + container.Bind().To(); + container.Bind().To(); + container.Bind().To().InSingletonScope(); + container.Bind().To(); + + //load dynamic plugins..: + var cfgFilePath = Path.Combine(container.Get().GetPath, "NinjectConfig.xml"); + + container.Load(cfgFilePath); + + var nM = container.Get(); + nM.NotifyRaceStarted(new NotificationEventArgs()); } - protected override void ConfigureRequestContainer(TinyIoCContainer container, NancyContext context) + protected override void ConfigureRequestContainer(IKernel container, NancyContext context) { base.ConfigureRequestContainer(container, context); // Here we register our user mapper as a per-request singleton. // As this is now per-request we could inject a request scoped // database "context" or other request scoped services. - container.Register(); - container.Register(); //register the storage provider.. - container.Register().AsSingleton(); + container.Bind().To(); //register the storage provider.. + container.Bind().To().InSingletonScope(); } - protected override void RequestStartup(TinyIoCContainer requestContainer, IPipelines pipelines, NancyContext context) + protected override void RequestStartup(IKernel requestContainer, IPipelines pipelines, NancyContext context) { // At request startup we modify the request pipelines to // include forms authentication - passing in our now request @@ -41,7 +59,7 @@ namespace RaceLapTimer new FormsAuthenticationConfiguration() { RedirectUrl = "~/login", - UserMapper = requestContainer.Resolve(), + UserMapper = requestContainer.Get(), }; FormsAuthentication.Enable(pipelines, formsAuthConfiguration); diff --git a/RaceLapTimer/RaceLapTimer/ConfigFilePathProvider.cs b/RaceLapTimer/RaceLapTimer/ConfigFilePathProvider.cs new file mode 100644 index 0000000..56714be --- /dev/null +++ b/RaceLapTimer/RaceLapTimer/ConfigFilePathProvider.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; +using Interfaces; + +namespace RaceLapTimer +{ + class ConfigFilePathProvider : IConfigFilePathProvider + { + public string GetPath + { + get + { + return new Uri(Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().CodeBase), "Configs")).LocalPath; + } + } + } +} diff --git a/RaceLapTimer/RaceLapTimer/Configs/NinjectConfig.xml b/RaceLapTimer/RaceLapTimer/Configs/NinjectConfig.xml new file mode 100644 index 0000000..0b9d7fd --- /dev/null +++ b/RaceLapTimer/RaceLapTimer/Configs/NinjectConfig.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/RaceLapTimer/RaceLapTimer/Extensions/Notifications/ContainerHelper.cs b/RaceLapTimer/RaceLapTimer/Extensions/Notifications/ContainerHelper.cs new file mode 100644 index 0000000..189a03a --- /dev/null +++ b/RaceLapTimer/RaceLapTimer/Extensions/Notifications/ContainerHelper.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using Interfaces; +using Ninject; + +namespace RaceLapTimer.Extensions.Notifications +{ + class ContainerHelper : IContainerHelper + { + private IKernel _container; + public ContainerHelper(IKernel container) + { + _container = container; + } + + public void RegisterType(Type typeToBindTo, Type typeBeingBound, string uniqueName) + { + if (string.IsNullOrEmpty(uniqueName)) + { + _container.Bind(typeToBindTo).To(typeBeingBound); + } + else + { + _container.Bind(typeToBindTo).To(typeBeingBound).Named(uniqueName); + } + } + + public T Get() + { + return _container.Get(); + } + + public IEnumerable GetAll() + { + return _container.GetAll(); + } + } +} \ No newline at end of file diff --git a/RaceLapTimer/RaceLapTimer/Extensions/Notifications/NotificationManager.cs b/RaceLapTimer/RaceLapTimer/Extensions/Notifications/NotificationManager.cs new file mode 100644 index 0000000..1fec36b --- /dev/null +++ b/RaceLapTimer/RaceLapTimer/Extensions/Notifications/NotificationManager.cs @@ -0,0 +1,112 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Security.Cryptography.X509Certificates; +using System.Text; +using System.Threading.Tasks; +using Interfaces; + +namespace RaceLapTimer.Extensions.Notifications +{ + class NotificationManager : INotifierManager + { + private readonly List _providers; + public NotificationManager(IPluginPathProvider pluginPath, IContainerHelper helper) + { + if (!Directory.Exists(pluginPath.GetPluginPath)) return; + var files = Directory.GetFiles(pluginPath.GetPluginPath); + + foreach (var file in files) + { + var ext = Path.GetExtension(file); + if (!IsAssembly(ext)) continue; + + var assembly = Assembly.LoadFrom(file); //need to use ReflectionOnlyLoadFrom rather than LoadFrom here, this will cause exception if another extension point is implemented + var pluginTypes = (from t in assembly.GetExportedTypes() + where t.GetInterfaces().Any(x=>x.Name==nameof(INotifierProviderFactory)) + select t).ToList(); + if (pluginTypes.Any()) + { + helper.RegisterType(typeof(INotifierProviderFactory), pluginTypes.First(), Path.GetFileNameWithoutExtension(file)); + } + } + + var providerFactories = helper.GetAll().ToList(); + _providers = new List(); + foreach (var factory in providerFactories) + { + _providers.Add(factory.CreateProvider()); + } + } + + public List GetAvailableNotifiers() + { + return _providers.Select(provider => provider.GetDisplayName()).ToList(); + } + + public void NotifyRaceStarted(NotificationEventArgs args) + { + try + { + foreach (var provider in _providers) + { + //provider.NotifyRaceStarted(args); + Task.Factory.StartNew(() => { provider.NotifyRaceStarted(args); }); + } + } + catch (Exception ex) + { + Debug.WriteLine(ex); + } + } + + public void NotifyRaceStarting(NotificationEventArgs args) + { + foreach (var provider in _providers) + { + Task.Factory.StartNew(() => provider.NotifyRaceStarting(args)); + } + } + + public void NotifyRaceLapEvent(NotificationEventArgs args, Pilot pilot) + { + foreach (var provider in _providers) + { + Task.Factory.StartNew(() => provider.NotifyRaceLapEvent(args, pilot)); + } + } + + public void NotifyRaceWinner(NotificationEventArgs args, Pilot pilot) + { + foreach (var provider in _providers) + { + Task.Factory.StartNew(() => provider.NotifyRaceWinner(args, pilot)); + } + } + + public void NotifyRaceFinished(NotificationEventArgs args) + { + foreach (var provider in _providers) + { + Task.Factory.StartNew(() => provider.NotifyRaceFinished(args)); + } + } + + private bool IsAssembly(string extension) + { + var validAssemblyExts = new List + { + "dll", "exe" + }; + var ext = extension.Remove(0, 1); + if (validAssemblyExts.Contains(ext)) + { + return true; + } + return false; + } + } +} diff --git a/RaceLapTimer/RaceLapTimer/PluginPathProvider.cs b/RaceLapTimer/RaceLapTimer/PluginPathProvider.cs new file mode 100644 index 0000000..13da206 --- /dev/null +++ b/RaceLapTimer/RaceLapTimer/PluginPathProvider.cs @@ -0,0 +1,18 @@ +using System; +using System.IO; +using System.Reflection; +using Interfaces; + +namespace RaceLapTimer +{ + public class PluginPathProvider : IPluginPathProvider + { + public string GetPluginPath + { + get + { + return new Uri(Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().CodeBase), "plugins")).LocalPath; + } + } + } +} \ No newline at end of file diff --git a/RaceLapTimer/RaceLapTimer/Plugins/placeholder.txt b/RaceLapTimer/RaceLapTimer/Plugins/placeholder.txt new file mode 100644 index 0000000..5f28270 --- /dev/null +++ b/RaceLapTimer/RaceLapTimer/Plugins/placeholder.txt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/RaceLapTimer/RaceLapTimer/RaceLapTimer.csproj b/RaceLapTimer/RaceLapTimer/RaceLapTimer.csproj index b82e0c7..c8189b0 100644 --- a/RaceLapTimer/RaceLapTimer/RaceLapTimer.csproj +++ b/RaceLapTimer/RaceLapTimer/RaceLapTimer.csproj @@ -55,6 +55,10 @@ ..\packages\Nancy.Authentication.Forms.1.4.1\lib\net40\Nancy.Authentication.Forms.dll True + + ..\packages\Nancy.Bootstrappers.Ninject.1.4.1\lib\net40\Nancy.Bootstrappers.Ninject.dll + True + ..\packages\Nancy.Owin.1.4.1\lib\net40\Nancy.Owin.dll True @@ -67,6 +71,18 @@ ..\packages\Newtonsoft.Json.6.0.4\lib\net45\Newtonsoft.Json.dll True + + ..\packages\Ninject.3.2.0.0\lib\net45-full\Ninject.dll + True + + + ..\packages\Ninject.Extensions.ChildKernel.3.2.0.0\lib\net45-full\Ninject.Extensions.ChildKernel.dll + True + + + ..\packages\Ninject.Extensions.Xml.3.2.0.0\lib\net45-full\Ninject.Extensions.Xml.dll + True + ..\packages\Owin.1.0\lib\net40\Owin.dll True @@ -106,6 +122,9 @@ + + + @@ -119,6 +138,7 @@ + Component @@ -172,6 +192,12 @@ + + PreserveNewest + + + PreserveNewest + Always diff --git a/RaceLapTimer/RaceLapTimer/packages.config b/RaceLapTimer/RaceLapTimer/packages.config index 720590a..b2cdb9b 100644 --- a/RaceLapTimer/RaceLapTimer/packages.config +++ b/RaceLapTimer/RaceLapTimer/packages.config @@ -10,8 +10,12 @@ + + + + \ No newline at end of file diff --git a/RaceLapTimer/RaceLapTimerHost/App.config b/RaceLapTimer/RaceLapTimerHost/App.config index 5e1fd16..7dd592e 100644 --- a/RaceLapTimer/RaceLapTimerHost/App.config +++ b/RaceLapTimer/RaceLapTimerHost/App.config @@ -24,6 +24,14 @@ + + + + + + + + \ No newline at end of file diff --git a/RaceLapTimer/RaceLapTimerHost/RaceLapTimerHost.csproj b/RaceLapTimer/RaceLapTimerHost/RaceLapTimerHost.csproj index 8d31780..22c0705 100644 --- a/RaceLapTimer/RaceLapTimerHost/RaceLapTimerHost.csproj +++ b/RaceLapTimer/RaceLapTimerHost/RaceLapTimerHost.csproj @@ -72,10 +72,18 @@ + + {9a93a12f-7591-406a-a4f3-41aa8299c4b4} + NLogLogger + {85A3CC28-096C-40A6-8C67-3AADE40EDF32} RaceLapTimer + + {734097b0-a764-40ad-957a-43fe4f085b65} + UdpNotifier + @@ -85,6 +93,10 @@ + + copy /B /Y "$(TargetDir)UdpNotifier.dll" "$(TargetDir)Plugins\UdpNotifier.dll" +copy /B /Y "$(TargetDir)NLogConfig.xml" "$(TargetDir)Configs\NLogConfig.xml" + + \ No newline at end of file diff --git a/RaceLapTimer/UdpNotifier/UdpNotifierProvider.cs b/RaceLapTimer/UdpNotifier/UdpNotifierProvider.cs new file mode 100644 index 0000000..61dc76e --- /dev/null +++ b/RaceLapTimer/UdpNotifier/UdpNotifierProvider.cs @@ -0,0 +1,63 @@ +using System; +using System.Net; +using System.Net.Sockets; +using System.Text; +using Interfaces; + +namespace UdpNotifier +{ + public class UdpNotifierProvider:INotifierProvider + { + private ILoggerService _logger; + + public UdpNotifierProvider(ILoggerService logger) + { + _logger = logger; + } + public string GetDisplayName() + { + return "UDP Notifier"; + } + + public string GetNotifierType() + { + return "UdpNotifierProvider"; + } + + public void NotifyRaceStarted(NotificationEventArgs args) + { + _logger.Trace("Sending RaceStartedNotification"); + Send(); + } + + public void NotifyRaceStarting(NotificationEventArgs args) + { + Send(); + } + + public void NotifyRaceLapEvent(NotificationEventArgs args, Pilot pilot) + { + Send(); + } + + public void NotifyRaceWinner(NotificationEventArgs args, Pilot pilot) + { + Send(); + } + + public void NotifyRaceFinished(NotificationEventArgs args) + { + Send(); + } + + private void Send() + { + var endpoint = new IPEndPoint(IPAddress.Parse("192.168.1.94"), 64000); + var client = new UdpClient(endpoint); + var ip = new IPEndPoint(IPAddress.Broadcast, 15000); + var bytes = Encoding.ASCII.GetBytes("Foo"); + client.Send(bytes, bytes.Length, ip); + client.Close(); + } + } +} \ No newline at end of file diff --git a/RaceLapTimer/UdpNotifier/UdpNotifierProviderFactory.cs b/RaceLapTimer/UdpNotifier/UdpNotifierProviderFactory.cs new file mode 100644 index 0000000..2eed2c5 --- /dev/null +++ b/RaceLapTimer/UdpNotifier/UdpNotifierProviderFactory.cs @@ -0,0 +1,28 @@ +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Interfaces; + +namespace UdpNotifier +{ + public class UdpNotifierProviderFactory : INotifierProviderFactory + { + private ILoggerService _logger; + + public UdpNotifierProviderFactory(ILoggerService logger) + { + _logger = logger; + } + + public INotifierProvider CreateProvider() + { + return new UdpNotifierProvider(_logger); + } + + public new string GetType() + { + return "UdpNotifierProviderFactory"; + } + } +}