public ResultPacketElement GetResultPacket() { NetworkReceive Receiver = new NetworkReceive(int.Parse(ConfigurationSettings.AppSettings["ResultPort"])); DataPack = Receiver.ReceiveData(); UnpackResult Unpack = new UnpackResult(); Unpack.ResultPacket = DataPack; return(Unpack.Unpack()); }
private async Task <MessageContext> ProcessMessage(IAgentContext agentContext, MessageContext messageContext) { UnpackResult unpacked = null; UnpackedMessageContext inboundMessageContext = null; if (messageContext is PackedMessageContext packedMessageContext) { (inboundMessageContext, unpacked) = await UnpackAsync(agentContext, packedMessageContext); Logger.LogInformation($"Agent Message Received : {inboundMessageContext.ToJson()}"); } if (Handlers.Where(handler => handler != null).FirstOrDefault( handler => handler.SupportedMessageTypes.Any( type => type == inboundMessageContext.GetMessageType())) is IMessageHandler messageHandler) { Logger.LogDebug("Processing message type {MessageType}, {MessageData}", inboundMessageContext.GetMessageType(), inboundMessageContext.Payload.GetUTF8String()); // Process message in handler var response = await messageHandler.ProcessAsync(agentContext, inboundMessageContext); // Process message with any registered middlewares foreach (var middleware in Middlewares) { await middleware.OnMessageAsync(agentContext, inboundMessageContext); } if (response != null) { if (inboundMessageContext.ReturnRoutingRequested()) { var result = inboundMessageContext.Connection != null ? await CryptoUtils.PackAsync(agentContext.Wallet, inboundMessageContext.Connection.TheirVk, response.ToByteArray()) : await CryptoUtils.PackAsync(agentContext.Wallet, unpacked.SenderVerkey, response.ToByteArray()); return(new PackedMessageContext(result)); } if (inboundMessageContext.Connection != null) { await MessageService.SendAsync(agentContext.Wallet, response, inboundMessageContext.Connection); } else { Logger.LogWarning("Return response available, but connection was not found or was in invalid state"); } } return(null); } throw new AriesFrameworkException(ErrorCode.InvalidMessage, $"Couldn't locate a message handler for type {inboundMessageContext.GetMessageType()}"); }
public UnpackResult Unpack(string inputText) { Reset(); var output = new UnpackResult(); if (string.IsNullOrEmpty(inputText)) { return(output); } var externalText = new StringBuilder(inputText.Length); externalText.Append(inputText[0]); var internalText = new StringBuilder(inputText.Length); this.text = inputText; for (int i = 1; i < inputText.Length; i++) { CalcuateLevels(i); if (curlyBracketLevel.Equals(1) & currentCharIsOpeningCurlyBracket) { externalText.Append(inputText[i]); externalText.Append("#index:" + internalStringIndex); continue; } else if (curlyBracketLevel.Equals(0) & currentCharIsClosingCurlyBracket) { output.InternalTexts.Add(internalText.ToString()); internalStringIndex++; internalText.Clear(); } if (curlyBracketLevel.Equals(0)) { externalText.Append(inputText[i]); } else { internalText.Append(inputText[i]); } } output.Text = externalText.ToString(); Reset(); return(output); }