# NetworkResurrector.Agent.Wrapper

[NetworkResurrector.Agent](https://lab.code-rove.com/gitea/tudor.stanciu/network-resurrector/src/branch/master/backend/src/agent) is a .NET service designed to execute various host machine actions, including **Shutdown**, **Restart**, **Sleep**, **Logout**, and **Lock**.

**NetworkResurrector.Agent.Wrapper** is a NuGet package that simplifies the integration of the agent within a .NET environment. It registers a service, `IResurrectorAgentService`, in the application's service collection, providing methods for each supported action. The package communicates with the agent's API, offering a convenient interface for developers to manage host machines through the agent.

Once installed, the only additional step is to call the `UseResurrectorAgentServices` method during application startup. After this, `IResurrectorAgentService` can be injected into any class within the application.

## Features

- Simple integration with **NetworkResurrector.Agent**.
- Provides easy-to-use methods for host machine actions (Shutdown, Restart, Sleep, Logout, Lock).
- Registers `IResurrectorAgentService` for dependency injection in the application.
- Facilitates communication with the agent's API controller.

## Package Repository

You can install **NetworkResurrector.Agent.Wrapper** from my self-hosted NuGet feed: [https://lab.code-rove.com/public-nuget-server/](https://lab.code-rove.com/public-nuget-server/)

## Installation

### Visual Studio

#### NuGet.config File

Add the following to your `NuGet.config` file:

```xml
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <clear />
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
    <add key="lab.nuget" value="https://lab.code-rove.com/public-nuget-server/v3/index.json" />
  </packageSources>
</configuration>
```
Place this file in your Visual Studio solution directory or configure the new NuGet feed in the NuGet Package Manager. After this, you can install **NetworkResurrector.Agent.Wrapper** using the NuGet Package Manager.

### CLI
To install via the .NET CLI, run the following command in your project directory:
```bash
dotnet add package NetworkResurrector.Agent.Wrapper --source https://lab.code-rove.com/public-nuget-server/v3/index.json
```

## Usage
Once installed, call the UseResurrectorAgentServices method in your application startup code to register the service:

```csharp
public void ConfigureServices(IServiceCollection services)
{
    services.UseResurrectorAgentServices();
}
```
After this, the `IResurrectorAgentService` will be available for injection into any class:
```csharp
public class MyService
{
    private readonly IResurrectorAgentService _resurrectorAgentService;

    public MyService(IResurrectorAgentService resurrectorAgentService)
    {
        _resurrectorAgentService = resurrectorAgentService;
    }

    public void ShutdownHost()
    {
        _resurrectorAgentService.Shutdown();
    }
}
```

