Skip to content

Commit

Permalink
merge from develop
Browse files Browse the repository at this point in the history
  • Loading branch information
luca-domenichini committed Dec 15, 2023
2 parents 09adfc6 + 9355f3c commit a694d5c
Show file tree
Hide file tree
Showing 47 changed files with 534 additions and 384 deletions.
1 change: 1 addition & 0 deletions .github/workflows/dotnet-prerelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ jobs:
run: |
dotnet nuget push Connectors\SmartIOT.Connector.Mqtt\bin\Release\SmartIOT.Connector.Mqtt.${{ steps.version.outputs.PRODUCT_VERSION }}.nupkg -s https://api.nuget.org/v3/index.json -k ${{ secrets.NUGET_API_KEY }}
dotnet nuget push Connectors\SmartIOT.Connector.Tcp\bin\Release\SmartIOT.Connector.Tcp.${{ steps.version.outputs.PRODUCT_VERSION }}.nupkg -s https://api.nuget.org/v3/index.json -k ${{ secrets.NUGET_API_KEY }}
dotnet nuget push Core\SmartIOT.Connector.DependencyInjection\bin\Release\SmartIOT.Connector.DependencyInjection.${{ steps.version.outputs.PRODUCT_VERSION }}.nupkg -s https://api.nuget.org/v3/index.json -k ${{ secrets.NUGET_API_KEY }}
dotnet nuget push Core\SmartIOT.Connector.Messages\bin\Release\SmartIOT.Connector.Messages.${{ steps.version.outputs.PRODUCT_VERSION }}.nupkg -s https://api.nuget.org/v3/index.json -k ${{ secrets.NUGET_API_KEY }}
dotnet nuget push Core\SmartIOT.Connector.Prometheus\bin\Release\SmartIOT.Connector.Prometheus.${{ steps.version.outputs.PRODUCT_VERSION }}.nupkg -s https://api.nuget.org/v3/index.json -k ${{ secrets.NUGET_API_KEY }}
dotnet nuget push Core\SmartIOT.Connector.Core\bin\Release\SmartIOT.Connector.Core.${{ steps.version.outputs.PRODUCT_VERSION }}.nupkg -s https://api.nuget.org/v3/index.json -k ${{ secrets.NUGET_API_KEY }}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/dotnet-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ jobs:
run: |
dotnet nuget push Connectors\SmartIOT.Connector.Mqtt\bin\Release\SmartIOT.Connector.Mqtt.${{ steps.version.outputs.PRODUCT_VERSION }}.nupkg -s https://api.nuget.org/v3/index.json -k ${{ secrets.NUGET_API_KEY }}
dotnet nuget push Connectors\SmartIOT.Connector.Tcp\bin\Release\SmartIOT.Connector.Tcp.${{ steps.version.outputs.PRODUCT_VERSION }}.nupkg -s https://api.nuget.org/v3/index.json -k ${{ secrets.NUGET_API_KEY }}
dotnet nuget push Core\SmartIOT.Connector.DependencyInjection\bin\Release\SmartIOT.Connector.DependencyInjection.${{ steps.version.outputs.PRODUCT_VERSION }}.nupkg -s https://api.nuget.org/v3/index.json -k ${{ secrets.NUGET_API_KEY }}
dotnet nuget push Core\SmartIOT.Connector.Messages\bin\Release\SmartIOT.Connector.Messages.${{ steps.version.outputs.PRODUCT_VERSION }}.nupkg -s https://api.nuget.org/v3/index.json -k ${{ secrets.NUGET_API_KEY }}
dotnet nuget push Core\SmartIOT.Connector.Prometheus\bin\Release\SmartIOT.Connector.Prometheus.${{ steps.version.outputs.PRODUCT_VERSION }}.nupkg -s https://api.nuget.org/v3/index.json -k ${{ secrets.NUGET_API_KEY }}
dotnet nuget push Core\SmartIOT.Connector.Core\bin\Release\SmartIOT.Connector.Core.${{ steps.version.outputs.PRODUCT_VERSION }}.nupkg -s https://api.nuget.org/v3/index.json -k ${{ secrets.NUGET_API_KEY }}
Expand Down
24 changes: 0 additions & 24 deletions Apps/SmartIOT.Connector.App/AspNetExtensions.cs

