public void StartUp()
        {
            // Construct InstanceContext to handle messages on callback interface.
            // An instance of ChatApp is created and passed to the InstanceContext.
            InstanceContext instanceContext = new InstanceContext(new TransactionNotifierService(this));

            // Create the participant with the given endpoint configuration
            // Each participant opens a duplex channel to the mesh
            // participant is an instance of the chat application that has opened a channel to the mesh
            DuplexChannelFactory <ITransactionNotifierChannel> factory =
                new DuplexChannelFactory <ITransactionNotifierChannel>(instanceContext, "ChatEndpoint");

            _channel = factory.CreateChannel();

            // Retrieve the PeerNode associated with the participant and register for online/offline events
            // PeerNode represents a node in the mesh. Mesh is the named collection of connected nodes.
            IOnlineStatus ostat = _channel.GetProperty <IOnlineStatus>();

            //ostat.Online += new EventHandler(OnOnline);
            //ostat.Offline += new EventHandler(OnOffline);

            _channel.Open();
        }
Exemple #2
0
        public static void Main()
        {
            // Get the sender ID from configuration
            string senderId = ConfigurationManager.AppSettings["sender"];

            // Create the sender with the given endpoint configuration
            // Sender is an instance of the sender side of the broadcast application that has opened a channel to mesh
            ChannelFactory <IBroadcastChannel> factory = new ChannelFactory <IBroadcastChannel>("BroadcastEndpoint");

            IBroadcastChannel sender = factory.CreateChannel();

            // Retrieve the PeerNode associated with the sender and register for online/offline events
            // PeerNode represents a node in the mesh. Mesh is the named collection of connected nodes.
            IOnlineStatus ostat = sender.GetProperty <IOnlineStatus>();

            ostat.Online  += new EventHandler(OnOnline);
            ostat.Offline += new EventHandler(OnOffline);

            // Open the sender so that the instance can join the mesh even before the first message is sent
            sender.Open();

            Console.WriteLine("{0} is ready", senderId);
            Console.WriteLine("Press <ENTER> to send annoucements after starting the receivers and going Online");
            Console.ReadLine();
            Console.WriteLine("Sending Announcement 1");
            sender.Announce("Announcement 1");
            Console.WriteLine("Sending Announcement 2");
            sender.Announce("Announcement 2");
            Console.WriteLine("Sending Announcement 3");
            sender.Announce("Announcement 3");
            Console.WriteLine("Press <ENTER> to terminate the sender.");
            Console.ReadLine();

            sender.Close();

            factory.Close();
        }
