public SimulatedChatRoom(PersistentChatEndpoint persistentChatEndpoint, SimulatedClient client, Uri roomUri) { currentOperation = new CurrentOperation(Log); Client = client; this.roomUri = roomUri; session = new ChatRoomSession(persistentChatEndpoint); }
private static void RoomChat(ChatRoomSession session) { Console.WriteLine(String.Format("Chatting in chat room [{0}]...", session.Name)); Console.WriteLine("\tsubscribe to incoming messages"); session.ChatMessageReceived += SessionChatMessageReceived; // Send a simple chat message const string rtfContent = @"{\rtf1\ansi\f0\pard This is a simple message with {\b RTF}\par}"; session.EndSendChatMessage(session.BeginSendChatMessage("This is a simple message with RTF", rtfContent, null, null)); // Send a simple story FormattedOutboundChatMessage chatSimpleStory = new FormattedOutboundChatMessage(false, "story title"); chatSimpleStory.AppendPlainText("story body"); session.EndSendChatMessage(session.BeginSendChatMessage(chatSimpleStory, null, null)); // Send a more complicated message FormattedOutboundChatMessage chatAdvancedMessage = new FormattedOutboundChatMessage(true); chatAdvancedMessage.AppendPlainText("This alert message has a channel link: "); chatAdvancedMessage.AppendChatRoomLink(session); chatAdvancedMessage.AppendPlainText(" it also has a hyperlink: "); chatAdvancedMessage.AppendHyperLink("skypetest.com", new Uri("http://sfb2015.skypetest.com")); session.EndSendChatMessage(session.BeginSendChatMessage(chatAdvancedMessage, null, null)); session.ChatMessageReceived -= SessionChatMessageReceived; Console.WriteLine("\tSuccess"); }
public ChatRoomSession creatRoom(String chatRoomName) { // Get a category categoryUri = SampleCommon.GetCategoryUri(persistentChatEndpoint, userName); Console.WriteLine(String.Format(" creatRoom name [{0}]...", chatRoomName)); // Create a new chat room roomUri = SampleCommon.RoomCreateUnderNonRootCategory(persistentChatEndpoint, categoryUri, chatRoomName); roomSession = SampleCommon.RoomJoinExisting(persistentChatEndpoint, roomUri); // roomSession = new ChatRoomSession(persistentChatEndpoint); 这里只能join,这种会提示状态不对,可能需要等几秒才正常 // Chat in the chat room RoomChat(roomSession); // Get the chat history from the room RoomChatHistory(roomSession, 3); // Search the chat history for a room RoomSearchChatHistory(persistentChatEndpoint, roomSession, "story body"); Console.WriteLine(String.Format(" creatRoom name [{0}] ------> info", chatRoomName)); return(roomSession); }
private static void RoomLeave(ChatRoomSession session) { Console.WriteLine(String.Format("Leaving chat room [{0}]...", session.Name)); session.EndLeave(session.BeginLeave(null, null)); Console.WriteLine("\tSuccess"); }
private static void RoomChatHistory(ChatRoomSession session) { Console.WriteLine(String.Format("Obtaining the chat history in chat room [{0}]...", session.Name)); // Get the three messages that were sent before, the simple chat message, the simple story, and the complicated message ReadOnlyCollection <ChatMessage> chatMessages = session.EndGetRecentChatHistory(session.BeginGetRecentChatHistory(3, null, null)); Console.WriteLine(string.Format("Three most recent chat history messages: \n\t1) {0} \n\t2) {1} \n\t3) {2}", chatMessages[0].MessageContent, chatMessages[1].MessageContent, chatMessages[2].MessageContent)); }
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); }
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); }
public void RoomLeave(ChatRoomSession session) { if (session == null) { return; } Console.WriteLine(String.Format("Leaving chat room [{0}]...{1}", session.Name, session.State)); session.EndLeave(session.BeginLeave(null, null)); Console.WriteLine("\tSuccess"); }
public ChatRoomSession enterRoom(String chatRoomName) { ChatRoomSnapshot roomSnapshot = SampleCommon.RoomSearchExisting(persistentChatEndpoint, chatRoomName); roomSession = SampleCommon.RoomJoinExisting(persistentChatEndpoint, roomSnapshot); Console.WriteLine(String.Format(" enterRoom name [{0}] ------> state:{1}", chatRoomName, roomSession.State)); foreach (ChatRoomParticipant cp in roomSession.Participants) { Console.WriteLine(String.Format(" enterRoom ChatRoomParticipant name [{0}] ------> info:{1} isManger:{2}", chatRoomName, cp.SipUri, cp.IsManager)); } Console.WriteLine(String.Format(" enterRoom ChatRoomParticipant name is out room [{0}] total :{1}", chatRoomName, roomSession.Participants.Count)); return(roomSession); }
public void RoomChatHistory(ChatRoomSession session, int recentCount) { if (session == null) { return; } Console.WriteLine(String.Format("Obtaining the chat history in chat room [{0}]. 最近{1}条", session.Name, recentCount)); // Get the three messages that were sent before, the simple chat message, the simple story, and the complicated message ReadOnlyCollection <ChatMessage> chatMessages = session.EndGetRecentChatHistory(session.BeginGetRecentChatHistory(recentCount, null, null)); for (int i = 0; i < chatMessages.Count; i++) { Console.WriteLine(string.Format("recent chat history messages \n\t 第{0}条:ID:{1} 作者:{2} 时间: {3}内容:{4}", i, chatMessages[i].MessageId, chatMessages[i].MessageAuthor, chatMessages[i].Timestamp, chatMessages[i].MessageContent)); } }
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 ChatRoomSession enterRoom(Uri url) { roomSession = SampleCommon.RoomJoinExisting(persistentChatEndpoint, roomUri); return(roomSession); }