本文整理汇总了C#中JabbR.Models.ChatRoom类的典型用法代码示例。如果您正苦于以下问题:C# ChatRoom类的具体用法?C# ChatRoom怎么用?C# ChatRoom使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ChatRoom类属于JabbR.Models命名空间,在下文中一共展示了ChatRoom类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: SetInviteCode
public void SetInviteCode(ChatUser user, ChatRoom room, string inviteCode)
{
EnsureOwner(user, room);
if (!room.Private)
{
throw new InvalidOperationException("Only private rooms can have invite codes");
}
// Set the invite code and save
room.InviteCode = inviteCode;
_repository.CommitChanges();
}
开发者ID:alexkopy,项目名称:JabbR,代码行数:12,代码来源:ChatService.cs
示例17: LeaveRoom
public void LeaveRoom(ChatUser user, ChatRoom room)
{
// Remove the user from the room
room.Users.Remove(user);
// Remove this room from the users' list
user.Rooms.Remove(room);
}
开发者ID:alexkopy,项目名称:JabbR,代码行数:8,代码来源:ChatService.cs
示例18: JoinRoom
public void JoinRoom(ChatUser user, ChatRoom room, string inviteCode)
{
// Throw if the room is private but the user isn't allowed
if (room.Private)
{
// First, check if the invite code is correct
if (!String.IsNullOrEmpty(inviteCode) && String.Equals(inviteCode, room.InviteCode, StringComparison.OrdinalIgnoreCase))
{
// It is, add the user to the allowed users so that future joins will work
room.AllowedUsers.Add(user);
}
if (!IsUserAllowed(room, user))
{
throw new InvalidOperationException(String.Format("Unable to join {0}. This room is locked and you don't have permission to enter. If you have an invite code, make sure to enter it in the /join command", room.Name));
}
}
// Add this room to the user's list of rooms
user.Rooms.Add(room);
// Add this user to the list of room's users
room.Users.Add(user);
}
开发者ID:alexkopy,项目名称:JabbR,代码行数:23,代码来源:ChatService.cs
示例19: KickUser
public void KickUser(ChatUser user, ChatUser targetUser, ChatRoom targetRoom)
{
EnsureOwner(user, targetRoom);
if (targetUser == user)
{
throw new InvalidOperationException("Why would you want to kick yourself?");
}
if (!IsUserInRoom(targetRoom, targetUser))
{
throw new InvalidOperationException(String.Format("'{0}' isn't in '{1}'.", targetUser.Name, targetRoom.Name));
}
// If this user isnt' the creator and the target user is an owner then throw
if (targetRoom.Creator != user && targetRoom.Owners.Contains(targetUser))
{
throw new InvalidOperationException("Owners cannot kick other owners. Only the room creator and kick an owner.");
}
LeaveRoom(targetUser, targetRoom);
}
开发者ID:alexkopy,项目名称:JabbR,代码行数:22,代码来源:ChatService.cs
示例20: OpenRoom
public void OpenRoom(ChatUser user, ChatRoom targetRoom)
{
EnsureOwner(user, targetRoom);
if (!targetRoom.Closed)
{
throw new InvalidOperationException(string.Format("{0} is already open.", targetRoom.Name));
}
// Open the room
targetRoom.Closed = false;
_repository.CommitChanges();
}
开发者ID:alexkopy,项目名称:JabbR,代码行数:13,代码来源:ChatService.cs
注:本文中的JabbR.Models.ChatRoom类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论