From ef6ff45f4023db58f2e914d2930b304c58cb37f8 Mon Sep 17 00:00:00 2001 From: Damien Date: Sat, 1 Mar 2025 14:43:13 -0500 Subject: [PATCH] feat!:comments for documentation in IDE --- .../MeilisearchServiceTests.cs | 211 ++++++++++++++++++ .../meilisearch.NET.Tests.csproj | 11 +- meilisearch.NET.sln | 6 + .../Extensions/MeilisearchClientExtensions.cs | 19 ++ .../Extensions/ServiceCollectionExtension.cs | 19 +- meilisearch.NET/MeiliSearchService.cs | 51 ++++- meilisearch.NET/Models/Index.cs | 35 +++ .../Models/MeilisearchUsageStats.cs | 26 +++ .../Models/ProcessResourceStats.cs | 35 ++- .../DocumentManagement/IDocumentManager.cs | 24 ++ .../Services/IndexManagement/IIndexManager.cs | 67 ++++++ .../ProcessManagement/BaseProcessManager.cs | 1 + .../ProcessManagement/IProcessManager.cs | 32 ++- 13 files changed, 515 insertions(+), 22 deletions(-) create mode 100644 meilisearch.NET.Tests/MeilisearchServiceTests.cs diff --git a/meilisearch.NET.Tests/MeilisearchServiceTests.cs b/meilisearch.NET.Tests/MeilisearchServiceTests.cs new file mode 100644 index 0000000..0e1d567 --- /dev/null +++ b/meilisearch.NET.Tests/MeilisearchServiceTests.cs @@ -0,0 +1,211 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Meilisearch; +using meilisearch.NET.Interfaces; +using meilisearch.NET.Models; +using meilisearch.NET.Services.DocumentManagement; +using meilisearch.NET.Services.IndexManagement; +using meilisearch.NET.Services.ProcessManagement; +using Moq; +using Xunit; + +namespace meilisearch.NET.Tests +{ + public class MeiliSearchServiceTests + { + private readonly Mock _mockProcessManager; + private readonly Mock _mockIndexManager; + private readonly Mock _mockDocumentManager; + private readonly Mock _mockClient; + private readonly MeiliSearchService _service; + + public MeiliSearchServiceTests() + { + _mockProcessManager = new Mock(); + _mockIndexManager = new Mock(); + _mockDocumentManager = new Mock(); + + _service = new MeiliSearchService( + _mockProcessManager.Object, + _mockIndexManager.Object, + _mockDocumentManager.Object + ); + } + + [Fact] + public async Task Start_CallsProcessManagerStartProcess() + { + // Arrange + _mockProcessManager.Setup(x => x.StartProcess()).Returns(Task.CompletedTask); + + // Act + await _service.Start(); + + // Assert + _mockProcessManager.Verify(x => x.StartProcess(), Times.Exactly(2)); + } + + [Fact] + public void GetTotalStorageUsage_CallsIndexManagerWithCorrectParameters() + { + // Arrange + const bool useCompressedSize = true; + const long expectedUsage = 1000L; + _mockIndexManager.Setup(x => x.GetTotalStorageUsage(useCompressedSize)).Returns(expectedUsage); + + // Act + var result = _service.GetTotalStorageUsage(useCompressedSize); + + // Assert + Assert.Equal(expectedUsage, result); + _mockIndexManager.Verify(x => x.GetTotalStorageUsage(useCompressedSize), Times.Once); + } + + [Fact] + public void GetIndexStorageUsage_CallsIndexManagerWithCorrectParameters() + { + // Arrange + const string indexName = "testIndex"; + const bool useCompressedSize = true; + const long expectedUsage = 500L; + _mockIndexManager.Setup(x => x.GetIndexStorageUsage(indexName, useCompressedSize)).Returns(expectedUsage); + + // Act + var result = _service.GetIndexStorageUsage(indexName, useCompressedSize); + + // Assert + Assert.Equal(expectedUsage, result); + _mockIndexManager.Verify(x => x.GetIndexStorageUsage(indexName, useCompressedSize), Times.Once); + } + + [Fact] + public void Stop_CallsProcessManagerStopProcess() + { + // Act + _service.Stop(); + + // Assert + _mockProcessManager.Verify(x => x.StopProcess(), Times.Once); + } + + [Fact] + public void IsRunning_ReturnsProcessManagerStatus() + { + // Arrange + const bool expectedStatus = true; + _mockProcessManager.Setup(x => x.IsProcessRunning()).Returns(expectedStatus); + + // Act + var result = _service.IsRunning(); + + // Assert + Assert.Equal(expectedStatus, result); + _mockProcessManager.Verify(x => x.IsProcessRunning(), Times.Once); + } + + [Fact] + public async Task SetIndexEnabled_CallsIndexManagerWithCorrectParameters() + { + // Arrange + const string indexName = "testIndex"; + const bool enabled = true; + _mockIndexManager.Setup(x => x.SetIndexEnabledAsync(indexName, enabled)).Returns(Task.CompletedTask); + + // Act + await _service.SetIndexEnabled(indexName, enabled); + + // Assert + _mockIndexManager.Verify(x => x.SetIndexEnabledAsync(indexName, enabled), Times.Once); + } + + [Fact] + public void GetResourceUsage_ReturnsProcessManagerStats() + { + // Arrange + var expectedStats = new ProcessResourceStats(); + _mockProcessManager.Setup(x => x.GetResourceUsage()).Returns(expectedStats); + + // Act + var result = _service.GetResourceUsage(); + + // Assert + Assert.Same(expectedStats, result); + _mockProcessManager.Verify(x => x.GetResourceUsage(), Times.Once); + } + + [Fact] + public async Task GetAllIndexes_ReturnsIndexManagerResults() + { + // Arrange + var expectedIndexes = new List { "index1", "index2" }; + _mockIndexManager.Setup(x => x.GetAllIndexes()).ReturnsAsync(expectedIndexes); + + // Act + var result = await _service.GetAllIndexes(); + + // Assert + Assert.Equal(expectedIndexes, result); + _mockIndexManager.Verify(x => x.GetAllIndexes(), Times.Once); + } + + [Fact] + public async Task CreateIndex_CallsIndexManagerWithCorrectParameters() + { + // Arrange + const string indexName = "testIndex"; + _mockIndexManager.Setup(x => x.CreateIndexAsync(indexName)).Returns(Task.CompletedTask); + + // Act + await _service.CreateIndex(indexName); + + // Assert + _mockIndexManager.Verify(x => x.CreateIndexAsync(indexName), Times.Once); + } + + [Fact] + public async Task DeleteIndex_CallsIndexManagerWithCorrectParameters() + { + // Arrange + const string indexName = "testIndex"; + _mockIndexManager.Setup(x => x.DeleteIndexAsync(indexName)).Returns(Task.CompletedTask); + + // Act + await _service.DeleteIndex(indexName); + + // Assert + _mockIndexManager.Verify(x => x.DeleteIndexAsync(indexName), Times.Once); + } + + [Fact] + public void AddDocument_CallsDocumentManagerWithCorrectParameters() + { + // Arrange + const string repositoryId = "testRepo"; + var document = new TestDocument(); + const bool autoCommit = true; + + // Act + _service.AddDocument(repositoryId, document, autoCommit); + + // Assert + _mockDocumentManager.Verify(x => x.AddDocument(repositoryId, document, autoCommit), Times.Once); + } + + [Fact] + public void Dispose_CallsProcessManagerDispose() + { + // Act + _service.Dispose(); + + // Assert + _mockProcessManager.Verify(x => x.Dispose(), Times.Once); + } + + // Helper class for testing + private class TestDocument : IDocument + { + public Guid Id { get; set; } + } + } +} \ No newline at end of file diff --git a/meilisearch.NET.Tests/meilisearch.NET.Tests.csproj b/meilisearch.NET.Tests/meilisearch.NET.Tests.csproj index 3dcd29b..7ca3002 100644 --- a/meilisearch.NET.Tests/meilisearch.NET.Tests.csproj +++ b/meilisearch.NET.Tests/meilisearch.NET.Tests.csproj @@ -13,13 +13,16 @@ - - - + + + - + + + + diff --git a/meilisearch.NET.sln b/meilisearch.NET.sln index 147cf43..af69a13 100644 --- a/meilisearch.NET.sln +++ b/meilisearch.NET.sln @@ -4,6 +4,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "meilisearch.NET", "meilisea EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "meilisearch.NET.example", "meilisearch.NET.example\meilisearch.NET.example.csproj", "{E753BBD6-6ADF-4DD4-8822-7279CD55DF58}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "meilisearch.NET.Tests", "meilisearch.NET.Tests\meilisearch.NET.Tests.csproj", "{FDCF4472-79F8-4AF2-AB02-00522C399E22}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -18,5 +20,9 @@ Global {E753BBD6-6ADF-4DD4-8822-7279CD55DF58}.Debug|Any CPU.Build.0 = Debug|Any CPU {E753BBD6-6ADF-4DD4-8822-7279CD55DF58}.Release|Any CPU.ActiveCfg = Release|Any CPU {E753BBD6-6ADF-4DD4-8822-7279CD55DF58}.Release|Any CPU.Build.0 = Release|Any CPU + {FDCF4472-79F8-4AF2-AB02-00522C399E22}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FDCF4472-79F8-4AF2-AB02-00522C399E22}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FDCF4472-79F8-4AF2-AB02-00522C399E22}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FDCF4472-79F8-4AF2-AB02-00522C399E22}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal diff --git a/meilisearch.NET/Extensions/MeilisearchClientExtensions.cs b/meilisearch.NET/Extensions/MeilisearchClientExtensions.cs index cab61ef..72c2442 100644 --- a/meilisearch.NET/Extensions/MeilisearchClientExtensions.cs +++ b/meilisearch.NET/Extensions/MeilisearchClientExtensions.cs @@ -2,8 +2,20 @@ namespace meilisearch.NET.Extensions; +/// +/// Extension methods for executing operations on MeiliSearch client. +/// public static class MeilisearchClientExtensions { + /// + /// Executes an action against MeiliSearch client that returns a value, automatically handling compressed index states. + /// + /// The type of value returned by the action + /// The MeiliSearch service instance + /// Name of the index to operate on + /// The action to execute against the MeiliSearch client + /// The result of the executed action + /// Thrown when MeiliSearch client is not initialized public static async Task SDK(this MeiliSearchService service, string indexName, Func> action) { var client = service.Client; @@ -26,6 +38,13 @@ public static class MeilisearchClientExtensions return result; } + /// + /// Executes an action against MeiliSearch client that doesn't return a value, automatically handling compressed index states. + /// + /// The MeiliSearch service instance + /// Name of the index to operate on + /// The action to execute against the MeiliSearch client + /// Thrown when MeiliSearch client is not initialized public static async Task SDK(this MeiliSearchService service, string indexName, Func action) { var client = service.Client; diff --git a/meilisearch.NET/Extensions/ServiceCollectionExtension.cs b/meilisearch.NET/Extensions/ServiceCollectionExtension.cs index d2f138e..fe351e9 100644 --- a/meilisearch.NET/Extensions/ServiceCollectionExtension.cs +++ b/meilisearch.NET/Extensions/ServiceCollectionExtension.cs @@ -7,8 +7,25 @@ using Microsoft.Extensions.DependencyInjection; namespace meilisearch.NET.Extensions; +/// +/// Provides extension methods for IServiceCollection to configure MeiliSearch services +/// public static class ServiceCollectionExtension { + /// + /// Adds MeiliSearch services to the dependency injection container + /// + /// The IServiceCollection to add services to + /// The IServiceCollection for chaining + /// + /// Registers the following services as singletons: + /// - MeilisearchClient (configured for localhost:7700) + /// - MeiliSearchService (with HttpClient) + /// - MeiliSearchConfiguration + /// - MeiliSearchProcessManager + /// - IIndexManager (implemented by IndexManager) + /// - IDocumentManager (implemented by DocumentManager) + /// public static IServiceCollection AddMeiliSearchService(this IServiceCollection services) { services.AddSingleton(sp => @@ -17,7 +34,7 @@ public static class ServiceCollectionExtension }); services.AddHttpClient(); services.AddSingleton(); - services.AddSingleton< MeiliSearchProcessManager>(); + services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); diff --git a/meilisearch.NET/MeiliSearchService.cs b/meilisearch.NET/MeiliSearchService.cs index c1b82e1..abeb2cf 100644 --- a/meilisearch.NET/MeiliSearchService.cs +++ b/meilisearch.NET/MeiliSearchService.cs @@ -1,55 +1,96 @@ using Meilisearch; using meilisearch.NET.Interfaces; +using meilisearch.NET.Models; using meilisearch.NET.Services.DocumentManagement; using meilisearch.NET.Services.IndexManagement; using meilisearch.NET.Services.ProcessManagement; namespace meilisearch.NET; +/// +/// Main service class for interacting with Meilisearch. Manages process, indexes and documents. +/// public class MeiliSearchService : IDisposable { - internal readonly MeiliSearchProcessManager ProcessManager; + internal readonly IProcessManager ProcessManager; internal readonly IIndexManager IndexManager; internal readonly IDocumentManager DocumentManager; internal readonly MeilisearchClient Client; + /// + /// Initializes a new instance of MeiliSearchService + /// + /// Manager for the Meilisearch process + /// Manager for index operations + /// Manager for document operations public MeiliSearchService( - MeiliSearchProcessManager processManager, + IProcessManager processManager, IIndexManager indexManager, - IDocumentManager documentManager, - MeilisearchClient client) + IDocumentManager documentManager) { - Client = client; ProcessManager = processManager; IndexManager = indexManager; DocumentManager = documentManager; ProcessManager.StartProcess().Wait(); } + /// Starts the Meilisearch process public async Task Start() => await ProcessManager.StartProcess(); + + /// Gets the total storage usage across all indexes + /// If true, returns compressed size for compressed indexes + /// Total storage usage in bytes public long GetTotalStorageUsage(bool useCompressedSize = true) => IndexManager.GetTotalStorageUsage(useCompressedSize); + + /// Gets the storage usage for a specific index + /// Name of the index + /// If true, returns compressed size for compressed indexes + /// Index storage usage in bytes public long GetIndexStorageUsage(string indexName, bool useCompressedSize = true) => IndexManager.GetIndexStorageUsage(indexName, useCompressedSize); + + /// Stops the Meilisearch process public void Stop() => ProcessManager.StopProcess(); + /// Checks if the Meilisearch process is running + /// True if process is running, false otherwise public bool IsRunning() => ProcessManager.IsProcessRunning(); + /// Enables or disables an index + /// Name of the index + /// True to enable, false to disable public Task SetIndexEnabled(string indexName, bool enabled) => IndexManager.SetIndexEnabledAsync(indexName, enabled); + /// Gets current resource usage statistics for the Meilisearch process + /// Process resource statistics public ProcessResourceStats GetResourceUsage() => ProcessManager.GetResourceUsage(); + /// Gets a list of all index names + /// List of index names public Task> GetAllIndexes() => IndexManager.GetAllIndexes(); + /// Creates a new index + /// Document type that implements IDocument + /// Name for the new index public Task CreateIndex(string indexName) where T : IDocument => IndexManager.CreateIndexAsync(indexName); + /// Deletes an existing index + /// Name of the index to delete public Task DeleteIndex(string indexName) => IndexManager.DeleteIndexAsync(indexName); + /// Adds a document to an index + /// ID of the target repository/index + /// Document to add + /// If true, immediately syncs to server public void AddDocument(string repositoryId, IDocument document, bool autoCommit = false) => DocumentManager.AddDocument(repositoryId, document, autoCommit); + /// + /// Disposes the MeiliSearchService instance and its associated process manager + /// public void Dispose() { ProcessManager.Dispose(); diff --git a/meilisearch.NET/Models/Index.cs b/meilisearch.NET/Models/Index.cs index bd926e3..10f5683 100644 --- a/meilisearch.NET/Models/Index.cs +++ b/meilisearch.NET/Models/Index.cs @@ -1,16 +1,51 @@ namespace meilisearch.NET.Models; +/// +/// Represents a Meilisearch index with its metadata and compression state. +/// public class Index { + /// + /// Gets or sets the name of the index. + /// public string Name { get; set; } = string.Empty; + + /// + /// Gets or sets the creation timestamp of the index in UTC. + /// public DateTime CreatedAt { get; set; } = DateTime.UtcNow; + + /// + /// Gets or sets the unique folder identifier where the index data is stored. + /// public string FolderId { get; set; } = string.Empty; + + /// + /// Gets or sets whether the index is currently compressed. + /// public bool IsCompressed { get; set; } = false; + + /// + /// Gets or sets the timestamp when the index was last compressed. + /// public DateTime? LastCompressedAt { get; set; } + + /// + /// Gets or sets the size of the index in bytes before compression. + /// public long? SizeBeforeCompression { get; set; } = 0; + /// + /// Initializes a new instance of the Index class. + /// public Index() { } + /// + /// Initializes a new instance of the Index class with specified parameters. + /// + /// The name of the index. + /// The folder identifier where index data is stored. + /// The creation timestamp of the index. public Index(string name, string folderId, DateTime createdAt) { Name = name; diff --git a/meilisearch.NET/Models/MeilisearchUsageStats.cs b/meilisearch.NET/Models/MeilisearchUsageStats.cs index 01461d4..b939f5e 100644 --- a/meilisearch.NET/Models/MeilisearchUsageStats.cs +++ b/meilisearch.NET/Models/MeilisearchUsageStats.cs @@ -1,11 +1,37 @@ namespace meilisearch.NET.Models; +/// +/// Represents resource usage statistics for a Meilisearch process +/// public class MeilisearchUsageStats { + /// + /// CPU usage as a percentage (0-100) + /// public double CpuPercentage { get; set; } + + /// + /// Memory usage in bytes + /// public long MemoryUsageBytes { get; set; } + + /// + /// Total bytes read from disk + /// public long DiskReadBytes { get; set; } + + /// + /// Total bytes written to disk + /// public long DiskWriteBytes { get; set; } + + /// + /// Number of threads used by the process + /// public int ThreadCount { get; set; } + + /// + /// Process identifier + /// public int ProcessId { get; set; } } \ No newline at end of file diff --git a/meilisearch.NET/Models/ProcessResourceStats.cs b/meilisearch.NET/Models/ProcessResourceStats.cs index c4488ad..3dcba2b 100644 --- a/meilisearch.NET/Models/ProcessResourceStats.cs +++ b/meilisearch.NET/Models/ProcessResourceStats.cs @@ -1,6 +1,37 @@ namespace meilisearch.NET.Models; -public class ProcessResourceStats +/// +/// Represents resource usage statistics for a process at a point in time. +/// +public record ProcessResourceStats { - + /// + /// Gets the CPU usage percentage of the process. + /// + public double CpuPercentage { get; init; } + + /// + /// Gets the memory usage in bytes of the process. + /// + public long MemoryUsageBytes { get; init; } + + /// + /// Gets the total number of bytes read from disk by the process. + /// + public long DiskReadBytes { get; init; } + + /// + /// Gets the total number of bytes written to disk by the process. + /// + public long DiskWriteBytes { get; init; } + + /// + /// Gets the process identifier. + /// + public int ProcessId { get; init; } + + /// + /// Gets the number of threads currently running in the process. + /// + public int ThreadCount { get; init; } } \ No newline at end of file diff --git a/meilisearch.NET/Services/DocumentManagement/IDocumentManager.cs b/meilisearch.NET/Services/DocumentManagement/IDocumentManager.cs index 1727980..7e8a84a 100644 --- a/meilisearch.NET/Services/DocumentManagement/IDocumentManager.cs +++ b/meilisearch.NET/Services/DocumentManagement/IDocumentManager.cs @@ -2,10 +2,34 @@ using meilisearch.NET.Interfaces; namespace meilisearch.NET.Services.DocumentManagement; +/// +/// Manages document operations for Meilisearch indexes. +/// public interface IDocumentManager { + /// + /// Adds a document to the specified repository. + /// + /// The ID of the repository to add the document to. + /// The document to add. + /// If true, automatically syncs the document to the server. void AddDocument(string repositoryId, IDocument document, bool autoCommit = false); + + /// + /// Synchronizes all pending documents to the Meilisearch server. + /// void SyncDocumentsToServer(); + + /// + /// Asynchronously adds a document to the specified repository. + /// + /// The ID of the repository to add the document to. + /// The document to add. + /// If true, automatically syncs the document to the server. Task AddDocumentAsync(string repositoryId, IDocument document, bool autoCommit = false); + + /// + /// Asynchronously synchronizes all pending documents to the Meilisearch server. + /// Task SyncDocumentsToServerAsync(); } \ No newline at end of file diff --git a/meilisearch.NET/Services/IndexManagement/IIndexManager.cs b/meilisearch.NET/Services/IndexManagement/IIndexManager.cs index 9edca6b..8758a9e 100644 --- a/meilisearch.NET/Services/IndexManagement/IIndexManager.cs +++ b/meilisearch.NET/Services/IndexManagement/IIndexManager.cs @@ -2,17 +2,84 @@ using meilisearch.NET.Interfaces; namespace meilisearch.NET.Services.IndexManagement; +/// +/// Manages Meilisearch index operations including creation, deletion, and storage management. +/// public interface IIndexManager { + /// + /// Retrieves a list of all index names from the Meilisearch server. + /// + /// A list of index names. Task> GetAllIndexes(); + + /// + /// Asynchronously creates a new index with the specified name for the given document type. + /// + /// The document type that implements IDocument. + /// The name of the index to create. Task CreateIndexAsync(string indexName) where T : IDocument; + + /// + /// Synchronously creates a new index with the specified name for the given document type. + /// + /// The document type that implements IDocument. + /// The name of the index to create. void CreateIndex(string indexName) where T : IDocument; + + /// + /// Asynchronously deletes the specified index. + /// + /// The name of the index to delete. Task DeleteIndexAsync(string indexName); + + /// + /// Synchronously deletes the specified index. + /// + /// The name of the index to delete. void DeleteIndex(string indexName); + + /// + /// Asynchronously enables or disables an index by compressing or decompressing it. + /// + /// The name of the index to modify. + /// True to enable (decompress), false to disable (compress). Task SetIndexEnabledAsync(string indexName, bool enabled); + + /// + /// Synchronously enables or disables an index by compressing or decompressing it. + /// + /// The name of the index to modify. + /// True to enable (decompress), false to disable (compress). void SetIndexEnabled(string indexName, bool enabled); + + /// + /// Asynchronously gets the storage usage of a specific index. + /// + /// The name of the index. + /// If true, returns compressed size for compressed indexes. + /// The storage usage in bytes. Task GetIndexStorageUsageAsync(string indexName, bool useCompressedSize = true); + + /// + /// Asynchronously gets the total storage usage of all indexes. + /// + /// If true, uses compressed sizes for compressed indexes. + /// The total storage usage in bytes. Task GetTotalStorageUsageAsync(bool useCompressedSize = true); + + /// + /// Synchronously gets the storage usage of a specific index. + /// + /// The name of the index. + /// If true, returns compressed size for compressed indexes. + /// The storage usage in bytes. long GetIndexStorageUsage(string indexName, bool useCompressedSize = true); + + /// + /// Synchronously gets the total storage usage of all indexes. + /// + /// If true, uses compressed sizes for compressed indexes. + /// The total storage usage in bytes. long GetTotalStorageUsage(bool useCompressedSize = true); } \ No newline at end of file diff --git a/meilisearch.NET/Services/ProcessManagement/BaseProcessManager.cs b/meilisearch.NET/Services/ProcessManagement/BaseProcessManager.cs index b6e8f7c..4f02e68 100644 --- a/meilisearch.NET/Services/ProcessManagement/BaseProcessManager.cs +++ b/meilisearch.NET/Services/ProcessManagement/BaseProcessManager.cs @@ -1,5 +1,6 @@ using System.Diagnostics; using meilisearch.NET.Exceptions; +using meilisearch.NET.Models; using Microsoft.Extensions.Logging; namespace meilisearch.NET.Services.ProcessManagement; diff --git a/meilisearch.NET/Services/ProcessManagement/IProcessManager.cs b/meilisearch.NET/Services/ProcessManagement/IProcessManager.cs index a36a9db..ebe7b90 100644 --- a/meilisearch.NET/Services/ProcessManagement/IProcessManager.cs +++ b/meilisearch.NET/Services/ProcessManagement/IProcessManager.cs @@ -1,21 +1,33 @@ using System.Diagnostics; +using meilisearch.NET.Models; namespace meilisearch.NET.Services.ProcessManagement; +/// +/// Defines the contract for managing a process lifecycle and monitoring its resources. +/// public interface IProcessManager : IDisposable { + /// + /// Starts the managed process asynchronously. + /// + /// A task representing the asynchronous operation. Task StartProcess(); + + /// + /// Stops the managed process. + /// void StopProcess(); + + /// + /// Checks if the managed process is currently running. + /// + /// True if the process is running, false otherwise. bool IsProcessRunning(); + + /// + /// Retrieves current resource usage statistics for the managed process. + /// + /// A ProcessResourceStats object containing resource usage information. ProcessResourceStats GetResourceUsage(); } - -public record ProcessResourceStats -{ - public double CpuPercentage { get; init; } - public long MemoryUsageBytes { get; init; } - public long DiskReadBytes { get; init; } - public long DiskWriteBytes { get; init; } - public int ProcessId { get; init; } - public int ThreadCount { get; init; } -} \ No newline at end of file