void HandleSubmit(CallInfo callInfo) { using (var stream = new MemoryStream()) { callInfo.Data.CopyTo(stream); stream.Position = 0; Hasher.Verify(stream, callInfo.Md5); var msg = CreatePhysicalMessage(headerManager.Reassemble(callInfo.ClientId, callInfo.Headers)); if (IsMsmqTransport) { msg.CorrelationId = StripSlashZeroFromCorrelationId(msg.CorrelationId); } msg.Body = new byte[stream.Length]; stream.Read(msg.Body, 0, msg.Body.Length); if (deduplicator.DeduplicateMessage(callInfo.ClientId, DateTime.UtcNow)) { MessageReceived(this, new MessageReceivedOnChannelArgs { Message = msg }); } else { Logger.InfoFormat("Message with id: {0} is already on the bus, dropping the request", callInfo.ClientId); } } }
void HandleSubmit(CallInfo callInfo) { persister.InsertMessage(callInfo.ClientId, DateTime.UtcNow, callInfo.Data, callInfo.Headers); if (callInfo.AutoAck) { HandleAck(callInfo); } }
internal void DispatchReceivedCallInfo(CallInfo callInfo) { switch (callInfo.Type) { case CallType.Submit: HandleSubmit(callInfo); break; case CallType.DatabusProperty: HandleDatabusProperty(callInfo); break; case CallType.Ack: HandleAck(callInfo); break; } }
void HandleDatabusProperty(CallInfo callInfo) { if (DataBus == null) { throw new InvalidOperationException("Databus transmission received without a configured databus"); } var newDatabusKey = DataBus.Put(callInfo.Data, callInfo.TimeToBeReceived); using (var databusStream = DataBus.Get(newDatabusKey)) { Hasher.Verify(databusStream, callInfo.Md5); } var specificDataBusHeaderToUpdate = callInfo.ReadDataBus(); headerManager.InsertHeader(callInfo.ClientId, specificDataBusHeaderToUpdate, newDatabusKey); }
void HandleDatabusProperty(CallInfo callInfo) { if (DataBus == null) throw new InvalidOperationException("Databus transmission received without a databus configured"); TimeSpan timeToBeReceived; if (!TimeSpan.TryParse(callInfo.Headers["NServiceBus.TimeToBeReceived"], out timeToBeReceived)) timeToBeReceived = TimeSpan.FromHours(1); string newDatabusKey; using (callInfo.Data) newDatabusKey = DataBus.Put(callInfo.Data, timeToBeReceived); var specificDataBusHeaderToUpdate = callInfo.Headers[GatewayHeaders.DatabusKey]; persister.UpdateHeader(callInfo.ClientId, specificDataBusHeaderToUpdate, newDatabusKey); }
void HandleAck(CallInfo callInfo) { byte[] outMessage; IDictionary<string, string> outHeaders; if (!persister.AckMessage(callInfo.ClientId, out outMessage, out outHeaders)) { Logger.InfoFormat("Message with id: {0} is already acked, dropping the request", callInfo.ClientId); return; } var msg = HeaderMapper.Map(outHeaders); msg.Body = outMessage; MessageReceived(this, new MessageReceivedOnChannelArgs { Message = msg }); }
/// <summary> /// Analyse source file for logging calls. Logging calls may be updated and the source modified. Behaviour depends on update mode. /// </summary> public void Analyse(ISourceFile file) { if (file == null) throw new ArgumentNullException(nameof(file)); var lines = file.ReadAllLines(); if (lines == null) return; var writeRequired = false; for (var lineNumber = 0; lineNumber < lines.Length; ++lineNumber) { var line = lines[lineNumber]; var previousLine = lineNumber > 0 ? lines[lineNumber - 1] : string.Empty; if (string.IsNullOrWhiteSpace(line)) continue; var callMatch = CallRegex.Match(line); if (callMatch.Success == false) continue; var messageMatch = MessageRegex.Match(previousLine); if (RequireMessage && messageMatch.Success == false) throw new Exception($"Failed to parse message for log call at line {lineNumber} of file '{file.Path}'"); LogLevel level; if (Enum.TryParse(callMatch.Groups[2].Value, out level) == false) throw new Exception($"Failed to parse log level '{callMatch.Groups[2].Value}' at line {lineNumber} of file '{file.Path}'"); var callInfo = new CallInfo { Id = callMatch.Groups[3].Value, Lvl = level, Msg = messageMatch.Success ? messageMatch.Groups[1].Value : null, File = file.Path, Line = lineNumber + 1 }; switch (UpdateMode) { case UpdateMode.All: callInfo.Id = Guid.NewGuid().ToString(); UpdateLine(lines, lineNumber, callMatch, callInfo); writeRequired = true; break; case UpdateMode.NonUnique: if (LogCallMap.ContainsKey(callInfo.Id) || string.IsNullOrWhiteSpace(callInfo.Id)) { callInfo.Id = Guid.NewGuid().ToString(); UpdateLine(lines, lineNumber, callMatch, callInfo); writeRequired = true; } break; default: if (string.IsNullOrWhiteSpace(callInfo.Id)) throw new Exception($"Zero length log identifier in file '{file.Path}'"); if (LogCallMap.ContainsKey(callInfo.Id)) throw new Exception($"Duplicate log identifier '{callInfo.Id}' in file '{file.Path}'"); break; } LogCallMap.Add(callInfo.Id, callInfo); } if (writeRequired) file.WriteAllLines(lines); }
private static void UpdateLine(string[] lines, int lineNumber, Match callMatch, CallInfo callInfo) { lines[lineNumber] = callMatch.Groups[1].Value + callInfo.Id + callMatch.Groups[4].Value; }
void HandleDatabusProperty(CallInfo callInfo) { if (DataBus == null) { throw new InvalidOperationException("Databus transmission received without a databus configured"); } var newDatabusKey = DataBus.Put(callInfo.Data, callInfo.TimeToBeReceived); var specificDataBusHeaderToUpdate = callInfo.ReadDataBus(); persister.UpdateHeader(callInfo.ClientId, specificDataBusHeaderToUpdate, newDatabusKey); }