public MainWindow() { InitializeComponent(); IPathControllerActions pathControllerActions = null; ConnectionWindow connectionWindow = new ConnectionWindow((IPathControllerActions actions) => { pathControllerActions = actions; }); if (!connectionWindow.ShowDialog().Value) { Close(); } else { viewModel = new PathControllerViewModel(pathControllerActions); DataContext = viewModel; } }
static void Main(string[] args) { IPathControllerActions actions = null; IReader reader = new ConsoleReader(); IWriter writer = new ConsoleWriter(); writer.WriteLine("Lab4"); try { ChannelFactory <IPathControllerActions> factory = new ChannelFactory <IPathControllerActions>(new NetNamedPipeBinding(), new EndpointAddress("net.pipe://localhost/pathController")); actions = factory.CreateChannel(); } catch (Exception e) { writer.WriteLine(e.Message); Pause(reader); return; } ClientMenuActions clientMenuActions = new ClientMenuActions(reader, writer, actions); AdvancedMenuController menuController = new AdvancedMenuController(clientMenuActions, reader, writer); bool finished = false; while (!finished) { try { finished = !menuController.PressKey(); } catch (Exception e) { writer.WriteLine(e.Message); finished = true; } } Pause(reader); }
private void ConnectButton_Click(object sender, RoutedEventArgs e) { try { ChannelFactory <IConnection> connectFactory = new ChannelFactory <IConnection>(new NetNamedPipeBinding(), new EndpointAddress(addressText.Text + "/connection")); IConnection connect = connectFactory.CreateChannel(); int id = connect.Connect(); ChannelFactory <IPathControllerActions> factory = new ChannelFactory <IPathControllerActions>(new NetNamedPipeBinding(), new EndpointAddress(addressText.Text + "/pathController/" + id.ToString())); IPathControllerActions actions = factory.CreateChannel(); actions.CheckConnection(); setPathControllerActions(actions); if (loadButton.IsChecked.Value) { string error = actions.Load(loadPathTextBox.Text); if (!(error is null)) { MessageBox.Show(error); return; } } else { actions.CreateBlocks(new BlockState[int.Parse(createPathTextBox.Text)]); } DialogResult = true; } catch (Exception exception) { MessageBox.Show(exception.Message); return; } }
public ClientMenuActions(IReader r, IWriter w, IPathControllerActions actions) { reader = r; writer = w; pathControllerActions = actions; }
public PathControllerViewModel(IPathControllerActions actions) { pathControllerActions = actions; Blocks = new ObservableCollection <Block>(); Initialize(); }