Plugins - local copied to the app folder

This commit is contained in:
Stoyan Zlatev
2024-06-05 13:56:32 +02:00
parent f7b4a13fb7
commit 09d88e5bdc
13 changed files with 131 additions and 64 deletions
+5 -11
View File
@@ -1,23 +1,17 @@
namespace CommonConsole
{
using Common.SqlExtensions;
using OmniPlus;
using OmniPlus.Features;
using System;
using System.Linq;
using System.Threading;
using System.IO;
public static class Program
{
public static void Main()
{
var a = 816242311982;
var b = (int)a;
Console.WriteLine(a);
Console.WriteLine(b);
var plugins = Directory.CreateDirectory(@"Z:\Programme_Sensus\plugins");
var files = plugins.GetFiles("*.Plugins.*.dll", SearchOption.AllDirectories);
Console.ReadKey();
//var connection = new OmniIrdaConnection("COM36");
//connection.StateChenged += Console.WriteLine;
//connection.Open();
@@ -12,6 +12,7 @@
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@@ -21,6 +22,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
@@ -29,6 +31,7 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
@@ -12,6 +12,7 @@
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@@ -22,6 +23,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<RegisterForComInterop>false</RegisterForComInterop>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
@@ -30,6 +32,7 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
@@ -12,6 +12,7 @@
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@@ -21,6 +22,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
@@ -29,6 +31,7 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
@@ -12,6 +12,7 @@
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@@ -21,6 +22,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
@@ -29,10 +31,14 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup>
<RunPostBuildEvent>OnOutputUpdated</RunPostBuildEvent>
</PropertyGroup>
<PropertyGroup>
<AutoGenerateBindingRedirects>false</AutoGenerateBindingRedirects>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
@@ -74,7 +80,6 @@
</PreBuildEvent>
</PropertyGroup>
<PropertyGroup>
<PostBuildEvent>
</PostBuildEvent>
<PostBuildEvent>xcopy "$(TargetDir)*.*" "\\sla12file\auftrag\Programme_Sensus\plugins\omni" /Y</PostBuildEvent>
</PropertyGroup>
</Project>
@@ -136,8 +136,8 @@
if (firstTP && flush > 0)
{
firstTP = false;
_ = new ManualResetEventSlim()
.Wait(flush, this.cancellationToken);
var awaiter = new ManualResetEventSlim();
awaiter.Wait(flush, this.cancellationToken);
}
if (this.cancellationToken.IsCancellationRequested)
@@ -12,6 +12,7 @@
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@@ -21,6 +22,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
@@ -29,6 +31,7 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup>
<RunPostBuildEvent>OnOutputUpdated</RunPostBuildEvent>
+4 -4
View File
@@ -4,12 +4,12 @@
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
<appSettings>
<add key="PluginsDirectory" value="\\sla12file\Auftrag\Programme_Sensus\plugins"/>
<add key="PluginsDirectory" value="Z:\Programme_Sensus\plugins"/>
<add key="PSNR" value="0000"/>
<!--<add key="HubURL" value="http://localhost:52822/LaaProductionWeb" />-->
<add key="HubURL" value="http://sla12iis01.emea.sensus.net/LaaProductionWeb" />
<add key="LaaProductionWeb" value="http://localhost:52822/LaaProductionWeb/" />
<add key="RemoteControl" value="http://localhost:52822/LaaProductionWeb" />
<add key="HubURL" value="http://sla12iis01.emea.sensus.net/LaaProductionWeb"/>
<add key="LaaProductionWeb" value="http://localhost:52822/LaaProductionWeb/"/>
<add key="RemoteControl" value="http://localhost:52822/LaaProductionWeb"/>
<add key="OmniDB" value="Server=SLASQL01.emea.sensus.net; Database=Auftrag; User ID=sa; Password=sqlserver;"/>
<add key="COMPorts" value="COM36"/>
<add key="FlushMinutes" value=""/>
@@ -15,6 +15,23 @@
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
<TargetFrameworkProfile />
<IsWebBootstrapper>false</IsWebBootstrapper>
<PublishUrl>Z:\Programme_Sensus\InspectionUI\</PublishUrl>
<Install>true</Install>
<InstallFrom>Unc</InstallFrom>
<UpdateEnabled>true</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<InstallUrl>\\sla12file\Auftrag\Programme_Sensus\InspectionUI\</InstallUrl>
<ApplicationRevision>5</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<PublishWizardCompleted>true</PublishWizardCompleted>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
@@ -25,6 +42,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
@@ -34,6 +52,19 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup>
<ManifestCertificateThumbprint>CF3FEABBF7AAC02E604ED3DE12ADF685DE6828DB</ManifestCertificateThumbprint>
</PropertyGroup>
<PropertyGroup>
<ManifestKeyFile>InspectionUI_TemporaryKey.pfx</ManifestKeyFile>
</PropertyGroup>
<PropertyGroup>
<GenerateManifests>true</GenerateManifests>
</PropertyGroup>
<PropertyGroup>
<SignManifests>true</SignManifests>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.AspNet.SignalR.Client, Version=2.4.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
@@ -136,18 +167,20 @@
<Project>{C6BFAC88-5647-4131-90B1-4D6265E08348}</Project>
<Name>InspectionUI.Abstraction</Name>
</ProjectReference>
<ProjectReference Include="..\InspectionUI.Plugins.Controls\InspectionUI.Plugins.Controls.csproj">
<Project>{ebf13d20-08c9-4984-8b21-6fb7419a622a}</Project>
<Name>InspectionUI.Plugins.Controls</Name>
</ProjectReference>
<ProjectReference Include="..\InspectionUI.Plugins.Omni\InspectionUI.Plugins.Omni.csproj">
<Project>{8e1431e9-9b14-4bc2-8b65-47357c97b1fc}</Project>
<Name>InspectionUI.Plugins.Omni</Name>
</ProjectReference>
<ProjectReference Include="..\InspectionUI.RemoteControl\InspectionUI.RemoteControl.csproj">
<Project>{41E949AD-FBF6-47A3-AC1D-7E17AB7F1252}</Project>
<Name>InspectionUI.RemoteControl</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>xcopy "$(TargetDir)*.*" "\\sla12file\vorlagen\Stoyan\OMNI prüfung\InspectionUI" /Y</PostBuildEvent>
</PropertyGroup>
</Project>
@@ -34,6 +34,7 @@
Padding="5"
SelectedValue="{Binding Plugin}"
Style="{DynamicResource ComboBoxStyle}"
Visibility="{Binding PluginsDropdownVisibility}"
VerticalContentAlignment="Center"
MinWidth="150" />
<TextBox Grid.Column="1"
@@ -17,6 +17,7 @@
private TestBench testBench;
private PluginsManager pluginsManager;
private Visibility notificationsVisibility;
private Visibility pluginsDropdownVisibility;
public MainWindowVM() : base()
{
@@ -32,6 +33,7 @@
this.testBench.Notification += notification
=> this.Notifications = notification;
this.notificationsVisibility = Visibility.Collapsed;
this.pluginsDropdownVisibility = Visibility.Collapsed;
this.LoadAvailablePlugins();
}
@@ -116,6 +118,12 @@
set => this.Set(() => this.notificationsVisibility = value);
}
public Visibility PluginsDropdownVisibility
{
get => this.pluginsDropdownVisibility;
set => this.Set(() => this.pluginsDropdownVisibility = value);
}
public ItemsGridVM ItemsGridSource { get; }
public ICommand LoadInspectionParameters { get; }
@@ -137,7 +145,6 @@
base.Dispose();
this.testBench?.Dispose();
this.TestBatch?.Dispose();
this.pluginsManager?.Dispose();
}
private void OnLoadInspectionParameters()
@@ -232,6 +239,16 @@
{
this.DispatcherInvoke(() => this.Plugins.Add(plugin));
}
if (this.Plugins.Count == 1)
{
this.Plugin = this.Plugins[0];
}
this.PluginsDropdownVisibility
= this.Plugins.Count > 1
? Visibility.Visible
: Visibility.Collapsed;
})
.ContinueWith(task =>
{
@@ -13,8 +13,6 @@
{
private readonly IDictionary<string, Type> entryPoints
= new Dictionary<string, Type>();
private readonly AppDomain pluginsDomain
= AppDomain.CreateDomain("Plugins");
internal bool IsActivated { get; private set; }
@@ -23,7 +21,7 @@
if (!string.IsNullOrWhiteSpace(plugin) && this.entryPoints.ContainsKey(plugin))
{
var entryPoint = this.entryPoints[plugin];
var instance = Activator.CreateInstance(entryPoint, testBench, App.Appsettings);
var instance = Activator.CreateInstance(entryPoint, new object[] { testBench, App.Appsettings });
if (instance is ITestBatch testBatch)
{
@@ -36,39 +34,23 @@
internal IEnumerable<string> AvailablePlugins()
{
var plugins = Directory.GetFiles(App.Appsettings.CurrentDirectory, "InspectionUI.Plugins.*.dll", SearchOption.AllDirectories);
var assemblyName = default(AssemblyName);
var assembly = default(Assembly);
var localDirectory = Path.GetDirectoryName(typeof(PluginsManager).Assembly.Location);
foreach (var plugin in plugins)
CopyDirectories(App.Appsettings.PluginsDirectory, localDirectory);
var pluginFiles = Directory.GetFiles(localDirectory, "*Plugins*.dll", SearchOption.AllDirectories);
foreach (var pluginFile in pluginFiles)
{
assemblyName = AssemblyName.GetAssemblyName(plugin);
assembly = this.pluginsDomain.Load(assemblyName);
var types = assembly.GetTypes();
var entryPoint = types.FirstOrDefault(x => !x.IsAbstract
&& !x.IsInterface
&& typeof(ITestBatch).IsAssignableFrom(x));
if (entryPoint is null)
{
continue;
}
var name = assemblyName
.Name
.Split('.')
.LastOrDefault();
foreach (var attr in entryPoint.GetCustomAttributes(true))
{
if (attr is TestBatchAttribute testBatchAttribute)
{
name = testBatchAttribute.DisplayName;
break;
}
}
var assembly = Assembly.LoadFrom(pluginFile);
var entryPoint = assembly
.GetTypes()
.FirstOrDefault(x => !x.IsAbstract && typeof(TestBatchBase).IsAssignableFrom(x));
var name = (entryPoint
.GetCustomAttributes(true)
?.FirstOrDefault(x => x is TestBatchAttribute _)
as TestBatchAttribute)
?.DisplayName ?? entryPoint.Name;
this.entryPoints[name] = entryPoint;
@@ -76,7 +58,29 @@
}
}
internal void Dispose()
=> AppDomain.Unload(this.pluginsDomain);
private static void CopyDirectories(string sourceDirectory, string destinationDirectory)
{
CopyFiles(sourceDirectory, destinationDirectory);
foreach (var subDirectory in Directory.GetDirectories(sourceDirectory))
{
var subDirectoryName = new DirectoryInfo(subDirectory).Name;
var destinationSubDirectoryPath = Path.Combine(destinationDirectory, subDirectoryName);
var destinationSubDirectory = Directory.CreateDirectory(destinationSubDirectoryPath).FullName;
CopyDirectories(subDirectory, destinationSubDirectory);
}
}
private static void CopyFiles(string sourceDirectory, string destinationDirectory)
{
foreach (var sourceFile in Directory.GetFiles(sourceDirectory))
{
var sourceFileName = Path.GetFileName(sourceFile);
var destinationFile = Path.Combine(destinationDirectory, sourceFileName);
File.Copy(sourceFile, destinationFile, true);
}
}
}
}
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="AppDomainToolkit" version="1.0.4.3" targetFramework="net45" />
<package id="Microsoft.AspNet.SignalR.Client" version="2.4.3" targetFramework="net40" />
<package id="Newtonsoft.Json" version="13.0.3" targetFramework="net48" requireReinstallation="true" />
</packages>