116 lines
3.2 KiB
C#
116 lines
3.2 KiB
C#
namespace OMNIPruefung.ViewModels.Content
|
|
{
|
|
using ExchangeHub;
|
|
|
|
using OMNIPruefung.Models;
|
|
using OMNIPruefung.ViewModels.Base;
|
|
using OMNIPruefung.ViewModels.Options;
|
|
|
|
using System;
|
|
using System.IO;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Input;
|
|
|
|
public class ExchangeHubContentVM : ContentVM
|
|
{
|
|
private readonly ExchangeHubSettings hubsettings;
|
|
private readonly ExchangeConnection connection;
|
|
|
|
public ExchangeHubContentVM() : base()
|
|
{
|
|
this.Header = "Exchange HUB";
|
|
this.Option = new ExchangeHubOptionVM(this);
|
|
this.Option.OptionSelected += this.NotifyOptionSelected;
|
|
this.Connect = new Command(this.ConnectHubHandler);
|
|
this.Disconnect = new Command(this.DisconnectHubHandler);
|
|
this.hubsettings = new ExchangeHubSettings();
|
|
this.connection = new ExchangeConnection();
|
|
this.connection.OutputDir = this.hubsettings.ExchangeHubOutputDir;
|
|
this.connection.StateChanged += this.Connection_StateChanged;
|
|
|
|
this.NotifyPropertyChanged(nameof(this.LogContent));
|
|
}
|
|
|
|
public string URL
|
|
{
|
|
get => this.hubsettings.ExchangeHubURL;
|
|
set
|
|
{
|
|
this.hubsettings.ExchangeHubURL = value;
|
|
|
|
this.NotifyPropertyChanged(nameof(this.URL));
|
|
}
|
|
}
|
|
|
|
public string OutputDir
|
|
{
|
|
get
|
|
{
|
|
if (string.IsNullOrWhiteSpace(this.hubsettings.ExchangeHubOutputDir))
|
|
{
|
|
this.hubsettings.ExchangeHubOutputDir = App.Path;
|
|
}
|
|
|
|
return this.hubsettings.ExchangeHubOutputDir;
|
|
}
|
|
|
|
set
|
|
{
|
|
this.hubsettings.ExchangeHubOutputDir = value;
|
|
this.connection.OutputDir = value;
|
|
|
|
this.NotifyPropertyChanged(nameof(this.OutputDir));
|
|
}
|
|
}
|
|
|
|
private bool connected;
|
|
public bool Connected
|
|
{
|
|
get => this.connected;
|
|
set
|
|
{
|
|
this.connected = value;
|
|
|
|
this.NotifyPropertyChanged(nameof(this.Connected));
|
|
this.NotifyPropertyChanged(nameof(this.Disconnected));
|
|
}
|
|
}
|
|
|
|
public bool Disconnected => !this.Connected;
|
|
|
|
public string LogContent { get; private set; }
|
|
|
|
public ICommand Connect { get; }
|
|
|
|
public ICommand Disconnect { get; }
|
|
|
|
private void ConnectHubHandler()
|
|
{
|
|
Task.Factory.StartNew(() =>
|
|
{
|
|
this.Connected = this.connection.Connect(this.URL);
|
|
});
|
|
}
|
|
|
|
private void Connection_StateChanged(string fileName)
|
|
{
|
|
try
|
|
{
|
|
this.LogContent = File.ReadAllText(fileName);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
this.LogContent = e.ToString();
|
|
}
|
|
|
|
this.NotifyPropertyChanged(nameof(this.LogContent));
|
|
}
|
|
|
|
private void DisconnectHubHandler()
|
|
{
|
|
this.connection.Dispose();
|
|
this.Connected = false;
|
|
}
|
|
}
|
|
}
|