Beispiel #1
0
 public SimulatedChatRoom(PersistentChatEndpoint persistentChatEndpoint, SimulatedClient client, Uri roomUri)
 {
     currentOperation = new CurrentOperation(Log);
     Client           = client;
     this.roomUri     = roomUri;
     session          = new ChatRoomSession(persistentChatEndpoint);
 }
Beispiel #2
0
            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 Uri RoomCreateUnderNonRootCategory(PersistentChatEndpoint persistentChatEndpoint, Uri parentCategoryUri, string chatRoomName)
        {
            Console.WriteLine(String.Format("Create new chat room [{0}] under [{1}]...", chatRoomName, parentCategoryUri));

            //   ChatRoomManagementServices chatRoomMgmt = persistentChatEndpoint.PersistentChatServices.ChatRoomManagementServices;
            ChatRoomManagementServices chatRoomMgmt = persistentChatEndpoint.PersistentChatServices.ChatRoomManagementServices;
            //   PersistentChatUserAdministrationServices userMgmt = persistentChatEndpoint.PersistentChatServices.UserAdministrationServices;



            ChatRoomSettings settings = new ChatRoomSettings(chatRoomName, parentCategoryUri);
            Uri roomUri = chatRoomMgmt.EndCreateChatRoom((chatRoomMgmt.BeginCreateChatRoom(settings, null, null)));

            // Add current user as member.
            PersistentChatUserServices userMgmt = persistentChatEndpoint.PersistentChatServices.UserServices;
            PersistentChatUser         user     = userMgmt.EndGetUser(userMgmt.BeginGetUser(new Uri(persistentChatEndpoint.InnerEndpoint.OwnerUri), null, null));

            ICollection <PersistentChatPrincipalSummary> members = new List <PersistentChatPrincipalSummary>();

            members.Add(user);
            chatRoomMgmt.EndAddUsersOrGroupsToRole(chatRoomMgmt.BeginAddUsersOrGroupsToRole(ChatRoomRole.Presenter, roomUri, members, null, null));
            chatRoomMgmt.EndAddUsersOrGroupsToRole(chatRoomMgmt.BeginAddUsersOrGroupsToRole(ChatRoomRole.Member, roomUri, members, null, null));

            //必须把自己加进去,创建和管理都是创建人的,其他的人设置会有问题


            Console.WriteLine("\t  Success  聊天室创建成果");
            return(roomUri);
        }
Beispiel #4
0
        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;
                }
            }
        }
        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 DisconnectPersistentChatServer(PersistentChatEndpoint persistentChatEndpoint)
        {
            Console.WriteLine("Disconnecting from Persistent Chat Server...");

            persistentChatEndpoint.EndTerminate(persistentChatEndpoint.BeginTerminate(null, null));

            Console.WriteLine("\tSuccess");
        }
Beispiel #7
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
            //////////////////////////////////////////////////////////////////////////////////////////////////

            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 PersistentChatUser GetUser(PersistentChatEndpoint persistentChatEndpoint, Uri uri)
        {
            Console.WriteLine(String.Format("GetUser --Uri------->eiail:", uri));
            PersistentChatUserServices ChatUserServices = persistentChatEndpoint.PersistentChatServices.UserServices;

            Console.WriteLine(String.Format("GetUser uri is get [{0}] ---Uri-----sss--->eiail:{1}", persistentChatEndpoint.InnerEndpoint.OwnerDisplayName, uri));
            PersistentChatUser pu = ChatUserServices.EndGetUser(
                ChatUserServices.BeginGetUser(uri, null, null));

            return(pu);
        }
        public static ChatRoomSession RoomJoinExisting(PersistentChatEndpoint persistentChatEndpoint, Uri roomUri)
        {
            Console.WriteLine(String.Format("Joining chat room by URI [{0}]...", roomUri));

            ChatRoomSession session = new ChatRoomSession(persistentChatEndpoint);

            session.EndJoin(session.BeginJoin(roomUri, null, null));

            Console.WriteLine("\tSuccess");

            return(session);
        }
