コード例 #1
0
        public void End()
        {
            try
            {
                if (IsConnected)
                {
                    if (participant != null)
                    {
                        participant.Leave(member);
                        participant.Close();
                        participant.Dispose();
                    }

                    if (factory != null)
                    {
                        factory.Close();
                    }
                }

                IsConnected = false;
            }
            catch (Exception)
            {
            }
        }
コード例 #2
0
 private void Form1_FormClosing(object sender, FormClosingEventArgs e)
 {
     try
     {
         if (channel != null)
         {
             channel.Leave(this.userName);
             channel.Close();
         }
         if (factory != null)
         {
             factory.Close();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }
コード例 #3
0
 private void ChatClient_FormClosing(object sender, FormClosingEventArgs e)
 {
     try
     {
         if (chtChnl != null)
         {
             chtChnl.Leave(this.clientName);
             chtChnl.Close();
         }
         if (factory != null)
         {
             factory.Close();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }
コード例 #4
0
ファイル: instance.cs プロジェクト: Br3nda/sfdocsamples
        // 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();
        }