当前位置: 首页>>代码示例>>C#>>正文


C# Models.ChatRoom类代码示例

本文整理汇总了C#中JabbR.Models.ChatRoom的典型用法代码示例。如果您正苦于以下问题:C# ChatRoom类的具体用法?C# ChatRoom怎么用?C# ChatRoom使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ChatRoom类属于JabbR.Models命名空间,在下文中一共展示了ChatRoom类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddOwner

        public void AddOwner(ChatUser ownerOrCreator, ChatUser targetUser, ChatRoom targetRoom)
        {
            // Ensure the user is owner of the target room
            EnsureOwner(ownerOrCreator, targetRoom);

            if (targetRoom.Owners.Contains(targetUser))
            {
                // If the target user is already an owner, then throw
                throw new InvalidOperationException(String.Format("'{0}' is already and owner of '{1}'.", targetUser.Name, targetRoom.Name));
            }

            // Make the user an owner
            targetRoom.Owners.Add(targetUser);
            targetUser.OwnedRooms.Add(targetRoom);

            if (targetRoom.Private)
            {
                if (!targetRoom.AllowedUsers.Contains(targetUser))
                {
                    // If the room is private make this user allowed
                    targetRoom.AllowedUsers.Add(targetUser);
                    targetUser.AllowedRooms.Add(targetRoom);
                }
            }
        }
开发者ID:skalinets,项目名称:JabbR,代码行数:25,代码来源:ChatService.cs

示例2: EnsureAllowed

 public static void EnsureAllowed(this ChatUser user, ChatRoom room)
 {
     if (room.Private && !room.IsUserAllowed(user))
     {
         throw new HubException(String.Format(LanguageResources.RoomAccessPermission, room.Name));
     }
 }
开发者ID:QuinntyneBrown,项目名称:JabbR,代码行数:7,代码来源:ModelExtensions.cs

示例3: SetUserInRoom

        public static void SetUserInRoom(this ICache cache, ChatUser user, ChatRoom room, bool value)
        {
            string key = CacheKeys.GetUserInRoom(user, room);

            // Cache this forever since people don't leave rooms often
            cache.Set(key, value, TimeSpan.FromDays(365));
        }
开发者ID:arri-cc,项目名称:JabbR,代码行数:7,代码来源:CacheExtensions.cs

示例4: EnsureAllowed

 public static void EnsureAllowed(this ChatUser user, ChatRoom room)
 {
     if (room.Private && !room.IsUserAllowed(user))
     {
         throw new InvalidOperationException("You do not have access to " + room.Name);
     }
 }
开发者ID:v-jli,项目名称:jean0603jabbr,代码行数:7,代码来源:ModelExtensions.cs

示例5: MakesOwnerAllowedIfRoomLocked

            public void MakesOwnerAllowedIfRoomLocked()
            {
                var repository = new InMemoryRepository();
                var user = new ChatUser
                {
                    Name = "foo"
                };
                var user2 = new ChatUser
                {
                    Name = "foo2"
                };
                repository.Add(user);
                repository.Add(user2);
                var room = new ChatRoom
                {
                    Name = "Room",
                    Creator = user,
                    Private = true
                };
                room.Owners.Add(user);
                user.OwnedRooms.Add(room);
                user.Rooms.Add(room);
                room.Users.Add(user);

                var service = new ChatService(repository, new Mock<ICryptoService>().Object);

                service.AddOwner(user, user2, room);

                Assert.True(user2.AllowedRooms.Contains(room));
                Assert.True(room.AllowedUsers.Contains(user2));
                Assert.True(room.Owners.Contains(user2));
                Assert.True(user2.OwnedRooms.Contains(room));
            }
开发者ID:Polows,项目名称:JabbR,代码行数:33,代码来源:ChatServiceFacts.cs

示例6: MakesUserOwner

            public void MakesUserOwner()
            {
                var repository = new InMemoryRepository();
                var user = new ChatUser
                {
                    Name = "foo"
                };
                var user2 = new ChatUser
                {
                    Name = "foo2"
                };
                repository.Add(user);
                repository.Add(user2);
                var room = new ChatRoom
                {
                    Name = "Room",
                    Creator = user
                };
                room.Owners.Add(user);
                user.OwnedRooms.Add(room);
                user.Rooms.Add(room);
                room.Users.Add(user);

                var service = new ChatService(repository);

                service.AddOwner(user, user2, room);

                Assert.True(room.Owners.Contains(user2));
                Assert.True(user2.OwnedRooms.Contains(room));
            }
开发者ID:kiliman,项目名称:JabbR,代码行数:30,代码来源:ChatServiceFacts.cs

示例7: CreateRoomRepository

            public IJabbrRepository CreateRoomRepository()
            {
                var repository = new InMemoryRepository();
                var room = new ChatRoom() { Name = "hashtag" };
                var user = new ChatUser() { Name = "testhashtaguser" };
                repository.Add(room);
                room.Users.Add(user);
                user.Rooms.Add(room);

                return repository;
            }