Beispiel #11
0
            private void OcsBeginEstablishFinished(IAsyncResult ar)
            {
                currentOperation.End("OcsBeginEstablishFinished", () => userEndpoint.EndEstablish(ar));

                currentOperation.Begin(string.Format("Connect to GC={0}", SampleCommon.PersistentChatServerUri),
                                       () =>
                {
                    // Connect to Persistent Chat Server
                    persistentChatEndpoint = new PersistentChatEndpoint(SampleCommon.PersistentChatServerUri, userEndpoint);
                    persistentChatEndpoint.BeginEstablish(ar1 => PersistentChatBeginEstablishFinished(ar1), null);
                });
            }
        public static ChatRoomSession RoomJoinExisting(PersistentChatEndpoint persistentChatEndpoint, ChatRoomSummary summary)
        {
            Console.WriteLine(String.Format("Joining chat room by NAME [{0}]...", summary.Name));

            ChatRoomSession session = new ChatRoomSession(persistentChatEndpoint);

            session.EndJoin(session.BeginJoin(summary, null, null));

            Console.WriteLine("\tSuccess");

            return(session);
        }
Beispiel #13
0
        private static void GetRiamoLists(PersistentChatEndpoint persistentChatEndpoint)
        {
            PersistentChatServices pcs = persistentChatEndpoint.PersistentChatServices;

            ReadOnlyCollection <ChatRoomSnapshot> chatRooms = pcs.EndBrowseMyChatRooms(pcs.BeginBrowseMyChatRooms(null, null, 1000));

            Console.WriteLine("My Rooms:");
            DumpChatRooms(chatRooms);

            chatRooms = pcs.EndBrowseChatRoomsIManage(pcs.BeginBrowseChatRoomsIManage(null, null, 1000));
            Console.WriteLine("Rooms that I manage:");
            DumpChatRooms(chatRooms);
        }
Beispiel #14
0
        private static void ChatRoomAddManagerAndMember(PersistentChatEndpoint persistentChatEndpoint, Uri chatroomUri, Uri userUri)
        {
            ChatRoomManagementServices chatroomMgmt = persistentChatEndpoint.PersistentChatServices.ChatRoomManagementServices;
            PersistentChatUserServices userMgmt     = persistentChatEndpoint.PersistentChatServices.UserServices;

            PersistentChatUser user = userMgmt.EndGetUser(userMgmt.BeginGetUser(userUri, null, null));
            List <PersistentChatPrincipalSummary> newUsers = new List <PersistentChatPrincipalSummary> {
                user
            };

            chatroomMgmt.EndAddUsersOrGroupsToRole((chatroomMgmt.BeginAddUsersOrGroupsToRole(ChatRoomRole.Manager, chatroomUri, newUsers, null, null)));
            chatroomMgmt.EndAddUsersOrGroupsToRole((chatroomMgmt.BeginAddUsersOrGroupsToRole(ChatRoomRole.Member, chatroomUri, newUsers, null, null)));
        }
        public static PersistentChatEndpoint ConnectPersistentChatServer(UserEndpoint userEndpoint, Uri persistentChatServerUri)
        {
            Console.WriteLine("{0} Connecting to Persistent Chat Server...", userEndpoint.EndpointUri);

            PersistentChatEndpoint persistentChatEndpoint = new PersistentChatEndpoint(persistentChatServerUri, userEndpoint);

            persistentChatEndpoint.EndEstablish(persistentChatEndpoint.BeginEstablish(null, null));
            Console.WriteLine("\t{0}-ConnectPersistentChatServer >>>>Successing" + userEndpoint.EndpointUri);

            DisplayServerInfo(persistentChatEndpoint.PersistentChatServices.ServerConfiguration);

            return(persistentChatEndpoint);
        }
        public void SetChatRoomPrivacySetting(PersistentChatEndpoint persistentChatEndpoint, Uri roomUri, ChatRoomPrivacy privacySetting)
        {
            Console.WriteLine("\t {0} client {1} SetChatRoomPrivacySetting privacySetting {2}  start", userName, roomUri, privacySetting);
            ChatRoomManagementServices ChatRoomServices = persistentChatEndpoint.PersistentChatServices.ChatRoomManagementServices;

            ChatRoom room = ChatRoomServices.EndGetChatRoom(
                ChatRoomServices.BeginGetChatRoom(roomUri, null, null));
            ChatRoomInformation roomInfo = new ChatRoomInformation(room);

            roomInfo.Privacy = privacySetting;
            ChatRoomServices.EndUpdateChatRoom(
                ChatRoomServices.BeginUpdateChatRoom(roomInfo, null, null));
            Console.WriteLine("\t {0} client {1} SetChatRoomPrivacySetting privacySetting {2} Success", userName, roomUri, privacySetting);
        }
        public void loginLyncServer()
        {
            // Connect to Lync Server
            userEndpoint = SampleCommon.ConnectLyncServer(sipUri.ToString(),
                                                          SampleCommon.LyncServer,
                                                          SampleCommon.UsingSso,
                                                          userDomanName,
                                                          password);

            // Connect to Persistent Chat Server
            persistentChatEndpoint = SampleCommon.ConnectPersistentChatServer(userEndpoint, SampleCommon.PersistentChatServerUri);
            Console.WriteLine(String.Format("please press any key continue login success    [{0}]...", userName));
            Console.ReadLine();
        }
        public void ChatRoomAddManagerAndMember(PersistentChatEndpoint persistentChatEndpoint, Uri chatroomUri, Uri userUri)
        {
            Console.WriteLine(String.Format("Adding manager+member [{0}] to Room [{1}]...", userUri, chatroomUri));

            ChatRoomManagementServices chatroomMgmt = persistentChatEndpoint.PersistentChatServices.ChatRoomManagementServices;
            PersistentChatUserServices userMgmt     = persistentChatEndpoint.PersistentChatServices.UserServices;

            PersistentChatUser user = userMgmt.EndGetUser(userMgmt.BeginGetUser(userUri, null, null));
            List <PersistentChatPrincipalSummary> newUsers = new List <PersistentChatPrincipalSummary> {
                user
            };

            chatroomMgmt.EndAddUsersOrGroupsToRole((chatroomMgmt.BeginAddUsersOrGroupsToRole(ChatRoomRole.Manager, chatroomUri, newUsers, null, null)));
            //    chatroomMgmt.EndAddUsersOrGroupsToRole((chatroomMgmt.BeginAddUsersOrGroupsToRole(ChatRoomRole.Member, chatroomUri, newUsers, null, null)));

            Console.WriteLine("\t {0} client {1} ChatRoomAddManagerAndMember  {2} Success", userName, chatroomUri, userUri);
        }
