feat!:comments for documentation in IDE
This commit is contained in:
parent
3d5b7db864
commit
ef6ff45f40
211
meilisearch.NET.Tests/MeilisearchServiceTests.cs
Normal file
211
meilisearch.NET.Tests/MeilisearchServiceTests.cs
Normal file
@ -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<IProcessManager> _mockProcessManager;
|
||||
private readonly Mock<IIndexManager> _mockIndexManager;
|
||||
private readonly Mock<IDocumentManager> _mockDocumentManager;
|
||||
private readonly Mock<MeilisearchClient> _mockClient;
|
||||
private readonly MeiliSearchService _service;
|
||||
|
||||
public MeiliSearchServiceTests()
|
||||
{
|
||||
_mockProcessManager = new Mock<IProcessManager>();
|
||||
_mockIndexManager = new Mock<IIndexManager>();
|
||||
_mockDocumentManager = new Mock<IDocumentManager>();
|
||||
|
||||
_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<string> { "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<TestDocument>(indexName)).Returns(Task.CompletedTask);
|
||||
|
||||
// Act
|
||||
await _service.CreateIndex<TestDocument>(indexName);
|
||||
|
||||
// Assert
|
||||
_mockIndexManager.Verify(x => x.CreateIndexAsync<TestDocument>(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; }
|
||||
}
|
||||
}
|
||||
}
|
@ -13,13 +13,16 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.0"/>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0"/>
|
||||
<PackageReference Include="NUnit" Version="3.14.0"/>
|
||||
<PackageReference Include="NUnit.Analyzers" Version="3.9.0"/>
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0"/>
|
||||
<PackageReference Include="Moq" Version="4.20.72" />
|
||||
<PackageReference Include="xunit" Version="2.9.3" />
|
||||
<PackageReference Include="xunit.extensibility.core" Version="2.9.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Using Include="NUnit.Framework"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\meilisearch.NET\meilisearch.NET.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -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
|
||||
|
@ -2,8 +2,20 @@
|
||||
|
||||
namespace meilisearch.NET.Extensions;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for executing operations on MeiliSearch client.
|
||||
/// </summary>
|
||||
public static class MeilisearchClientExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Executes an action against MeiliSearch client that returns a value, automatically handling compressed index states.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of value returned by the action</typeparam>
|
||||
/// <param name="service">The MeiliSearch service instance</param>
|
||||
/// <param name="indexName">Name of the index to operate on</param>
|
||||
/// <param name="action">The action to execute against the MeiliSearch client</param>
|
||||
/// <returns>The result of the executed action</returns>
|
||||
/// <exception cref="InvalidOperationException">Thrown when MeiliSearch client is not initialized</exception>
|
||||
public static async Task<T> SDK<T>(this MeiliSearchService service, string indexName, Func<MeilisearchClient, Task<T>> action)
|
||||
{
|
||||
var client = service.Client;
|
||||
@ -26,6 +38,13 @@ public static class MeilisearchClientExtensions
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Executes an action against MeiliSearch client that doesn't return a value, automatically handling compressed index states.
|
||||
/// </summary>
|
||||
/// <param name="service">The MeiliSearch service instance</param>
|
||||
/// <param name="indexName">Name of the index to operate on</param>
|
||||
/// <param name="action">The action to execute against the MeiliSearch client</param>
|
||||
/// <exception cref="InvalidOperationException">Thrown when MeiliSearch client is not initialized</exception>
|
||||
public static async Task SDK(this MeiliSearchService service, string indexName, Func<MeilisearchClient, Task> action)
|
||||
{
|
||||
var client = service.Client;
|
||||
|
@ -7,8 +7,25 @@ using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace meilisearch.NET.Extensions;
|
||||
|
||||
/// <summary>
|
||||
/// Provides extension methods for IServiceCollection to configure MeiliSearch services
|
||||
/// </summary>
|
||||
public static class ServiceCollectionExtension
|
||||
{
|
||||
/// <summary>
|
||||
/// Adds MeiliSearch services to the dependency injection container
|
||||
/// </summary>
|
||||
/// <param name="services">The IServiceCollection to add services to</param>
|
||||
/// <returns>The IServiceCollection for chaining</returns>
|
||||
/// <remarks>
|
||||
/// Registers the following services as singletons:
|
||||
/// - MeilisearchClient (configured for localhost:7700)
|
||||
/// - MeiliSearchService (with HttpClient)
|
||||
/// - MeiliSearchConfiguration
|
||||
/// - MeiliSearchProcessManager
|
||||
/// - IIndexManager (implemented by IndexManager)
|
||||
/// - IDocumentManager (implemented by DocumentManager)
|
||||
/// </remarks>
|
||||
public static IServiceCollection AddMeiliSearchService(this IServiceCollection services)
|
||||
{
|
||||
services.AddSingleton<MeilisearchClient>(sp =>
|
||||
@ -17,7 +34,7 @@ public static class ServiceCollectionExtension
|
||||
});
|
||||
services.AddHttpClient<MeiliSearchService>();
|
||||
services.AddSingleton<MeiliSearchConfiguration>();
|
||||
services.AddSingleton< MeiliSearchProcessManager>();
|
||||
services.AddSingleton<MeiliSearchProcessManager>();
|
||||
services.AddSingleton<IIndexManager, IndexManager>();
|
||||
services.AddSingleton<IDocumentManager, DocumentManager>();
|
||||
services.AddSingleton<MeiliSearchService>();
|
||||
|
@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// Main service class for interacting with Meilisearch. Manages process, indexes and documents.
|
||||
/// </summary>
|
||||
public class MeiliSearchService : IDisposable
|
||||
{
|
||||
internal readonly MeiliSearchProcessManager ProcessManager;
|
||||
internal readonly IProcessManager ProcessManager;
|
||||
internal readonly IIndexManager IndexManager;
|
||||
internal readonly IDocumentManager DocumentManager;
|
||||
internal readonly MeilisearchClient Client;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of MeiliSearchService
|
||||
/// </summary>
|
||||
/// <param name="processManager">Manager for the Meilisearch process</param>
|
||||
/// <param name="indexManager">Manager for index operations</param>
|
||||
/// <param name="documentManager">Manager for document operations</param>
|
||||
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();
|
||||
}
|
||||
|
||||
/// <summary>Starts the Meilisearch process</summary>
|
||||
public async Task Start() => await ProcessManager.StartProcess();
|
||||
|
||||
/// <summary>Gets the total storage usage across all indexes</summary>
|
||||
/// <param name="useCompressedSize">If true, returns compressed size for compressed indexes</param>
|
||||
/// <returns>Total storage usage in bytes</returns>
|
||||
public long GetTotalStorageUsage(bool useCompressedSize = true)
|
||||
=> IndexManager.GetTotalStorageUsage(useCompressedSize);
|
||||
|
||||
/// <summary>Gets the storage usage for a specific index</summary>
|
||||
/// <param name="indexName">Name of the index</param>
|
||||
/// <param name="useCompressedSize">If true, returns compressed size for compressed indexes</param>
|
||||
/// <returns>Index storage usage in bytes</returns>
|
||||
public long GetIndexStorageUsage(string indexName, bool useCompressedSize = true)
|
||||
=> IndexManager.GetIndexStorageUsage(indexName, useCompressedSize);
|
||||
|
||||
/// <summary>Stops the Meilisearch process</summary>
|
||||
public void Stop() => ProcessManager.StopProcess();
|
||||
|
||||
/// <summary>Checks if the Meilisearch process is running</summary>
|
||||
/// <returns>True if process is running, false otherwise</returns>
|
||||
public bool IsRunning() => ProcessManager.IsProcessRunning();
|
||||
|
||||
/// <summary>Enables or disables an index</summary>
|
||||
/// <param name="indexName">Name of the index</param>
|
||||
/// <param name="enabled">True to enable, false to disable</param>
|
||||
public Task SetIndexEnabled(string indexName, bool enabled)
|
||||
=> IndexManager.SetIndexEnabledAsync(indexName, enabled);
|
||||
|
||||
/// <summary>Gets current resource usage statistics for the Meilisearch process</summary>
|
||||
/// <returns>Process resource statistics</returns>
|
||||
public ProcessResourceStats GetResourceUsage() => ProcessManager.GetResourceUsage();
|
||||
|
||||
/// <summary>Gets a list of all index names</summary>
|
||||
/// <returns>List of index names</returns>
|
||||
public Task<List<string>> GetAllIndexes() => IndexManager.GetAllIndexes();
|
||||
|
||||
/// <summary>Creates a new index</summary>
|
||||
/// <typeparam name="T">Document type that implements IDocument</typeparam>
|
||||
/// <param name="indexName">Name for the new index</param>
|
||||
public Task CreateIndex<T>(string indexName) where T : IDocument
|
||||
=> IndexManager.CreateIndexAsync<T>(indexName);
|
||||
|
||||
/// <summary>Deletes an existing index</summary>
|
||||
/// <param name="indexName">Name of the index to delete</param>
|
||||
public Task DeleteIndex(string indexName) => IndexManager.DeleteIndexAsync(indexName);
|
||||
|
||||
/// <summary>Adds a document to an index</summary>
|
||||
/// <param name="repositoryId">ID of the target repository/index</param>
|
||||
/// <param name="document">Document to add</param>
|
||||
/// <param name="autoCommit">If true, immediately syncs to server</param>
|
||||
public void AddDocument(string repositoryId, IDocument document, bool autoCommit = false)
|
||||
=> DocumentManager.AddDocument(repositoryId, document, autoCommit);
|
||||
|
||||
/// <summary>
|
||||
/// Disposes the MeiliSearchService instance and its associated process manager
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
ProcessManager.Dispose();
|
||||
|
@ -1,16 +1,51 @@
|
||||
namespace meilisearch.NET.Models;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a Meilisearch index with its metadata and compression state.
|
||||
/// </summary>
|
||||
public class Index
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the name of the index.
|
||||
/// </summary>
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the creation timestamp of the index in UTC.
|
||||
/// </summary>
|
||||
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the unique folder identifier where the index data is stored.
|
||||
/// </summary>
|
||||
public string FolderId { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether the index is currently compressed.
|
||||
/// </summary>
|
||||
public bool IsCompressed { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the timestamp when the index was last compressed.
|
||||
/// </summary>
|
||||
public DateTime? LastCompressedAt { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the size of the index in bytes before compression.
|
||||
/// </summary>
|
||||
public long? SizeBeforeCompression { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the Index class.
|
||||
/// </summary>
|
||||
public Index() { }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the Index class with specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="name">The name of the index.</param>
|
||||
/// <param name="folderId">The folder identifier where index data is stored.</param>
|
||||
/// <param name="createdAt">The creation timestamp of the index.</param>
|
||||
public Index(string name, string folderId, DateTime createdAt)
|
||||
{
|
||||
Name = name;
|
||||
|
@ -1,11 +1,37 @@
|
||||
namespace meilisearch.NET.Models;
|
||||
|
||||
/// <summary>
|
||||
/// Represents resource usage statistics for a Meilisearch process
|
||||
/// </summary>
|
||||
public class MeilisearchUsageStats
|
||||
{
|
||||
/// <summary>
|
||||
/// CPU usage as a percentage (0-100)
|
||||
/// </summary>
|
||||
public double CpuPercentage { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Memory usage in bytes
|
||||
/// </summary>
|
||||
public long MemoryUsageBytes { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Total bytes read from disk
|
||||
/// </summary>
|
||||
public long DiskReadBytes { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Total bytes written to disk
|
||||
/// </summary>
|
||||
public long DiskWriteBytes { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Number of threads used by the process
|
||||
/// </summary>
|
||||
public int ThreadCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Process identifier
|
||||
/// </summary>
|
||||
public int ProcessId { get; set; }
|
||||
}
|
@ -1,6 +1,37 @@
|
||||
namespace meilisearch.NET.Models;
|
||||
|
||||
public class ProcessResourceStats
|
||||
/// <summary>
|
||||
/// Represents resource usage statistics for a process at a point in time.
|
||||
/// </summary>
|
||||
public record ProcessResourceStats
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Gets the CPU usage percentage of the process.
|
||||
/// </summary>
|
||||
public double CpuPercentage { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the memory usage in bytes of the process.
|
||||
/// </summary>
|
||||
public long MemoryUsageBytes { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the total number of bytes read from disk by the process.
|
||||
/// </summary>
|
||||
public long DiskReadBytes { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the total number of bytes written to disk by the process.
|
||||
/// </summary>
|
||||
public long DiskWriteBytes { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the process identifier.
|
||||
/// </summary>
|
||||
public int ProcessId { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of threads currently running in the process.
|
||||
/// </summary>
|
||||
public int ThreadCount { get; init; }
|
||||
}
|
@ -2,10 +2,34 @@ using meilisearch.NET.Interfaces;
|
||||
|
||||
namespace meilisearch.NET.Services.DocumentManagement;
|
||||
|
||||
/// <summary>
|
||||
/// Manages document operations for Meilisearch indexes.
|
||||
/// </summary>
|
||||
public interface IDocumentManager
|
||||
{
|
||||
/// <summary>
|
||||
/// Adds a document to the specified repository.
|
||||
/// </summary>
|
||||
/// <param name="repositoryId">The ID of the repository to add the document to.</param>
|
||||
/// <param name="document">The document to add.</param>
|
||||
/// <param name="autoCommit">If true, automatically syncs the document to the server.</param>
|
||||
void AddDocument(string repositoryId, IDocument document, bool autoCommit = false);
|
||||
|
||||
/// <summary>
|
||||
/// Synchronizes all pending documents to the Meilisearch server.
|
||||
/// </summary>
|
||||
void SyncDocumentsToServer();
|
||||
|
||||
/// <summary>
|
||||
/// Asynchronously adds a document to the specified repository.
|
||||
/// </summary>
|
||||
/// <param name="repositoryId">The ID of the repository to add the document to.</param>
|
||||
/// <param name="document">The document to add.</param>
|
||||
/// <param name="autoCommit">If true, automatically syncs the document to the server.</param>
|
||||
Task AddDocumentAsync(string repositoryId, IDocument document, bool autoCommit = false);
|
||||
|
||||
/// <summary>
|
||||
/// Asynchronously synchronizes all pending documents to the Meilisearch server.
|
||||
/// </summary>
|
||||
Task SyncDocumentsToServerAsync();
|
||||
}
|
@ -2,17 +2,84 @@ using meilisearch.NET.Interfaces;
|
||||
|
||||
namespace meilisearch.NET.Services.IndexManagement;
|
||||
|
||||
/// <summary>
|
||||
/// Manages Meilisearch index operations including creation, deletion, and storage management.
|
||||
/// </summary>
|
||||
public interface IIndexManager
|
||||
{
|
||||
/// <summary>
|
||||
/// Retrieves a list of all index names from the Meilisearch server.
|
||||
/// </summary>
|
||||
/// <returns>A list of index names.</returns>
|
||||
Task<List<string>> GetAllIndexes();
|
||||
|
||||
/// <summary>
|
||||
/// Asynchronously creates a new index with the specified name for the given document type.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The document type that implements IDocument.</typeparam>
|
||||
/// <param name="indexName">The name of the index to create.</param>
|
||||
Task CreateIndexAsync<T>(string indexName) where T : IDocument;
|
||||
|
||||
/// <summary>
|
||||
/// Synchronously creates a new index with the specified name for the given document type.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The document type that implements IDocument.</typeparam>
|
||||
/// <param name="indexName">The name of the index to create.</param>
|
||||
void CreateIndex<T>(string indexName) where T : IDocument;
|
||||
|
||||
/// <summary>
|
||||
/// Asynchronously deletes the specified index.
|
||||
/// </summary>
|
||||
/// <param name="indexName">The name of the index to delete.</param>
|
||||
Task DeleteIndexAsync(string indexName);
|
||||
|
||||
/// <summary>
|
||||
/// Synchronously deletes the specified index.
|
||||
/// </summary>
|
||||
/// <param name="indexName">The name of the index to delete.</param>
|
||||
void DeleteIndex(string indexName);
|
||||
|
||||
/// <summary>
|
||||
/// Asynchronously enables or disables an index by compressing or decompressing it.
|
||||
/// </summary>
|
||||
/// <param name="indexName">The name of the index to modify.</param>
|
||||
/// <param name="enabled">True to enable (decompress), false to disable (compress).</param>
|
||||
Task SetIndexEnabledAsync(string indexName, bool enabled);
|
||||
|
||||
/// <summary>
|
||||
/// Synchronously enables or disables an index by compressing or decompressing it.
|
||||
/// </summary>
|
||||
/// <param name="indexName">The name of the index to modify.</param>
|
||||
/// <param name="enabled">True to enable (decompress), false to disable (compress).</param>
|
||||
void SetIndexEnabled(string indexName, bool enabled);
|
||||
|
||||
/// <summary>
|
||||
/// Asynchronously gets the storage usage of a specific index.
|
||||
/// </summary>
|
||||
/// <param name="indexName">The name of the index.</param>
|
||||
/// <param name="useCompressedSize">If true, returns compressed size for compressed indexes.</param>
|
||||
/// <returns>The storage usage in bytes.</returns>
|
||||
Task<long> GetIndexStorageUsageAsync(string indexName, bool useCompressedSize = true);
|
||||
|
||||
/// <summary>
|
||||
/// Asynchronously gets the total storage usage of all indexes.
|
||||
/// </summary>
|
||||
/// <param name="useCompressedSize">If true, uses compressed sizes for compressed indexes.</param>
|
||||
/// <returns>The total storage usage in bytes.</returns>
|
||||
Task<long> GetTotalStorageUsageAsync(bool useCompressedSize = true);
|
||||
|
||||
/// <summary>
|
||||
/// Synchronously gets the storage usage of a specific index.
|
||||
/// </summary>
|
||||
/// <param name="indexName">The name of the index.</param>
|
||||
/// <param name="useCompressedSize">If true, returns compressed size for compressed indexes.</param>
|
||||
/// <returns>The storage usage in bytes.</returns>
|
||||
long GetIndexStorageUsage(string indexName, bool useCompressedSize = true);
|
||||
|
||||
/// <summary>
|
||||
/// Synchronously gets the total storage usage of all indexes.
|
||||
/// </summary>
|
||||
/// <param name="useCompressedSize">If true, uses compressed sizes for compressed indexes.</param>
|
||||
/// <returns>The total storage usage in bytes.</returns>
|
||||
long GetTotalStorageUsage(bool useCompressedSize = true);
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
using System.Diagnostics;
|
||||
using meilisearch.NET.Exceptions;
|
||||
using meilisearch.NET.Models;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace meilisearch.NET.Services.ProcessManagement;
|
||||
|
@ -1,21 +1,33 @@
|
||||
using System.Diagnostics;
|
||||
using meilisearch.NET.Models;
|
||||
|
||||
namespace meilisearch.NET.Services.ProcessManagement;
|
||||
|
||||
/// <summary>
|
||||
/// Defines the contract for managing a process lifecycle and monitoring its resources.
|
||||
/// </summary>
|
||||
public interface IProcessManager : IDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// Starts the managed process asynchronously.
|
||||
/// </summary>
|
||||
/// <returns>A task representing the asynchronous operation.</returns>
|
||||
Task StartProcess();
|
||||
|
||||
/// <summary>
|
||||
/// Stops the managed process.
|
||||
/// </summary>
|
||||
void StopProcess();
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the managed process is currently running.
|
||||
/// </summary>
|
||||
/// <returns>True if the process is running, false otherwise.</returns>
|
||||
bool IsProcessRunning();
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves current resource usage statistics for the managed process.
|
||||
/// </summary>
|
||||
/// <returns>A ProcessResourceStats object containing resource usage information.</returns>
|
||||
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; }
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user