private static void BrowseChatRoomByName(PersistentChatEndpoint persistentChatEndpoint, string chatRoomName)
        {
            Console.WriteLine(string.Format("Searching for chat room with name = [{0}]", chatRoomName));
            ChatRoomSnapshot chatRoom = SampleCommon.RoomSearchExisting(persistentChatEndpoint, chatRoomName);

            Console.WriteLine(string.Format("\tFound chat room: [Name: {0}, Description: {1}, NumParticipants: {2}, Uri: {3}]",
                                            chatRoom.Name, chatRoom.Description, chatRoom.NumberOfParticipants, chatRoom.ChatRoomUri));
        }
        public ChatRoomSession enterRoom(String chatRoomName)
        {
            ChatRoomSnapshot roomSnapshot = SampleCommon.RoomSearchExisting(persistentChatEndpoint, chatRoomName);

            roomSession = SampleCommon.RoomJoinExisting(persistentChatEndpoint, roomSnapshot);
            Console.WriteLine(String.Format(" enterRoom name   [{0}] ------> state:{1}", chatRoomName, roomSession.State));
            foreach (ChatRoomParticipant cp in roomSession.Participants)
            {
                Console.WriteLine(String.Format(" enterRoom ChatRoomParticipant name   [{0}] ------> info:{1}  isManger:{2}", chatRoomName, cp.SipUri, cp.IsManager));
            }

            Console.WriteLine(String.Format(" enterRoom ChatRoomParticipant name  is out room [{0}]  total :{1}", chatRoomName, roomSession.Participants.Count));


            return(roomSession);
        }
        public static void startSampleChat()
        {
            string chatRoomName = "A5 ngwei---1" + TestRunUniqueId;

            try
            {
                ChatRoomSession roomSession;

                // Connect to Lync Server
                UserEndpoint userEndpoint = SampleCommon.ConnectLyncServer(SampleCommon.UserSipUri,
                                                                           SampleCommon.LyncServer,
                                                                           SampleCommon.UsingSso,
                                                                           SampleCommon.Username,
                                                                           SampleCommon.Password);



                // Connect to Persistent Chat Server
                PersistentChatEndpoint persistentChatEndpoint = SampleCommon.ConnectPersistentChatServer(userEndpoint, SampleCommon.PersistentChatServerUri);

                // Get a category
                Uri catUri = SampleCommon.GetCategoryUri(persistentChatEndpoint);

                // Create a new chat room
                Uri roomUri = SampleCommon.RoomCreateUnderNonRootCategory(persistentChatEndpoint, catUri, chatRoomName);



                // Change this to try out different ways to join the same channel
                string answer = GetRoomAnswer();

                bool joinByUri = answer.Equals("U");
                if (joinByUri)
                {
                    // OPTION 1: Join by using the result of the Create operation:
                    roomSession = SampleCommon.RoomJoinExisting(persistentChatEndpoint, roomUri);
                }
                else
                {
                    // OPTION 2: Join by searching for the room by name:
                    ChatRoomSnapshot roomSnapshot = SampleCommon.RoomSearchExisting(persistentChatEndpoint, chatRoomName);
                    roomSession = SampleCommon.RoomJoinExisting(persistentChatEndpoint, roomSnapshot);
                }

                // Chat in the chat room
                RoomChat(roomSession);

                // Get the chat history from the room
                RoomChatHistory(roomSession);

                // Search the chat history for a room
                RoomSearchChatHistory(persistentChatEndpoint, roomSession, "story body");
                SampleLoadTest.roomUri = roomUri;
                //  SampleLoadTest.getClient();

                //  SampleLoadTest.stopClient();


                Console.Write(@" roomSession--------   leave ");
                Console.ReadLine();


                // Leave room
                RoomLeave(roomSession);


                Console.Write(@" DisconnectPersistentChatServer   leave ");
                Console.ReadLine();
                // Disconnect from Persistent Chat and from Lync Server
                SampleCommon.DisconnectPersistentChatServer(persistentChatEndpoint);
                SampleCommon.DisconnectLyncServer(userEndpoint);
            }
            catch (InvalidOperationException invalidOperationException)
            {
                Console.Out.WriteLine("InvalidOperationException: " + invalidOperationException.Message);
            }
            catch (ArgumentNullException argumentNullException)
            {
                Console.Out.WriteLine("ArgumentNullException: " + argumentNullException.Message);
            }
            catch (ArgumentException argumentException)
            {
                Console.Out.WriteLine("ArgumentException: " + argumentException.Message);
            }
            catch (Microsoft.Rtc.Signaling.AuthenticationException authenticationException)
            {
                Console.Out.WriteLine("AuthenticationException: " + authenticationException.Message);
            }
            catch (Microsoft.Rtc.Signaling.FailureResponseException failureResponseException)
            {
                Console.Out.WriteLine("FailureResponseException: " + failureResponseException.Message);
            }
            catch (UriFormatException uriFormatException)
            {
                Console.Out.WriteLine("UriFormatException: " + uriFormatException.Message);
            }
            catch (Exception exception)
            {
                Console.Out.WriteLine("Exception: " + exception.Message);
            }
        }
