1
0
mirror of synced 2024-11-15 01:33:51 +00:00
PettingZoo/View/ConnectionWindow.xaml.cs

74 lines
2.1 KiB
C#
Raw Normal View History

2016-06-18 14:50:32 +00:00
using System.Windows;
using System.Windows.Input;
using AutoMapper;
using PettingZoo.Connection;
using PettingZoo.Infrastructure;
2016-06-18 14:50:32 +00:00
using PettingZoo.ViewModel;
namespace PettingZoo.View
{
public class WindowConnectionInfoBuilder : IConnectionInfoBuilder
{
private readonly UserSettings userSettings;
private static readonly IMapper ConnectionInfoMapper = new MapperConfiguration(cfg =>
{
cfg.RecognizeDestinationPrefixes("Last");
cfg.RecognizePrefixes("Last");
cfg.CreateMap<ConnectionInfo, ConnectionWindowSettings>().ReverseMap();
}).CreateMapper();
public WindowConnectionInfoBuilder(UserSettings userSettings)
{
this.userSettings = userSettings;
}
2016-06-18 14:50:32 +00:00
public ConnectionInfo Build()
{
var connectionInfo = ConnectionInfoMapper.Map<ConnectionInfo>(userSettings.ConnectionWindow);
var viewModel = new ConnectionViewModel(connectionInfo);
2016-06-20 10:30:03 +00:00
2016-06-18 14:50:32 +00:00
var dialog = new ConnectionWindow(viewModel)
{
Owner = Application.Current.MainWindow
};
2016-06-20 10:30:03 +00:00
viewModel.CloseWindow += (sender, args) =>
{
dialog.DialogResult = true;
};
2016-06-18 14:50:32 +00:00
connectionInfo = dialog.ShowDialog().GetValueOrDefault() ? viewModel.ToModel() : null;
if (connectionInfo != null)
{
ConnectionInfoMapper.Map(connectionInfo, userSettings.ConnectionWindow);
userSettings.Save();
}
return connectionInfo;
2016-06-18 14:50:32 +00:00
}
}
public partial class ConnectionWindow
2016-06-18 14:50:32 +00:00
{
2016-06-18 18:30:12 +00:00
public ConnectionWindow(ConnectionViewModel viewModel)
2016-06-18 14:50:32 +00:00
{
2016-06-18 18:30:12 +00:00
WindowStartupLocation = WindowStartupLocation.CenterOwner;
2016-06-18 14:50:32 +00:00
InitializeComponent();
DataContext = viewModel;
}
private void NumericPreviewTextInput(object sender, TextCompositionEventArgs args)
{
if (!char.IsDigit(args.Text, args.Text.Length - 1))
args.Handled = true;
}
2016-06-18 14:50:32 +00:00
}
}