Beispiel #1
0
        private void ConnectToMesh()
        {
            try
            {
                _instanceContext = new InstanceContext(this);

                _binding = new NetPeerTcpBinding("SharedTextEditorBinding");

                _channelFactory = new DuplexChannelFactory <ISharedTextEditorP2PChannel>(_instanceContext,
                                                                                         "SharedTextEditorEndpointP2P");

                var endpointAddress = new EndpointAddress(_channelFactory.Endpoint.Address.ToString());

                _channelFactory.Endpoint.Address = endpointAddress;
                _p2pChannel = _channelFactory.CreateChannel();

                //setup the event handlers for handling online/offline events
                _statusHandler = _p2pChannel.GetProperty <IOnlineStatus>();

                if (_statusHandler != null)
                {
                    _statusHandler.Online  += ostat_Online;
                    _statusHandler.Offline += ostat_Offline;
                }

                //call empty method to force connection to mesh
                _p2pChannel.InitializeMesh();
                _editor.UpdateConnectionState(true);
            }
            catch (Exception)
            {
                _editor.UpdateConnectionState(false);
            }
        }
        private void ConnectToMesh()
        {
            try
            {
                _instanceContext = new InstanceContext(this);

                _binding = new NetPeerTcpBinding("SharedTextEditorBinding");

                _channelFactory = new DuplexChannelFactory<ISharedTextEditorP2PChannel>(_instanceContext,
                    "SharedTextEditorEndpointP2P");

                var endpointAddress = new EndpointAddress(_channelFactory.Endpoint.Address.ToString());

                _channelFactory.Endpoint.Address = endpointAddress;
                _p2pChannel = _channelFactory.CreateChannel();

                //setup the event handlers for handling online/offline events
                _statusHandler = _p2pChannel.GetProperty<IOnlineStatus>();

                if (_statusHandler != null)
                {
                    _statusHandler.Online += ostat_Online;
                    _statusHandler.Offline += ostat_Offline;
                }

                //call empty method to force connection to mesh
                _p2pChannel.InitializeMesh();
                _editor.UpdateConnectionState(true);
            }
            catch (Exception)
            {
                _editor.UpdateConnectionState(false);
            }
        }