-
Notifications
You must be signed in to change notification settings - Fork 601
/
IAsyncStorage.cs
170 lines (152 loc) · 7.69 KB
/
IAsyncStorage.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
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace StackExchange.Profiling.Storage
{
/// <summary>
/// How lists should be sorted.
/// </summary>
public enum ListResultsOrder
{
/// <summary>
/// Ascending Order
/// </summary>
Ascending = 0,
/// <summary>
/// Descending Order
/// </summary>
Descending = 1
}
/// <summary>
/// Provides saving and loading <see cref="MiniProfiler"/>s to a storage medium.
/// </summary>
public interface IAsyncStorage
{
/// <summary>
/// List the latest profiling results.
/// </summary>
/// <param name="maxResults">The maximum number of results to return.</param>
/// <param name="start">(Optional) The start of the date range to fetch.</param>
/// <param name="finish">(Optional) The end of the date range to fetch.</param>
/// <param name="orderBy">(Optional) The order to fetch profiler IDs in.</param>
IEnumerable<Guid> List(
int maxResults,
DateTime? start = null,
DateTime? finish = null,
ListResultsOrder orderBy = ListResultsOrder.Descending);
/// <summary>
/// Stores <paramref name="profiler"/> under its <see cref="MiniProfiler.Id"/>.
/// </summary>
/// <param name="profiler">The <see cref="MiniProfiler"/> to save.</param>
/// <remarks>
/// Should also ensure the profiler is stored as being unviewed by its profiling <see cref="MiniProfiler.User"/>.
/// </remarks>
void Save(MiniProfiler profiler);
/// <summary>
/// Returns a <see cref="MiniProfiler"/> from storage based on <paramref name="id"/>,
/// which should map to <see cref="MiniProfiler.Id"/>.
/// </summary>
/// <param name="id">The profiler ID to load.</param>
/// <returns>The loaded <see cref="MiniProfiler"/>.</returns>
/// <remarks>
/// Should also update that the resulting profiler has been marked as viewed by its
/// profiling <see cref="MiniProfiler.User"/>.
/// </remarks>
MiniProfiler? Load(Guid id);
/// <summary>
/// Sets a particular profiler session so it is considered "unviewed"
/// </summary>
/// <param name="user">The user to set this profiler ID as unviewed for.</param>
/// <param name="id">The profiler ID to set unviewed.</param>
void SetUnviewed(string? user, Guid id);
/// <summary>
/// Sets a particular profiler session to "viewed"
/// </summary>
/// <param name="user">The user to set this profiler ID as viewed for.</param>
/// <param name="id">The profiler ID to set viewed.</param>
void SetViewed(string? user, Guid id);
/// <summary>
/// Returns a list of <see cref="MiniProfiler.Id"/>s that haven't been seen by <paramref name="user"/>.
/// </summary>
/// <param name="user">User identified by the current <c>MiniProfilerOptions.UserProvider</c></param>
List<Guid> GetUnviewedIds(string? user);
/// <summary>
/// Asynchronously list the latest profiling results.
/// </summary>
/// <param name="maxResults">The maximum number of results to return.</param>
/// <param name="start">(Optional) The start of the date range to fetch.</param>
/// <param name="finish">(Optional) The end of the date range to fetch.</param>
/// <param name="orderBy">(Optional) The order to fetch profiler IDs in.</param>
Task<IEnumerable<Guid>> ListAsync(
int maxResults,
DateTime? start = null,
DateTime? finish = null,
ListResultsOrder orderBy = ListResultsOrder.Descending);
/// <summary>
/// Asynchronously stores <paramref name="profiler"/> under its <see cref="MiniProfiler.Id"/>.
/// </summary>
/// <param name="profiler">The <see cref="MiniProfiler"/> to save.</param>
/// <remarks>
/// Should also ensure the profiler is stored as being unviewed by its profiling <see cref="MiniProfiler.User"/>.
/// </remarks>
Task SaveAsync(MiniProfiler profiler);
/// <summary>
/// Asynchronously returns a <see cref="MiniProfiler"/> from storage based on <paramref name="id"/>,
/// which should map to <see cref="MiniProfiler.Id"/>.
/// </summary>
/// <param name="id">The profiler ID to load.</param>
/// <returns>The loaded <see cref="MiniProfiler"/>.</returns>
/// <remarks>
/// Should also update that the resulting profiler has been marked as viewed by its
/// profiling <see cref="MiniProfiler.User"/>.
/// </remarks>
Task<MiniProfiler?> LoadAsync(Guid id);
/// <summary>
/// Asynchronously sets a particular profiler session so it is considered "unviewed"
/// </summary>
/// <param name="user">The user to set this profiler ID as unviewed for.</param>
/// <param name="id">The profiler ID to set unviewed.</param>
Task SetUnviewedAsync(string? user, Guid id);
/// <summary>
/// Asynchronously sets a particular profiler session to "viewed"
/// </summary>
/// <param name="user">The user to set this profiler ID as viewed for.</param>
/// <param name="id">The profiler ID to set viewed.</param>
Task SetViewedAsync(string? user, Guid id);
/// <summary>
/// Asynchronously returns a list of <see cref="MiniProfiler.Id"/>s that haven't been seen by <paramref name="user"/>.
/// </summary>
/// <param name="user">User identified by the current <c>MiniProfilerOptions.UserProvider</c></param>
Task<List<Guid>> GetUnviewedIdsAsync(string? user);
}
/// <summary>
/// Extension methods for <see cref="IAsyncStorage"/>.
/// </summary>
public static class AsyncStorageExtensions
{
/// <summary>
/// Sets a specific <see cref="MiniProfiler"/> to "unviewed".
/// </summary>
/// <param name="storage">The <see cref="IAsyncStorage"/> provider.</param>
/// <param name="profiler">The <see cref="MiniProfiler"/> to set to "unviewed".</param>
public static void SetUnviewed(this IAsyncStorage storage, MiniProfiler profiler) => storage.SetUnviewed(profiler.User, profiler.Id);
/// <summary>
/// Asynchronously sets a specific <see cref="MiniProfiler"/> to "unviewed".
/// </summary>
/// <param name="storage">The <see cref="IAsyncStorage"/> provider.</param>
/// <param name="profiler">The <see cref="MiniProfiler"/> to set to "unviewed".</param>
public static Task SetUnviewedAsync(this IAsyncStorage storage, MiniProfiler profiler) => storage.SetUnviewedAsync(profiler.User, profiler.Id);
/// <summary>
/// Sets a specific <see cref="MiniProfiler"/> to "viewed".
/// </summary>
/// <param name="storage">The <see cref="IAsyncStorage"/> provider.</param>
/// <param name="profiler">The <see cref="MiniProfiler"/> to set to "viewed".</param>
public static void SetViewed(this IAsyncStorage storage, MiniProfiler profiler) => storage.SetViewed(profiler.User, profiler.Id);
/// <summary>
/// Asynchronously sets a specific <see cref="MiniProfiler"/> to "viewed".
/// </summary>
/// <param name="storage">The <see cref="IAsyncStorage"/> provider.</param>
/// <param name="profiler">The <see cref="MiniProfiler"/> to set to "viewed".</param>
public static Task SetViewedAsync(this IAsyncStorage storage, MiniProfiler profiler) => storage.SetViewedAsync(profiler.User, profiler.Id);
}
}