create nlogLogger project.

create UdpNotifier project.
implemented IPluginPathProvider and IConfigFilePathProvider, IContainerHelper and INotifierManager.
This commit is contained in:
chris.watts90@outlook.com 2017-05-24 22:34:40 +01:00
parent a30a9a5453
commit a07923d214
33 changed files with 3846 additions and 9 deletions

View File

@ -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; }
}
}

View File

@ -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<T>();
IEnumerable<T> GetAll<T>();
void RegisterType(Type typeToBindTo, Type typeBeingBound, string uniqueName);
}
}

View File

@ -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);
}
}

View File

@ -0,0 +1,14 @@
using System.Collections.Generic;
namespace Interfaces
{
public interface INotifierManager
{
List<string> 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);
}
}

View File

@ -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);
}
}

View File

@ -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();
}
}

View File

@ -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; }
}
}

View File

@ -40,8 +40,16 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="IConfigFilePathProvider.cs" />
<Compile Include="IContainerHelper.cs" />
<Compile Include="ILoggerService.cs" />
<Compile Include="IPluginPathProvider.cs" />
<Compile Include="ConfigurationSetting.cs" />
<Compile Include="CompetitionRace.cs" />
<Compile Include="INotifierManager.cs" />
<Compile Include="INotifierProvider.cs" />
<Compile Include="INotifierProviderFactory.cs" />
<Compile Include="NotificationEventArgs.cs" />
<Compile Include="Pilot.cs" />
<Compile Include="RaceSession.cs" />
<Compile Include="IUserStorage.cs" />

View File

@ -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; }
}
}

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
autoReload="true">
<targets>
<target name="viewer" xsi:type="Chainsaw" address="udp://127.0.0.1:4000" />
</targets>
<rules>
<logger name="*" minlevel="Trace" writeTo="viewer" />
</rules>
</nlog>

View File

@ -0,0 +1,76 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{9A93A12F-7591-406A-A4F3-41AA8299C4B4}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>NLogLogger</RootNamespace>
<AssemblyName>NLogLogger</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
<HintPath>..\packages\NLog.4.4.9\lib\net45\NLog.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="NLogLoggingService.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Interfaces\Interfaces.csproj">
<Project>{5c6dcc59-19f3-46ad-a479-926610f36257}</Project>
<Name>Interfaces</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="NLogSchema\NLog.xsd">
<SubType>Designer</SubType>
</None>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Content Include="NLogConfig.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectView>ProjectFiles</ProjectView>
</PropertyGroup>
</Project>

View File

@ -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);
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -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")]

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NLog" version="4.4.9" targetFramework="net452" />
</packages>

View File

@ -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

View File

@ -23,6 +23,14 @@
<assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.1.0.0" newVersion="3.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Ninject" publicKeyToken="c7192dc5380945e7" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.2.0.0" newVersion="3.2.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Ninject.Extensions.ChildKernel" publicKeyToken="c7192dc5380945e7" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.2.0.0" newVersion="3.2.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

View File

@ -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<IPluginPathProvider>().To<PluginPathProvider>();
container.Bind<IConfigFilePathProvider>().To<ConfigFilePathProvider>();
container.Bind<IContainerHelper>().To<ContainerHelper>();
container.Bind<INotifierManager>().To<NotificationManager>().InSingletonScope();
container.Bind<IDbProvider>().To<TestProvider>();
//load dynamic plugins..:
var cfgFilePath = Path.Combine(container.Get<IConfigFilePathProvider>().GetPath, "NinjectConfig.xml");
container.Load(cfgFilePath);
var nM = container.Get<INotifierManager>();
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<IDbProvider, TestProvider>();
container.Register<IUserStorage, UserStorage>(); //register the storage provider..
container.Register<IUserMapper, UserDatabase>().AsSingleton();
container.Bind<IUserStorage>().To<UserStorage>(); //register the storage provider..
container.Bind<IUserMapper>().To<UserDatabase>().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<IUserMapper>(),
UserMapper = requestContainer.Get<IUserMapper>(),
};
FormsAuthentication.Enable(pipelines, formsAuthConfiguration);

View File

@ -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;
}
}
}
}

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8" ?>
<module name="mainAppModules">
<bind service="Interfaces.ILoggerService, Interfaces" to="NLogLogger.NLogLoggingService, NLogLogger" scope="singleton" />
</module>

View File

@ -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<T>()
{
return _container.Get<T>();
}
public IEnumerable<T> GetAll<T>()
{
return _container.GetAll<T>();
}
}
}

View File

@ -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<INotifierProvider> _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<INotifierProviderFactory>().ToList();
_providers = new List<INotifierProvider>();
foreach (var factory in providerFactories)
{
_providers.Add(factory.CreateProvider());
}
}
public List<string> 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<string>
{
"dll", "exe"
};
var ext = extension.Remove(0, 1);
if (validAssemblyExts.Contains(ext))
{
return true;
}
return false;
}
}
}

View File

@ -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;
}
}
}
}

View File

@ -0,0 +1 @@


View File

