using System;
using System.Diagnostics;
using System.Globalization;
namespace Octokit
{
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public class UpdateMaintenanceRequest : FormUrlEncodedParameters
{
///
/// Maintenance request with default details (results in Maintenance mode being turned off immediately)
///
public UpdateMaintenanceRequest()
{
Maintenance = new UpdateMaintenanceRequestDetails();
}
///
/// Maintenance request with specific details
///
public UpdateMaintenanceRequest(UpdateMaintenanceRequestDetails maintenance)
{
Ensure.ArgumentNotNull(maintenance, "maintenance");
Maintenance = maintenance;
}
///
/// Details for the maintenance request
///
public UpdateMaintenanceRequestDetails Maintenance { get; protected set; }
internal string DebuggerDisplay
{
get
{
return string.Format(CultureInfo.InvariantCulture, "Maintenance: {0}", this.Maintenance.DebuggerDisplay);
}
}
}
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public class UpdateMaintenanceRequestDetails
{
///
/// Maintenance request details with default values (results in Maintenance mode being turned off immediately)
///
public UpdateMaintenanceRequestDetails()
{ }
///
/// Maintenance request details to enable/disable maintenance mode immediately
///
/// true to enable, false to disable
public UpdateMaintenanceRequestDetails(bool enabled)
{
Enabled = enabled;
When = "now";
}
///
/// Maintenance request details to enable/disable maintenance at a specified time (only applicable when enabling maintenance)
///
/// true to enable, false to disable
/// A phrase specifying when maintenance mode will be enabled. Phrase uses humanized forms supported by the mojombo/chronic library used by the GitHub API
/// such as "this friday at 5pm" or "5 minutes before midday tomorrow"
/// If enabled is false, the when parameter is ignored and maintenance is turned off immediately
public UpdateMaintenanceRequestDetails(bool enabled, string when)
{
Ensure.ArgumentNotNullOrEmptyString(when, "when");
Enabled = enabled;
When = when;
}
///
/// Maintenance request details to enable/disable maintenance at a specified time (only applicable when enabling maintenance)
///
/// true to enable, false to disable
/// A specifying when maintenance mode will be enabled.
/// If enabled is false, the when parameter is ignored and maintenance is turned off immediately
public UpdateMaintenanceRequestDetails(bool enabled, DateTimeOffset when)
{
Enabled = enabled;
When = when.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ",
CultureInfo.InvariantCulture);
}
///
/// Whether maintenance mode is enabled or disabled
///
public bool Enabled { get; protected set; }
///
/// When maintenance mode will take effect (only applicable when enabling maintenance)
///
public string When { get; protected set; }
internal string DebuggerDisplay
{
get
{
return string.Format(CultureInfo.InvariantCulture, "Enabled: {0} When: {1}", this.Enabled, this.When);
}
}
}
}