gtb: pwd change, register
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
namespace InspectionUI.ViewModels
|
||||
{
|
||||
using InspectionUI.Models;
|
||||
|
||||
using OmniPlus;
|
||||
|
||||
public class DefaultsHeaderRow : ItemsGridRowVM
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
namespace InspectionUI.ViewModels
|
||||
{
|
||||
using InspectionUI.Models;
|
||||
|
||||
using OmniPlus;
|
||||
|
||||
public class DefaultsRowVM : ItemsGridRowVM
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
public abstract class ItemsGridVM : VM, IEnumerable<ItemsGridRowVM>
|
||||
{
|
||||
private readonly IList<ItemsGridRowVM> rows;
|
||||
private readonly List<ItemsGridRowVM> rows;
|
||||
|
||||
protected ItemsGridVM() : base()
|
||||
{
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
namespace InspectionUI.ViewModels
|
||||
{
|
||||
using OmniPlus;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Windows.Input;
|
||||
|
||||
public class MainVM : VM
|
||||
@@ -13,13 +13,18 @@
|
||||
this.Reload = new Command(this.ReloadCommand);
|
||||
this.StartInspection = new Command(this.StartInspectionCommand);
|
||||
this.CancelInspection = new Command(this.CancelInspectionCommand);
|
||||
this.MetersPool = new MetersPoolVM(this.ConnectionType);
|
||||
this.Sizes = this.MetersPool.LoadSizes();
|
||||
this.Size = this.Sizes.FirstOrDefault();
|
||||
this.Types = this.MetersPool.LoadTypes();
|
||||
this.Type = this.Types.FirstOrDefault();
|
||||
}
|
||||
|
||||
private int size;
|
||||
public int Size
|
||||
private string size;
|
||||
public string Size
|
||||
{
|
||||
get => Math.Max(this.size - 5, 0);
|
||||
set => this.Set(() => this.size = value + 5);
|
||||
get => this.size;
|
||||
set => this.Set(() => this.size = value);
|
||||
}
|
||||
|
||||
private string type;
|
||||
@@ -36,6 +41,13 @@
|
||||
set => this.Set(() => this.suchnr = value);
|
||||
}
|
||||
|
||||
private int connectionType;
|
||||
public int ConnectionType
|
||||
{
|
||||
get => this.connectionType;
|
||||
set => this.Set(() => this.connectionType = value);
|
||||
}
|
||||
|
||||
private bool keepCorrection;
|
||||
public bool KeepCorrection
|
||||
{
|
||||
@@ -83,29 +95,40 @@
|
||||
private set => this.Set(() => this.metersPoolVM = value);
|
||||
}
|
||||
|
||||
public IList<string> Sizes { get; }
|
||||
|
||||
public IList<string> Types { get; }
|
||||
|
||||
private void ReloadCommand()
|
||||
{
|
||||
this.EnableButtons(false);
|
||||
|
||||
this.IsReloadEnabled = false;
|
||||
this.Errors = default(string);
|
||||
|
||||
if (this.MetersPool != null)
|
||||
{
|
||||
this.MetersPool.Dispose();
|
||||
}
|
||||
|
||||
this.MetersPool = new MetersPoolVM();
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(this.SuchNr))
|
||||
{
|
||||
this.MetersPool.LoadAuftrag(this.SuchNr);
|
||||
|
||||
if (!this.MetersPool.HasPruefpunkte)
|
||||
{
|
||||
this.IsReloadEnabled = true;
|
||||
this.Errors = $"Keine daten gefunden für FertigungauftragsNr: {this.suchnr}";
|
||||
}
|
||||
}
|
||||
else if (this.size >= 0 && !string.IsNullOrWhiteSpace(this.type))
|
||||
else if (!string.IsNullOrWhiteSpace(this.size) && !string.IsNullOrWhiteSpace(this.type))
|
||||
{
|
||||
this.MetersPool.LoadAuftrag((byte)this.size, this.type);
|
||||
this.MetersPool.LoadAuftrag(this.size, this.type);
|
||||
|
||||
if (!this.MetersPool.HasPruefpunkte)
|
||||
{
|
||||
this.IsReloadEnabled = true;
|
||||
this.Errors = $"Keine daten gefunden für Größe: {this.size} und Typ: {this.type}";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.IsReloadEnabled = true;
|
||||
this.Errors = "FertigungauftragsNr oder Größe und Typ eingeben!";
|
||||
}
|
||||
|
||||
@@ -122,10 +145,6 @@
|
||||
this.EnableButtons(true);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
this.EnableButtons(true);
|
||||
}
|
||||
}
|
||||
|
||||
private void StartInspectionCommand()
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
using OmniPlus;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Timers;
|
||||
@@ -10,13 +12,20 @@
|
||||
|
||||
public class MeterVM : ItemsGridRowVM
|
||||
{
|
||||
private readonly Queue<string> states;
|
||||
private readonly OmniMeter meter;
|
||||
private readonly Thread logger;
|
||||
|
||||
private int uinr = 0;
|
||||
private int uinr;
|
||||
private bool active;
|
||||
|
||||
public MeterVM(OmniMeter meter) : base()
|
||||
{
|
||||
this.meter = meter;
|
||||
this.meter.StateChanged += this.Meter_StateChanged;
|
||||
this.states = new Queue<string>();
|
||||
this.logger = this.OpenLogging();
|
||||
this.logger.Start(this);
|
||||
|
||||
this.Add(new ItemsGridHeaderVM { Value = $"{this.meter.SlotNr, 2}." });
|
||||
this.Add(new ItemsGridCellVM());
|
||||
@@ -55,6 +64,35 @@
|
||||
get => this.serialNr;
|
||||
set => this.Set(() => this.serialNr = value, value, "{0}", 2);
|
||||
}
|
||||
|
||||
internal Task ConnectAsync(int connectionType, CancellationToken cancellationToken)
|
||||
{
|
||||
void Connect(object state)
|
||||
{
|
||||
if (state is MeterVM vm)
|
||||
{
|
||||
vm.meter.Connect(connectionType);
|
||||
}
|
||||
}
|
||||
|
||||
return this.StartTask(Connect, cancellationToken);
|
||||
}
|
||||
|
||||
public Task IdentifySelfAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
void IdentifySelf(object state)
|
||||
{
|
||||
if (state is MeterVM vm)
|
||||
{
|
||||
vm.meter.IdentifySelf();
|
||||
|
||||
vm.MeterNr = vm.meter.MeterNr;
|
||||
vm.active = vm.meter.IsActive;
|
||||
}
|
||||
}
|
||||
|
||||
return this.StartTask(IdentifySelf, cancellationToken);
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
@@ -64,7 +102,16 @@
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
this.meter.NotifyStateChanged($"[{DateTime.Now}] {e}");
|
||||
this.meter.NotifyStateChanged(e);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
this.logger.Abort();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
base.Dispose();
|
||||
@@ -74,18 +121,13 @@
|
||||
{
|
||||
void LoadTestRun(object state)
|
||||
{
|
||||
if (state is MeterVM meterVM)
|
||||
if (state is MeterVM vm && vm.active)
|
||||
{
|
||||
if (!meterVM.meter.IsConnected)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
meterVM.meter.LoadTestRun();
|
||||
vm.meter.LoadTestRun();
|
||||
}
|
||||
}
|
||||
|
||||
return this.StartNewTask(LoadTestRun, this, cancellationToken);
|
||||
return this.StartTask(LoadTestRun, cancellationToken);
|
||||
}
|
||||
|
||||
public Task InitializeInspectionAsync(bool keepCorrection, CancellationToken cancellationToken)
|
||||
@@ -97,87 +139,67 @@
|
||||
|
||||
void InitializeInspection(object state)
|
||||
{
|
||||
if (state is MeterVM meterVM)
|
||||
if (state is MeterVM vm && vm.active)
|
||||
{
|
||||
meterVM.uinr = 0;
|
||||
vm.uinr = 0;
|
||||
|
||||
var meter = meterVM.meter;
|
||||
|
||||
if (!meter.IsConnected)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var meter = vm.meter;
|
||||
|
||||
meter.InitializeForInspection(keepCorrection);
|
||||
meterVM.Set(meter.TestRun.CrrfBefore, "{0:0.0}", 3);
|
||||
vm.Set(meter.TestRun.CrrfBefore, "{0:0.0}", 3);
|
||||
}
|
||||
}
|
||||
|
||||
return this.StartNewTask(InitializeInspection, this, cancellationToken);
|
||||
return this.StartTask(InitializeInspection, cancellationToken);
|
||||
}
|
||||
|
||||
public Task StartCalibrationAsync(OmniPruefpunkt pp, CancellationToken cancellationToken)
|
||||
{
|
||||
void StartCalibration(object state)
|
||||
{
|
||||
if (state is MeterVM meterVM)
|
||||
if (state is MeterVM vm && vm.active)
|
||||
{
|
||||
meterVM.uinr++;
|
||||
vm.uinr++;
|
||||
|
||||
var _pp = pp;
|
||||
var meter = meterVM.meter;
|
||||
|
||||
if (!meter.IsConnected)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var meter = vm.meter;
|
||||
|
||||
meter.StartCalibration((ushort)_pp.Rotations, (ushort)_pp.Duration);
|
||||
meterVM.ShowRestTime(_pp.Duration, meterVM.uinr * 3 + 1);
|
||||
vm.ShowRestTime(_pp.Duration, vm.uinr * 3 + 1);
|
||||
}
|
||||
}
|
||||
|
||||
return this.StartNewTask(StartCalibration, this, cancellationToken);
|
||||
return this.StartTask(StartCalibration, cancellationToken);
|
||||
}
|
||||
|
||||
public Task StopCalibrationAsync(OmniPruefpunkt pp, double refm3s, CancellationToken cancellationToken)
|
||||
{
|
||||
void StopCalibration(object state)
|
||||
{
|
||||
if (state is MeterVM meterVM)
|
||||
if (state is MeterVM vm && vm.active)
|
||||
{
|
||||
var _pp = pp;
|
||||
var meter = meterVM.meter;
|
||||
|
||||
if (!meter.IsConnected)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var meter = vm.meter;
|
||||
|
||||
var response = meter.StopCalibration(_pp, refm3s);
|
||||
var index = meterVM.uinr * 3 + 1;
|
||||
var index = vm.uinr * 3 + 1;
|
||||
|
||||
meterVM.Set(response.Item2, "{0}", index);
|
||||
meterVM.Set(response.Item1, "{0:0.0000000}", index + 1);
|
||||
meterVM.Set(response.Item3, "{0:0.00}", index + 2);
|
||||
vm.Set(response.Item2, "{0}", index);
|
||||
vm.Set(response.Item1, "{0:0.0000000}", index + 1);
|
||||
vm.Set(response.Item3, "{0:0.00}", index + 2);
|
||||
}
|
||||
}
|
||||
|
||||
return this.StartNewTask(StopCalibration, this, cancellationToken);
|
||||
return this.StartTask(StopCalibration, cancellationToken);
|
||||
}
|
||||
|
||||
public Task FinishInspectionAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
void FinishInspection(object state)
|
||||
{
|
||||
if (state is MeterVM meterVM)
|
||||
if (state is MeterVM vm && vm.active)
|
||||
{
|
||||
var meter = meterVM.meter;
|
||||
|
||||
if (!meter.IsConnected)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var meter = vm.meter;
|
||||
|
||||
meter.FinishInspection();
|
||||
|
||||
@@ -186,16 +208,16 @@
|
||||
? Brushes.Green
|
||||
: Brushes.Red;
|
||||
|
||||
meterVM.Set(x => x.Foreground = foreground, meterVM.LastIndex);
|
||||
meterVM.Set(crrf, "{0:0.0}", meterVM.LastIndex);
|
||||
meterVM.uinr = 1;
|
||||
vm.Set(x => x.Foreground = foreground, vm.LastIndex);
|
||||
vm.Set(crrf, "{0:0.0}", vm.LastIndex);
|
||||
vm.uinr = 1;
|
||||
|
||||
foreach (var testedPP in meter.TestRun.TestedPoints)
|
||||
{
|
||||
var index = meterVM.uinr * 3 + 1 + 2;
|
||||
var index = vm.uinr * 3 + 1 + 2;
|
||||
|
||||
meterVM.Set(testedPP.Acc, "{0:0.00}", index);
|
||||
meterVM.Set(x =>
|
||||
vm.Set(testedPP.Acc, "{0:0.00}", index);
|
||||
vm.Set(x =>
|
||||
{
|
||||
foreground = testedPP.Succeeded == true
|
||||
? Brushes.Green
|
||||
@@ -203,12 +225,12 @@
|
||||
x.Foreground = foreground;
|
||||
}, index);
|
||||
|
||||
meterVM.uinr++;
|
||||
vm.uinr++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this.StartNewTask(FinishInspection, this, cancellationToken);
|
||||
return this.StartTask(FinishInspection, cancellationToken);
|
||||
}
|
||||
|
||||
private void ShowRestTime(int duration, int index)
|
||||
@@ -246,5 +268,49 @@
|
||||
|
||||
this.Set(default(string), "{0}", index);
|
||||
}
|
||||
|
||||
private Task StartTask(Action<object> executable, CancellationToken cancellationToken)
|
||||
{
|
||||
return this
|
||||
.StartNewTask(executable, this, cancellationToken)
|
||||
.ContinueWith(t =>
|
||||
{
|
||||
if (t.Exception != null && t.AsyncState is MeterVM vm)
|
||||
{
|
||||
vm.meter.NotifyStateChanged(t.Exception);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void Meter_StateChanged(object state)
|
||||
{
|
||||
this.states.Enqueue($"[{DateTime.Now:HH:mm:ss.fff}] {state}{Environment.NewLine}");
|
||||
}
|
||||
|
||||
private Thread OpenLogging()
|
||||
{
|
||||
return new Thread(state =>
|
||||
{
|
||||
if (state is MeterVM vm)
|
||||
{
|
||||
var root = Directory.CreateDirectory(App.CurrentDirectory);
|
||||
var ps = root.CreateSubdirectory($"{vm.meter.PSNR ?? "0000"}");
|
||||
var slot = ps.CreateSubdirectory($"{vm.meter.SlotNr}");
|
||||
var file = Path.Combine(slot.FullName, $"{DateTime.Now:yyyyMMddHHmmss}.txt");
|
||||
var awaiter = new ManualResetEventSlim();
|
||||
|
||||
while (true)
|
||||
{
|
||||
while (vm.states.Count > 0)
|
||||
{
|
||||
File.AppendAllText(file, vm.states.Dequeue());
|
||||
}
|
||||
|
||||
awaiter.Wait(1000);
|
||||
awaiter.Reset();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
using OmniPlus;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
@@ -12,19 +13,34 @@
|
||||
public class MetersPoolVM : ItemsGridVM
|
||||
{
|
||||
private readonly OmniContext omniContext;
|
||||
private readonly int connectionType;
|
||||
|
||||
private CancellationTokenSource cancellationTokenSource;
|
||||
private ReferenceMeterVM referenceMeter;
|
||||
|
||||
public MetersPoolVM() : base()
|
||||
public MetersPoolVM(int connectionType) : base()
|
||||
{
|
||||
this.omniContext = OmniContext.Current;
|
||||
this.connectionType = connectionType;
|
||||
this.omniContext = OmniContext.Create(Appsettings.OmniDB, Appsettings.CurrentDirectory);
|
||||
}
|
||||
|
||||
public Boolean HasPruefpunkte { get; private set; }
|
||||
|
||||
internal IList<String> LoadTypes()
|
||||
{
|
||||
return this.omniContext.LoadTypes();
|
||||
}
|
||||
|
||||
internal IList<String> LoadSizes()
|
||||
{
|
||||
return this.omniContext.LoadSizes();
|
||||
}
|
||||
|
||||
public void CancelInspection()
|
||||
{
|
||||
this.cancellationTokenSource?.Cancel();
|
||||
this.referenceMeter?.Stop();
|
||||
this.Dispose();
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
@@ -36,9 +52,15 @@
|
||||
|
||||
public void LoadMetersAsync()
|
||||
{
|
||||
if (!this.HasPruefpunkte)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this.referenceMeter = new ReferenceMeterVM(OmniContext.Current);
|
||||
|
||||
this.Add(this.referenceMeter);
|
||||
|
||||
this.omniContext.LoadMeters(Appsettings.COMPorts, Appsettings.PSNR);
|
||||
|
||||
foreach (var meter in this.omniContext.Meters)
|
||||
@@ -47,32 +69,55 @@
|
||||
}
|
||||
|
||||
this.NotifyPropertyChanged();
|
||||
|
||||
this.cancellationTokenSource = new CancellationTokenSource();
|
||||
var cancellationToken = this.cancellationTokenSource.Token;
|
||||
|
||||
var tasks = new List<Task>();
|
||||
var metersVM = this
|
||||
.Select(x => x is MeterVM m ? m : null)
|
||||
.Where(x => x != null)
|
||||
.ToArray();
|
||||
|
||||
foreach (var vm in metersVM)
|
||||
{
|
||||
tasks.Add(vm.ConnectAsync(this.connectionType, cancellationToken));
|
||||
}
|
||||
|
||||
this.WaitAll(tasks);
|
||||
|
||||
foreach (var vm in metersVM)
|
||||
{
|
||||
tasks.Add(vm.IdentifySelfAsync(cancellationToken));
|
||||
}
|
||||
|
||||
this.WaitAll(tasks);
|
||||
this.NotifyPropertyChanged();
|
||||
}
|
||||
|
||||
public void RunInspection(bool keepCorrection = false)
|
||||
{
|
||||
// show reference meter seconds
|
||||
this.cancellationTokenSource = new CancellationTokenSource();
|
||||
var cancellationToken = this.cancellationTokenSource.Token;
|
||||
var tasks = new List<Task>();
|
||||
var meters = this
|
||||
var metersVM = this
|
||||
.Select(x => x is MeterVM m ? m : null)
|
||||
.Where(x => x != null)
|
||||
.ToArray();
|
||||
|
||||
foreach (var meterVM in meters)
|
||||
foreach (var vm in metersVM)
|
||||
{
|
||||
tasks.Add(meterVM.LoadTestRunAsync(cancellationToken));
|
||||
tasks.Add(vm.LoadTestRunAsync(cancellationToken));
|
||||
}
|
||||
|
||||
this.ContinueWhenAll(tasks);
|
||||
this.WaitAll(tasks);
|
||||
|
||||
foreach (var meterVM in meters)
|
||||
foreach (var vm in metersVM)
|
||||
{
|
||||
tasks.Add(meterVM.InitializeInspectionAsync(keepCorrection, cancellationToken));
|
||||
tasks.Add(vm.InitializeInspectionAsync(keepCorrection, cancellationToken));
|
||||
}
|
||||
|
||||
this.ContinueWhenAll(tasks);
|
||||
this.WaitAll(tasks);
|
||||
|
||||
var pruefpunkte = this.omniContext
|
||||
.Auftrag
|
||||
@@ -92,12 +137,12 @@
|
||||
break;
|
||||
}
|
||||
|
||||
foreach (var meterVM in meters)
|
||||
foreach (var vm in metersVM)
|
||||
{
|
||||
tasks.Add(meterVM.StartCalibrationAsync(pp, cancellationToken));
|
||||
tasks.Add(vm.StartCalibrationAsync(pp, cancellationToken));
|
||||
}
|
||||
|
||||
this.ContinueWhenAll(tasks);
|
||||
this.WaitAll(tasks);
|
||||
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
@@ -111,12 +156,12 @@
|
||||
break;
|
||||
}
|
||||
|
||||
foreach (var meterVM in meters)
|
||||
foreach (var vm in metersVM)
|
||||
{
|
||||
tasks.Add(meterVM.StopCalibrationAsync(pp, refm3s, cancellationToken));
|
||||
tasks.Add(vm.StopCalibrationAsync(pp, refm3s, cancellationToken));
|
||||
}
|
||||
|
||||
this.ContinueWhenAll(tasks);
|
||||
this.WaitAll(tasks);
|
||||
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
@@ -126,26 +171,42 @@
|
||||
|
||||
this.referenceMeter.Stop();
|
||||
|
||||
foreach (var meterVM in meters)
|
||||
foreach (var vm in metersVM)
|
||||
{
|
||||
tasks.Add(meterVM.FinishInspectionAsync(cancellationToken));
|
||||
tasks.Add(vm.FinishInspectionAsync(cancellationToken));
|
||||
}
|
||||
|
||||
this.ContinueWhenAll(tasks);
|
||||
this.WaitAll(tasks);
|
||||
}
|
||||
|
||||
internal void LoadAuftrag(byte size, string type)
|
||||
internal void LoadAuftrag(string size, string type)
|
||||
{
|
||||
this.Dispose();
|
||||
this.NotifyPropertyChanged();
|
||||
|
||||
this.omniContext.LoadAuftrag(size, type);
|
||||
|
||||
this.UpdateItemsGridHeaders();
|
||||
this.HasPruefpunkte = this.omniContext.Pruefpunkte.Any();
|
||||
|
||||
if (this.HasPruefpunkte)
|
||||
{
|
||||
this.UpdateItemsGridHeaders();
|
||||
}
|
||||
}
|
||||
|
||||
internal void LoadAuftrag(string suchNr)
|
||||
{
|
||||
this.Dispose();
|
||||
this.NotifyPropertyChanged();
|
||||
|
||||
this.omniContext.LoadAuftrag(suchNr);
|
||||
|
||||
this.UpdateItemsGridHeaders();
|
||||
this.HasPruefpunkte = this.omniContext.Pruefpunkte.Any();
|
||||
|
||||
if (this.HasPruefpunkte)
|
||||
{
|
||||
this.UpdateItemsGridHeaders();
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateItemsGridHeaders()
|
||||
|
||||
@@ -0,0 +1,206 @@
|
||||
namespace InspectionUI.ViewModels
|
||||
{
|
||||
using InspectionUI.Models;
|
||||
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
public class PluginsVM : VM
|
||||
{
|
||||
const string Plugins = nameof(Plugins);
|
||||
const string Abstraction = nameof(Abstraction);
|
||||
|
||||
private readonly FileSystemWatcher fileSystemWatcher;
|
||||
private readonly DirectoryInfo pluginsDirectory;
|
||||
private readonly string basePlugin;
|
||||
|
||||
public PluginsVM()
|
||||
{
|
||||
var pluginsPath = Path.Combine(Appsettings.CurrentDirectory, Plugins);
|
||||
this.pluginsDirectory = Directory.CreateDirectory(pluginsPath);
|
||||
this.basePlugin = Path.Combine(this.pluginsDirectory.Parent.FullName, $"{Plugins}.{Abstraction}.dll");
|
||||
this.fileSystemWatcher = new FileSystemWatcher()
|
||||
{
|
||||
Path = this.pluginsDirectory.FullName,
|
||||
EnableRaisingEvents = true,
|
||||
Filter = $"{Plugins}.*.dll",
|
||||
IncludeSubdirectories = false,
|
||||
NotifyFilter = NotifyFilters.CreationTime
|
||||
| NotifyFilters.FileName,
|
||||
};
|
||||
this.fileSystemWatcher.Created += this.FileSystemWatcher_PluginAdded;
|
||||
this.fileSystemWatcher.Deleted += this.FileSystemWatcher_PluginDeleted;
|
||||
this.fileSystemWatcher.Changed += this.FileSystemWatcher_PluginUpdated;
|
||||
this.fileSystemWatcher.Renamed += this.FileSystemWatcher_PluginUpdated;
|
||||
this.ItemsSource = new ObservableCollection<PluginVM>();
|
||||
|
||||
this.LoadExistingPlugins();
|
||||
}
|
||||
|
||||
public ObservableCollection<PluginVM> ItemsSource { get; }
|
||||
|
||||
private void FileSystemWatcher_PluginAdded(object sender, FileSystemEventArgs args)
|
||||
{
|
||||
if (args.ChangeType == WatcherChangeTypes.Created)
|
||||
{
|
||||
var plugin = this.LoadPlugin(args.FullPath);
|
||||
|
||||
if (plugin != null)
|
||||
{
|
||||
this.DispatcherInvoke(() =>
|
||||
{
|
||||
this.ItemsSource.Add(plugin);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void FileSystemWatcher_PluginUpdated(object sender, FileSystemEventArgs args)
|
||||
{
|
||||
if (args.ChangeType == WatcherChangeTypes.Changed || args.ChangeType == WatcherChangeTypes.Renamed)
|
||||
{
|
||||
var plugin = this.LoadPlugin(args.FullPath);
|
||||
|
||||
if (plugin != null)
|
||||
{
|
||||
this.DispatcherInvoke(() =>
|
||||
{
|
||||
this.ItemsSource.Add(plugin);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void FileSystemWatcher_PluginDeleted(object sender, FileSystemEventArgs args)
|
||||
{
|
||||
if (args.ChangeType == WatcherChangeTypes.Deleted)
|
||||
{
|
||||
var plugin = this.ItemsSource.FirstOrDefault(x => x.Path == args.FullPath);
|
||||
|
||||
if (plugin != null)
|
||||
{
|
||||
this.DispatcherInvoke(() =>
|
||||
{
|
||||
this.ItemsSource.Remove(plugin);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadExistingPlugins()
|
||||
{
|
||||
foreach (var fileInfo in this.pluginsDirectory.GetFiles())
|
||||
{
|
||||
if (fileInfo.Name.StartsWith(Plugins) && fileInfo.Extension.EndsWith("dll"))
|
||||
{
|
||||
var plugin = this.LoadPlugin(fileInfo.FullName);
|
||||
|
||||
if (plugin != null)
|
||||
{
|
||||
this.DispatcherInvoke(() =>
|
||||
{
|
||||
this.ItemsSource.Add(plugin);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private PluginVM LoadPlugin(string pluginDLL)
|
||||
{
|
||||
if (pluginDLL == this.basePlugin)
|
||||
{
|
||||
return default(PluginVM);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var domain = AppDomain.CreateDomain($"{Guid.NewGuid()}");
|
||||
//var abstraction = domain.Load(new AssemblyName { CodeBase = this.basePlugin });
|
||||
var plugin = domain.Load(new AssemblyName { CodeBase = pluginDLL });
|
||||
var pluginAttributes = plugin.GetCustomAttributes(true);
|
||||
var pluginVM = new PluginVM
|
||||
{
|
||||
Path = pluginDLL,
|
||||
Version = plugin.GetName().Version.ToString()
|
||||
};
|
||||
var pluginVMProperties = typeof(PluginVM)
|
||||
.GetProperties(BindingFlags.Public | BindingFlags.Instance);
|
||||
|
||||
foreach (var property in pluginVMProperties)
|
||||
{
|
||||
var propertyName = property.Name;
|
||||
|
||||
try
|
||||
{
|
||||
if (property.GetValue(pluginVM, null) is null)
|
||||
{
|
||||
foreach (var attribute in pluginAttributes)
|
||||
{
|
||||
var attributeType = attribute.GetType();
|
||||
|
||||
if (attributeType.Name == $"Assembly{propertyName}Attribute")
|
||||
{
|
||||
var attributeProperty = attributeType.GetProperty(propertyName, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance);
|
||||
|
||||
if (attributeProperty != null)
|
||||
{
|
||||
var attributeValue = attributeType
|
||||
.GetProperty(propertyName)
|
||||
?.GetValue(attribute, null)
|
||||
?.ToString();
|
||||
|
||||
property.SetValue(pluginVM, attributeValue, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
AppDomain.Unload(domain);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
return pluginVM;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return default(PluginVM);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class PluginVM : VM
|
||||
{
|
||||
public string Path { get; set; }
|
||||
|
||||
public string Title { get; set; }
|
||||
|
||||
public string Description { get; set; }
|
||||
|
||||
public string Company { get; set; }
|
||||
|
||||
public string Product { get; set; }
|
||||
|
||||
public string Copyright { get; set; }
|
||||
|
||||
public string Trademark { get; set; }
|
||||
|
||||
public string Culture { get; set; }
|
||||
|
||||
public string Version { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -21,8 +21,7 @@
|
||||
public ReferenceMeterVM(OmniContext omniContext) : base()
|
||||
{
|
||||
this.omniContext = omniContext;
|
||||
this.signarR = new ExchangeConnection();
|
||||
this.signarR.StateChanged += this.SignarR_StateChanged;
|
||||
this.signarR = new ExchangeConnection();
|
||||
this.signarR.Connect(Appsettings.HubURL);
|
||||
this.ppnr = 1;
|
||||
|
||||
@@ -193,8 +192,6 @@
|
||||
waitHandle.Wait(timeout * interval);
|
||||
waitHandle.Reset();
|
||||
|
||||
// OmniPlusFormulas.OutDebugM3S(ref referenceV);
|
||||
|
||||
this.signarR.StopReferenceMessurement -= ReceiveFlow;
|
||||
timer.Elapsed -= TimerElapsed;
|
||||
|
||||
@@ -220,19 +217,14 @@
|
||||
this.signarR.SendStopFlow();
|
||||
this.signarR.Disconnect();
|
||||
}
|
||||
catch (Exception e)
|
||||
catch (Exception)
|
||||
{
|
||||
AppLogger.Log($"[...] {e}");
|
||||
|
||||
}
|
||||
|
||||
base.Dispose();
|
||||
}
|
||||
|
||||
private void SignarR_StateChanged(string value, string groupName)
|
||||
{
|
||||
AppLogger.Log($"[{groupName}] {value}");
|
||||
}
|
||||
|
||||
private void LoadHeaders()
|
||||
{
|
||||
this.DispatcherInvoke(() =>
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
namespace InspectionUI.ViewModels
|
||||
{
|
||||
using InspectionUI.Models;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
@@ -28,7 +26,7 @@
|
||||
App.Exiting -= this.Dispose;
|
||||
}
|
||||
|
||||
protected void ContinueWhenAll(List<Task> tasks, Action continuationCallback = null)
|
||||
protected void WaitAll(List<Task> tasks, Action continuationCallback = null)
|
||||
{
|
||||
if (tasks is null || tasks.Count == 0)
|
||||
{
|
||||
@@ -38,14 +36,6 @@
|
||||
Task.Factory
|
||||
.ContinueWhenAll(tasks.ToArray(), _tasks =>
|
||||
{
|
||||
foreach (var task in _tasks)
|
||||
{
|
||||
if (task.Exception != null)
|
||||
{
|
||||
AppLogger.Log(task.Exception);
|
||||
}
|
||||
}
|
||||
|
||||
tasks.Clear();
|
||||
continuationCallback?.Invoke();
|
||||
})
|
||||
@@ -89,28 +79,14 @@
|
||||
{
|
||||
return Task
|
||||
.Factory
|
||||
.StartNew(action, cancellationToken)
|
||||
.ContinueWith(task =>
|
||||
{
|
||||
if (task.Exception != null)
|
||||
{
|
||||
AppLogger.Log(task.Exception);
|
||||
}
|
||||
}, cancellationToken);
|
||||
.StartNew(action, cancellationToken);
|
||||
}
|
||||
|
||||
protected Task StartNewTask(Action<object> action, object state, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return Task
|
||||
.Factory
|
||||
.StartNew(action, state, cancellationToken)
|
||||
.ContinueWith(task =>
|
||||
{
|
||||
if (task.Exception != null)
|
||||
{
|
||||
AppLogger.Log(task.Exception);
|
||||
}
|
||||
}, cancellationToken);
|
||||
.StartNew(action, state, cancellationToken);
|
||||
}
|
||||
|
||||
protected class Command : ICommand
|
||||
|
||||
Reference in New Issue
Block a user