2021-12-18 11:18:35 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace PettingZoo.Core.Settings
|
|
|
|
|
{
|
|
|
|
|
public interface IConnectionSettingsRepository
|
|
|
|
|
{
|
2021-12-18 17:40:22 +00:00
|
|
|
|
Task<StoredConnectionSettings> GetLastUsed();
|
|
|
|
|
Task StoreLastUsed(bool storePassword, ConnectionSettings connectionSettings);
|
2021-12-18 11:18:35 +00:00
|
|
|
|
|
|
|
|
|
Task<IEnumerable<StoredConnectionSettings>> GetStored();
|
2021-12-18 17:40:22 +00:00
|
|
|
|
Task<StoredConnectionSettings> Add(string displayName, bool storePassword, ConnectionSettings connectionSettings);
|
|
|
|
|
Task<StoredConnectionSettings> Update(Guid id, string displayName, bool storePassword, ConnectionSettings connectionSettings);
|
2021-12-18 11:18:35 +00:00
|
|
|
|
Task Delete(Guid id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class ConnectionSettings
|
|
|
|
|
{
|
|
|
|
|
public string Host { get; }
|
|
|
|
|
public string VirtualHost { get; }
|
|
|
|
|
public int Port { get; }
|
|
|
|
|
public string Username { get; }
|
2021-12-18 17:40:22 +00:00
|
|
|
|
public string Password { get; }
|
2021-12-18 11:18:35 +00:00
|
|
|
|
|
|
|
|
|
public bool Subscribe { get; }
|
|
|
|
|
public string Exchange { get; }
|
|
|
|
|
public string RoutingKey { get; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static readonly ConnectionSettings Default = new("localhost", "/", 5672, "guest", "guest", false, "", "#");
|
|
|
|
|
|
|
|
|
|
|
2021-12-18 17:40:22 +00:00
|
|
|
|
public ConnectionSettings(string host, string virtualHost, int port, string username, string password,
|
2021-12-18 11:18:35 +00:00
|
|
|
|
bool subscribe, string exchange, string routingKey)
|
|
|
|
|
{
|
|
|
|
|
Host = host;
|
|
|
|
|
VirtualHost = virtualHost;
|
|
|
|
|
Port = port;
|
|
|
|
|
Username = username;
|
|
|
|
|
Password = password;
|
|
|
|
|
|
|
|
|
|
Subscribe = subscribe;
|
|
|
|
|
Exchange = exchange;
|
|
|
|
|
RoutingKey = routingKey;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public bool SameParameters(ConnectionSettings value, bool comparePassword = true)
|
|
|
|
|
{
|
|
|
|
|
return Host == value.Host &&
|
|
|
|
|
VirtualHost == value.VirtualHost &&
|
|
|
|
|
Port == value.Port &&
|
|
|
|
|
Username == value.Username &&
|
|
|
|
|
(!comparePassword || Password == value.Password) &&
|
|
|
|
|
Subscribe == value.Subscribe &&
|
|
|
|
|
Exchange == value.Exchange &&
|
|
|
|
|
RoutingKey == value.RoutingKey;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class StoredConnectionSettings : ConnectionSettings
|
|
|
|
|
{
|
|
|
|
|
public Guid Id { get; }
|
|
|
|
|
public string DisplayName { get; }
|
2021-12-18 17:40:22 +00:00
|
|
|
|
public bool StorePassword { get; }
|
2021-12-18 11:18:35 +00:00
|
|
|
|
|
2021-12-18 17:40:22 +00:00
|
|
|
|
|
|
|
|
|
public StoredConnectionSettings(Guid id, string displayName, bool storePassword, string host, string virtualHost, int port, string username,
|
|
|
|
|
string password, bool subscribe, string exchange, string routingKey)
|
2021-12-18 11:18:35 +00:00
|
|
|
|
: base(host, virtualHost, port, username, password, subscribe, exchange, routingKey)
|
|
|
|
|
{
|
|
|
|
|
Id = id;
|
|
|
|
|
DisplayName = displayName;
|
2021-12-18 17:40:22 +00:00
|
|
|
|
StorePassword = storePassword;
|
2021-12-18 11:18:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-12-18 17:40:22 +00:00
|
|
|
|
public StoredConnectionSettings(Guid id, string displayName, bool storePassword, ConnectionSettings connectionSettings)
|
|
|
|
|
: base(connectionSettings.Host, connectionSettings.VirtualHost, connectionSettings.Port, connectionSettings.Username,
|
|
|
|
|
connectionSettings.Password, connectionSettings.Subscribe, connectionSettings.Exchange, connectionSettings.RoutingKey)
|
2021-12-18 11:18:35 +00:00
|
|
|
|
{
|
|
|
|
|
Id = id;
|
|
|
|
|
DisplayName = displayName;
|
2021-12-18 17:40:22 +00:00
|
|
|
|
StorePassword = storePassword;
|
2021-12-18 11:18:35 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|