开发者ID:redsquare,项目名称:JabbR,代码行数:11,代码来源:TextTransformFacts.cs

示例8: IsUserInRoom

        public static bool IsUserInRoom(this IJabbrRepository repository, ICache cache, ChatUser user, ChatRoom room)
        {
            bool? cached = cache.IsUserInRoom(user, room);

            if (cached == null)
            {
                cached = repository.IsUserInRoom(user, room);
                cache.SetUserInRoom(user, room, cached.Value);
            }

            return cached.Value;
        }
开发者ID:shimazoe,项目名称:cchat2,代码行数:12,代码来源:RepositoryExtensions.cs

示例9: AddMessage

        public ChatMessage AddMessage(ChatUser user, ChatRoom room, string content)
        {
            var chatMessage = new ChatMessage
            {
                Id = Guid.NewGuid().ToString("d"),
                User = user,
                Content = content,
                When = DateTimeOffset.UtcNow,
                Room = room
            };

            _repository.Add(chatMessage);

            return chatMessage;
        }
开发者ID:skalinets,项目名称:JabbR,代码行数:15,代码来源:ChatService.cs

示例10: AddsNewMessageToRepository

            public void AddsNewMessageToRepository()
            {
                var repository = new InMemoryRepository();
                var user = new ChatUser
                {
                    Name = "foo"
                };
                repository.Add(user);
                var room = new ChatRoom
                {
                    Name = "Room"
                };
                repository.Add(room);
                room.Users.Add(user);
                user.Rooms.Add(room);

                var service = new ChatService(repository);
                ChatMessage message = service.AddMessage(user, room, "Content");

                Assert.NotNull(message);
                Assert.Same(message, room.Messages.First());
                Assert.Equal("Content", message.Content);
            }
开发者ID:kiliman,项目名称:JabbR,代码行数:23,代码来源:ChatServiceFacts.cs

示例11: AddsNewMessageToRepository

            public void AddsNewMessageToRepository()
            {
                var repository = new InMemoryRepository();
                var user = new ChatUser
                {
                    Name = "foo"
                };
                repository.Add(user);
                var room = new ChatRoom
                {
                    Name = "Room"
                };
                repository.Add(room);
                room.Users.Add(user);
                user.Rooms.Add(room);

                var service = new ChatService(new Mock<ICache>().Object, repository, new Mock<ICryptoService>().Object);
                ChatMessage message = service.AddMessage(user, room, Guid.NewGuid().ToString(), "Content");

                Assert.NotNull(message);
                Assert.Same(message, room.Messages.First());
                Assert.Equal("Content", message.Content);
            }
开发者ID:nonintanon,项目名称:JabbR,代码行数:23,代码来源:ChatServiceFacts.cs

示例12: CloseRoom

        public void CloseRoom(ChatUser user, ChatRoom targetRoom)
        {
            EnsureOwner(user, targetRoom);

            if (targetRoom.Closed)
            {
                throw new InvalidOperationException(String.Format("{0} is already closed.", targetRoom.Name));
            }

            // Make sure the (owner) user is not in the room.
            if (targetRoom.Users.Contains(user))
            {
                throw new InvalidOperationException("You are trying to close a room which you are still in. Please leave the room before closing it.");
            }

            // Kick all existing users in the room.
            foreach (var targetUser in targetRoom.Users.ToList())
            {
                LeaveRoom(targetUser, targetRoom);
            }

            // Make the room closed.
            targetRoom.Closed = true;

            _repository.CommitChanges();
        }
开发者ID:alexkopy,项目名称:JabbR,代码行数:26,代码来源:ChatService.cs

示例13: ChangeTopic

 public void ChangeTopic(ChatUser user, ChatRoom room, string newTopic)
 {
     EnsureOwner(user, room);
     room.Topic = newTopic;
     _repository.CommitChanges();
 }
开发者ID:alexkopy,项目名称:JabbR,代码行数:6,代码来源:ChatService.cs

示例14: EnsureOwner

 private static void EnsureOwner(ChatUser user, ChatRoom room)
 {
     if (!room.Owners.Contains(user))
     {
         throw new InvalidOperationException("You are not an owner of room '" + room.Name + "'");
     }
 }
开发者ID:alexkopy,项目名称:JabbR,代码行数:7,代码来源:ChatService.cs

示例15: IsUserInRoom

 internal static bool IsUserInRoom(ChatRoom room, ChatUser user)
 {
     return room.Users.Any(r => r.Name.Equals(user.Name, StringComparison.OrdinalIgnoreCase));
 }
开发者ID:alexkopy,项目名称:JabbR,代码行数:4,代码来源:ChatService.cs


注:本文中的JabbR.Models.ChatRoom类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。