Exemple #3
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(txtUserName.Text.Trim()))
            {
                try
                {
                    NewJoin     += new UserJoined(ChatClient_NewJoin);
                    MessageSent += new UserSendMessage(ChatClient_MessageSent);
                    RemoveUser  += new UserLeft(ChatClient_RemoveUser);

                    channel       = null;
                    this.userName = txtUserName.Text.Trim();
                    InstanceContext context = new InstanceContext(
                        new ChatClient(txtUserName.Text.Trim()));
                    factory =
                        new DuplexChannelFactory <IChatChannel>(context, "ChatEndPoint");
                    channel = factory.CreateChannel();
                    IOnlineStatus status = channel.GetProperty <IOnlineStatus>();
                    status.Offline += new EventHandler(Offline);
                    status.Online  += new EventHandler(Online);
                    channel.Open();
                    channel.Join(this.userName);
                    grpMessageWindow.Enabled   = true;
                    grpUserList.Enabled        = true;
                    grpUserCredentials.Enabled = false;
                    this.AcceptButton          = btnSend;
                    rtbMessages.AppendText("*****************************WEL-COME to Chat Application*****************************\r\n");
                    txtSendMessage.Select();
                    txtSendMessage.Focus();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
        }
Exemple #4
0
        // Host the chat instance within this EXE console application.
        public static void Main()
        {
            Console.WriteLine("Enter your nickname [default=DefaultName]: ");
            string member = Console.ReadLine();

            if (member == "")
            {
                member = "DefaultName";
            }

            // Construct InstanceContext to handle messages on callback interface.
            // An instance of ChatApp is created and passed to the InstanceContext.
            InstanceContext instanceContext = new InstanceContext(new ChatApp(member));

            // Create the participant with the given endpoint configuration
            // Each participant opens a duplex channel to the mesh
            // participant is an instance of the chat application that has opened a channel to the mesh
            DuplexChannelFactory <IChatChannel> factory = new DuplexChannelFactory <IChatChannel>(instanceContext, "ChatEndpoint");

            IChatChannel participant = factory.CreateChannel();

            // Retrieve the PeerNode associated with the participant and register for online/offline events
            // PeerNode represents a node in the mesh. Mesh is the named collection of connected nodes.
            IOnlineStatus ostat = participant.GetProperty <IOnlineStatus>();

            ostat.Online  += new EventHandler(OnOnline);
            ostat.Offline += new EventHandler(OnOffline);

            try
            {
                participant.Open();
            }
            catch (CommunicationException)
            {
                Console.WriteLine("Could not find resolver.  If you are using a custom resolver, please ensure");
                Console.WriteLine("that the service is running before executing this sample.  Refer to the readme");
                Console.WriteLine("for more details.");
                return;
            }


            Console.WriteLine("{0} is ready", member);
            Console.WriteLine("Type chat messages after going Online");
            Console.WriteLine("Press q<ENTER> to terminate this instance.");

            // Announce self to other participants
            participant.Join(member);

            // loop until the user quits
            while (true)
            {
                string line = Console.ReadLine();
                if (line == "q")
                {
                    break;
                }
                participant.Chat(member, line);
            }
            // Leave the mesh
            participant.Leave(member);
            participant.Close();
            factory.Close();
        }
 protected override void Dispose(bool disposing)
 {
     targetForm            = null;
     onlineStatusInterface = null;
     base.Dispose(disposing);
 }
 public void SetOnlineStatusInterface(IOnlineStatus statusObject)
 {
     onlineStatusInterface = statusObject;
     onlineStatusInterface.OnlineStatusChanged -= OnlineStatusChanged;
     onlineStatusInterface.OnlineStatusChanged += OnlineStatusChanged;
 }
Exemple #7
0
        public bool Start(IPAddress endpoint)
        {
            bool            result          = true;
            InstanceContext instanceContext = new InstanceContext(this);

            //factory = new DuplexChannelFactory<IChatChannel>(instanceContext, "ChatEndpoint");


            factory = new DuplexChannelFactory <IChatChannel>(instanceContext);


            //MessageBox.Show("localaddress endpoint: " + endpoint.ToString());

            // TODO: regel hieronder UIT
            //factory.Endpoint.Address = new EndpointAddress("net.p2p://" + endpoint.ToString() + ":8089/ZeebregtsChannelService/Chat");

            // TODO: regel hieronder AAN
            //factory.Endpoint.Address = new EndpointAddress("net.p2p://" + "127.0.0.1" + ":8089/ZeebregtsChannelService/Chat");

            // TODO: regel hieronder UIT
            factory.Endpoint.Address = new EndpointAddress("net.p2p://" + "localhost" + ":8089/ZeebregtsChannelService/Chat");

            NetPeerTcpBinding binding = new NetPeerTcpBinding(); // ("ChatEndpoint");

            // TODO: regel hieronder uit
            binding.ListenIPAddress = endpoint; // IPAddress.Parse("127.0.0.1"); // endpoint;


            binding.Port          = 8089;
            binding.Resolver.Mode = System.ServiceModel.PeerResolvers.PeerResolverMode.Custom;

            NetTcpBinding resolver = new NetTcpBinding();

            resolver.Security.Mode = SecurityMode.None;

            binding.Resolver.Custom.Address = new EndpointAddress("net.tcp://192.160.0.120:8089/ZeebregtsChannelService/peerResolverService");
            binding.Security.Mode           = SecurityMode.None;

            binding.Resolver.Custom.Binding = resolver;
            factory.Endpoint.Binding        = binding;

            ContractDescription cd = ContractDescription.GetContract(typeof(ZeebregtsLogic.IChat));

            factory.Endpoint.Contract = cd; // new System.ServiceModel.Description.ContractDescription("IChat"); //, "ZeebregtsLogic");
            factory.Endpoint.Name     = "ChatEndpoint";



            participant = factory.CreateChannel(instanceContext);

            //MessageBox.Show("localaddress: " + participant.LocalAddress.ToString());
            //MessageBox.Show("chatserver: " + Global.ChannelServiceIpAddress);
            //MessageBox.Show("port: " + Global.ChannelServicePort.ToString());

            IOnlineStatus ostat = participant.GetProperty <IOnlineStatus>();

            ostat.Online  += new EventHandler(OnOnline);
            ostat.Offline += new EventHandler(OnOffline);

            try
            {
                participant.Open();
                IsConnected = true;
            }
            catch (CommunicationException ex)
            {
                string test2 = ex.InnerException.Message;
                //MessageBox.Show(test2);

                result = false;

                IsConnected = false;
                return(result);
            }

            participant.Join(member);
            return(result);
        }
 public void CloseConferencService()
 {
     //TODO: Протестировать закрытие. Закрыть, потом опять попытаться открыть...
     participant.Close();
       //  instanceContext = null;
     factory = null;
     ostat = null;
 }
        private void btnLogin_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(txtUserName.Text.Trim()))
            {
                try
                {
                    NewJoin     += new UserJoined(ChatClient_NewJoin);
                    MessageSent += new UserSendMessage(ChatClient_MessageSent);
                    RemoveUser  += new UserLeft(ChatClient_RemoveUser);

                    channel       = null;
                    this.userName = txtUserName.Text.Trim();
                    /**/
                    #region IpAddress
                    string      strHostName = System.Net.Dns.GetHostName();
                    string      IPAddress   = "";
                    IPHostEntry ipEntry     = System.Net.Dns.GetHostEntry(strHostName);

                    foreach (IPAddress ipAddress in ipEntry.AddressList)
                    {
                        if (ipAddress.AddressFamily.ToString() == "InterNetwork")
                        {
                            IPAddress = ipAddress.ToString();
                        }
                    }

                    string Address    = string.Format("net.tcp://{0}/ChatServer", IPAddress);
                    Uri    URiAddress = new Uri(Address, UriKind.RelativeOrAbsolute);

                    #endregion

                    InstanceContext instanceContext = new InstanceContext(new ChatClient(txtUserName.Text.Trim()));



                    ////NetPeerTcpBinding chatBinding = new NetPeerTcpBinding();
                    ////Uri baseAddress = new Uri(Address);
                    ////chatBinding.Port = 0;
                    ////chatBinding.Security.Mode = SecurityMode.None;
                    ////chatBinding.Resolver.Mode = PeerResolverMode.Custom;
                    ////chatBinding.Resolver.Custom.Address = new EndpointAddress(baseAddress);
                    ////chatBinding.Resolver.Custom.Binding = new NetTcpBinding(SecurityMode.None);
                    ////chatBinding.Resolver.Custom.Binding.OpenTimeout = TimeSpan.FromMinutes(5);
                    ////DuplexChannelFactory<IChatChannel> factory = new DuplexChannelFactory<IChatChannel>(instanceContext, chatBinding, "net.p2p://chatMesh/ChatServer");
                    ////channel = factory.CreateChannel();

                    /**/
                    InstanceContext context = new InstanceContext(
                        new ChatClient(txtUserName.Text.Trim()));
                    factory =
                        new DuplexChannelFactory <IChatChannel>(context, "ChatEndPoint");
                    ((System.ServiceModel.NetPeerTcpBinding)(((System.ServiceModel.ChannelFactory)(factory)).Endpoint.Binding)).Resolver.Custom.Address = new EndpointAddress(string.Format("net.tcp://{0}/ChatServer", IPAddress));
                    channel = factory.CreateChannel();
                    /**/

                    IOnlineStatus status = channel.GetProperty <IOnlineStatus>();
                    status.Offline += new EventHandler(Offline);
                    status.Online  += new EventHandler(Online);
                    channel.Open();
                    channel.Join(this.userName);
                    grpMessageWindow.Enabled   = true;
                    grpUserList.Enabled        = true;
                    grpUserCredentials.Enabled = false;
                    this.AcceptButton          = btnSend;
                    rtbMessages.AppendText("'''''''''''''''''''''WEL-COME to Chat Application''''''''''''''''''''''\r\n");
                    txtSendMessage.Select();
                    //txtSendMessage.Focus();
                    cmbProject.Focus();

                    CreateComponentTable();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
        }
Exemple #10
0
        public static void Main()
        {
            // Get the sender ID from configuration
            string senderId         = ConfigurationManager.AppSettings["sender"];
            string recognizedSender = "CN=" + senderId;

            // Create the sender with the given endpoint configuration
            // Sender is an instance of the sender side of the broadcast application that has opened a channel to mesh
            using (ChannelFactory <IQuoteChannel> cf = new ChannelFactory <IQuoteChannel>("BroadcastEndpoint"))
            {
                X509Certificate2 senderCredentials = GetCertificate(StoreName.My, StoreLocation.CurrentUser, recognizedSender, X509FindType.FindBySubjectDistinguishedName);
                cf.Credentials.Peer.Certificate = senderCredentials;
                cf.Credentials.Peer.MessageSenderAuthentication.CertificateValidationMode  = X509CertificateValidationMode.Custom;
                cf.Credentials.Peer.MessageSenderAuthentication.CustomCertificateValidator = new SenderValidator(senderCredentials);

                using (IQuoteChannel sender = (IQuoteChannel)cf.CreateChannel())
                {
                    // Retrieve the PeerNode associated with the sender and register for online/offline events
                    // PeerNode represents a node in the mesh. Mesh is the named collection of connected nodes.
                    IOnlineStatus ostat = sender.GetProperty <IOnlineStatus>();
                    ostat.Online  += new EventHandler(OnOnline);
                    ostat.Offline += new EventHandler(OnOffline);

                    // Open the sender
                    sender.Open();
                    Console.WriteLine("** {0} is ready", senderId);

                    //Info that sender sends out to the receivers (mesh))
                    string name         = "InfoSolo";
                    double currentValue = Double.Parse("100");
                    double change       = Double.Parse("45");

                    Console.WriteLine("Enter stock value and pass <ENTER> to broadcast update to receivers.");
                    Console.WriteLine("Enter a blank value to terminate application");

                    while (true)
                    {
                        Console.WriteLine("New Value: ");
                        double newvalue = 0;
                        string value    = Console.ReadLine();

                        if (String.IsNullOrEmpty(value))
                        {
                            break;
                        }

                        if (!Double.TryParse(value, out newvalue))
                        {
                            Console.WriteLine("Invalid value entered.  Please enter a numeric value.");
                            continue;
                        }

                        change       = newvalue - currentValue;
                        currentValue = newvalue;
                        sender.PriceChange(name, change, currentValue);

                        Console.WriteLine("Updated value sent.");
                    }
                }
            }
        }
        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);
            }
        }