This file was deleted.

21 changes: 19 additions & 2 deletions Apps/SmartIOT.Connector.App/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Asp.Versioning.ApiExplorer;
using Serilog;
using SmartIOT.Connector.DependencyInjection;
using SmartIOT.Connector.Prometheus;
using SmartIOT.Connector.RestApi;
using System.Diagnostics;
using System.Text.Json;
Expand Down Expand Up @@ -33,7 +35,7 @@ public static void Main(string[] args)
{
ReadCommentHandling = JsonCommentHandling.Skip
});
if (configuration == null)
if (configuration?.Configuration is null)
{
Console.WriteLine($"Configuration not valid for file {path}");
return;
Expand All @@ -48,7 +50,12 @@ public static void Main(string[] args)
builder.Logging.AddSerilog(dispose: true);

// Add SmartIOT.Connector services to the container.
builder.Services.AddSmartIotConnectorRunner(configuration);
builder.Services.AddSmartIOTConnector(cfg =>
{
cfg.WithAutoDiscoverConnectorFactories()
.WithAutoDiscoverDeviceDriverFactories()
.WithConfiguration(configuration.Configuration);
});

// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
Expand All @@ -69,8 +76,17 @@ public static void Main(string[] args)
o.ServiceName = typeof(Program).Assembly.GetName().Name!;
});

// ----------------------------------------------------------------------------
// build app
var app = builder.Build();

// configure more things on SmartIOT.Connector
app.UseSmartIOTConnector(cfg =>
{
if (configuration.PrometheusConfiguration is not null)
cfg.AddPrometheus(configuration.PrometheusConfiguration);
});

// Configure the HTTP request pipeline.
app.UseSwagger();
app.UseSwaggerUI(options =>
Expand All @@ -93,6 +109,7 @@ public static void Main(string[] args)
var logger = app.Services.GetRequiredService<ILogger<Program>>();
logger.LogInformation("{NewLine}{NewLine} --> SmartIOT.Connector v{version}{NewLine}", Environment.NewLine, Environment.NewLine, version, Environment.NewLine);

// --------------------------------------------------------------------------------
app.Run();
}

Expand Down
112 changes: 0 additions & 112 deletions Apps/SmartIOT.Connector.App/Runner.cs

This file was deleted.

3 changes: 2 additions & 1 deletion Apps/SmartIOT.Connector.App/SmartIOT.Connector.App.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFrameworks>net8.0</TargetFrameworks>
Expand Down Expand Up @@ -35,6 +35,7 @@
<ProjectReference Include="..\..\Connectors\SmartIOT.Connector.Mqtt\SmartIOT.Connector.Mqtt.csproj" />
<ProjectReference Include="..\..\Connectors\SmartIOT.Connector.Tcp\SmartIOT.Connector.Tcp.csproj" />
<ProjectReference Include="..\..\Core\SmartIOT.Connector.Core\SmartIOT.Connector.Core.csproj" />
<ProjectReference Include="..\..\Core\SmartIOT.Connector.DependencyInjection\SmartIOT.Connector.DependencyInjection.csproj" />
<ProjectReference Include="..\..\Core\SmartIOT.Connector.Prometheus\SmartIOT.Connector.Prometheus.csproj" />
<ProjectReference Include="..\..\Core\SmartIOT.Connector.RestApi\SmartIOT.Connector.RestApi.csproj" />
<ProjectReference Include="..\..\Devices\SmartIOT.Connector.Plc.S7Net\SmartIOT.Connector.Plc.S7Net.csproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,12 @@ public class AggregatingConnectorEventQueue : AggregatingQueue<CompositeConnecto
return null;
}

#pragma warning disable S1172 // Unused method parameters should be removed

