EliteBGS/LoadEntriesWindow.xaml.cs

53 lines
1.5 KiB
C#
Raw Normal View History

2022-01-23 15:52:19 +01:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using EDJournal;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace EliteBGS {
/// <summary>
/// Interaction logic for LoadEntriesWindow.xaml
/// </summary>
public partial class LoadEntriesWindow : Window {
public delegate void EntriesLoadedDelegate(List<Entry> entries);
public event EntriesLoadedDelegate EntriesLoaded;
public LoadEntriesWindow() {
InitializeComponent();
}
private void Load_Click(object sender, RoutedEventArgs e) {
string lines = Lines.Text.Trim();
if (lines.Length <= 0) {
return;
}
try {
List<Entry> entries = new List<Entry>();
foreach (string line in lines.Split('\n')) {
Entry entry = Entry.Parse(line);
entries.Add(entry);
}
if (entries.Count > 0) {
EntriesLoaded?.Invoke(entries);
}
} catch (Exception exception) {
MessageBox.Show(string.Format("There was an error while parsing the JSON: {0}",
exception.ToString()));
}
}
}
}