Initial commit
This commit is contained in:
commit
4b1294b32d
23 changed files with 5134 additions and 0 deletions
54
MathInterpreter/MainWindow.axaml.cs
Normal file
54
MathInterpreter/MainWindow.axaml.cs
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
using System;
|
||||
using System.Globalization;
|
||||
using System.Threading.Tasks;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Interactivity;
|
||||
using MathInterpreter.Core;
|
||||
using MsBox.Avalonia;
|
||||
using MsBox.Avalonia.Base;
|
||||
using MsBox.Avalonia.Enums;
|
||||
|
||||
namespace MathInterpreter;
|
||||
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
DataContext = this;
|
||||
}
|
||||
|
||||
|
||||
private async void Calculate(object sender, RoutedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
string input = ExpressionInput.Text ?? throw new InvalidOperationException("Input must not be empty");
|
||||
var expression = new MathExpression(input);
|
||||
Result.Text = expression.Result.ToString(CultureInfo.InvariantCulture);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
string exStr = UnwrapException(ex);
|
||||
await ShowError(exStr);
|
||||
}
|
||||
}
|
||||
|
||||
private static string UnwrapException(Exception exception)
|
||||
{
|
||||
string message = exception.Message;
|
||||
|
||||
if (exception.InnerException != null)
|
||||
{
|
||||
message += $"{Environment.NewLine}Inner exception: {UnwrapException(exception.InnerException)}";
|
||||
}
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
private static async ValueTask ShowError(string message)
|
||||
{
|
||||
IMsBox<ButtonResult> box = MessageBoxManager.GetMessageBoxStandard("Error", message);
|
||||
await box.ShowAsync();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue