Make cfgProviders asynchronous

(in a quite bad ways sometimes...)
develop
LEdoian 3 years ago
parent eb7d1dda65
commit 8d1dffc743

@ -77,7 +77,7 @@ namespace QuickPlay
{ {
// TODO: decide sensibly // TODO: decide sensibly
var cfgProvider = new HttpConfigurationProvider(playerConfigUrl); var cfgProvider = new HttpConfigurationProvider(playerConfigUrl);
return cfgProvider.GetConfiguration(); return cfgProvider.GetConfigurationAsync().Result; // Bad code, but hopefully we dont hang.
} }
// We want to compare by values. // We want to compare by values.
@ -131,7 +131,7 @@ namespace QuickPlay
interface IPlayerConfigurationProvider interface IPlayerConfigurationProvider
{ {
PlayerConfiguration GetConfiguration(); Task<PlayerConfiguration> GetConfigurationAsync();
} }
sealed class HttpConfigurationProvider : IPlayerConfigurationProvider sealed class HttpConfigurationProvider : IPlayerConfigurationProvider
@ -141,7 +141,7 @@ namespace QuickPlay
{ {
configUrl = url; configUrl = url;
} }
public async Task<PlayerConfiguration> GetConfiguration() public async Task<PlayerConfiguration> GetConfigurationAsync()
{ {
var client = new HttpClient() ; var client = new HttpClient() ;
var resp = await client.GetStreamAsync(configUrl); var resp = await client.GetStreamAsync(configUrl);
@ -162,15 +162,15 @@ namespace QuickPlay
{ {
this.reader = new StreamReader(filename); this.reader = new StreamReader(filename);
} }
public PlayerConfiguration GetConfiguration() public Task<PlayerConfiguration> GetConfigurationAsync()
{ {
return PlayerConfiguration.FromFile(reader); return Task.FromResult(PlayerConfiguration.FromFile(reader));
} }
} }
sealed class DummyConfigurationProvider : IPlayerConfigurationProvider sealed class DummyConfigurationProvider : IPlayerConfigurationProvider
{ {
public PlayerConfiguration GetConfiguration() => null; public Task<PlayerConfiguration> GetConfigurationAsync() => null;
} }
class Song: IPlayable class Song: IPlayable

@ -60,6 +60,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="Mono.Android" /> <Reference Include="Mono.Android" />
@ -68,6 +69,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Configuration.cs" /> <Compile Include="Configuration.cs" />
<Compile Include="IniParser.cs" />
<Compile Include="Interfaces.cs" /> <Compile Include="Interfaces.cs" />
<Compile Include="MpdMonitorService.cs" /> <Compile Include="MpdMonitorService.cs" />
<Compile Include="MainActivity.cs" /> <Compile Include="MainActivity.cs" />

Loading…
Cancel
Save