/// <summary> /// Builds an event with the current data in this builder. If you want to create and send an event immediately, /// use <see cref="CaptureAsync"/> instead. /// </summary> public SentryEvent Build() { return(new SentryEvent { EventId = (EventId ?? Guid.NewGuid()).ToString("N"), Timestamp = Timestamp ?? DateTime.UtcNow, Logger = Logger, Platform = Platform, Sdk = Sdk, Level = Level ?? (Exception == null ? SeverityLevel.Info : SeverityLevel.Error), Culprit = Culprit, ServerName = ServerName, Release = Release, Tags = Tags.Any() ? Tags.ToDictionary(p => p.Key, p => p.Value) : null, Environment = Environment, Modules = Modules.Any() ? Modules : null, Extra = Extra, Fingerprint = Fingerprint.Any() ? Fingerprint : null, Exception = Exception != null && Exception.Any() ? Exception : null, Message = Message, Breadcrumbs = Breadcrumbs, Request = Request, User = User, Contexts = Contexts.Any() ? Contexts.ToDictionary(p => p.Key, p => p.Value) : null }); }
public virtual void CheckAll(params Action[] cases) { if (cases == null) { return; } Exception[] errors = new Exception[cases.Length]; for (int i = 0; i < errors.Length; i++) { try { cases[i].Invoke(); errors[i] = null; } catch (Exception e) { errors[i] = e; } } if (errors.Any(e => e != null)) { throw new AggregateException("Cases failed: " + string.Join(", ", Enumerable.Range(0, errors.Length).Where(i => errors[i] != null)) + " -", errors.Where(e => e != null)); } }
public async Task Invoke_GivenAggregateExceptionIsThrown_ShouldWriteToResponse() { // Arrange var context = GetHrrpContext(); var expectedStatusCode = HttpStatusCode.InternalServerError; var expectedErrors = new Exception[] { new Exception("Error 1"), new Exception("Error 2") }; Mock.Get(_next) .Setup(d => d(It.IsAny <HttpContext>())) .Throws(new AggregateException(expectedErrors)); // Act await _sut.Invoke(context); // Assert context.Response.StatusCode.Should().Be((int)expectedStatusCode); GetResponse(context) .Errors .Should() .Contain((error) => expectedErrors.Any(e => e.Message == error.Detail)); }
/// <summary> /// Broadcasts a message to all message passing endpoints in the partition. /// The delivery of the message to a particular endpoint will not be affected /// if the delivery to another results in an exception. /// </summary> public void Broadcast(Action <IMessagePassingEndpoint> sendFunc) { var stgs = this.ToList(); var exs = new Exception[stgs.Count]; Task.WhenAll(stgs.Select((stg, i) => { try { sendFunc(stg); } catch (Exception ex) { exs[i] = ex; } return(Task.FromResult(0)); })).Wait(); if (!exs.Any(_ => _ != null)) { return; } else { throw new BroadcastException(stgs.ZipWith(exs)); } }
public async Task <TResponse[]> Broadcast <TResponse>(Func <IMessagePassingEndpoint, Task <TResponse> > sendFunc) where TResponse : IDisposable { var stgs = this.ToList(); var exs = new Exception[stgs.Count]; var vals = new TResponse[stgs.Count]; await Task.WhenAll(stgs.Select(async(stg, i) => { try { vals[i] = await sendFunc(stg); } catch (Exception ex) { exs[i] = ex; } })); if (!exs.Any(_ => _ != null)) { return(vals); } else { throw new BroadcastException <TResponse>(stgs.ZipWith(exs), stgs.ZipWith(vals)); } }
public IEnumerable <TResponse> Broadcast <TResponse>(Func <IMessagePassingEndpoint, TResponse> sendFunc) where TResponse : IDisposable { var stgs = this.ToList(); var exs = new Exception[stgs.Count]; var vals = new TResponse[stgs.Count]; Task.WhenAll(stgs.Select((stg, i) => { try { vals[i] = sendFunc(stg); } catch (Exception ex) { exs[i] = ex; } return(Task.FromResult(0)); })).Wait(); if (!exs.Any(_ => _ != null)) { return(vals); } else { throw new BroadcastException <TResponse>(stgs.ZipWith(exs), stgs.ZipWith(vals)); } }