本文整理汇总了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);
}
}
}
示例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));
}
}
示例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));
}
示例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);
}
}
示例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));
}
示例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));
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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();
}
示例13: ChangeTopic
public void ChangeTopic(ChatUser user, ChatRoom room, string newTopic)
{
EnsureOwner(user, room);
room.Topic = newTopic;
_repository.CommitChanges();
}
示例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 + "'");
}
}
示例15: IsUserInRoom
internal static bool IsUserInRoom(ChatRoom room, ChatUser user)
{
return room.Users.Any(r => r.Name.Equals(user.Name, StringComparison.OrdinalIgnoreCase));
}