private static void SetupRooms(PersistentChatEndpoint persistentChatEndpoint) { string chatRoomName = "SampleRiamo_Room" + TestRunUniqueId; // Get a category Uri catUri = SampleCommon.GetCategoryUri(persistentChatEndpoint); // Create a new chat room Uri roomUri = SampleCommon.RoomCreateUnderNonRootCategory(persistentChatEndpoint, catUri, chatRoomName); PersistentChatUserServices userMgmt = persistentChatEndpoint.PersistentChatServices.UserServices; PersistentChatUser persistentChatUser = userMgmt.EndGetUser(userMgmt.BeginGetUser(new Uri(persistentChatEndpoint.InnerEndpoint.OwnerUri), null, null)); ChatRoomManagementServices chatRoomMgmt = persistentChatEndpoint.PersistentChatServices.ChatRoomManagementServices; try { ICollection <PersistentChatPrincipalSummary> members = new List <PersistentChatPrincipalSummary> { persistentChatUser }; chatRoomMgmt.EndAddUsersOrGroupsToRole(chatRoomMgmt.BeginAddUsersOrGroupsToRole(ChatRoomRole.Member, roomUri, members, null, null)); } catch (CommandFailedException cfe) { if (!cfe.ToString().Contains("These principals are already defined")) { throw; } } }
public void Stop() { currentOperation.Stop( () => { // Wait for rooms to stop doing work List <WaitHandle> waitHandles = new List <WaitHandle>(); foreach (SimulatedChatRoom room in chatRoomSessions) { waitHandles.Add(room.WaitForStopped); room.Stop(); } if (waitHandles.Count > 0) { WaitHandle.WaitAll(waitHandles.ToArray()); } }, () => { // Teardown chatRoomSessions.Clear(); chatRooms.Clear(); if (persistentChatEndpoint != null) { SampleCommon.DisconnectPersistentChatServer(persistentChatEndpoint); persistentChatEndpoint = null; } if (userEndpoint != null) { SampleCommon.DisconnectOfficeCommunicationServer(userEndpoint); userEndpoint = null; } }); }
public static void getClient() { // Generate the clients and the user uris that they'll use to authenticate with Lync Server. // These users must already exist in the test environment and be SIP-enabled. for (int i = 2; i <= 5; i++) { SimulatedClient client = new SimulatedClient(SampleCommon.GetLoadTestUserUri(i), SampleCommon.GetLoadTestUserName(i), SampleCommon.GetLoadTestUserPassword(i)); Console.WriteLine("getClient:" + client.UserUri + " userName:"******" client:" + client.Password); clients.Add(client); } Console.WriteLine("Press any key to start the test, 已经加载的用户"); Console.ReadKey(); // Create new chat rooms. List <Uri> chatRooms = SetupChatRooms(clients); // Let user control when the test run starts. Console.WriteLine(); Console.WriteLine("Press any key to start the test, then press any key later to longin stop the test..."); Console.ReadKey(); // Start the connection process for each client. Once connected, each client will do work // (join chat rooms, chat, etc.) until they are told to Stop(). foreach (SimulatedClient client in clients) { Console.WriteLine("正在登陆:" + client.UserUri + " userName:"******" client:" + client.Password); // NOTE: Could wait a random delay here between each login. // client.Start(chatRooms); Console.ReadKey(); Console.WriteLine("登陆end:" + client.UserUri + " userName:"******" client:" + client.Password); } }
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 static void Main(string[] args) { ////////////////////////////////////////////////////////////////////////////////////////////////// // Note: Assuming that category(ies) have been created and this user is a creator on some of them ////////////////////////////////////////////////////////////////////////////////////////////////// try { // Connect to OCS 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); SetupRooms(persistentChatEndpoint); GetRiamoLists(persistentChatEndpoint); // Disconnect from both Persistent Chat Server and 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); } }
private static void BrowseChatRoomsByFilterCriteria(PersistentChatEndpoint persistentChatEndpoint, string criteria, bool searchDesc, string member, string manager, Uri categoryUri, string addinName, bool disabled, ChatRoomPrivacy?privacy, ChatRoomBehavior?behavior, bool?invites, bool searchInvites, int maxResults) { Console.WriteLine(string.Format("Searchinf for chat rooms satisfying filter conditions")); SampleCommon.RoomSearchWithFilterCriteria(persistentChatEndpoint, criteria, searchDesc, member, manager, categoryUri, addinName, disabled, privacy, behavior, invites, searchInvites, maxResults); }
public static void Main(string[] args) { using (FileStream file = new FileStream(SampleCommon.LoadTestLogFile, FileMode.Create, FileAccess.Write, FileShare.Read)) { using (logWriter = new StreamWriter(file)) { Log("LOG OPENED: " + DateTime.Now); // Generate the clients and the user uris that they'll use to authenticate with OCS. // These users must already exist in the test environment and be SIP-enabled. List <SimulatedClient> clients = new List <SimulatedClient>(); for (int i = SampleCommon.LoadTestFirstUserIndex; i <= SampleCommon.LoadTestLastUserIndex; i++) { SimulatedClient client = new SimulatedClient(SampleCommon.GetLoadTestUserUri(i), SampleCommon.GetLoadTestUserName(i), SampleCommon.GetLoadTestUserPassword(i)); clients.Add(client); } // Create new chat rooms. List <Uri> chatRooms = SetupChatRooms(clients); // Let user control when the test run starts. Console.WriteLine(); Console.WriteLine("Press any key to start the test, then press any key later to stop the test..."); Console.ReadKey(); // Start the connection process for each client. Once connected, each client will do work // (join chat rooms, chat, etc.) until they are told to Stop(). foreach (SimulatedClient client in clients) { // NOTE: Could wait a random delay here between each login. client.Start(chatRooms); } // Let user control when the test run stops. while (!Console.KeyAvailable) { Thread.Sleep(50); } Console.ReadKey(); // Stop all the objects and cleanup. foreach (SimulatedClient client in clients) { client.Stop(); } } } }
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); } }
/// <summary> /// Create the category and chat rooms if they are missing, or simply find their Uris if they /// exist already (presumably from a previous run of this sample code). /// </summary> /// <param name="clients"></param> /// <returns></returns> private static List <Uri> SetupChatRooms(IEnumerable <SimulatedClient> clients) { List <Uri> chatRooms = new List <Uri>(); try { UserEndpoint userEndpoint = SampleCommon.ConnectOfficeCommunicationServer(SampleCommon.UserSipUri, SampleCommon.OcsServer, SampleCommon.UsingSso, SampleCommon.Username, SampleCommon.Password); PersistentChatEndpoint persistentChatEndpoint = SampleCommon.ConnectPersistentChatServer(userEndpoint, SampleCommon. PersistentChatServerUri); // Get a category Uri categoryUri = SampleCommon.GetCategoryUri(persistentChatEndpoint); foreach (string roomName in SampleCommon.LoadTestChatRoomNames) { Uri roomUri = SampleCommon.RoomCreateUnderNonRootCategory(persistentChatEndpoint, categoryUri, roomName + "_" + TestRunUniqueId); chatRooms.Add(roomUri); // Setup all the test users as Managers and Members in this chat room // thus allowing these users to join the chat rooms during this sample's execution. foreach (SimulatedClient client in clients) { ChatRoomAddManagerAndMember(persistentChatEndpoint, roomUri, client.UserUri); } } 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); } return(chatRooms); }
public static void Main(string[] args) { ////////////////////////////////////////////////////////////////////////////////////////////////// // Note: Assuming that category(ies) have been created and this user is a creator on some of them ///////////////////////////////////////////////////////////////////////////////////////////////// try { // Connect to OCS 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 10 chat rooms IList <ChatRoomHelper> chatRooms = new List <ChatRoomHelper>(); for (int i = 0; i < 10; i++) { // Create a new chat room string chatRoomName; if (i < 5) { chatRoomName = "SampleSearch_TestRoom" + TestRunUniqueId; } else { chatRoomName = "Sample_TestRoom" + TestRunUniqueId; } chatRoomName += i; Uri chatRoomUri = SampleCommon.RoomCreateUnderNonRootCategory(persistentChatEndpoint, catUri, chatRoomName); chatRooms.Add(new ChatRoomHelper(chatRoomName, chatRoomUri)); } // Find chat rooms by name int randIndex = Random.Next(10); BrowseChatRoomByName(persistentChatEndpoint, chatRooms[randIndex].ChatRoomName); // Find chat rooms under a category BrowseChatRoomByCategory(persistentChatEndpoint, catUri); // Find chat rooms by criteria BrowseChatRoomsByCriteria(persistentChatEndpoint, "Sample_TestRoom"); // Find chat rooms by filter conditions: // Search Criteria: Name has "Sample" in it, UserSipUri is a member of the room, The room is Scoped and of type // Normal, and has invitations settings set to Inherit and we want only 100 results // All search criteria that we don't want to search under is passed as null BrowseChatRoomsByFilterCriteria(persistentChatEndpoint, "Sample", false, SampleCommon.UserSipUri, null, null, null, false, ChatRoomPrivacy.Closed, ChatRoomBehavior.Normal, null, true, 100); } 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); } }
private static void BrowseChatRoomsByCriteria(PersistentChatEndpoint persistentChatEndpoint, string criteria) { Console.WriteLine(string.Format("Searching for chat rooms with criteria [{0}]", criteria)); SampleCommon.RoomSearchWithCriteria(persistentChatEndpoint, criteria); }
private static void BrowseChatRoomByCategory(PersistentChatEndpoint persistentChatEndpoint, Uri categoryUri) { Console.WriteLine(string.Format("Searching for chat rooms under category [{0}]", categoryUri)); SampleCommon.RoomSearchUnderCategory(persistentChatEndpoint, categoryUri); }
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); } }
/// <summary> /// Create the category and chat rooms if they are missing, or simply find their Uris if they /// exist already (presumably from a previous run of this sample code). /// </summary> /// <param name="clients"></param> /// <returns></returns> private static List <Uri> SetupChatRooms(IEnumerable <SimulatedClient> clients) { List <Uri> chatRooms = new List <Uri>(); try { UserEndpoint userEndpoint = SampleCommon.ConnectLyncServer(SampleCommon.UserSipUri, SampleCommon.LyncServer, SampleCommon.UsingSso, SampleCommon.Username, SampleCommon.Password); PersistentChatEndpoint persistentChatEndpoint = SampleCommon.ConnectPersistentChatServer(userEndpoint, SampleCommon. PersistentChatServerUri); Console.WriteLine("Press any key to start the test, then press any key later to longin the test..."); Console.ReadKey(); foreach (string roomName in SampleCommon.LoadTestChatRoomNames) { chatRooms.Add(roomUri); // Setup all the test users as Managers and Members in this chat room // thus allowing these users to join the chat rooms during this sample's execution. foreach (SimulatedClient client in clients) { ChatRoomAddManagerAndMember(persistentChatEndpoint, roomUri, client.UserUri); } } 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); } return(chatRooms); }