-
Notifications
You must be signed in to change notification settings - Fork 95
/
Copy pathIFileWritingService.cs
58 lines (51 loc) · 2.27 KB
/
IFileWritingService.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
namespace Microsoft.ComponentDetection.Common;
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
/// <summary>
/// Provides methods for writing files.
/// </summary>
public interface IFileWritingService : IDisposable, IAsyncDisposable
{
/// <summary>
/// Initializes the file writing service with the given base path.
/// </summary>
/// <param name="basePath">The base path to use for all file operations.</param>
void Init(string basePath);
/// <summary>
/// Appends the object to the file as JSON.
/// </summary>
/// <param name="relativeFilePath">The relative path to the file.</param>
/// <param name="obj">The object to append.</param>
/// <typeparam name="T">The type of the object to append.</typeparam>
void AppendToFile<T>(string relativeFilePath, T obj);
/// <summary>
/// Writes the text to the file.
/// </summary>
/// <param name="relativeFilePath">The relative path to the file.</param>
/// <param name="text">The text to write.</param>
void WriteFile(string relativeFilePath, string text);
/// <summary>
/// Writes the text to the file.
/// </summary>
/// <param name="relativeFilePath">The relative path to the file.</param>
/// <param name="text">The text to write.</param>
/// <param name="cancellationToken">Token to cancel the file write operation.</param>
/// <returns>A task that represents the asynchronous operation.</returns>
Task WriteFileAsync(string relativeFilePath, string text, CancellationToken cancellationToken = default);
/// <summary>
/// Writes the object to the file as JSON.
/// </summary>
/// <param name="relativeFilePath">The relative path to the file.</param>
/// <param name="obj">The object to write.</param>
/// <typeparam name="T">The type of the object to write.</typeparam>
void WriteFile<T>(FileInfo relativeFilePath, T obj);
/// <summary>
/// Resolves the complete file path from the given relative file path.
/// Replaces occurrences of {timestamp} with the shared file timestamp.
/// </summary>
/// <param name="relativeFilePath">The relative path to the file.</param>
/// <returns>The complete file path.</returns>
string ResolveFilePath(string relativeFilePath);
}