From fbe4be554fb16ca4cd37288171c2e086c6f7ee20 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 12 Sep 2021 21:19:58 -0500 Subject: rename ApplicationState to State --- src/slskd/Application/Application.cs | 8 +- src/slskd/Application/ApplicationState.cs | 93 ---------------------- .../API/Controllers/ApplicationController.cs | 4 +- .../API/Controllers/ConfigurationController.cs | 4 +- .../Management/API/Controllers/ServerController.cs | 4 +- .../API/Controllers/ConversationsController.cs | 4 +- .../Messaging/API/Controllers/RoomsController.cs | 4 +- src/slskd/Startup.cs | 2 +- src/slskd/State.cs | 93 ++++++++++++++++++++++ 9 files changed, 108 insertions(+), 108 deletions(-) delete mode 100644 src/slskd/Application/ApplicationState.cs create mode 100644 src/slskd/State.cs (limited to 'src') diff --git a/src/slskd/Application/Application.cs b/src/slskd/Application/Application.cs index 73c82d11..1e5f3584 100644 --- a/src/slskd/Application/Application.cs +++ b/src/slskd/Application/Application.cs @@ -45,7 +45,7 @@ namespace slskd public Application( OptionsAtStartup optionsAtStartup, IOptionsMonitor optionsMonitor, - IManagedState state, + IManagedState state, ITransferTracker transferTracker, IBrowseTracker browseTracker, IConversationTracker conversationTracker, @@ -154,7 +154,7 @@ namespace slskd private IRoomTracker RoomTracker { get; set; } private ISharedFileCache SharedFileCache { get; set; } private DateTime SharesRefreshStarted { get; set; } - private IManagedState State { get; } + private IManagedState State { get; } private ITransferTracker TransferTracker { get; set; } public Task AcknowledgePrivateMessageAsync(int id) => SoulseekClient.AcknowledgePrivateMessageAsync(id); @@ -502,7 +502,7 @@ namespace slskd private void Client_StateChanged(object sender, SoulseekClientStateChangedEventArgs e) { - State.SetValue(state => state with { Server = new ServerState() { Address = Client.Address, IPEndPoint = Client.IPEndPoint, State = Client.State, Username = Client.Username } }); + State.SetValue(state => state with { Server = state.Server with { Address = Client.Address, IPEndPoint = Client.IPEndPoint, State = Client.State, Username = Client.Username } }); } private void Client_TransferProgressUpdated(object sender, TransferProgressUpdatedEventArgs args) @@ -844,7 +844,7 @@ namespace slskd } } - private void State_OnChange((ApplicationState Previous, ApplicationState Current) state) + private void State_OnChange((State Previous, State Current) state) { Logger.Debug("State changed from {Previous} to {Current}", state.Previous.ToJson(), state.Current.ToJson()); } diff --git a/src/slskd/Application/ApplicationState.cs b/src/slskd/Application/ApplicationState.cs deleted file mode 100644 index c9322eb3..00000000 --- a/src/slskd/Application/ApplicationState.cs +++ /dev/null @@ -1,93 +0,0 @@ -// -// Copyright (c) slskd Team. All rights reserved. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published -// by the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see https://www.gnu.org/licenses/. -// - -namespace slskd -{ - using System.Net; - using System.Text.Json.Serialization; - using Soulseek; - - /// - /// Application service state. - /// - public record ApplicationState - { - public VersionState Version { get; init; } = new VersionState(); - public bool PendingReconnect { get; init; } - public bool PendingRestart { get; init; } - public bool PendingShareRescan { get; init; } - public ServerState Server { get; init; } = new ServerState(); - public SharedFileCacheState SharedFileCache { get; init; } = new SharedFileCacheState(); - } - - public record VersionState - { - public string Current { get; init; } = Program.InformationalVersion; - public string Latest { get; init; } = null; - public bool? IsUpdateAvailable { get; init; } = null; - public bool IsCanary { get; init; } = Program.IsCanary; - } - - public record ServerState - { - public string Address { get; init; } - - [JsonConverter(typeof(IPEndPointConverter))] - public IPEndPoint IPEndPoint { get; init; } - public SoulseekClientStates State { get; init; } - public string Username { get; init; } - public bool IsConnected => State.HasFlag(SoulseekClientStates.Connected); - public bool IsLoggedIn => State.HasFlag(SoulseekClientStates.LoggedIn); - public bool IsTransitioning => State.HasFlag(SoulseekClientStates.Connecting) || State.HasFlag(SoulseekClientStates.Disconnecting) || State.HasFlag(SoulseekClientStates.LoggingIn); - } - - /// - /// Share cache state. - /// - public record SharedFileCacheState - { - /// - /// Gets a value indicating whether the cache is being filled. - /// - public bool Filling { get; init; } = false; - - /// - /// Gets a value indicating whether the cache is faulted. - /// - public bool Faulted { get; init; } = false; - - /// - /// Gets the current fill progress. - /// - public double FillProgress { get; init; } - - /// - /// Gets the number of cached directories. - /// - public int Directories { get; init; } - - /// - /// Gets the number of cached files. - /// - public int Files { get; init; } - - /// - /// Gets the number of directories excluded by filters. - /// - public int ExcludedDirectories { get; init; } - } -} \ No newline at end of file diff --git a/src/slskd/Application/Management/API/Controllers/ApplicationController.cs b/src/slskd/Application/Management/API/Controllers/ApplicationController.cs index 8115b3fc..470e5a30 100644 --- a/src/slskd/Application/Management/API/Controllers/ApplicationController.cs +++ b/src/slskd/Application/Management/API/Controllers/ApplicationController.cs @@ -37,7 +37,7 @@ namespace slskd.Management.API public ApplicationController( IHostApplicationLifetime lifetime, IApplication application, - IStateMonitor applicationStateMonitor) + IStateMonitor applicationStateMonitor) { Lifetime = lifetime; Application = application; @@ -45,7 +45,7 @@ namespace slskd.Management.API } private IApplication Application { get; } - private IStateMonitor ApplicationStateMonitor { get; } + private IStateMonitor ApplicationStateMonitor { get; } private IHostApplicationLifetime Lifetime { get; } /// diff --git a/src/slskd/Application/Management/API/Controllers/ConfigurationController.cs b/src/slskd/Application/Management/API/Controllers/ConfigurationController.cs index b8c81f84..c28c5c7e 100644 --- a/src/slskd/Application/Management/API/Controllers/ConfigurationController.cs +++ b/src/slskd/Application/Management/API/Controllers/ConfigurationController.cs @@ -36,7 +36,7 @@ namespace slskd.Management.API public ConfigurationController( IApplication application, IOptionsSnapshot optionsShapshot, - IStateMonitor applicationStateMonitor) + IStateMonitor applicationStateMonitor) { Application = application; OptionsShapshot = optionsShapshot; @@ -45,7 +45,7 @@ namespace slskd.Management.API private IApplication Application { get; } private IOptionsSnapshot OptionsShapshot { get; } - private IStateMonitor ApplicationStateMonitor { get; } + private IStateMonitor ApplicationStateMonitor { get; } [HttpGet] [Route("")] diff --git a/src/slskd/Application/Management/API/Controllers/ServerController.cs b/src/slskd/Application/Management/API/Controllers/ServerController.cs index 127b59c0..f929b46e 100644 --- a/src/slskd/Application/Management/API/Controllers/ServerController.cs +++ b/src/slskd/Application/Management/API/Controllers/ServerController.cs @@ -33,14 +33,14 @@ namespace slskd.Management.API { public ServerController( IApplication application, - IStateMonitor applicationStateMonitor) + IStateMonitor applicationStateMonitor) { Application = application; ApplicationStateMonitor = applicationStateMonitor; } private IApplication Application { get; } - private IStateMonitor ApplicationStateMonitor { get; } + private IStateMonitor ApplicationStateMonitor { get; } /// /// Connects the client. diff --git a/src/slskd/Application/Messaging/API/Controllers/ConversationsController.cs b/src/slskd/Application/Messaging/API/Controllers/ConversationsController.cs index b3c07690..961b8ca8 100644 --- a/src/slskd/Application/Messaging/API/Controllers/ConversationsController.cs +++ b/src/slskd/Application/Messaging/API/Controllers/ConversationsController.cs @@ -42,7 +42,7 @@ namespace slskd.Messaging.API /// public ConversationsController( IApplication application, - IStateMonitor applicationStateMonotor, + IStateMonitor applicationStateMonotor, IConversationTracker tracker) { Application = application; @@ -51,7 +51,7 @@ namespace slskd.Messaging.API } private IApplication Application { get; } - private IStateMonitor ApplicationStateMonitor { get; } + private IStateMonitor ApplicationStateMonitor { get; } private IConversationTracker Tracker { get; } /// diff --git a/src/slskd/Application/Messaging/API/Controllers/RoomsController.cs b/src/slskd/Application/Messaging/API/Controllers/RoomsController.cs index d7b605d1..07b58f6f 100644 --- a/src/slskd/Application/Messaging/API/Controllers/RoomsController.cs +++ b/src/slskd/Application/Messaging/API/Controllers/RoomsController.cs @@ -38,7 +38,7 @@ namespace slskd.Messaging.API { public RoomsController( IApplication application, - IStateMonitor applicationStateMonitor, + IStateMonitor applicationStateMonitor, IRoomTracker tracker) { Application = application; @@ -47,7 +47,7 @@ namespace slskd.Messaging.API } private IApplication Application { get; } - private IStateMonitor ApplicationStateMonitor { get; } + private IStateMonitor ApplicationStateMonitor { get; } private IRoomTracker Tracker { get; } /// diff --git a/src/slskd/Startup.cs b/src/slskd/Startup.cs index 1f6f2878..c03f8603 100644 --- a/src/slskd/Startup.cs +++ b/src/slskd/Startup.cs @@ -104,7 +104,7 @@ namespace slskd return true; }); - services.AddManagedState(state => state with { Version = state.Version with { Current = "9000" } }); + services.AddManagedState(state => state with { Version = state.Version with { Current = "9000" } }); services.AddCors(options => options.AddPolicy("AllowAll", builder => builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader())); diff --git a/src/slskd/State.cs b/src/slskd/State.cs new file mode 100644 index 00000000..d87761ca --- /dev/null +++ b/src/slskd/State.cs @@ -0,0 +1,93 @@ +// +// Copyright (c) slskd Team. All rights reserved. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published +// by the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see https://www.gnu.org/licenses/. +// + +namespace slskd +{ + using System.Net; + using System.Text.Json.Serialization; + using Soulseek; + + /// + /// Application service state. + /// + public record State + { + public VersionState Version { get; init; } = new VersionState(); + public bool PendingReconnect { get; init; } + public bool PendingRestart { get; init; } + public bool PendingShareRescan { get; init; } + public ServerState Server { get; init; } = new ServerState(); + public SharedFileCacheState SharedFileCache { get; init; } = new SharedFileCacheState(); + } + + public record VersionState + { + public string Current { get; init; } = Program.InformationalVersion; + public string Latest { get; init; } = null; + public bool? IsUpdateAvailable { get; init; } = null; + public bool IsCanary { get; init; } = Program.IsCanary; + } + + public record ServerState + { + public string Address { get; init; } + + [JsonConverter(typeof(IPEndPointConverter))] + public IPEndPoint IPEndPoint { get; init; } + public SoulseekClientStates State { get; init; } + public string Username { get; init; } + public bool IsConnected => State.HasFlag(SoulseekClientStates.Connected); + public bool IsLoggedIn => State.HasFlag(SoulseekClientStates.LoggedIn); + public bool IsTransitioning => State.HasFlag(SoulseekClientStates.Connecting) || State.HasFlag(SoulseekClientStates.Disconnecting) || State.HasFlag(SoulseekClientStates.LoggingIn); + } + + /// + /// Share cache state. + /// + public record SharedFileCacheState + { + /// + /// Gets a value indicating whether the cache is being filled. + /// + public bool Filling { get; init; } = false; + + /// + /// Gets a value indicating whether the cache is faulted. + /// + public bool Faulted { get; init; } = false; + + /// + /// Gets the current fill progress. + /// + public double FillProgress { get; init; } + + /// + /// Gets the number of cached directories. + /// + public int Directories { get; init; } + + /// + /// Gets the number of cached files. + /// + public int Files { get; init; } + + /// + /// Gets the number of directories excluded by filters. + /// + public int ExcludedDirectories { get; init; } + } +} \ No newline at end of file -- cgit v1.2.3