1
0
mirror of synced 2024-11-14 17:33:49 +00:00
PettingZoo/ViewModel/MainBaseViewModel.cs
2016-06-18 16:50:32 +02:00

53 lines
1.4 KiB
C#

using System.Windows.Input;
using PettingZoo.Infrastructure;
using PettingZoo.Model;
namespace PettingZoo.ViewModel
{
public class MainBaseViewModel : BaseViewModel
{
private readonly IConnectionInfoBuilder connectionInfoBuilder;
private readonly IConnectionFactory connectionFactory;
private ConnectionInfo connectionInfo;
private IConnection connection;
public ConnectionInfo ConnectionInfo {
get
{
return connectionInfo;
}
private set
{
if (value != connectionInfo)
{
connectionInfo = value;
RaisePropertyChanged();
}
}
}
public ICommand ConnectCommand { get; private set; }
public MainBaseViewModel(IConnectionInfoBuilder connectionInfoBuilder, IConnectionFactory connectionFactory)
{
this.connectionInfoBuilder = connectionInfoBuilder;
this.connectionFactory = connectionFactory;
ConnectCommand = new DelegateCommand(ConnectExecute);
}
protected void ConnectExecute()
{
var newInfo = connectionInfoBuilder.Build();
if (newInfo != null)
{
ConnectionInfo = newInfo;
connection = connectionFactory.CreateConnection(connectionInfo);
}
}
}
}