Exemplo n.º 4
0
        public static void Main(string[] args)
        {
            //////////////////////////////////////////////////////////////////////////////////////////////////
            // Note: Assuming that category(ies) have been created and this user is a creator on some of them
            //////////////////////////////////////////////////////////////////////////////////////////////////

            //// Appending a GUID here so you can run this sample multiple times without attempting to create
            //// the same channel twice.
            string chatRoomName = "SampleChat_TestRoom" + TestRunUniqueId;

            try
            {
                ChatRoomSession roomSession;

                // Connect to Lync Server
                UserEndpoint userEndpoint = SampleCommon.ConnectOfficeCommunicationServer(SampleCommon.UserSipUri,
                                                                                          SampleCommon.OcsServer,
                                                                                          SampleCommon.UsingSso,
                                                                                          SampleCommon.Username,
                                                                                          SampleCommon.Password);

                // Connect to Persistent Chat Server
                PersistentChatEndpoint persistentChatEndpoint = SampleCommon.ConnectPersistentChatServer(userEndpoint, SampleCommon.PersistentChatServerUri);

                // Get a category
                Uri catUri = SampleCommon.GetCategoryUri(persistentChatEndpoint);

                // Create a new chat room
                Uri roomUri = SampleCommon.RoomCreateUnderNonRootCategory(persistentChatEndpoint, catUri, chatRoomName);

                // Change this to try out different ways to join the same channel
                string answer = GetRoomAnswer();

                bool joinByUri = answer.Equals("U");
                if (joinByUri)
                {
                    // OPTION 1: Join by using the result of the Create operation:
                    roomSession = SampleCommon.RoomJoinExisting(persistentChatEndpoint, roomUri);
                }
                else
                {
                    // OPTION 2: Join by searching for the room by name:
                    ChatRoomSnapshot roomSnapshot = SampleCommon.RoomSearchExisting(persistentChatEndpoint, chatRoomName);
                    roomSession = SampleCommon.RoomJoinExisting(persistentChatEndpoint, roomSnapshot);
                }

                // Chat in the chat room
                RoomChat(roomSession);

                // Get the chat history from the room
                RoomChatHistory(roomSession);

                // Search the chat history for a room
                RoomSearchChatHistory(persistentChatEndpoint, roomSession, "story body");

                // Leave room
                RoomLeave(roomSession);

                // Disconnect from Persistent Chat and from OCS
                SampleCommon.DisconnectPersistentChatServer(persistentChatEndpoint);
                SampleCommon.DisconnectOfficeCommunicationServer(userEndpoint);
            }
            catch (InvalidOperationException invalidOperationException)
            {
                Console.Out.WriteLine("InvalidOperationException: " + invalidOperationException.Message);
            }
            catch (ArgumentNullException argumentNullException)
            {
                Console.Out.WriteLine("ArgumentNullException: " + argumentNullException.Message);
            }
            catch (ArgumentException argumentException)
            {
                Console.Out.WriteLine("ArgumentException: " + argumentException.Message);
            }
            catch (Microsoft.Rtc.Signaling.AuthenticationException authenticationException)
            {
                Console.Out.WriteLine("AuthenticationException: " + authenticationException.Message);
            }
            catch (Microsoft.Rtc.Signaling.FailureResponseException failureResponseException)
            {
                Console.Out.WriteLine("FailureResponseException: " + failureResponseException.Message);
            }
            catch (UriFormatException uriFormatException)
            {
                Console.Out.WriteLine("UriFormatException: " + uriFormatException.Message);
            }
            catch (Exception exception)
            {
                Console.Out.WriteLine("Exception: " + exception.Message);
            }
        }