コード例 #1
0
        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);
            }
        }
コード例 #2
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);
            }
        }