.net 6 for library, changing event firing on watcher
This commit is contained in:
parent
46b7cb37bd
commit
7fe603ab3d
@ -72,7 +72,7 @@ namespace Selector.CLI
|
|||||||
|
|
||||||
var watcherIndices = await InitInstances();
|
var watcherIndices = await InitInstances();
|
||||||
|
|
||||||
Logger.LogInformation($"Starting {watcherIndices.Count()} affected watcher collection(s)...");
|
Logger.LogInformation("Starting {count} affected watcher collection(s)...", watcherIndices.Count());
|
||||||
StartWatcherCollections(watcherIndices);
|
StartWatcherCollections(watcherIndices);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,7 +87,7 @@ namespace Selector.CLI
|
|||||||
.Include(w => w.User)
|
.Include(w => w.User)
|
||||||
.Where(w => !string.IsNullOrWhiteSpace(w.User.SpotifyRefreshToken)))
|
.Where(w => !string.IsNullOrWhiteSpace(w.User.SpotifyRefreshToken)))
|
||||||
{
|
{
|
||||||
Logger.LogInformation($"Creating new [{dbWatcher.Type}] watcher");
|
Logger.LogInformation("Creating new [{type}] watcher", dbWatcher.Type);
|
||||||
|
|
||||||
var watcherCollectionIdx = dbWatcher.UserId;
|
var watcherCollectionIdx = dbWatcher.UserId;
|
||||||
indices.Add(watcherCollectionIdx);
|
indices.Add(watcherCollectionIdx);
|
||||||
@ -118,7 +118,7 @@ namespace Selector.CLI
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Logger.LogDebug($"[{dbWatcher.User.UserName}] No Last.fm username, skipping play counter");
|
Logger.LogDebug("[{username}] No Last.fm username, skipping play counter", dbWatcher.User.UserName);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@ -140,12 +140,12 @@ namespace Selector.CLI
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Logger.LogInformation($"Starting watcher collection [{index}]");
|
Logger.LogInformation("Starting watcher collection [{index}]", index);
|
||||||
Watchers[index].Start();
|
Watchers[index].Start();
|
||||||
}
|
}
|
||||||
catch (KeyNotFoundException)
|
catch (KeyNotFoundException)
|
||||||
{
|
{
|
||||||
Logger.LogError($"Unable to retrieve watcher collection [{index}] when starting");
|
Logger.LogError("Unable to retrieve watcher collection [{index}] when starting", index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -156,7 +156,7 @@ namespace Selector.CLI
|
|||||||
|
|
||||||
foreach((var key, var watcher) in Watchers)
|
foreach((var key, var watcher) in Watchers)
|
||||||
{
|
{
|
||||||
Logger.LogInformation($"Stopping watcher collection [{key}]");
|
Logger.LogInformation("Stopping watcher collection [{key}]", key);
|
||||||
watcher.Stop();
|
watcher.Stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ namespace Selector.CLI
|
|||||||
|
|
||||||
var watcherIndices = await InitInstances();
|
var watcherIndices = await InitInstances();
|
||||||
|
|
||||||
Logger.LogInformation($"Starting {watcherIndices.Count()} affected watcher collection(s)...");
|
Logger.LogInformation("Starting {count} affected watcher collection(s)...", watcherIndices.Count());
|
||||||
StartWatcherCollections(watcherIndices);
|
StartWatcherCollections(watcherIndices);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,12 +145,12 @@ namespace Selector.CLI
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Logger.LogInformation($"Starting watcher collection [{index}]");
|
Logger.LogInformation("Starting watcher collection [{index}]", index);
|
||||||
Watchers[index].Start();
|
Watchers[index].Start();
|
||||||
}
|
}
|
||||||
catch (KeyNotFoundException)
|
catch (KeyNotFoundException)
|
||||||
{
|
{
|
||||||
Logger.LogError($"Unable to retrieve watcher collection [{index}] when starting");
|
Logger.LogError("Unable to retrieve watcher collection [{index}] when starting", index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -161,7 +161,7 @@ namespace Selector.CLI
|
|||||||
|
|
||||||
foreach((var key, var watcher) in Watchers)
|
foreach((var key, var watcher) in Watchers)
|
||||||
{
|
{
|
||||||
Logger.LogInformation($"Stopping watcher collection [{key}]");
|
Logger.LogInformation("Stopping watcher collection [{key}]", key);
|
||||||
watcher.Stop();
|
watcher.Stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
<PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="6.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="6.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="6.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="6.0.0" />
|
||||||
<PackageReference Include="NLog" Version="4.7.12" />
|
<PackageReference Include="NLog" Version="4.7.13" />
|
||||||
<PackageReference Include="NLog.Extensions.Logging" Version="1.7.4" />
|
<PackageReference Include="NLog.Extensions.Logging" Version="1.7.4" />
|
||||||
<PackageReference Include="SpotifyAPI.Web" Version="6.2.2" />
|
<PackageReference Include="SpotifyAPI.Web" Version="6.2.2" />
|
||||||
<PackageReference Include="System.CommandLine" Version="2.0.0-beta1.21308.1" />
|
<PackageReference Include="System.CommandLine" Version="2.0.0-beta1.21308.1" />
|
||||||
|
@ -12,15 +12,18 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.2.0" />
|
<PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.2.0" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="6.0.0" />
|
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="6.0.1" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="6.0.0" />
|
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="6.0.1" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.0" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.1" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.0">
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.1">
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.0" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.1">
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="6.0.0" />
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="6.0.1" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />
|
||||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="6.0.1" />
|
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="6.0.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
@ -13,13 +13,13 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="6.0.0" />
|
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="6.0.1" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="6.0.0" />
|
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="6.0.1" />
|
||||||
|
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="6.0.0" />
|
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="6.0.1" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.2.0" />
|
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.2.0" />
|
||||||
|
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.0">
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.1">
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
@ -27,8 +27,8 @@
|
|||||||
<PackageReference Include="Microsoft.Extensions.Hosting.Systemd" Version="6.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Hosting.Systemd" Version="6.0.0" />
|
||||||
|
|
||||||
<PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="6.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="6.0.0" />
|
||||||
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="6.0.0" />
|
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="6.0.1" />
|
||||||
<PackageReference Include="NLog" Version="4.7.12" />
|
<PackageReference Include="NLog" Version="4.7.13" />
|
||||||
<PackageReference Include="NLog.Extensions.Logging" Version="1.7.4" />
|
<PackageReference Include="NLog.Extensions.Logging" Version="1.7.4" />
|
||||||
<PackageReference Include="NLog.Web.AspNetCore" Version="4.14.0" />
|
<PackageReference Include="NLog.Web.AspNetCore" Version="4.14.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
@ -74,6 +74,10 @@ namespace Selector
|
|||||||
{
|
{
|
||||||
Logger.LogDebug($"Ignoring podcast episdoe [{episode.DisplayString()}]");
|
Logger.LogDebug($"Ignoring podcast episdoe [{episode.DisplayString()}]");
|
||||||
}
|
}
|
||||||
|
else if (e.Current.Item is null)
|
||||||
|
{
|
||||||
|
Logger.LogDebug($"Skipping audio feature pulling for null item [{e.Current.DisplayString()}]");
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Logger.LogError($"Unknown item pulled from API [{e.Current.Item}]");
|
Logger.LogError($"Unknown item pulled from API [{e.Current.Item}]");
|
||||||
|
@ -141,6 +141,10 @@ namespace Selector
|
|||||||
{
|
{
|
||||||
Logger.LogDebug($"Ignoring podcast episdoe [{episode.DisplayString()}]");
|
Logger.LogDebug($"Ignoring podcast episdoe [{episode.DisplayString()}]");
|
||||||
}
|
}
|
||||||
|
else if (e.Current.Item is null)
|
||||||
|
{
|
||||||
|
Logger.LogDebug($"Skipping play count pulling for null item [{e.Current.DisplayString()}]");
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Logger.LogError($"Unknown item pulled from API [{e.Current.Item}]");
|
Logger.LogError($"Unknown item pulled from API [{e.Current.Item}]");
|
||||||
|
@ -21,15 +21,15 @@ namespace Selector
|
|||||||
|
|
||||||
if (currentPlaying.Item is FullTrack track)
|
if (currentPlaying.Item is FullTrack track)
|
||||||
{
|
{
|
||||||
return $"{currentPlaying.IsPlaying}, {track.DisplayString()}, {currentPlaying.Device?.DisplayString()}";
|
return $"{currentPlaying.IsPlaying}, {track.DisplayString()}, {currentPlaying.Device?.DisplayString() ?? "no device"}, {currentPlaying?.Context?.DisplayString() ?? "no context"}";
|
||||||
}
|
}
|
||||||
else if (currentPlaying.Item is FullEpisode episode)
|
else if (currentPlaying.Item is FullEpisode episode)
|
||||||
{
|
{
|
||||||
return $"{currentPlaying.IsPlaying}, {episode.DisplayString()}, {currentPlaying.Device?.DisplayString()}";
|
return $"{currentPlaying.IsPlaying}, {episode.DisplayString()}, {currentPlaying.Device?.DisplayString() ?? "no device"}";
|
||||||
}
|
}
|
||||||
else if (currentPlaying.Item is null)
|
else if (currentPlaying.Item is null)
|
||||||
{
|
{
|
||||||
return $"{currentPlaying.IsPlaying}, no item, {currentPlaying.Device?.DisplayString()}";
|
return $"{currentPlaying.IsPlaying}, no item, {currentPlaying.Device?.DisplayString() ?? "no device"}";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>netstandard2.1</TargetFramework>
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
<EnableDefaultCompileItems>true</EnableDefaultCompileItems>
|
<EnableDefaultCompileItems>true</EnableDefaultCompileItems>
|
||||||
<LangVersion>latest</LangVersion>
|
<LangVersion>latest</LangVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
@ -29,7 +29,16 @@ namespace Selector
|
|||||||
Logger.LogDebug("Starting watcher");
|
Logger.LogDebug("Starting watcher");
|
||||||
while (true) {
|
while (true) {
|
||||||
cancelToken.ThrowIfCancellationRequested();
|
cancelToken.ThrowIfCancellationRequested();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
await WatchOne(cancelToken);
|
await WatchOne(cancelToken);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Logger.LogError(ex, "Exception occured while conducting single poll operation");
|
||||||
|
}
|
||||||
|
|
||||||
Logger.LogTrace($"Finished watch one, delaying {PollPeriod}ms...");
|
Logger.LogTrace($"Finished watch one, delaying {PollPeriod}ms...");
|
||||||
await Task.Delay(PollPeriod, cancelToken);
|
await Task.Delay(PollPeriod, cancelToken);
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,7 @@ namespace Selector
|
|||||||
try{
|
try{
|
||||||
Logger.LogTrace("Making Spotify call");
|
Logger.LogTrace("Making Spotify call");
|
||||||
var polledCurrent = await spotifyClient.GetCurrentPlayback();
|
var polledCurrent = await spotifyClient.GetCurrentPlayback();
|
||||||
Logger.LogTrace($"Received Spotify call [{polledCurrent?.DisplayString()}]");
|
Logger.LogTrace("Received Spotify call [{context}]", polledCurrent?.DisplayString());
|
||||||
|
|
||||||
if (polledCurrent != null) StoreCurrentPlaying(polledCurrent);
|
if (polledCurrent != null) StoreCurrentPlaying(polledCurrent);
|
||||||
|
|
||||||
@ -76,17 +76,38 @@ namespace Selector
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// STARTED PLAYBACK
|
// STARTED PLAYBACK
|
||||||
|
if(Previous?.Context is null && Live?.Context is not null)
|
||||||
|
{
|
||||||
|
Logger.LogDebug("Context started: {context}", Live?.Context.DisplayString());
|
||||||
|
OnContextChange(GetEvent());
|
||||||
|
}
|
||||||
|
|
||||||
|
if(Previous?.Item is null && Live?.Item is not null)
|
||||||
|
{
|
||||||
|
if (Live.Item is FullTrack track)
|
||||||
|
{
|
||||||
|
Logger.LogDebug("Item started: {track}", track.DisplayString());
|
||||||
|
}
|
||||||
|
else if (Live.Item is FullEpisode episode)
|
||||||
|
{
|
||||||
|
Logger.LogDebug("Item started: {episode}", episode.DisplayString());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Logger.LogDebug("Item started: {item}", Live.Item);
|
||||||
|
}
|
||||||
|
OnItemChange(GetEvent());
|
||||||
|
}
|
||||||
|
|
||||||
if(Previous is null && Live is not null)
|
if(Previous is null && Live is not null)
|
||||||
{
|
{
|
||||||
Logger.LogDebug($"Playback started: {Live.DisplayString()}");
|
Logger.LogDebug("Playback started: {context}", Live.DisplayString());
|
||||||
OnPlayingChange(GetEvent());
|
OnPlayingChange(GetEvent());
|
||||||
OnItemChange(GetEvent());
|
|
||||||
OnContextChange(GetEvent());
|
|
||||||
}
|
}
|
||||||
// STOPPED PLAYBACK
|
// STOPPED PLAYBACK
|
||||||
else if(Previous is not null && Live is null)
|
else if(Previous is not null && Live is null)
|
||||||
{
|
{
|
||||||
Logger.LogDebug($"Playback stopped: {Previous.DisplayString()}");
|
Logger.LogDebug("Playback stopped: {context}", Previous.DisplayString());
|
||||||
OnPlayingChange(GetEvent());
|
OnPlayingChange(GetEvent());
|
||||||
OnItemChange(GetEvent());
|
OnItemChange(GetEvent());
|
||||||
OnContextChange(GetEvent());
|
OnContextChange(GetEvent());
|
||||||
@ -99,7 +120,7 @@ namespace Selector
|
|||||||
&& Live.Item is FullTrack currentTrack)
|
&& Live.Item is FullTrack currentTrack)
|
||||||
{
|
{
|
||||||
if(!eq.IsEqual(previousTrack, currentTrack)) {
|
if(!eq.IsEqual(previousTrack, currentTrack)) {
|
||||||
Logger.LogDebug($"Track changed: {previousTrack.DisplayString()} -> {currentTrack.DisplayString()}");
|
Logger.LogDebug("Track changed: {prevTrack} -> {currentTrack}", previousTrack.DisplayString(), currentTrack.DisplayString());
|
||||||
OnItemChange(GetEvent());
|
OnItemChange(GetEvent());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,11 +153,11 @@ namespace Selector
|
|||||||
}
|
}
|
||||||
else if (Previous.Item is null)
|
else if (Previous.Item is null)
|
||||||
{
|
{
|
||||||
Logger.LogWarning($"Previous item was null [{Previous.DisplayString()}]");
|
Logger.LogTrace($"Previous item was null [{Previous.DisplayString()}]");
|
||||||
}
|
}
|
||||||
else if (Live.Item is null)
|
else if (Live.Item is null)
|
||||||
{
|
{
|
||||||
Logger.LogWarning($"Live item was null [{Live.DisplayString()}]");
|
Logger.LogTrace($"Live item was null [{Live.DisplayString()}]");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Logger.LogError($"Unknown combination of previous and current playing contexts, [{Previous.DisplayString()}] [{Live.DisplayString()}]");
|
Logger.LogError($"Unknown combination of previous and current playing contexts, [{Previous.DisplayString()}] [{Live.DisplayString()}]");
|
||||||
|
Loading…
Reference in New Issue
Block a user