2016-06-18 14:50:32 +00:00
|
|
|
|
using System.Windows;
|
2016-06-21 09:43:51 +00:00
|
|
|
|
using System.Windows.Input;
|
2016-06-21 15:05:14 +00:00
|
|
|
|
using AutoMapper;
|
2016-06-18 14:50:32 +00:00
|
|
|
|
using PettingZoo.Model;
|
|
|
|
|
using PettingZoo.ViewModel;
|
|
|
|
|
|
|
|
|
|
namespace PettingZoo.View
|
|
|
|
|
{
|
|
|
|
|
public class WindowConnectionInfoBuilder : IConnectionInfoBuilder
|
|
|
|
|
{
|
2016-06-21 15:05:14 +00:00
|
|
|
|
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()
|
|
|
|
|
{
|
2016-06-21 15:05:14 +00:00
|
|
|
|
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
|
|
|
|
|
2016-06-21 15:05:14 +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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2016-06-20 12:20:37 +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;
|
|
|
|
|
}
|
2016-06-21 09:43:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|