private XmlDocument GetPreparedXml(SingleRequest request) { XmlDocument xml = new XmlDocument(); XmlElement elementRows = xml.CreateElement("rows"); List <RequestCommunication> communicationsList = request.Communication ?? new List <RequestCommunication>(); foreach (RequestCommunication communication in communicationsList) { XmlElement elementRow = xml.CreateElement("row"); XmlElement elementCommunicationTypeId = xml.CreateElement("CommunicationTypeId"); elementCommunicationTypeId.InnerText = communication.CommunicationTypeId.ToString(); XmlElement elementNumber = xml.CreateElement("Number"); elementNumber.InnerText = communication.Number; elementRow.AppendChild(elementCommunicationTypeId); elementRow.AppendChild(elementNumber); AddElementsToRow(xml, elementRow, request); elementRows.AppendChild(elementRow); } if (communicationsList.Count < 1) { XmlElement elementRow = xml.CreateElement("row"); AddElementsToRow(xml, elementRow, request); elementRows.AppendChild(elementRow); } xml.AppendChild(elementRows); return(xml); }
private void CheckRequest(SingleRequest <T> request) { if (request == null) { throw new ArgumentNullException("SingleRequest can not be null!"); } }
public override Task <VehicleModel> GetVehicle(SingleRequest request, ServerCallContext context) { _logger.LogInformation($"Search vehicle with id: {request.Id}"); var response = Storage.Vehicles.FirstOrDefault(e => e.Id == request.Id); return(Task.FromResult(response)); }
public List <Guid> FindDuplicatesOnSave(string schemaName, SingleRequest request) { DeduplicationProcessing deduplicationProcessing = ClassFactory.Get <DeduplicationProcessing>(new ConstructorArgument("userConnection", UserConnection)); List <Guid> result = deduplicationProcessing.FindDuplicates(schemaName, request); return(result); }
public Message <T> SingleRequest(SingleRequest <T> request) { try { return(brokerRequestProxy.SingleRequest(request)); } catch (Exception e) { Console.WriteLine($"Exception while sending request: {e.Message}"); return(null); } }
private void AddElementsToRow(XmlDocument xml, XmlElement elementRow, SingleRequest request) { XmlElement elementName = xml.CreateElement("Name"); elementName.InnerText = request.Name; elementRow.AppendChild(elementName); if (request.Id != Guid.Empty) { XmlElement elementId = xml.CreateElement("Id"); elementId.InnerText = request.Id.ToString(); elementRow.AppendChild(elementId); } }
public Message <T> SingleRequest(SingleRequest <T> request) { try { var record = ReadRecord(request); return(record != null ? new Message <T>() { Topic = record.Topic, Data = record.Data } : null); } catch (Exception e) { Console.WriteLine($"Error while processing request: {e.Message}"); throw; } }
private Record <T> ReadRecord(SingleRequest <T> request) { CheckRequest(request); Record <T> record = null; streamDataLocker.EnterReadLock(); if (streamData.ContainsKey(request.Topic) && streamData[request.Topic].Count > request.Offset) { record = streamData[request.Topic][request.Offset]; } streamDataLocker.ExitReadLock(); return(record); }
public async Task <IActionResult> Single([FromQuery] SingleRequest req) { Logger.LogInformation($"Get product with filter: name={req?.Name}, bestRatingProduct={req?.BestRatingProduct}, worstRatingProduct={req?.WorstRatingProduct}"); var product = await Service.Single(req.Name, req.BestRatingProduct, req.WorstRatingProduct).ConfigureAwait(false); if (product == null) { return(NotFound($"name={req?.Name}, bestRatingProduct={req?.BestRatingProduct}, worstRatingProduct={req?.WorstRatingProduct}")); } var result = new SingleResponse { Code = product.Code, Name = product.Name, Description = product.Description }; return(Ok(result)); }
private static void Work(Topic topic) { var consumer = new Consumer <Topic>(); while (decision) { var request = new SingleRequest <Topic>() { Topic = topic, Offset = offset }; var message = consumer.SingleRequest(request); if (message != null) { offset++; } } }
private void Update() { if (m_readyForNextSingleRequest) { if (m_onGetSingleRequests.Count > 0) { SingleRequest request = m_onGetSingleRequests.Peek(); GetCharacter(request.CharacterID); } } if (m_readyForNextCharactersRequest) { if (m_onGetCharactersRequests.Count > 0) { CharactersRequest request = m_onGetCharactersRequests.Peek(); GetCharacters(request.PlayerID); } } }
public virtual List <Guid> FindDuplicates(string schemaName, SingleRequest data) { XmlDocument xml = GetPreparedXml(data); return(FindDuplicates(schemaName, xml)); }
/// <summary> /// Processing of a message received from a client. /// </summary> /// <param name="Client">TCP client who send the message.</param> /// <param name="IncomingMessage">Full ProtoBuf message to be processed.</param> /// <returns>true if the conversation with the client should continue, false if a protocol violation error occurred and the client should be disconnected.</returns> public async Task <bool> ProcessMessageAsync(ClientBase Client, IProtocolMessage IncomingMessage) { IncomingClient client = (IncomingClient)Client; ProxProtocolMessage incomingMessage = (ProxProtocolMessage)IncomingMessage; ProxMessageBuilder messageBuilder = client.MessageBuilder; bool res = false; log.Debug("()"); try { // Update time until this client's connection is considered inactive. client.NextKeepAliveTime = DateTime.UtcNow.AddMilliseconds(client.KeepAliveIntervalMs); log.Trace("Client ID {0} NextKeepAliveTime updated to {1}.", client.Id.ToHex(), client.NextKeepAliveTime.ToString("yyyy-MM-dd HH:mm:ss")); log.Trace("Received message type is {0}, message ID is {1}.", incomingMessage.MessageTypeCase, incomingMessage.Id); switch (incomingMessage.MessageTypeCase) { case Message.MessageTypeOneofCase.Request: { ProxProtocolMessage responseMessage = messageBuilder.CreateErrorProtocolViolationResponse(incomingMessage); Request request = incomingMessage.Request; log.Trace("Request conversation type is {0}.", request.ConversationTypeCase); switch (request.ConversationTypeCase) { case Request.ConversationTypeOneofCase.SingleRequest: { SingleRequest singleRequest = request.SingleRequest; SemVer version = new SemVer(singleRequest.Version); log.Trace("Single request type is {0}, version is {1}.", singleRequest.RequestTypeCase, version); if (!version.IsValid()) { responseMessage.Response.Details = "version"; break; } switch (singleRequest.RequestTypeCase) { case SingleRequest.RequestTypeOneofCase.Ping: responseMessage = ProcessMessagePingRequest(client, incomingMessage); break; case SingleRequest.RequestTypeOneofCase.ListRoles: responseMessage = ProcessMessageListRolesRequest(client, incomingMessage); break; default: log.Warn("Invalid request type '{0}'.", singleRequest.RequestTypeCase); break; } break; } case Request.ConversationTypeOneofCase.ConversationRequest: { ConversationRequest conversationRequest = request.ConversationRequest; log.Trace("Conversation request type is {0}.", conversationRequest.RequestTypeCase); if (conversationRequest.Signature.Length > 0) { log.Trace("Conversation signature is '{0}'.", conversationRequest.Signature.ToByteArray().ToHex()); } else { log.Trace("No signature provided."); } switch (conversationRequest.RequestTypeCase) { case ConversationRequest.RequestTypeOneofCase.Start: responseMessage = ProcessMessageStartConversationRequest(client, incomingMessage); break; case ConversationRequest.RequestTypeOneofCase.VerifyIdentity: responseMessage = ProcessMessageVerifyIdentityRequest(client, incomingMessage); break; default: log.Warn("Invalid request type '{0}'.", conversationRequest.RequestTypeCase); // Connection will be closed in ReceiveMessageLoop. break; } break; } default: log.Error("Unknown conversation type '{0}'.", request.ConversationTypeCase); // Connection will be closed in ReceiveMessageLoop. break; } if (responseMessage != null) { // Send response to client. res = await client.SendMessageAsync(responseMessage); if (res) { // If the message was sent successfully to the target, we close the connection in case it was a protocol violation error response. if (responseMessage.MessageTypeCase == Message.MessageTypeOneofCase.Response) { res = responseMessage.Response.Status != Status.ErrorProtocolViolation; } } } else { // If there is no response to send immediately to the client, // we want to keep the connection open. res = true; } break; } case Message.MessageTypeOneofCase.Response: { Response response = incomingMessage.Response; log.Trace("Response status is {0}, details are '{1}', conversation type is {2}.", response.Status, response.Details, response.ConversationTypeCase); // Find associated request. If it does not exist, disconnect the client as it // send a response without receiving a request. This is protocol violation, // but as this is a reponse, we have no how to inform the client about it, // so we just disconnect it. UnfinishedRequest unfinishedRequest = client.GetAndRemoveUnfinishedRequest(incomingMessage.Id); if ((unfinishedRequest != null) && (unfinishedRequest.RequestMessage != null)) { ProxProtocolMessage requestMessage = (ProxProtocolMessage)unfinishedRequest.RequestMessage; Request request = requestMessage.Request; // We now check whether the response message type corresponds with the request type. // This is only valid if the status is Ok. If the message types do not match, we disconnect // for the protocol violation again. bool typeMatch = false; bool isErrorResponse = response.Status != Status.Ok; if (!isErrorResponse) { if (response.ConversationTypeCase == Response.ConversationTypeOneofCase.SingleResponse) { typeMatch = (request.ConversationTypeCase == Request.ConversationTypeOneofCase.SingleRequest) && ((int)response.SingleResponse.ResponseTypeCase == (int)request.SingleRequest.RequestTypeCase); } else { typeMatch = (request.ConversationTypeCase == Request.ConversationTypeOneofCase.ConversationRequest) && ((int)response.ConversationResponse.ResponseTypeCase == (int)request.ConversationRequest.RequestTypeCase); } } else { typeMatch = true; } if (typeMatch) { // Now we know the types match, so we can rely on request type even if response is just an error. switch (request.ConversationTypeCase) { case Request.ConversationTypeOneofCase.SingleRequest: { SingleRequest singleRequest = request.SingleRequest; switch (singleRequest.RequestTypeCase) { default: log.Warn("Invalid conversation type '{0}' of the corresponding request.", request.ConversationTypeCase); // Connection will be closed in ReceiveMessageLoop. break; } break; } case Request.ConversationTypeOneofCase.ConversationRequest: { ConversationRequest conversationRequest = request.ConversationRequest; switch (conversationRequest.RequestTypeCase) { default: log.Warn("Invalid type '{0}' of the corresponding request.", conversationRequest.RequestTypeCase); // Connection will be closed in ReceiveMessageLoop. break; } break; } default: log.Error("Unknown conversation type '{0}' of the corresponding request.", request.ConversationTypeCase); // Connection will be closed in ReceiveMessageLoop. break; } } else { log.Warn("Message type of the response ID {0} does not match the message type of the request ID {1}, the connection will be closed.", incomingMessage.Id, unfinishedRequest.RequestMessage.Id); // Connection will be closed in ReceiveMessageLoop. } } else { log.Warn("No unfinished request found for incoming response ID {0}, the connection will be closed.", incomingMessage.Id); // Connection will be closed in ReceiveMessageLoop. } break; } default: log.Error("Unknown message type '{0}', connection to the client will be closed.", incomingMessage.MessageTypeCase); await SendProtocolViolation(client); // Connection will be closed in ReceiveMessageLoop. break; } } catch (Exception e) { log.Error("Exception occurred, connection to the client will be closed: {0}", e.ToString()); await SendProtocolViolation(client); // Connection will be closed in ReceiveMessageLoop. } if (res && client.ForceDisconnect) { log.Debug("Connection to the client will be forcefully closed."); res = false; } log.Debug("(-):{0}", res); return(res); }
public void SetDuplicatesOnSave(string schemaName, List <string> notDuplicateList, SingleRequest request) { if (notDuplicateList.Any()) { notDuplicateList.Add(request.Id.ToString()); AddToIgnoreList(schemaName, notDuplicateList); } }
/// <summary> /// Processing of a message received from a client. /// </summary> /// <param name="Client">TCP client who send the message.</param> /// <param name="IncomingMessage">Full ProtoBuf message to be processed.</param> /// <returns>true if the conversation with the client should continue, false if a protocol violation error occurred and the client should be disconnected.</returns> public async Task <bool> ProcessMessageAsync(IncomingClient Client, Message IncomingMessage) { MessageBuilder messageBuilder = Client.MessageBuilder; bool res = false; log.Debug("()"); try { log.Trace("Received message type is {0}, message ID is {1}.", IncomingMessage.MessageTypeCase, IncomingMessage.Id); switch (IncomingMessage.MessageTypeCase) { case Message.MessageTypeOneofCase.Request: { Message responseMessage = messageBuilder.CreateErrorProtocolViolationResponse(IncomingMessage); Request request = IncomingMessage.Request; log.Trace("Request conversation type is {0}.", request.ConversationTypeCase); switch (request.ConversationTypeCase) { case Request.ConversationTypeOneofCase.SingleRequest: { SingleRequest singleRequest = request.SingleRequest; SemVer version = new SemVer(singleRequest.Version); log.Trace("Single request type is {0}, version is {1}.", singleRequest.RequestTypeCase, version); if (!version.IsValid()) { responseMessage.Response.Details = "version"; break; } switch (singleRequest.RequestTypeCase) { case SingleRequest.RequestTypeOneofCase.Ping: responseMessage = ProcessMessagePingRequest(Client, IncomingMessage); break; case SingleRequest.RequestTypeOneofCase.ListRoles: responseMessage = ProcessMessageListRolesRequest(Client, IncomingMessage); break; default: log.Warn("Invalid request type '{0}'.", singleRequest.RequestTypeCase); break; } break; } case Request.ConversationTypeOneofCase.ConversationRequest: { ConversationRequest conversationRequest = request.ConversationRequest; log.Trace("Conversation request type is {0}.", conversationRequest.RequestTypeCase); if (conversationRequest.Signature.Length > 0) { log.Trace("Conversation signature is '{0}'.", Crypto.ToHex(conversationRequest.Signature.ToByteArray())); } else { log.Trace("No signature provided."); } switch (conversationRequest.RequestTypeCase) { case ConversationRequest.RequestTypeOneofCase.Start: responseMessage = ProcessMessageStartConversationRequest(Client, IncomingMessage); break; case ConversationRequest.RequestTypeOneofCase.VerifyIdentity: responseMessage = ProcessMessageVerifyIdentityRequest(Client, IncomingMessage); break; case ConversationRequest.RequestTypeOneofCase.StartNeighborhoodInitialization: responseMessage = ProcessMessageStartNeighborhoodInitializationRequest(Client, IncomingMessage); break; case ConversationRequest.RequestTypeOneofCase.FinishNeighborhoodInitialization: responseMessage = ProcessMessageFinishNeighborhoodInitializationRequest(Client, IncomingMessage); break; case ConversationRequest.RequestTypeOneofCase.NeighborhoodSharedProfileUpdate: responseMessage = ProcessMessageNeighborhoodSharedProfileUpdateRequest(Client, IncomingMessage); break; case ConversationRequest.RequestTypeOneofCase.StopNeighborhoodUpdates: responseMessage = ProcessMessageStopNeighborhoodUpdatesRequest(Client, IncomingMessage); break; default: log.Warn("Invalid request type '{0}'.", conversationRequest.RequestTypeCase); // Connection will be closed in ReceiveMessageLoop. break; } break; } default: log.Error("Unknown conversation type '{0}'.", request.ConversationTypeCase); // Connection will be closed in ReceiveMessageLoop. break; } if (responseMessage != null) { // Send response to client. res = await Client.SendMessageAsync(responseMessage); } else { // If there is no response to send immediately to the client, // we want to keep the connection open. res = true; } break; } case Message.MessageTypeOneofCase.Response: { Response response = IncomingMessage.Response; log.Trace("Response status is {0}, details are '{1}', conversation type is {2}.", response.Status, response.Details, response.ConversationTypeCase); // Find associated request. If it does not exist, disconnect the client as it // send a response without receiving a request. This is protocol violation, // but as this is a reponse, we have no how to inform the client about it, // so we just disconnect it. UnfinishedRequest unfinishedRequest = Client.GetAndRemoveUnfinishedRequest(IncomingMessage.Id); if ((unfinishedRequest != null) && (unfinishedRequest.RequestMessage != null)) { Message requestMessage = unfinishedRequest.RequestMessage; Request request = requestMessage.Request; // We now check whether the response message type corresponds with the request type. // This is only valid if the status is Ok. If the message types do not match, we disconnect // for the protocol violation again. bool typeMatch = false; bool isErrorResponse = response.Status != Status.Ok; if (!isErrorResponse) { if (response.ConversationTypeCase == Response.ConversationTypeOneofCase.SingleResponse) { typeMatch = (request.ConversationTypeCase == Request.ConversationTypeOneofCase.SingleRequest) && ((int)response.SingleResponse.ResponseTypeCase == (int)request.SingleRequest.RequestTypeCase); } else { typeMatch = (request.ConversationTypeCase == Request.ConversationTypeOneofCase.ConversationRequest) && ((int)response.ConversationResponse.ResponseTypeCase == (int)request.ConversationRequest.RequestTypeCase); } } else { typeMatch = true; } if (typeMatch) { // Now we know the types match, so we can rely on request type even if response is just an error. switch (request.ConversationTypeCase) { case Request.ConversationTypeOneofCase.SingleRequest: { SingleRequest singleRequest = request.SingleRequest; switch (singleRequest.RequestTypeCase) { default: log.Warn("Invalid conversation type '{0}' of the corresponding request.", request.ConversationTypeCase); // Connection will be closed in ReceiveMessageLoop. break; } break; } case Request.ConversationTypeOneofCase.ConversationRequest: { ConversationRequest conversationRequest = request.ConversationRequest; switch (conversationRequest.RequestTypeCase) { case ConversationRequest.RequestTypeOneofCase.NeighborhoodSharedProfileUpdate: res = ProcessMessageNeighborhoodSharedProfileUpdateResponse(Client, IncomingMessage, unfinishedRequest); break; case ConversationRequest.RequestTypeOneofCase.FinishNeighborhoodInitialization: res = ProcessMessageFinishNeighborhoodInitializationResponse(Client, IncomingMessage, unfinishedRequest); break; default: log.Warn("Invalid type '{0}' of the corresponding request.", conversationRequest.RequestTypeCase); // Connection will be closed in ReceiveMessageLoop. break; } break; } default: log.Error("Unknown conversation type '{0}' of the corresponding request.", request.ConversationTypeCase); // Connection will be closed in ReceiveMessageLoop. break; } } else { log.Warn("Message type of the response ID {0} does not match the message type of the request ID {1}, the connection will be closed.", IncomingMessage.Id); // Connection will be closed in ReceiveMessageLoop. } } else { log.Warn("No unfinished request found for incoming response ID {0}, the connection will be closed.", IncomingMessage.Id); // Connection will be closed in ReceiveMessageLoop. } break; } default: log.Error("Unknown message type '{0}', connection to the client will be closed.", IncomingMessage.MessageTypeCase); await SendProtocolViolation(Client); // Connection will be closed in ReceiveMessageLoop. break; } } catch (Exception e) { log.Error("Exception occurred, connection to the client will be closed: {0}", e.ToString()); await SendProtocolViolation(Client); // Connection will be closed in ReceiveMessageLoop. } if (res && Client.ForceDisconnect) { log.Debug("Connection to the client will be forcefully closed."); res = false; } profileServer.AddMessage(IncomingMessage, Client.ServerRole, res ? Client : null); log.Debug("(-):{0}", res); return(res); }