using System.Globalization;
using Umbraco.Cms.Core.Models.Entities;
using Umbraco.Extensions;
namespace Umbraco.Cms.Core.Models;
///
/// Represents a registered server in a multiple-servers environment.
///
public class ServerRegistration : EntityBase, IServerRegistration
{
private bool _isActive;
private bool _isSchedulingPublisher;
private string? _serverAddress;
private string? _serverIdentity;
///
/// Initializes a new instance of the class.
///
public ServerRegistration()
{
}
///
/// Initializes a new instance of the class.
///
/// The unique id of the server registration.
/// The server URL.
/// The unique server identity.
/// The date and time the registration was created.
/// The date and time the registration was last accessed.
/// A value indicating whether the registration is active.
/// A value indicating whether the registration is scheduling publisher.
public ServerRegistration(int id, string? serverAddress, string? serverIdentity, DateTime registered, DateTime accessed, bool isActive, bool isSchedulingPublisher)
{
UpdateDate = accessed;
CreateDate = registered;
Key = id.ToString(CultureInfo.InvariantCulture).EncodeAsGuid();
Id = id;
ServerAddress = serverAddress;
ServerIdentity = serverIdentity;
IsActive = isActive;
IsSchedulingPublisher = isSchedulingPublisher;
}
///
/// Initializes a new instance of the class.
///
/// The server URL.
/// The unique server identity.
/// The date and time the registration was created.
public ServerRegistration(string serverAddress, string serverIdentity, DateTime registered)
{
CreateDate = registered;
UpdateDate = registered;
Key = 0.ToString(CultureInfo.InvariantCulture).EncodeAsGuid();
ServerAddress = serverAddress;
ServerIdentity = serverIdentity;
}
///
/// Gets or sets the server URL.
///
public string? ServerAddress
{
get => _serverAddress;
set => SetPropertyValueAndDetectChanges(value, ref _serverAddress, nameof(ServerAddress));
}
///
/// Gets or sets the server unique identity.
///
public string? ServerIdentity
{
get => _serverIdentity;
set => SetPropertyValueAndDetectChanges(value, ref _serverIdentity, nameof(ServerIdentity));
}
///
/// Gets or sets a value indicating whether the server is active.
///
public bool IsActive
{
get => _isActive;
set => SetPropertyValueAndDetectChanges(value, ref _isActive, nameof(IsActive));
}
///
/// Gets or sets a value indicating whether the server has the SchedulingPublisher role
///
public bool IsSchedulingPublisher
{
get => _isSchedulingPublisher;
set => SetPropertyValueAndDetectChanges(value, ref _isSchedulingPublisher, nameof(IsSchedulingPublisher));
}
///
/// Gets the date and time the registration was created.
///
public DateTime Registered
{
get => CreateDate;
set => CreateDate = value;
}
///
/// Gets the date and time the registration was last accessed.
///
public DateTime Accessed
{
get => UpdateDate;
set => UpdateDate = value;
}
///
/// Converts the value of this instance to its equivalent string representation.
///
///
public override string ToString() => string.Format("{{\"{0}\", \"{1}\", {2}active, {3}master}}", ServerAddress, ServerIdentity, IsActive ? string.Empty : "!", IsSchedulingPublisher ? string.Empty : "!");
}