add Async method to interface for IPluginLocator

fix async issue causing deadlock.
created ProviderDetails stub to give provider details.
This commit is contained in:
chris.watts90@outlook.com 2017-06-23 13:15:28 +01:00
parent 14e82f65c3
commit 156722e0eb
6 changed files with 36 additions and 20 deletions

View File

@ -1,9 +1,11 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks;
namespace Interfaces namespace Interfaces
{ {
public interface IPluginLocator public interface IPluginLocator
{ {
Task<List<T>> LocateAsync<T>();
List<T> Locate<T>(); List<T> Locate<T>();
} }
} }

View File

@ -52,6 +52,7 @@
<Compile Include="INotifierProviderFactory.cs" /> <Compile Include="INotifierProviderFactory.cs" />
<Compile Include="NotificationEventArgs.cs" /> <Compile Include="NotificationEventArgs.cs" />
<Compile Include="Pilot.cs" /> <Compile Include="Pilot.cs" />
<Compile Include="ProviderDetails.cs" />
<Compile Include="RaceSession.cs" /> <Compile Include="RaceSession.cs" />
<Compile Include="IUserStorage.cs" /> <Compile Include="IUserStorage.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Interfaces
{
public class ProviderDetails
{
public string ProviderName { get; set; }
public string ProviderAuthor { get; set; }
public string ProviderDescription { get; set; }
}
}

View File

@ -11,12 +11,16 @@ namespace RaceLapTimer.Extensions.Notifications
{ {
class NotificationManager : INotifierManager class NotificationManager : INotifierManager
{ {
private readonly List<INotifierProvider> _providers; private List<INotifierProvider> _providers;
public NotificationManager(IPluginPathProvider pluginPath, IContainerHelper helper, IPluginLocator locator)
public NotificationManager(IPluginLocator locator)
{ {
var providerFactories = locator.Locate<INotifierProviderFactory>(); RegisterProviders(locator);
}
//var providerFactories = helper.GetAll<INotifierProviderFactory>().ToList();
private async void RegisterProviders(IPluginLocator locator)
{
var providerFactories = await locator.LocateAsync<INotifierProviderFactory>();
_providers = new List<INotifierProvider>(); _providers = new List<INotifierProvider>();
foreach (var factory in providerFactories) foreach (var factory in providerFactories)
{ {
@ -35,7 +39,6 @@ namespace RaceLapTimer.Extensions.Notifications
{ {
foreach (var provider in _providers) foreach (var provider in _providers)
{ {
//provider.NotifyRaceStarted(args);
Task.Factory.StartNew(() => { provider.NotifyRaceStarted(args); }); Task.Factory.StartNew(() => { provider.NotifyRaceStarted(args); });
} }
} }
@ -90,13 +93,5 @@ namespace RaceLapTimer.Extensions.Notifications
} }
return false; return false;
} }
private class DiscoveredPlugin
{
public string FilePath { get; set; }
public Type PluginType { get; set; }
public Type TypeToBindTo { get; set; }
public string UniqueName { get; set; }
}
} }
} }

View File

@ -20,10 +20,10 @@ namespace RaceLapTimer.Extensions
_pluginPath = pluginPath; _pluginPath = pluginPath;
} }
//public async List<T> Locate<T>() public async Task<List<T>> LocateAsync<T>()
//{ {
// return await Task.Run(()=> Locate<T>()); return await Task.Run(() => Locate<T>());
//} }
public List<T> Locate<T>() public List<T> Locate<T>()
{ {

View File

@ -90,8 +90,10 @@
<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'))" /> <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> </Target>
<PropertyGroup> <PropertyGroup>
<PostBuildEvent>copy /B /Y "$(TargetDir)UdpNotifier.dll" "$(TargetDir)Plugins\UdpNotifier.dll" <PostBuildEvent>copy /B /Y "$(SolutionDir)UdpNotifier\$(OutDir)UdpNotifier.dll" "$(TargetDir)Plugins\UdpNotifier.dll"
copy /B /Y "$(TargetDir)NLogConfig.xml" "$(TargetDir)Configs\NLogConfig.xml"</PostBuildEvent> copy /B /Y "$(SolutionDir)IrDaemonNotifier\$(OutDir)IrDaemonNotifier.dll" "$(TargetDir)Plugins\IrDaemonNotifier.dll"
copy /B /Y "$(TargetDir)NLogConfig.xml" "$(TargetDir)Configs\NLogConfig.xml"
copy /B /Y "$(SolutionDir)RaceLapTimer\$(OutDir)Ninject.Extensions.Xml.dll" "$(TargetDir)Ninject.Extensions.Xml.dll"</PostBuildEvent>
</PropertyGroup> </PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- 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. Other similar extension points exist, see Microsoft.Common.targets.