Quellcode durchsuchen

Update python runtime for MQTTnet.Server.

release/3.x.x
Christian Kratky vor 4 Jahren
Ursprung
Commit
c89918a890
7 geänderte Dateien mit 34 neuen und 38 gelöschten Zeilen
  1. +2
    -2
      Source/MQTTnet.Server/MQTTnet.Server.csproj
  2. +5
    -5
      Source/MQTTnet.Server/Scripting/DataSharing/DataSharingService.cs
  3. +4
    -4
      Source/MQTTnet.Server/Scripting/PythonIOStream.cs
  4. +17
    -17
      Source/MQTTnet.Server/Scripting/PythonScriptHostService.cs
  5. +3
    -3
      Source/MQTTnet.Server/Scripting/PythonScriptInstance.cs
  6. +2
    -2
      Source/MQTTnet.Server/Web/Startup.cs
  7. +1
    -5
      Source/MQTTnet.Server/appsettings.json

+ 2
- 2
Source/MQTTnet.Server/MQTTnet.Server.csproj Datei anzeigen

@@ -43,8 +43,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="IronPython" Version="2.7.9" />
<PackageReference Include="IronPython.StdLib" Version="2.7.9" />
<PackageReference Include="IronPython" Version="2.7.10-candidate1" />
<PackageReference Include="IronPython.StdLib" Version="2.7.10-candidate1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.3" />
<PackageReference Include="MSTest.TestAdapter" Version="2.1.1" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="5.3.1" />


+ 5
- 5
Source/MQTTnet.Server/Scripting/DataSharing/DataSharingService.cs Datei anzeigen

@@ -1,14 +1,14 @@
using System;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using Microsoft.Extensions.Logging;

namespace MQTTnet.Server.Scripting.DataSharing
{
public class DataSharingService
{
private readonly Dictionary<string, object> _storage = new Dictionary<string, object>();
private readonly PythonScriptHostService _pythonScriptHostService;
private readonly ILogger<DataSharingService> _logger;
readonly Dictionary<string, object> _storage = new Dictionary<string, object>();
readonly PythonScriptHostService _pythonScriptHostService;
readonly ILogger<DataSharingService> _logger;

public DataSharingService(PythonScriptHostService pythonScriptHostService, ILogger<DataSharingService> logger)
{


+ 4
- 4
Source/MQTTnet.Server/Scripting/PythonIOStream.cs Datei anzeigen

@@ -1,14 +1,14 @@
using System;
using Microsoft.Extensions.Logging;
using System;
using System.IO;
using System.Text;
using Microsoft.Extensions.Logging;

namespace MQTTnet.Server.Scripting
{
public class PythonIOStream : Stream
{
private readonly ILogger _logger;
private readonly Encoding _encoder = Encoding.UTF8;
readonly ILogger _logger;
readonly Encoding _encoder = Encoding.UTF8;

public PythonIOStream(ILogger<PythonIOStream> logger)
{


+ 17
- 17
Source/MQTTnet.Server/Scripting/PythonScriptHostService.cs Datei anzeigen

@@ -1,4 +1,8 @@
using System;
using Microsoft.Extensions.Logging;
using Microsoft.Scripting;
using Microsoft.Scripting.Hosting;
using MQTTnet.Server.Configuration;
using System;
using System.Collections.Generic;
using System.Dynamic;
using System.IO;
@@ -6,22 +10,18 @@ using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Microsoft.Scripting;
using Microsoft.Scripting.Hosting;
using MQTTnet.Server.Configuration;

namespace MQTTnet.Server.Scripting
{
public class PythonScriptHostService
{
private readonly IDictionary<string, object> _proxyObjects = new ExpandoObject();
private readonly List<PythonScriptInstance> _scriptInstances = new List<PythonScriptInstance>();
private readonly string _scriptsPath;
private readonly ScriptingSettingsModel _scriptingSettings;
private readonly ILogger<PythonScriptHostService> _logger;
private readonly ScriptEngine _scriptEngine;
readonly IDictionary<string, object> _proxyObjects = new ExpandoObject();
readonly List<PythonScriptInstance> _scriptInstances = new List<PythonScriptInstance>();
readonly string _scriptsPath;
readonly ScriptingSettingsModel _scriptingSettings;
readonly ILogger<PythonScriptHostService> _logger;
readonly ScriptEngine _scriptEngine;
public PythonScriptHostService(ScriptingSettingsModel scriptingSettings, PythonIOStream pythonIOStream, ILogger<PythonScriptHostService> logger)
{
_scriptingSettings = scriptingSettings ?? throw new ArgumentNullException(nameof(scriptingSettings));
@@ -139,7 +139,7 @@ namespace MQTTnet.Server.Scripting
}
}

private async Task TryInitializeScriptAsync(string path)
async Task TryInitializeScriptAsync(string path)
{
var uid = new FileInfo(path).Name.Replace(".py", string.Empty, StringComparison.OrdinalIgnoreCase);

@@ -155,7 +155,7 @@ namespace MQTTnet.Server.Scripting
{
_scriptInstances.Add(scriptInstance);
}
_logger.LogInformation($"Initialized script '{uid}'.");
}
catch (Exception exception)
@@ -164,7 +164,7 @@ namespace MQTTnet.Server.Scripting
}
}

private PythonScriptInstance CreateScriptInstance(string uid, string path, string code)
PythonScriptInstance CreateScriptInstance(string uid, string path, string code)
{
var scriptScope = _scriptEngine.CreateScope();

@@ -173,11 +173,11 @@ namespace MQTTnet.Server.Scripting

scriptScope.SetVariable("mqtt_net_server", _proxyObjects);
compiledCode.Execute(scriptScope);
return new PythonScriptInstance(uid, path, scriptScope);
}

private void AddSearchPaths(ScriptEngine scriptEngine)
void AddSearchPaths(ScriptEngine scriptEngine)
{
if (_scriptingSettings.IncludePaths?.Any() != true)
{


+ 3
- 3
Source/MQTTnet.Server/Scripting/PythonScriptInstance.cs Datei anzeigen

@@ -1,12 +1,12 @@
using System;
using IronPython.Runtime;
using IronPython.Runtime;
using Microsoft.Scripting.Hosting;
using System;

namespace MQTTnet.Server.Scripting
{
public class PythonScriptInstance
{
private readonly ScriptScope _scriptScope;
readonly ScriptScope _scriptScope;

public PythonScriptInstance(string uid, string path, ScriptScope scriptScope)
{


+ 2
- 2
Source/MQTTnet.Server/Web/Startup.cs Datei anzeigen

@@ -152,7 +152,7 @@ namespace MQTTnet.Server.Web
.AddCookie();
}

private void ReadMqttSettings(IServiceCollection services)
void ReadMqttSettings(IServiceCollection services)
{
var mqttSettings = new MqttSettingsModel();
Configuration.Bind("MQTT", mqttSettings);
@@ -163,7 +163,7 @@ namespace MQTTnet.Server.Web
services.AddSingleton(scriptingSettings);
}

private static void ConfigureWebSocketEndpoint(
static void ConfigureWebSocketEndpoint(
IApplicationBuilder application,
MqttServerService mqttServerService,
MqttSettingsModel mqttSettings)


+ 1
- 5
Source/MQTTnet.Server/appsettings.json Datei anzeigen

@@ -52,11 +52,7 @@
},
"Scripting": {
"ScriptsPath": "Scripts",
"IncludePaths": [
"Lib",
"/usr/lib/python2.7",
"C:\\Python27\\Lib"
]
"IncludePaths": []
},
"Logging": {
"LogLevel": {


Laden…
Abbrechen
Speichern