Beispiel #19
0
        private static void ChatRoomAddManagerAndMember(PersistentChatEndpoint persistentChatEndpoint, Uri chatroomUri, Uri userUri)
        {
            Log(String.Format("Adding manager+member [{0}] to Room [{1}]...", userUri, chatroomUri));

            ChatRoomManagementServices chatroomMgmt = persistentChatEndpoint.PersistentChatServices.ChatRoomManagementServices;
            PersistentChatUserServices userMgmt     = persistentChatEndpoint.PersistentChatServices.UserServices;

            PersistentChatUser user = userMgmt.EndGetUser(userMgmt.BeginGetUser(userUri, null, null));
            List <PersistentChatPrincipalSummary> newUsers = new List <PersistentChatPrincipalSummary> {
                user
            };

            chatroomMgmt.EndAddUsersOrGroupsToRole((chatroomMgmt.BeginAddUsersOrGroupsToRole(ChatRoomRole.Manager, chatroomUri, newUsers, null, null)));
            chatroomMgmt.EndAddUsersOrGroupsToRole((chatroomMgmt.BeginAddUsersOrGroupsToRole(ChatRoomRole.Member, chatroomUri, newUsers, null, null)));

            Log("\tSuccess");
        }
        public static Uri GetCategoryUri(PersistentChatEndpoint persistentChatEndpoint)
        {
            ChatRoomManagementServices chatRoomManagementServices = persistentChatEndpoint.PersistentChatServices.ChatRoomManagementServices;
            IAsyncResult asyncResult = chatRoomManagementServices.BeginFindCategoriesWithCreateRights(null, null);
            ReadOnlyCollection <ChatRoomCategorySummary> categories = chatRoomManagementServices.EndFindCategoriesWithCreateRights(asyncResult);

            int categoryIndex = -1;

            while (categoryIndex < 0 || categoryIndex >= categories.Count)
            {
                Console.WriteLine(string.Format(
                                      "Please enter the index of the category you would like to work under (0-based): [{0}]",
                                      string.Join(", ", categories.Select(cat => cat.Name))));
                int.TryParse(Console.ReadLine(), out categoryIndex);
            }
            return(categories[categoryIndex].Uri);
        }
        private static void RoomSearchChatHistory(PersistentChatEndpoint persistentChatEndpoint, ChatRoomSession session, string searchString)
        {
            Console.WriteLine(string.Format("Searching the chat history in chat room [{0}] for string [{1}]", session.Name, searchString));

            // Search the chat history
            IAsyncResult asyncResult = persistentChatEndpoint.PersistentChatServices.BeginQueryChatHistory(new List <Uri> {
                session.ChatRoomUri
            },
                                                                                                           searchString, false, false, null, null);
            ReadOnlyCollection <ChatHistoryResult> results = persistentChatEndpoint.PersistentChatServices.EndQueryChatHistory(asyncResult);

            foreach (ChatHistoryResult result in results)
            {
                Console.WriteLine(string.Format("\tChat Room [{0}] contains the following matches:", result.ChatRoomName));
                foreach (ChatMessage message in result.Messages)
                {
                    Console.WriteLine(string.Format("\t\tMessage: {0}", message.MessageContent));
                }
            }
        }
        public static ReadOnlyCollection <ChatRoomSnapshot> RoomSearchUnderCategory(PersistentChatEndpoint persistentChatEndpoint, Uri categoryUri, int maxResults = 100)
        {
            Console.WriteLine(String.Format("Searching for chat rooms under category [{0}] with max result size of [{1}]...", categoryUri, maxResults));

            PersistentChatServices chatServices = persistentChatEndpoint.PersistentChatServices;

            ReadOnlyCollection <ChatRoomSnapshot> chatRooms = chatServices.EndBrowseChatRoomsByCategoryUri(
                chatServices.BeginBrowseChatRoomsByCategoryUri(categoryUri, maxResults, null, null));

            Console.WriteLine(String.Format("\tFound {0} chat room(s):", chatRooms.Count));
            if (chatRooms.Count > 0)
            {
                foreach (ChatRoomSnapshot snapshot in chatRooms)
                {
                    Console.WriteLine(String.Format("\tname: {0}\n\turi:{1}", snapshot.Name, snapshot.ChatRoomUri));
                }
                return(chatRooms);
            }
            return(null);
        }
        public static ReadOnlyCollection <ChatRoomSnapshot> RoomSearchWithCriteria(PersistentChatEndpoint persistentChatEndpoint, string chatRoomCriteria,
                                                                                   int maxResults = 100)
        {
            Console.WriteLine(String.Format("Searching for chat room [{0}] with a maxResults set of [{1}]...", chatRoomCriteria, maxResults));

            PersistentChatServices chatServices = persistentChatEndpoint.PersistentChatServices;

            ReadOnlyCollection <ChatRoomSnapshot> chatRooms = chatServices.EndBrowseChatRoomsByCriteria(
                chatServices.BeginBrowseChatRoomsByCriteria(chatRoomCriteria, false, true, true, maxResults, null, null));

            Console.WriteLine(String.Format("\tFound {0} chat room(s):", chatRooms.Count));
            if (chatRooms.Count > 0)
            {
                foreach (ChatRoomSnapshot snapshot in chatRooms)
                {
                    Console.WriteLine(String.Format("\tname: {0}\n\turi:{1}", snapshot.Name, snapshot.ChatRoomUri));
                }
                return(chatRooms);
            }
            return(null);
        }
        public static PersistentChatUser GetUser(PersistentChatEndpoint persistentChatEndpoint, string lastName, string firstName, string email)
        {
            Console.WriteLine(String.Format("GetUser ---++++++++++++----vv-->eiail:{0}", email));
            PersistentChatUserServices ChatUserServices = persistentChatEndpoint.PersistentChatServices.UserServices;
            bool moreAvailable;
            PersistentChatPrincipalSummary ps = ChatUserServices.EndFindUsers(ChatUserServices.BeginFindUsers(lastName, firstName, email, null, null), out moreAvailable).FirstOrDefault();

            if (ps == null)
            {
                Console.WriteLine(String.Format("GetUser  do'nt get [{0}]...  PersistentChatPrincipalSummary is null eiail:{1}", persistentChatEndpoint.InnerEndpoint.OwnerDisplayName, email));
                //    Console.ReadLine();
                return(null);
            }
            Console.WriteLine(String.Format("GetUser uri is get [{0}] ---PersistentChatPrincipalSummary isn't null------>eiail:{1}", persistentChatEndpoint.InnerEndpoint.OwnerDisplayName, ps.Uri));
            PersistentChatUser pu = ChatUserServices.EndGetUser(
                ChatUserServices.BeginGetUser(ps.Uri, null, null));

            // ChatUserServices.BeginGetUser(ps.Uri, null, null));
            Console.ReadLine();
            Console.WriteLine(String.Format("GetUser uri is get [{0}] --88888888888----->eiail:{1}", persistentChatEndpoint.InnerEndpoint.OwnerDisplayName, ps.Uri));
            return(pu);
        }
        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);
            }
        }
