-
Notifications
You must be signed in to change notification settings - Fork 471
Expand file tree
/
Copy pathLocalRepoRegistration.cs
More file actions
64 lines (57 loc) · 2.45 KB
/
Copy pathLocalRepoRegistration.cs
File metadata and controls
64 lines (57 loc) · 2.45 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using System.Text.Json;
using System.Text.Json.Serialization;
namespace GVFS.Common
{
/// <summary>
/// One entry in the user-level repo registry on disk. Field set and
/// JSON shape MUST match GVFS.Service.RepoRegistration so that the
/// user-level registry file (written by <see cref="LocalRepoRegistry"/>)
/// is wire-compatible with any registry the legacy service has written
/// in the past. If a new field is added here, the same field must also
/// be added to GVFS.Service.RepoRegistration (and vice versa) along
/// with a registry-format-version bump.
/// </summary>
public class LocalRepoRegistration
{
public LocalRepoRegistration()
{
}
public LocalRepoRegistration(string enlistmentRoot, string ownerSID)
{
this.EnlistmentRoot = enlistmentRoot;
this.OwnerSID = ownerSID;
this.IsActive = true;
}
public string EnlistmentRoot { get; set; }
public string OwnerSID { get; set; }
public bool IsActive { get; set; }
// Uses LocalRepoRegistrationJsonContext (assembly-local source generator)
// rather than GVFSJsonContext. The service-side RepoRegistration uses
// its own ServiceJsonContext for the same reason — neither type can be
// registered in GVFSJsonContext because GVFSJsonContext lives in
// GVFS.Common and the service-side type lives in GVFS.Service (wrong
// dependency direction). Keeping symmetric local contexts here means
// the on-disk JSON shape is governed by identical source-gen behavior
// on both sides.
public static LocalRepoRegistration FromJson(string json)
{
return JsonSerializer.Deserialize(json, LocalRepoRegistrationJsonContext.Default.LocalRepoRegistration);
}
public string ToJson()
{
return JsonSerializer.Serialize(this, LocalRepoRegistrationJsonContext.Default.LocalRepoRegistration);
}
public override string ToString()
{
return string.Format(
"({0} - {1}) {2}",
this.IsActive ? "Active" : "Inactive",
this.OwnerSID,
this.EnlistmentRoot);
}
}
[JsonSerializable(typeof(LocalRepoRegistration))]
internal partial class LocalRepoRegistrationJsonContext : JsonSerializerContext
{
}
}