private void RunConversation() { Task.Factory.StartNew(() => { if (!this.CanStartSimulation()) { return; } Task.Delay(this.random.Next(1000, 3000)).Wait(); ChatroomParticipant participant = GetRandomParticipant(); if (!this.SimulateStartTyping(participant)) { return; } this.SimulateTyping(); this.SimulateEndTyping(participant); this.SimulateTexting(participant); this.EndSimulation(); this.RunConversation(); }); }
public Author ConvertToAuthor(object dataItem, AuthorConverterContext context) { ChatroomParticipant participant = (ChatroomParticipant)dataItem; Author author = this.AuthorsMap.GetOrCreateAuthor(participant); return(author); }
private void OnSignalReceived(ChatroomSignalEventArgs e) { if (e.Signal.StartsWith(ChatroomService.ParticipantStartedTypingMessage)) { string stringId = e.Signal.Substring(ChatroomService.ParticipantStartedTypingMessage.Length + 1); int id = int.Parse(stringId); ChatroomParticipant participant = this.chatroomService.GetParticipant(id); this.typingParticipants.Add(participant); } else if (e.Signal.StartsWith(ChatroomService.ParticipantFinishedTypingMessage)) { string stringId = e.Signal.Substring(ChatroomService.ParticipantFinishedTypingMessage.Length + 1); int id = int.Parse(stringId); ChatroomParticipant participant = this.chatroomService.GetParticipant(id); this.typingParticipants.Remove(participant); } else if (e.Signal.StartsWith(ChatroomService.ParticipantTextedMessage)) { string stringIdAndMessage = e.Signal.Substring(ChatroomService.ParticipantTextedMessage.Length + 1); string stringId = stringIdAndMessage.Substring(0, stringIdAndMessage.IndexOf(" ")); int id = int.Parse(stringId); ChatroomParticipant participant = this.chatroomService.GetParticipant(id); string message = e.Signal.Substring(ChatroomService.ParticipantTextedMessage.Length + stringId.Length + 2); this.Items.Add(new ChatroomTextMessage { Sender = participant, Message = message, }); } }
private void SimulateEndTyping(ChatroomParticipant participant) { lock (this.currentlyTyping) { this.currentlyTyping.Remove(participant); } this.SendFinishedTypingSignal(participant); }
private void InitParticipants() { this.participants = new List <ChatroomParticipant>(); int count = this.random.Next(3, 6); int r = this.random.Next(0, 10); for (int i = 0; i < count; i++) { Tuple <string, string> info = this.GetParticipantInfo(r + i); ChatroomParticipant participant = new ChatroomParticipant { ShortName = info.Item1, Avatar = info.Item2 }; this.participants.Add(participant); } }
public ChatroomViewModel() { string prefix = Device.RuntimePlatform == Device.UWP ? "Assets/" : null; string avatar = prefix + "Logo.png"; this.user = new ChatroomParticipant { ShortName = "User", Avatar = avatar, }; this.items = new ObservableCollection <ChatroomMessage>(); this.typingParticipants = new ObservableCollection <ChatroomParticipant>(); this.chatroomService = new ChatroomService(); this.AddHistory(); this.chatroomService.Signal += this.ChatroomService_Signal; this.sendMessageCommand = new Command(this.OnSendMessage, this.CanSendMessage); }
private bool SimulateStartTyping(ChatroomParticipant participant) { lock (this.currentlyTyping) { if (this.currentlyTyping.Contains(participant)) { return(false); } this.currentlyTyping.Add(participant); } this.SendStartTypingSignal(participant); if (this.random.Next(0, 3) == 0) { this.RunConversation(); } return(true); }
private void SendTextedSignal(ChatroomParticipant participant) { string signal = string.Format("{0} {1} {2}", ParticipantTextedMessage, participant.Id, ParticipantLines.GetRandomLine()); this.SendSignal(signal); }
private void SendFinishedTypingSignal(ChatroomParticipant participant) { string signal = string.Format("{0} {1}", ParticipantFinishedTypingMessage, participant.Id); this.SendSignal(signal); }
private void SimulateTexting(ChatroomParticipant participant) { this.SendTextedSignal(participant); }
public static void SetAuthor(BindableObject bindable, ChatroomParticipant value) { bindable.SetValue(AuthorProperty, value); }