59 lines
1.7 KiB
C#
59 lines
1.7 KiB
C#
using System;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Avalonia.Controls;
|
|
using Avalonia.Interactivity;
|
|
using Avalonia.Threading;
|
|
using XSDVisualiser.Parsing;
|
|
using XSDVisualiser.Utils;
|
|
|
|
namespace XSDVisualiser.Desktop
|
|
{
|
|
public partial class MainWindow : Window
|
|
{
|
|
private Button _openBtn = null!;
|
|
private TextBox _output = null!;
|
|
|
|
public MainWindow()
|
|
{
|
|
InitializeComponent();
|
|
_openBtn = this.FindControl<Button>("OpenBtn");
|
|
_output = this.FindControl<TextBox>("Output");
|
|
_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);
|
|
var text = Serialization.ToJson(model);
|
|
Dispatcher.UIThread.Post(() => _output.Text = text);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Dispatcher.UIThread.Post(() => _output.Text = ex.ToString());
|
|
}
|
|
});
|
|
}
|
|
}
|
|
}
|