/// <summary> /// Waits until the profile server receives a response message to the specific request message. /// </summary> /// <param name="Role">Specifies the role of the server to which the message had to arrive to be accepted by this wait function.</param> /// <param name="RequestMessage">Request message for which corresponding response we are waiting for.</param> /// <param name="ClearMessageList">If set to true, the message list will be cleared once the wait is finished.</param> /// <returns>Message the profile server received.</returns> public async Task <IncomingServerMessage> WaitForResponse(ServerRole Role, Message RequestMessage, bool ClearMessageList = true) { log.Trace("()"); IncomingServerMessage res = null; bool done = false; while (!done) { lock (messageListLock) { foreach (IncomingServerMessage ism in messageList) { if (!Role.HasFlag(ism.Role)) { continue; } Message message = ism.IncomingMessage; if (message.MessageTypeCase != Message.MessageTypeOneofCase.Response) { continue; } if (message.Id != RequestMessage.Id) { continue; } res = ism; done = true; break; } if (done && ClearMessageList) { messageList.Clear(); } } if (!done) { try { await Task.Delay(1000, shutdownCancellationTokenSource.Token); } catch { } } } log.Trace("(-)"); return(res); }
/// <summary> /// Adds a new message to the message list. /// </summary> /// <param name="IncomingMessage">New message to add to the message list.</param> public void AddMessage(Message IncomingMessage, ServerRole Role, IncomingClient Client) { log.Trace("()"); IncomingServerMessage msg = new IncomingServerMessage() { Role = Role, IncomingMessage = IncomingMessage, Client = Client }; lock (messageListLock) { messageList.Add(msg); } log.Trace("(-)"); }