private CompositeConnectorEvent? AggregateExceptionEvents(object? sender, ExceptionEventArgs item1, ExceptionEventArgs item2)
{
return null;
}

#pragma warning restore S1172 // Unused method parameters should be removed
}
2 changes: 1 addition & 1 deletion Core/SmartIOT.Connector.Core/Connector/AggregatingQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public T PopWait(CancellationToken cancellationToken)
{
T? item = default;

while (_queue.Any())
while (_queue.Count > 0)
{
if (item == default)
{
Expand Down
44 changes: 22 additions & 22 deletions Core/SmartIOT.Connector.Core/Factory/ConnectorFactory.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
namespace SmartIOT.Connector.Core.Factory
namespace SmartIOT.Connector.Core.Factory;

public class ConnectorFactory : IConnectorFactory
{
public class ConnectorFactory : IConnectorFactory
{
private readonly List<IConnectorFactory> _factories = new List<IConnectorFactory>();
private readonly List<IConnectorFactory> _factories = new List<IConnectorFactory>();

public void Add(IConnectorFactory factory)
{
_factories.Add(factory);
}

public void Add(IConnectorFactory factory)
{
_factories.Add(factory);
}
public void AddRange(IList<IConnectorFactory> connectorFactories)
{
_factories.AddRange(connectorFactories);
}
public bool Any(Func<IConnectorFactory, bool> predicate)
{
return _factories.Any(x => predicate(x));
}
public void AddRange(IList<IConnectorFactory> connectorFactories)
{
_factories.AddRange(connectorFactories);
}

public IConnector? CreateConnector(string connectionString)
{
return _factories.Select(x => x.CreateConnector(connectionString))
.FirstOrDefault(x => x != null);
}
public bool Any(Func<IConnectorFactory, bool> predicate)
{
return _factories.Exists(x => predicate(x));
}

}
public IConnector? CreateConnector(string connectionString)
{
return _factories.Select(x => x.CreateConnector(connectionString))
.FirstOrDefault(x => x != null);
}
}
55 changes: 24 additions & 31 deletions Core/SmartIOT.Connector.Core/Factory/DeviceDriverFactory.cs
Original file line number Diff line number Diff line change
@@ -1,41 +1,34 @@
using SmartIOT.Connector.Core.Conf;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SmartIOT.Connector.Core.Factory
{
public class DeviceDriverFactory : IDeviceDriverFactory
{
private readonly List<IDeviceDriverFactory> _factories = new List<IDeviceDriverFactory>();
namespace SmartIOT.Connector.Core.Factory;

public void Add(IDeviceDriverFactory factory)
{
_factories.Add(factory);
}
public class DeviceDriverFactory : IDeviceDriverFactory
{
private readonly List<IDeviceDriverFactory> _factories = new List<IDeviceDriverFactory>();

public void AddRange(IList<IDeviceDriverFactory> deviceDriverFactories)
{
_factories.AddRange(deviceDriverFactories);
}
public void Add(IDeviceDriverFactory factory)
{
_factories.Add(factory);
}

public bool Any() => _factories.Any();
public void AddRange(IList<IDeviceDriverFactory> deviceDriverFactories)
{
_factories.AddRange(deviceDriverFactories);
}

public bool Any(Func<object, bool> predicate) => _factories.Any(predicate);
public bool Any() => _factories.Count > 0;

public IDeviceDriver? CreateDriver(DeviceConfiguration deviceConfiguration)
{
foreach (var factory in _factories)
{
var d = factory.CreateDriver(deviceConfiguration);
if (d != null)
return d;
}
public bool Any(Func<object, bool> predicate) => _factories.Exists(x => predicate.Invoke(x));

return null;
}
public IDeviceDriver? CreateDriver(DeviceConfiguration deviceConfiguration)
{
foreach (var factory in _factories)
{
var d = factory.CreateDriver(deviceConfiguration);
if (d != null)
return d;
}

}
return null;
}
}
Loading

0 comments on commit a694d5c

Please sign in to comment.