From 1e87c47a84ab5b2188fb34aa642b8bae123dc2d3 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Thu, 13 Oct 2022 09:42:06 -0500 Subject: add Host types --- src/slskd/Shares/Types/Host.cs | 69 +++++++++++++++++++++++++++++++++++++ src/slskd/Shares/Types/HostState.cs | 35 +++++++++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 src/slskd/Shares/Types/Host.cs create mode 100644 src/slskd/Shares/Types/HostState.cs (limited to 'src') diff --git a/src/slskd/Shares/Types/Host.cs b/src/slskd/Shares/Types/Host.cs new file mode 100644 index 00000000..45706b23 --- /dev/null +++ b/src/slskd/Shares/Types/Host.cs @@ -0,0 +1,69 @@ +// +// 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.Shares +{ + using System.Collections.Generic; + using System.Linq; + + /// + /// A share host. + /// + public class Host + { + /// + /// Initializes a new instance of the class. + /// + /// The name of the host. + /// The collection of hosted shares. + /// The initial state of the host. + public Host(string name, IEnumerable shares = null, HostState state = HostState.Offline) + { + Name = name; + Shares = shares ?? Enumerable.Empty(); + State = state; + } + + /// + /// Gets the name of the host. + /// + /// Corresponds to the configured of the host. + public string Name { get; } + + /// + /// Gets the collection of hosted shares. + /// + public IEnumerable Shares { get; private set; } + + /// + /// Gets the host state. + /// + public HostState State { get; private set; } + + /// + /// Sets the hosted shares for the host. + /// + /// The collection of shares. + public void SetShares(IEnumerable shares) => Shares = shares; + + /// + /// Sets the state of the host. + /// + /// The new state. + public void SetState(HostState state) => State = state; + } +} \ No newline at end of file diff --git a/src/slskd/Shares/Types/HostState.cs b/src/slskd/Shares/Types/HostState.cs new file mode 100644 index 00000000..b10074d3 --- /dev/null +++ b/src/slskd/Shares/Types/HostState.cs @@ -0,0 +1,35 @@ +// +// 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.Shares +{ + /// + /// The state of a share host. + /// + public enum HostState + { + /// + /// Offline; unable to service requests. + /// + Offline = 0, + + /// + /// Online; able to service requests. + /// + Online = 1, + } +} -- cgit v1.2.3