/
ServiceState.cs
46 lines (38 loc) · 1.39 KB
/
ServiceState.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.Text;
namespace Microsoft.Extensions.Hosting.Systemd
{
/// <summary>
/// Describes a service state change.
/// </summary>
public struct ServiceState
{
private readonly byte[] _data;
/// <summary>
/// Service startup is finished.
/// </summary>
public static readonly ServiceState Ready = new ServiceState("READY=1");
/// <summary>
/// Service is beginning its shutdown.
/// </summary>
public static readonly ServiceState Stopping = new ServiceState("STOPPING=1");
/// <summary>
/// Create custom ServiceState.
/// </summary>
/// <param name="state">A <see cref="string"/> representation of service state.</param>
public ServiceState(string state)
{
ThrowHelper.ThrowIfNull(state);
_data = Encoding.UTF8.GetBytes(state);
}
/// <summary>
/// String representation of service state.
/// </summary>
/// <returns>The <see cref="string"/> representation of the service state.</returns>
public override string ToString()
=> _data == null ? string.Empty : Encoding.UTF8.GetString(_data);
internal byte[] GetData() => _data;
}
}