55 lines
1.6 KiB
C#
55 lines
1.6 KiB
C#
using System;
|
|
using System.Threading.Tasks;
|
|
using Avalonia.Controls;
|
|
using Avalonia.Interactivity;
|
|
using Avalonia.Threading;
|
|
using XSDVisualiser.Models;
|
|
using XSDVisualiser.Parsing;
|
|
|
|
namespace XSDVisualiser.Desktop
|
|
{
|
|
public partial class MainWindow : Window
|
|
{
|
|
private Button _openBtn = null!;
|
|
|
|
public MainWindow()
|
|
{
|
|
InitializeComponent();
|
|
_openBtn = this.FindControl<Button>("OpenBtn");
|
|
_openBtn.Click += OpenBtn_Click;
|
|
}
|
|
|
|
private async void OpenBtn_Click(object? sender, RoutedEventArgs e)
|
|
{
|
|
var ofd = new OpenFileDialog
|
|
{
|
|
AllowMultiple = false,
|
|
Title = "Open XSD file"
|
|
};
|
|
ofd.Filters!.Add(new FileDialogFilter { Name = "XSD schema", Extensions = { "xsd" } });
|
|
var files = await ofd.ShowAsync(this);
|
|
if (files != null && files.Length > 0)
|
|
{
|
|
await ParseAndShowAsync(files[0]);
|
|
}
|
|
}
|
|
|
|
private Task ParseAndShowAsync(string path)
|
|
{
|
|
return Task.Run(() =>
|
|
{
|
|
try
|
|
{
|
|
var parser = new XsdSchemaParser();
|
|
var model = parser.Parse(path);
|
|
Dispatcher.UIThread.Post(() => DataContext = model);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Dispatcher.UIThread.Post(() => DataContext = new SchemaModel { TargetNamespace = ex.Message });
|
|
}
|
|
});
|
|
}
|
|
}
|
|
}
|