public void Submit()
        {
            var listener = new TcpListener(IPAddress.Loopback, 0);

            listener.Start();
            var port = ((IPEndPoint)listener.LocalEndpoint).Port;

            listener.BeginAcceptSocket(AcceptAndRead, listener);
            ExceptionDTO DTO = null;

            try
            {
                int a = 100;
                int b = 200;
                var c = a / (b - 200);
            }
            catch (Exception e)
            {
                DTO = new ExceptionDTO(e);
            }
            var e1 = new ErrorReportDTO("dsjklsdfl", DTO, new[] { new ContextCollectionDTO("name1"), new ContextCollectionDTO("name2") });

            var url = new Uri("http://localhost:" + port + "/receiver");
            var sut = new UploadToCoderr(url, "cramply", "majs");

            sut.UploadReport(e1);
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Build an report, but do not upload it
        /// </summary>
        /// <param name="context">
        ///     context passed to all context providers when collecting information. This context is typically
        ///     implemented by one of the integration libraries to provide more context that can be used to process the
        ///     environment.
        /// </param>
        /// <remarks>
        ///     <para>
        ///         Will collect context info and generate a report.
        ///     </para>
        /// </remarks>
        /// <exception cref="ArgumentNullException">exception;contextData</exception>
        public ErrorReportDTO Build(IErrorReporterContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            if (context.Exception is CoderrClientException)
            {
                return(null);
            }
            if (IsReported(context.Exception))
            {
                return(null);
            }
            ErrorReporterContext.MoveCollectionsInException(context.Exception, context.ContextCollections);
            InvokePreProcessor(context);

            _configuration.ContextProviders.Collect(context);

            // Invoke partition collection AFTER other context info providers
            // since those other collections might provide the property that
            // we want to create partions on.
            InvokePartitionCollection(context);

            var reportId = ReportIdGenerator.Generate(context.Exception);

            AddAddemblyVersion(context.ContextCollections);
            var report = new ErrorReportDTO(reportId, new ExceptionDTO(context.Exception),
                                            context.ContextCollections.ToArray());

            return(report);
        }
 private void UploadReportNow(ErrorReportDTO dto)
 {
     foreach (var uploader in _uploaders)
     {
         uploader.UploadReport(dto);
     }
 }
        /// <summary>
        ///     Initializes a new instance of the <see cref="ReportDialog" /> class.
        /// </summary>
        public ReportDialog(ErrorReportDTO dto)
        {
            _dto = dto ?? throw new ArgumentNullException(nameof(dto));

            InitializeComponent();

            var img = Assembly.GetExecutingAssembly()
                      .GetManifestResourceStream(GetType().Namespace + ".Resources.nomorelogs.jpg");

            pictureBox1.Image = Image.FromStream(img);

            if (!Err.Configuration.UserInteraction.AskUserForDetails)
            {
                controlsPanel.Controls.Remove(errorDescription1);
            }
            if (!Err.Configuration.UserInteraction.AskForEmailAddress)
            {
                controlsPanel.Controls.Remove(notificationControl1);
            }
            if (!Err.Configuration.UserInteraction.AskUserForPermission)
            {
                btnCancel.Hide();
            }

            var height = CalculateFormHeight();

            Height = height;
            if (controlsPanel.Controls.Count == 2)
            {
                Width = 550;
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// 建立Dto及上傳
        /// </summary>
        /// <param name="exception"></param>
        /// <returns></returns>
        public static ErrorReportDTO GenerateUploadReport(Exception exception)
        {
            ErrorReportDTO dto = GenerateReport(exception);

            UploadReport(dto);
            return(dto);
        }
Exemplo n.º 6
0
        public static string GetCollectionProperty(this ErrorReportDTO report, string collectionName,
                                                   string propertyName)
        {
            var collection = report.ContextCollections.First(x => x.Name == collectionName);

            return(collection.Properties[propertyName]);
        }
        public void SubmitShouldCorrectlyBuild()
        {
            var          apiKey       = Guid.NewGuid();
            const string sharedSecret = "SomeSharedSecret";
            var          url          = new Uri("http://localhost");
            var          reporter     = new UploadToCoderr(url, apiKey.ToString(), sharedSecret);
            ExceptionDTO DTO          = null;

            try
            {
                int a = 100;
                int b = 200;
                var c = a / (b - 200);
            }
            catch (Exception e)
            {
                DTO = new ExceptionDTO(e);
            }

            ErrorReportDTO e1 = new ErrorReportDTO("dsadasdas", DTO,
                                                   new[] { new ContextCollectionDTO("name1"), new ContextCollectionDTO("name2") });

            var compress = reporter.CompressErrorReport(e1);
            var deflated = reporter.DeflateErrorReport(compress);

            Assert.True(compress.Length >= 200);
            Assert.Contains("dsadasdas", deflated);
        }
        /// <summary>
        ///     Compress an ErrorReport as JSON string
        /// </summary>
        /// <param name="errorReport">ErrorReport</param>
        /// <returns>Compressed JSON representation of the ErrorReport.</returns>
        internal byte[] CompressErrorReport(ErrorReportDTO errorReport)
        {
            var reportJson = JsonConvert.SerializeObject(errorReport, Formatting.None,
                                                         new JsonSerializerSettings
            {
                TypeNameHandling = TypeNameHandling.None,
                ContractResolver =
                    new IncludeNonPublicMembersContractResolver()
            });
            var buffer = Encoding.UTF8.GetBytes(reportJson);

            //collected by GZipStream
            var outMs = new MemoryStream();

            using (var zipStream = new GZipStream(outMs, CompressionMode.Compress))
            {
                zipStream.Write(buffer, 0, buffer.Length);

                //MUST close the stream, flush doesn't help and without close
                // the memory stream won't get its bytes
                zipStream.Close();

                var result = outMs.ToArray();
                return(result);
            }
        }
Exemplo n.º 9
0
 /// <summary>
 ///     Upload an error report.
 /// </summary>
 /// <param name="dto">Typically generated by <see cref="GenerateReport(System.Exception)" />.</param>
 public static void UploadReport(ErrorReportDTO dto)
 {
     if (dto == null)
     {
         throw new ArgumentNullException("dto");
     }
     Configuration.Uploaders.Upload(dto);
 }
Exemplo n.º 10
0
        public void the_report_should_be_assign_to_the_property_so_that_we_can_filter_on_it()
        {
            var report = new ErrorReportDTO("aa", new ExceptionDTO(new Exception()), new ContextCollectionDTO[0]);

            var sut = new ReportFilterContext(report);

            sut.Report.Should().BeSameAs(report);
        }
Exemplo n.º 11
0
        private static void SetUniqueStackTrace(ErrorReportDTO report)
        {
            var exType = report.Exception.GetType();
            var value  = exType.GetProperty("StackTrace").GetValue(report.Exception);

            value = "  at " + Guid.NewGuid().ToString("N") + ":line 40\r\n" + value;
            exType.GetProperty("StackTrace").SetValue(report.Exception, value);
        }
Exemplo n.º 12
0
        public void should_allow_reports_per_default()
        {
            var report = new ErrorReportDTO("aa", new ExceptionDTO(new Exception()), new ContextCollectionDTO[0]);

            var sut = new ReportFilterContext(report);

            sut.CanSubmitReport.Should().BeTrue();
        }
Exemplo n.º 13
0
        public async Task CreateWithoutSignature(Action <ErrorReportDTO> visitor = null)
        {
            _reporter.DisableSignature();
            _report = _reporter.ReportUnique(Guid.NewGuid().ToString("N"), visitor);
            _reporter.EnableSignature();

            DTO = await _apiClient.GetIncident(_applicationId, _report.Exception.Message);
        }
Exemplo n.º 14
0
        //
        // Summary:
        //     Upload an error report.
        //
        // Parameters:
        //   dto:
        //     Typically generated by OneTrueError.Client.OneTrue.GenerateReport(System.Exception).
        public static void UploadReport(ErrorReportDTO dto)
        {
            ExecuteRetryer retryer = new ExecuteRetryer();

            retryer.Execute(() =>
            {
                OneTrue.UploadReport(dto);
            });
        }
 public ErrorReportDialogPresenter()
 {
     _dto                 = ErrorReportDetailsProvider.DtoReport;
     SubmitCommand        = new DelegateCommand(SubmitReport);
     CancelCommand        = new DelegateCommand(CancelReport);
     ErrorMessage         = new ErrorMessagePresenter(ErrorReportDetailsProvider.ExceptionMessage);
     UserErrorDescription = new UserErrorDescriptionPresenter();
     NotificationControl  = new NotificationControlPresenter();
 }
        /// <summary>
        ///     Initializes a new instance of the <see cref="ReportFilterContext" /> class.
        /// </summary>
        /// <param name="report">The report.</param>
        /// <exception cref="System.ArgumentNullException">report</exception>
        public ReportFilterContext(ErrorReportDTO report)
        {
            if (report == null)
            {
                throw new ArgumentNullException("report");
            }

            Report          = report;
            CanSubmitReport = true;
        }
 public void UploadReport(ErrorReportDTO report)
 {
     if (_queueReportsAccessor())
     {
         _reportQueue.Enqueue(report);
     }
     else
     {
         UploadReportNow(report);
     }
 }
Exemplo n.º 18
0
        public ErrorReportDTO ReportCopy(ErrorReportDTO blueprint, string message,
                                         Action <ErrorReportDTO> customizations = null)
        {
            var id        = ReportIdGenerator.Generate(new Exception());
            var newDto    = new ExceptionDTO(blueprint.Exception);
            var newReport = new ErrorReportDTO(id, blueprint.Exception, blueprint.ContextCollections);

            customizations?.Invoke(newReport);
            _config.Uploaders.Upload(newReport);
            return(newReport);
        }
Exemplo n.º 19
0
        private static void EnsureApplicationVersion(ErrorReportDTO dto)
        {
            foreach (var collection in dto.ContextCollections)
            {
                if (collection.Properties.TryGetValue(ExceptionProcessor.AppAssemblyVersion, out var version))
                {
                    return;
                }
            }

            _exceptionProcessor.AddAddemblyVersion(dto.ContextCollections);
        }
        public void Should_not_throw_exception_when_ThrowExceptions_is_true_and_report_upload_succeeds()
        {
            var uri           = new Uri($"http://localhost:{_listener.LocalPort}/coderr/");
            var collectionDto = new ContextCollectionDTO("MyName", new Dictionary <string, string> {
                { "Key", "Val" }
            });
            var report = new ErrorReportDTO("aaa", new ExceptionDTO(new Exception()), new[] { collectionDto });

            var sut = new UploadToCoderr(uri, "api", "secret", () => false, () => true);

            sut.UploadReport(report);
        }
Exemplo n.º 21
0
        public static ContextCollectionDTO GetCollection(this ErrorReportDTO report, string name)
        {
            var collection = report.ContextCollections.FirstOrDefault(x => x.Name == name);

            if (collection == null)
            {
                var availableCollections = string.Join(", ", report.ContextCollections.Select(x => x.Name));
                throw new AssertionFailedException($"Collection '{name}' was not found. Available collections are: {availableCollections}.");
            }

            return(collection);
        }
Exemplo n.º 22
0
        public void should_pack_and_sign_an_entity_correctly()
        {
            var          apiKey       = Guid.NewGuid();
            const string sharedSecret = "SomeSharedSecret";
            var          url          = new Uri("http://localhost");
            var          reporter     = new UploadTocodeRR(url, apiKey.ToString(), sharedSecret);
            var          dto          = CreateExceptionDTO();

            var e1 = new ErrorReportDTO("dsadasdas", dto,
                                        new[] { new ContextCollectionDTO("name1"), new ContextCollectionDTO("name2") });

            var message = reporter.CreateRequest("http://somewherre.com/report", e1);
        }
Exemplo n.º 23
0
        public ReportDialog(ErrorReportDTO dto, string exceptionMessage)
        {
            if (dto == null)
            {
                throw new ArgumentNullException(nameof(dto));
            }
            ErrorReportDetailsProvider.DtoReport        = dto;
            ErrorReportDetailsProvider.ExceptionMessage = exceptionMessage;
            InitializeComponent();
            var height = CalculateFormHeight();

            Height = height;
        }
Exemplo n.º 24
0
        /// <summary>
        ///     Process exception.
        /// </summary>
        /// <param name="context">
        ///     Used to reports (like for ASP.NET) can attach information which can be used during the context
        ///     collection pipeline.
        /// </param>
        /// <remarks>
        ///     <para>
        ///         Will collect context info, generate a report, go through filters and finally upload it.
        ///     </para>
        /// </remarks>
        /// <returns>
        ///     Report if filter allowed the generated report; otherwise <c>null</c>.
        /// </returns>
        /// <seealso cref="IReportFilter" />
        public ErrorReportDTO Process(IErrorReporterContext context)
        {
            var contextInfo = _configuration.ContextProviders.Collect(context);
            var reportId    = ReportIdGenerator.Generate(context.Exception);
            var report      = new ErrorReportDTO(reportId, new ExceptionDTO(context.Exception), contextInfo.ToArray());
            var canUpload   = _configuration.FilterCollection.CanUploadReport(report);

            if (!canUpload)
            {
                return(null);
            }
            return(report);
        }
Exemplo n.º 25
0
        public void should_be_able_to_upload_correctly()
        {
            var listener = new ListenerStub();
            var dto      = CreateExceptionDTO();
            var e1       = new ErrorReportDTO("dsjklsdfl", dto,
                                              new[] { new ContextCollectionDTO("name1"), new ContextCollectionDTO("name2") });

            var url = new Uri($"http://localhost:{listener.ListenerPort}/");
            var sut = new UploadToCoderr(url, "cramply", "majs");

            sut.UploadReport(e1);

            listener.Wait(5000).Should().BeTrue();
        }
Exemplo n.º 26
0
        /// <summary>
        ///     Process exception.
        /// </summary>
        /// <param name="exception">caught exception</param>
        /// <remarks>
        ///     <para>
        ///         Will collect context info, generate a report, go through filters and finally upload it.
        ///     </para>
        /// </remarks>
        public void Process(Exception exception)
        {
            var context     = new ErrorReporterContext(null, exception);
            var contextInfo = _configuration.ContextProviders.Collect(context);
            var reportId    = ReportIdGenerator.Generate(exception);
            var report      = new ErrorReportDTO(reportId, new ExceptionDTO(exception), contextInfo.ToArray());
            var canUpload   = _configuration.FilterCollection.CanUploadReport(report);

            if (!canUpload)
            {
                return;
            }
            _configuration.Uploaders.Upload(report);
        }
Exemplo n.º 27
0
 /// <summary>
 ///     Invoke callbacks
 /// </summary>
 /// <param name="dto">Report to be uploaded.</param>
 /// <returns><c>false</c> if any of the callbacks return <c>false</c>; otherwise <c>true</c></returns>
 /// <remarks>
 ///     <para>
 ///         All callbacks will be invoked, even if one of them returns <c>false</c>.
 ///     </para>
 /// </remarks>
 public void Upload(ErrorReportDTO dto)
 {
     if (dto == null)
     {
         throw new ArgumentNullException("dto");
     }
     if (_configuration.QueueReports)
     {
         _reportQueue.Add(dto);
     }
     else
     {
         UploadReportNow(dto);
     }
 }
Exemplo n.º 28
0
        public static string GetCollectionProperty(this ErrorReportDTO dto, string collectionName, string propertyName)
        {
            var col = dto.ContextCollections.FirstOrDefault(x => x.Name == collectionName);

            if (col != null)
            {
                return(col.Property(propertyName));
            }

            var collectionNames = string.Join(",", dto.ContextCollections.Select(x => x.Name));

            throw new AssertActualExpectedException(collectionName, null,
                                                    $"Failed to find collection \'{collectionName}\', existing collections: {collectionNames}."
                                                    );
        }
        /// <summary>
        ///     Upload the report to the web service.
        /// </summary>
        /// <param name="report">CreateReport to submit</param>
        public void UploadReport(ErrorReportDTO report)
        {
            if (report == null)
            {
                throw new ArgumentNullException("report");
            }

            if (!NetworkInterface.GetIsNetworkAvailable() || _queueReportsAccessor())
            {
                _reportQueue.Add(report);
            }
            else
            {
                TryUploadReportNow(report);
            }
        }
Exemplo n.º 30
0
        protected void Process(ErrorReportDTO report)
        {
            if (report == null)
            {
                return;
            }

            var canUpload = _configuration.FilterCollection.CanUploadReport(report);

            if (!canUpload)
            {
                return;
            }

            _configuration.Uploaders.Upload(report);
        }