Beispiel #26
0
        /// <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);
        }
        private static void BrowseChatRoomsByCriteria(PersistentChatEndpoint persistentChatEndpoint, string criteria)
        {
            Console.WriteLine(string.Format("Searching for chat rooms with criteria [{0}]", criteria));

            SampleCommon.RoomSearchWithCriteria(persistentChatEndpoint, criteria);
        }
        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);
            }
        }
        public static ChatRoomSnapshot RoomSearchExisting(PersistentChatEndpoint persistentChatEndpoint, string chatRoomName)
        {
            ReadOnlyCollection <ChatRoomSnapshot> chatRooms = RoomSearchWithCriteria(persistentChatEndpoint, chatRoomName);

            return(chatRooms != null ? chatRooms[0] : null);
        }
        public static ReadOnlyCollection <ChatRoomSnapshot> RoomSearchWithFilterCriteria(PersistentChatEndpoint persistentChatEndpoint, string criteria,
                                                                                         bool searchDesc, string member, string manager, Uri categoryUri, string addinName, bool disabled, ChatRoomPrivacy?privacy,
                                                                                         ChatRoomBehavior?behavior, bool?invitations, bool searchInvites, int maxResults)
        {
            Console.WriteLine(string.Format("Searching for chat rooms with max results size of [{0}]...", maxResults));

            PersistentChatServices     chatServices       = persistentChatEndpoint.PersistentChatServices;
            ChatRoomManagementServices chatRoomManagement = chatServices.ChatRoomManagementServices;

            // get the addin guid if an addin was provided
            Guid?addinGuid = null;

            if (addinName != null)
            {
                ReadOnlyCollection <PersistentChatAddIn> addins =
                    chatRoomManagement.EndGetAllAddIns(chatRoomManagement.BeginGetAllAddIns(null, null));
                foreach (PersistentChatAddIn addin in addins.Where(addin => addin.Name.Equals(addinName)))
                {
                    addinGuid = addin.AddInId;
                    break;
                }
            }

            IAsyncResult asyncResult = chatServices.BeginBrowseChatRoomsByFilterCriteria(criteria, searchDesc,
                                                                                         member, manager,
                                                                                         categoryUri,
                                                                                         addinGuid, disabled, privacy,
                                                                                         behavior, invitations,
                                                                                         searchInvites, maxResults, null,
                                                                                         null);

            ReadOnlyCollection <ChatRoomSnapshot> chatRooms = chatServices.EndBrowseChatRoomsByFilterCriteria(asyncResult);

            Console.WriteLine(String.Format("\tFound {0} chat room(s):", chatRooms.Count));
            if (chatRooms.Count > 0)
            {
                foreach (ChatRoomSnapshot snapshot in chatRooms)
                {
                    Console.WriteLine(String.Format("\tname: {0}\n\turi:{1}", snapshot.Name, snapshot.ChatRoomUri));
                }
                return(chatRooms);
            }
            return(null);
        }