示例#1
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;
                }
            }
        }
        //-----------------------------------------------------------
        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);
        }
示例#3
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 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);
        }
示例#5
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);
        }
        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);
        }
        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);
        }