Skip to content

Commit

Permalink
CHG rename SmartIOT.Connector.ConsoleApp to SmartIOT.Connector.App
Browse files Browse the repository at this point in the history
  • Loading branch information
luca-domenichini committed Dec 14, 2023
1 parent 01ca6d6 commit 7b640e5
Show file tree
Hide file tree
Showing 22 changed files with 52 additions and 120 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -348,4 +348,4 @@ MigrationBackup/

# Ionide (cross platform F# VS Code tools) working folder
.ionide/
/Apps/SmartIOT.Connector.ConsoleApp/log.txt
/Apps/SmartIOT.Connector.App/log.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using SmartIOT.Connector.Core;
using SmartIOT.Connector.Prometheus;

namespace SmartIOT.Connector.ConsoleApp;
namespace SmartIOT.Connector.App;

public class AppConfiguration
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
using SmartIOT.Connector.Core;
using SmartIOT.Connector.Core.Factory;

namespace SmartIOT.Connector.ConsoleApp;
namespace SmartIOT.Connector.App;

public static class AspNetExtensions
{
public static IServiceCollection AddSmartIotConnectorRunner(this IServiceCollection services, AppConfiguration configuration)
{
// Add SmartIOT.Connector services to the container.
services.AddSingleton<AppConfiguration>(configuration);
services.AddSingleton<SmartIotConnector>(s => s.GetRequiredService<Runner>().SmartIotConnector);
services.AddSingleton(configuration);
services.AddSingleton(s => s.GetRequiredService<Runner>().SmartIotConnector);
services.AddSingleton<IConnectorFactory>(s => s.GetRequiredService<Runner>().ConnectorFactory);
services.AddSingleton<IDeviceDriverFactory>(s => s.GetRequiredService<Runner>().DeviceDriverFactory);
services.AddSingleton<ISchedulerFactory>(s => s.GetRequiredService<Runner>().SchedulerFactory);
services.AddSingleton<ITimeService>(s => s.GetRequiredService<Runner>().TimeService);
services.AddSingleton(s => s.GetRequiredService<Runner>().SchedulerFactory);
services.AddSingleton(s => s.GetRequiredService<Runner>().TimeService);

// add custom Runner as a singleton and as a hosted service
services.AddSingleton<Runner>();
services.AddHostedService<Runner>(sp => sp.GetRequiredService<Runner>());
services.AddHostedService(sp => sp.GetRequiredService<Runner>());

return services;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using SmartIOT.Connector.RestApi.Services;
using System.Text.Json;

namespace SmartIOT.Connector.ConsoleApp;
namespace SmartIOT.Connector.App;

internal class ConfigurationPersister : IConfigurationPersister
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ ARG version
# Copy everything
COPY . ./
# Restore as distinct layers
RUN dotnet restore SmartIOT.Connector.ConsoleApp.sln
RUN dotnet restore SmartIOT.Connector.App.sln

RUN dotnet build --no-restore -c Release SmartIOT.Connector.ConsoleApp.sln
RUN dotnet build --no-restore -c Release SmartIOT.Connector.App.sln

RUN dotnet publish -c Release -o out /p:version=$version SmartIOT.Connector.ConsoleApp.sln
RUN dotnet publish -c Release -o out /p:version=$version SmartIOT.Connector.App.sln

# Build runtime image
FROM mcr.microsoft.com/dotnet/aspnet:6.0
WORKDIR /app
COPY --from=build-env /build/out .
ENTRYPOINT ["dotnet", "SmartIOT.Connector.ConsoleApp.dll", "/SmartIOT.Connector/smartiot-config.json"]
ENTRYPOINT ["dotnet", "SmartIOT.Connector.App.dll", "/SmartIOT.Connector/smartiot-config.json"]
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Diagnostics;
using System.Text.Json;

namespace SmartIOT.Connector.ConsoleApp;
namespace SmartIOT.Connector.App;

public class Program
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
}
},
"profiles": {
"SmartIOT.Connector.ConsoleApp": {
"SmartIOT.Connector.App": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "swagger",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SmartIOT.Connector.ConsoleApp
# SmartIOT.Connector.App

This project implements a simple SmartIOT.Connector runner able to run a SmartIOT.Connector instance as a console application.

Expand All @@ -11,15 +11,15 @@ The sample configuration will log to the console and to daily rolling file <code
The Console runner can also be run on Docker. You just need to map a volume pointing the configuration folder <code>/SmartIOT.Connector</code> and expose the ports needed for external communications.<br>
The container image will look for configuration file at <code>/SmartIOT.Connector/smartiot-config.json</code>

A prebuilt Docker image is also available on Docker Hub. Use the following command to pull the latest image, or browse https://hub.docker.com/repository/docker/lucadomenichini/smartiot-connector-consoleapp for available tags.
A prebuilt Docker image is also available on Docker Hub. Use the following command to pull the latest image, or browse https://hub.docker.com/repository/docker/lucadomenichini/smartiot-connector-app for available tags.

<pre>docker pull lucadomenichini/smartiot-connector-consoleapp:latest</pre>
<pre>docker pull lucadomenichini/smartiot-connector-app:latest</pre>

### Building the Docker image from source

Provided you installed docker on your machine, go to SmartIOT.Connector root project folder and type:

<pre>docker build -t smartiot-connector -f Apps/SmartIOT.Connector.ConsoleApp/Dockerfile .</pre>
<pre>docker build -t smartiot-connector -f Apps/SmartIOT.Connector.App/Dockerfile .</pre>

### Running the container

Expand All @@ -32,6 +32,6 @@ Type this to run the container and expose ports on the host machine:
docker run -it --rm -v /path/to/smartiot-connector/configuration/folder:/SmartIOT.Connector -p 9001:9001 -p 1883:1883 smartiot-connector
</pre>

Suppose you have downloaded the solution on Windows on folder C:\develop\SmartIOT.Connector. You will have an <code>smartiot-config.json</code> file under the <code>SmartIOT.Connector.ConsoleApp</code> project folder.<br>
Suppose you have downloaded the solution on Windows on folder C:\develop\SmartIOT.Connector. You will have an <code>smartiot-config.json</code> file under the <code>SmartIOT.Connector.App</code> project folder.<br>
Type this to use that configuration file:<pre>
docker run -it --rm -v C:\develop\SmartIOT.Connector\Apps\SmartIOT.Connector.ConsoleApp:/SmartIOT.Connector -p 9001:9001 -p 1883:1883 smartiot-connector</pre>
docker run -it --rm -v C:\develop\SmartIOT.Connector\Apps\SmartIOT.Connector.App:/SmartIOT.Connector -p 9001:9001 -p 1883:1883 smartiot-connector</pre>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using SmartIOT.Connector.Core.Factory;
using SmartIOT.Connector.Prometheus;

namespace SmartIOT.Connector.ConsoleApp;
namespace SmartIOT.Connector.App;

public class Runner : IHostedService
{
Expand Down
2 changes: 1 addition & 1 deletion Core/SmartIOT.Connector.RestApi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ To plug the controllers you just need to call an extension method to your AspNet
builder.Services.AddSmartIotConnectorRestApi(new ConfigurationPersister(configuration, path));
```

See project [SmartIOT.Connector.ConsoleApp](../../Apps/SmartIOT.Connector.ConsoleApp/README.md) to see how that's done in details.
See project [SmartIOT.Connector.App](../../Apps/SmartIOT.Connector.App/README.md) to see how that's done in details.

You can then use the Swagger API page to test your API calls:

Expand Down
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,15 @@ smartiot.Stop();
- [REST API guide](./Core/SmartIOT.Connector.RestApi/README.md)
- [Customization guide](./Docs/Customize.md)

## SmartIOT.Connector.ConsoleApp and Docker integration
## SmartIOT.Connector.App and Docker integration

If you want to run SmartIOT.Connector as a standalone application or as a Docker container, see project [SmartIOT.Connector.ConsoleApp](./Apps/SmartIOT.Connector.ConsoleApp/README.md) for further details.
If you want to run SmartIOT.Connector as a standalone application or as a Docker container, see project [SmartIOT.Connector.App](./Apps/SmartIOT.Connector.App/README.md) for further details.

Here is a quick link to the Docker image repository: <https://hub.docker.com/repository/docker/lucadomenichini/smartiot-connector-consoleapp>
Here is a quick link to the Docker image repository: <https://hub.docker.com/repository/docker/lucadomenichini/smartiot-connector-app>

## Run as a Windows Service

The application [SmartIOT.Connector.ConsoleApp](./Apps/SmartIOT.Connector.ConsoleApp/README.md) supports being run as a WinService.
The application [SmartIOT.Connector.App](./Apps/SmartIOT.Connector.App/README.md) supports being run as a WinService.
All you need to do is install it and run.
Follow [this guide](https://learn.microsoft.com/en-us/dotnet/core/extensions/windows-service?pivots=dotnet-8-0#create-the-windows-service) for further informations

Expand Down Expand Up @@ -132,13 +132,12 @@ I will do my best to keep the interfaces stable, but there are possibilities to
- [ ] GRPC Server Connector
- [X] TCP Server Connector
- [X] TCP Client Connector
- [ ] Web app with monitoring capabilities (included in default ConsoleApp project)
- [ ] Web app with monitoring capabilities (included in default App project)
- [X] Nuget packages on nuget.org - <https://www.nuget.org/packages?q=SmartIOT.Connector>
- [X] Docker runner image on dockerhub - <https://hub.docker.com/repository/docker/lucadomenichini/smartiot-connector-consoleapp>
- [ ] Apps
- [X] Docker runner image on dockerhub - <https://hub.docker.com/repository/docker/lucadomenichini/smartiot-connector-app>
- [X] Apps
- [X] Run SmartIOT.Connector as a console app
- [X] Run SmartIOT.Connector as a Docker image
- [ ] Run SmartIOT.Connector as a WPF app
- [X] Run SmartIOT.Connector as a WinService
- [ ] Testers: connector counterpart as WPF app
- [ ] GRPC Client
Expand Down
67 changes: 0 additions & 67 deletions SmartIOT.Connector.ConsoleApp.sln

This file was deleted.

20 changes: 10 additions & 10 deletions SmartIOT.Connector.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
ProjectSection(SolutionItems) = preProject
.dockerignore = .dockerignore
.editorconfig = .editorconfig
docker-build-consoleapp.bat = docker-build-consoleapp.bat
docker-push-consoleapp.bat = docker-push-consoleapp.bat
docker-run-consoleapp.bat = docker-run-consoleapp.bat
docker-build-app.bat = docker-build-app.bat
docker-push-app.bat = docker-push-app.bat
docker-run-app.bat = docker-run-app.bat
dotnet-build-and-push.bat = dotnet-build-and-push.bat
.github\workflows\dotnet-develop.yml = .github\workflows\dotnet-develop.yml
.github\workflows\dotnet-master.yml = .github\workflows\dotnet-master.yml
Expand Down Expand Up @@ -55,8 +55,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SmartIOT.Connector.TcpServe
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Apps", "Apps", "{56D33DD2-28C6-45C5-B994-54FA4D8055F5}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SmartIOT.Connector.ConsoleApp", "Apps\SmartIOT.Connector.ConsoleApp\SmartIOT.Connector.ConsoleApp.csproj", "{B6B46E61-F57A-4843-BEF6-180C82382E15}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SmartIOT.Connector.Mocks", "Tests\SmartIOT.Connector.Mocks\SmartIOT.Connector.Mocks.csproj", "{442D217B-E924-4A67-BE4F-FE68D8471C11}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SmartIOT.Connector.RestApi", "Core\SmartIOT.Connector.RestApi\SmartIOT.Connector.RestApi.csproj", "{E39654FA-5AA3-4C69-94B8-0BEF1272349C}"
Expand All @@ -65,6 +63,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SmartIOT.Connector.RestApi.
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SmartIOT.Connector.Plc.SnapModBus", "Devices\SmartIOT.Connector.Plc.SnapModBus\SmartIOT.Connector.Plc.SnapModBus.csproj", "{BA4F5CF9-A2F9-4CA4-BAE1-27AEF1EC2800}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SmartIOT.Connector.App", "Apps\SmartIOT.Connector.App\SmartIOT.Connector.App.csproj", "{2943C3E6-C95D-4D9F-A3DE-FCA2B6AB3349}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -131,10 +131,6 @@ Global
{AEA92EE6-91CC-4D88-AF51-2B5A2714B328}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AEA92EE6-91CC-4D88-AF51-2B5A2714B328}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AEA92EE6-91CC-4D88-AF51-2B5A2714B328}.Release|Any CPU.Build.0 = Release|Any CPU
{B6B46E61-F57A-4843-BEF6-180C82382E15}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B6B46E61-F57A-4843-BEF6-180C82382E15}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B6B46E61-F57A-4843-BEF6-180C82382E15}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B6B46E61-F57A-4843-BEF6-180C82382E15}.Release|Any CPU.Build.0 = Release|Any CPU
{442D217B-E924-4A67-BE4F-FE68D8471C11}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{442D217B-E924-4A67-BE4F-FE68D8471C11}.Debug|Any CPU.Build.0 = Debug|Any CPU
{442D217B-E924-4A67-BE4F-FE68D8471C11}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -151,6 +147,10 @@ Global
{BA4F5CF9-A2F9-4CA4-BAE1-27AEF1EC2800}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BA4F5CF9-A2F9-4CA4-BAE1-27AEF1EC2800}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BA4F5CF9-A2F9-4CA4-BAE1-27AEF1EC2800}.Release|Any CPU.Build.0 = Release|Any CPU
{2943C3E6-C95D-4D9F-A3DE-FCA2B6AB3349}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2943C3E6-C95D-4D9F-A3DE-FCA2B6AB3349}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2943C3E6-C95D-4D9F-A3DE-FCA2B6AB3349}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2943C3E6-C95D-4D9F-A3DE-FCA2B6AB3349}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -164,9 +164,9 @@ Global
{58E07F42-929C-40B0-A61B-C9AC8B88855C} = {E8D19B9A-719C-4FCF-931B-2492F32063D4}
{57778892-A6E7-410D-86C8-5CF061F40DF6} = {805C2ECD-B0EB-4021-B040-DB1C487D132A}
{AEA92EE6-91CC-4D88-AF51-2B5A2714B328} = {805C2ECD-B0EB-4021-B040-DB1C487D132A}
{B6B46E61-F57A-4843-BEF6-180C82382E15} = {56D33DD2-28C6-45C5-B994-54FA4D8055F5}
{442D217B-E924-4A67-BE4F-FE68D8471C11} = {E8D19B9A-719C-4FCF-931B-2492F32063D4}
{4EC87D61-7FC7-413A-9B35-7D15AAB2308F} = {E8D19B9A-719C-4FCF-931B-2492F32063D4}
{2943C3E6-C95D-4D9F-A3DE-FCA2B6AB3349} = {56D33DD2-28C6-45C5-B994-54FA4D8055F5}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {72862639-80E2-4903-910B-7FC4EC818672}
Expand Down
6 changes: 3 additions & 3 deletions docker-build-consoleapp.bat → docker-build-app.bat
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
echo off

set LOCAL_IMAGE=smartiot-connector-consoleapp
set REMOTE_IMAGE=lucadomenichini/smartiot-connector-consoleapp
set LOCAL_IMAGE=smartiot-connector-app
set REMOTE_IMAGE=lucadomenichini/smartiot-connector-app
set /P TAG_NAME="Enter the tag name to assign to image %REMOTE_IMAGE%: "

docker build --build-arg version=%TAG_NAME% -t %LOCAL_IMAGE%:latest -f Apps/SmartIOT.Connector.ConsoleApp/Dockerfile .
docker build --build-arg version=%TAG_NAME% -t %LOCAL_IMAGE%:latest -f Apps/SmartIOT.Connector.App/Dockerfile .

docker tag %LOCAL_IMAGE%:latest %REMOTE_IMAGE%:latest
docker tag %LOCAL_IMAGE%:latest %REMOTE_IMAGE%:%TAG_NAME%
2 changes: 1 addition & 1 deletion docker-push-consoleapp.bat → docker-push-app.bat
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
echo off

set REMOTE_IMAGE=lucadomenichini/smartiot-connector-consoleapp
set REMOTE_IMAGE=lucadomenichini/smartiot-connector-app
set /P TAG_NAME="Enter the tag name to push for image %REMOTE_IMAGE%: "

docker push %REMOTE_IMAGE%:%TAG_NAME%
Expand Down
1 change: 1 addition & 0 deletions docker-run-app.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
docker run -it --rm -v C:\develop\SmartIOT.Connector\Apps\SmartIOT.Connector.App:/SmartIOT.Connector -p 1883:1883 smartiot-connector-app:latest
1 change: 0 additions & 1 deletion docker-run-consoleapp.bat

This file was deleted.

Loading

0 comments on commit 7b640e5

Please sign in to comment.