@ -55,6 +55,10 @@
<HintPath>..\packages\Nancy.Authentication.Forms.1.4.1\lib\net40\Nancy.Authentication.Forms.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Nancy.Bootstrappers.Ninject, Version=1.4.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Nancy.Bootstrappers.Ninject.1.4.1\lib\net40\Nancy.Bootstrappers.Ninject.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Nancy.Owin, Version=1.4.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Nancy.Owin.1.4.1\lib\net40\Nancy.Owin.dll</HintPath>
<Private>True</Private>
@ -67,6 +71,18 @@
<HintPath>..\packages\Newtonsoft.Json.6.0.4\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Ninject, Version=3.2.0.0, Culture=neutral, PublicKeyToken=c7192dc5380945e7, processorArchitecture=MSIL">
<HintPath>..\packages\Ninject.3.2.0.0\lib\net45-full\Ninject.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Ninject.Extensions.ChildKernel, Version=3.2.0.0, Culture=neutral, PublicKeyToken=c7192dc5380945e7, processorArchitecture=MSIL">
<HintPath>..\packages\Ninject.Extensions.ChildKernel.3.2.0.0\lib\net45-full\Ninject.Extensions.ChildKernel.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Ninject.Extensions.Xml, Version=3.2.0.0, Culture=neutral, PublicKeyToken=c7192dc5380945e7, processorArchitecture=MSIL">
<HintPath>..\packages\Ninject.Extensions.Xml.3.2.0.0\lib\net45-full\Ninject.Extensions.Xml.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Owin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f0ebd12fd5e55cc5, processorArchitecture=MSIL">
<HintPath>..\packages\Owin.1.0\lib\net40\Owin.dll</HintPath>
<Private>True</Private>
@ -106,6 +122,9 @@
<Compile Include="ApiControllers\SoundApiModule.cs" />
<Compile Include="ApiControllers\SystemApiModule.cs" />
<Compile Include="AuthenticationBootstrapper.cs" />
<Compile Include="ConfigFilePathProvider.cs" />
<Compile Include="Extensions\Notifications\ContainerHelper.cs" />
<Compile Include="Extensions\Notifications\NotificationManager.cs" />
<Compile Include="Modules\HistoryModule.cs" />
<Compile Include="ApiControllers\InfoApiModule.cs" />
<Compile Include="Modules\LoginModule.cs" />
@ -119,6 +138,7 @@
<Compile Include="Modules\UserModule.cs" />
<Compile Include="NancyRootPathProvider.cs" />
<Compile Include="NancyUser.cs" />
<Compile Include="PluginPathProvider.cs" />
<Compile Include="RaceLapTimer.cs">
<SubType>Component</SubType>
</Compile>
@ -172,6 +192,12 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Content Include="Configs\NinjectConfig.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Plugins\placeholder.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="www\images\pilotPic.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>

View File

@ -10,8 +10,12 @@
<package id="Microsoft.Owin.Hosting" version="3.1.0" targetFramework="net452" />
<package id="Nancy" version="1.4.3" targetFramework="net452" />
<package id="Nancy.Authentication.Forms" version="1.4.1" targetFramework="net452" />
<package id="Nancy.Bootstrappers.Ninject" version="1.4.1" targetFramework="net452" />
<package id="Nancy.Owin" version="1.4.1" targetFramework="net452" />
<package id="Nancy.Viewengines.Razor" version="1.4.3" targetFramework="net452" />
<package id="Newtonsoft.Json" version="6.0.4" targetFramework="net452" />
<package id="Ninject" version="3.2.0.0" targetFramework="net452" />
<package id="Ninject.Extensions.ChildKernel" version="3.2.0.0" targetFramework="net452" />
<package id="Ninject.Extensions.Xml" version="3.2.0.0" targetFramework="net452" />
<package id="Owin" version="1.0" targetFramework="net452" />
</packages>

View File

@ -24,6 +24,14 @@
<assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.1.0.0" newVersion="3.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Ninject" publicKeyToken="c7192dc5380945e7" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.2.0.0" newVersion="3.2.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Ninject.Extensions.ChildKernel" publicKeyToken="c7192dc5380945e7" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.2.0.0" newVersion="3.2.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

View File

@ -72,10 +72,18 @@
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\NLogLogger\NLogLogger.csproj">
<Project>{9a93a12f-7591-406a-a4f3-41aa8299c4b4}</Project>
<Name>NLogLogger</Name>
</ProjectReference>
<ProjectReference Include="..\RaceLapTimer\RaceLapTimer.csproj">
<Project>{85A3CC28-096C-40A6-8C67-3AADE40EDF32}</Project>
<Name>RaceLapTimer</Name>
</ProjectReference>
<ProjectReference Include="..\UdpNotifier\UdpNotifier.csproj">
<Project>{734097b0-a764-40ad-957a-43fe4f085b65}</Project>
<Name>UdpNotifier</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\Nancy.Viewengines.Razor.1.4.3\build\Nancy.ViewEngines.Razor.targets" Condition="Exists('..\packages\Nancy.Viewengines.Razor.1.4.3\build\Nancy.ViewEngines.Razor.targets')" />
@ -85,6 +93,10 @@
</PropertyGroup>
<Error Condition="!Exists('..\packages\Nancy.Viewengines.Razor.1.4.3\build\Nancy.ViewEngines.Razor.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Nancy.Viewengines.Razor.1.4.3\build\Nancy.ViewEngines.Razor.targets'))" />
</Target>
<PropertyGroup>
<PostBuildEvent>copy /B /Y "$(TargetDir)UdpNotifier.dll" "$(TargetDir)Plugins\UdpNotifier.dll"
copy /B /Y "$(TargetDir)NLogConfig.xml" "$(TargetDir)Configs\NLogConfig.xml"</PostBuildEvent>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">

View File

@ -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("UdpNotifier")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("UdpNotifier")]
[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("734097b0-a764-40ad-957a-43fe4f085b65")]
// 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")]

View File

@ -0,0 +1,61 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{734097B0-A764-40AD-957A-43FE4F085B65}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>UdpNotifier</RootNamespace>
<AssemblyName>UdpNotifier</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="UdpNotifierProviderFactory.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="UdpNotifierProvider.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Interfaces\Interfaces.csproj">
<Project>{5C6DCC59-19F3-46AD-A479-926610F36257}</Project>
<Name>Interfaces</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@ -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();
}
}
}

View File

@ -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";
}
}
}