# Getting Started

# Prerequisites

Shaper is a multiplatform project.

For production or staging environment, you need only the latest "ASP.NET Core Runtime".

[https://dotnet.microsoft.com/en-us/download/dotnet](https://dotnet.microsoft.com/en-us/download/dotnet)

For development, you need also the latest "Visual Studio".

[https://visualstudio.microsoft.com/en-us/downloads/](https://visualstudio.microsoft.com/en-us/downloads/)

If you want to use a local database, "Microsoft SQL Server" is recommended.

[https://www.microsoft.com/en-us/sql-server/sql-server-downloads ](https://www.microsoft.com/en-us/sql-server/sql-server-downloads)

## Cloud or On Premise

Shaper is based on ASP.NET so you can host it where you want:

- On Premise with Windows and IIS
- On Premise with Linux and Nginx
- In a Docker environment
- On Microsoft Azure
- ...and so on!

# Development Environment

Clone the "Shaper" main library from GitHub [https://github.com/brayns-it/shaper](https://github.com/brayns-it/shaper)

Create a new empty ASP.NET Core Project and simply call "InitializeShaper" and "MapShaperApi".

```c#
using Brayns.Shaper;

var builder = WebApplication.CreateBuilder(args);
builder.InitializeShaper();

var app = builder.Build();
app.MapShaperApi();

app.Run();
```

"MapShaperApi" will map two path in your web application:

- /api to serve REST request with GET, POST, PUT or DELETE method
- /rpc to serve special JSON request for the client

If you want to use also the web client (not only API) you have to clone "Shaper Web" library from GitHub [https://github.com/brayns-it/shaper-web](https://github.com/brayns-it/shaper-web)

Simply declare the web client and Web Sockets support:

```c#
app.MapShaperClient();
app.UseWebSockets();
```

"MapShaperClient" will catch all requests from "/client" base URI and serve the default index.html client page.

If you want to redirect also "/" path to default client page, add the following code:

```c#
app.MapShaperDefault();
```

Enable serving of static files and allows unknown MIME types (for example to enable Let's Encrypt HTTP validaton):

```c#
app.UseStaticFiles(new StaticFileOptions
{
    ServeUnknownFileTypes = true,
    DefaultContentType = "application/other"
});
```

To enable scheduled task:

```c#
app.UseShaperMonitor();
```

Mark the ASP.NET assembly as Shaper App container within the "AssemblyInfo" file (create it if doesn't exists):

```c#
[assembly: Brayns.Shaper.Classes.AppCollection]
```

Create the following directory structure:

- **code** (that contains specific project code)
- **var** (that contains configuration and logs)
- **var\\resources** (that contains embedded resources)
- **wwwroot** (that contains HTTP served resources)

## Complete "program.cs" example

```c#
using Brayns.Shaper;

var builder = WebApplication.CreateBuilder(args);
builder.InitializeShaper();

var app = builder.Build();
app.MapShaperApi();
app.MapShaperClient();
app.MapShaperDefault();
app.UseWebSockets();
app.UseStaticFiles(new StaticFileOptions
{
    ServeUnknownFileTypes = true,
    DefaultContentType = "application/other"
});
app.UseShaperMonitor();

app.Run();

```

## Project Configuration

Project Configuration (csproj) must be adapted to:

- Embed PO files with translations
- Deploy **var\\resources** folder

```xml
<Project Sdk="Microsoft.NET.Sdk.Web">
  ...
  ...
  
  <ItemGroup>
    <None Remove="**/*.po" />
  </ItemGroup>

  <ItemGroup>
    <EmbeddedResource Include="**/*.po" />
  </ItemGroup>

  <ItemGroup>
    <None Update="var\resources\**">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
  </ItemGroup>

  ...
  ...
</Project>  
```

## Publish Profile

Add the following lines to Publish Profile (pubxml) to preserve "var" directory:

```xml
<Project>
  ...
  ...
  
  <ItemGroup>
    <Content Update="var\resources" CopyToPublishDirectory="PreserveNewest" />
    <Content Update="var\**" CopyToPublishDirectory="Never" />
  </ItemGroup>

  ..
  ..
</Project>
```