Repository navigation
Expand file tree
/
Copy pathRegistryCacheReport.cs
More file actions
78 lines (61 loc) · 2.47 KB
/
Copy pathRegistryCacheReport.cs
File metadata and controls
78 lines (61 loc) · 2.47 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
using System;
using System.Collections.Generic;
using Microsoft.Extensions.Options;
namespace UnityNuGet.Server
{
/// <summary>
/// Main class that stores relevant messages that may appear during the build of the Unity packages with <see cref="RegistryCache"/>.
/// </summary>
public class RegistryCacheReport(RegistryCacheSingleton registryCacheSingleton, IOptions<RegistryOptions> registryOptionsAccessor)
{
private readonly RegistryCacheSingleton _registryCacheSingleton = registryCacheSingleton;
private readonly RegistryOptions _registryOptions = registryOptionsAccessor.Value;
private readonly List<string> _informationMessages = [];
private readonly List<string> _warningMessages = [];
private readonly List<string> _errorMessages = [];
private DateTime? _lastUpdate;
public IEnumerable<string> InformationMeessages => _informationMessages;
public IEnumerable<string> WarningMessages => _warningMessages;
public IEnumerable<string> ErrorMessages => _errorMessages;
public bool Running { get; private set; }
public double Progress
{
get
{
int currentIndex = _registryCacheSingleton.ProgressPackageIndex;
int totalCount = _registryCacheSingleton.ProgressTotalPackageCount;
double percent = totalCount != 0 ? (double)currentIndex * 100 / totalCount : 0;
return percent;
}
}
public TimeSpan? TimeRemainingForNextUpdate
{
get
{
if (_errorMessages.Count == 0)
{
return _lastUpdate != null ? _lastUpdate.Value.Add(_registryOptions.UpdateInterval) - DateTime.UtcNow : null;
}
else
{
return TimeSpan.FromSeconds(0);
}
}
}
public void AddInformation(string message) => _informationMessages.Add(message);
public void AddWarning(string message) => _warningMessages.Add(message);
public void AddError(string message) => _errorMessages.Add(message);
public void Start()
{
Running = true;
_informationMessages.Clear();
_warningMessages.Clear();
_errorMessages.Clear();
}
public void Complete()
{
Running = false;
_lastUpdate = DateTime.UtcNow;
}
}
}