Exemple #1
0
        private StringBuilder GetExceptionDetails(SerializableException exception, string exceptionInfo, string?additionalInfo)
        {
            StringBuilder exceptionDetails = new();

            if (!string.IsNullOrEmpty(exceptionInfo))
            {
                // Tests may be run on VMs, and AppendLine() could be either \r\n or \n
                exceptionDetails.Append('\n');
                exceptionDetails.Append(exceptionInfo.Trim());
                exceptionDetails.Append('\n');
                exceptionDetails.Append('\n');
            }

            exceptionDetails.Append("```\n");
            exceptionDetails.Append(exception.ToString().Trim());
            exceptionDetails.Append('\n');
            exceptionDetails.Append("```\n");
            exceptionDetails.Append('\n');

            if (!string.IsNullOrWhiteSpace(additionalInfo))
            {
                exceptionDetails.Append(additionalInfo.Trim());
                exceptionDetails.Append('\n');
            }

            return(exceptionDetails);
        }
            public override bool Send(string fileName, Stream file, Report report, SerializableException exception)
            {
                report.CustomInfo = new BugReportExtraInfo();

                var data = string.Concat("<BugReport>", report.ToString(), exception.ToString(), "</BugReport>");

                return(_sender.SendData(CompressionTools.ZipString(data)));
            }
Exemple #3
0
        private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            var serializableException = new SerializableException((Exception)e.ExceptionObject);

            var fileName      = "error.log";
            var fileDirectory = Path.GetDirectoryName(Application.ResourceAssembly.Location);
            var filePath      = Path.Combine(fileDirectory, fileName);

            File.WriteAllText(filePath, serializableException.ToString());

            CleanUp();
        }
Exemple #4
0
        public override bool Send(string fileName, Stream file, Report report, SerializableException exception)
        {
            // Advanced method with ability to post variables along with file (do not forget to urlencode the query parameters)
            // http://www.codeproject.com/KB/cs/uploadfileex.aspx
            // http://stackoverflow.com/questions/566462/upload-files-with-httpwebrequest-multipart-form-data
            // http://stackoverflow.com/questions/767790/how-do-i-upload-an-image-file-using-a-post-request-in-c
            // http://netomatix.com/HttpPostData.aspx

            /* upload.php file my look like the one below (note that uploaded files are not statically named in this case script may need modification)
             *
             * <?php
             * $uploadDir = 'Upload/';
             * $uploadFile = $uploadDir . basename($_FILES['file']['name']);
             * if (is_uploaded_file($_FILES['file']['tmp_name']))
             * {
             *     echo "File ". $_FILES['file']['name'] ." is successfully uploaded!\r\n";
             *     if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadFile))
             *     {
             *         echo "File is successfully stored! ";
             *     }
             *     else print_r($_FILES);
             * }
             * else
             * {
             *     echo "Upload Failed!";
             *     print_r($_FILES);
             * }
             * ?>
             */
            file.Position = 0;

            StreamUpload stream = StreamUpload.Create();

            if (PostReport)
            {
                stream.Add("report", report.ToString());
            }
            if (PostException)
            {
                stream.Add("exception", exception.ToString());
            }
            stream.Add(file, "file", fileName, "application/zip");
            string response = stream.Upload(this.Url).Response();

            Logger.Info("Response from HTTP server: " + response);
            file.Position = 0;

            return(true);
        }
Exemple #5
0
        public static void Can_Serialize_An_Exception()
        {
            var ex1 = new Exception("My Inner Exception 2");
            var ex2 = new Exception("My Exception 1", ex1);

            SerializableException originalException = new SerializableException(ex2);

            // Save the full ToString() value, including the exception message and stack trace.

            var rawBytes = originalException.SerializeException();
            SerializableException newException = rawBytes.DeSerializeException();

            string originalExceptionAsString = originalException.ToString();
            string newExceptionAsString      = newException.ToString();

            // Double-check that the exception message and stack trace (owned by the base Exception) are preserved
            Assert.AreEqual(originalExceptionAsString, newExceptionAsString);
        }
		public static void Can_Serialize_An_Exception()
		{
			var ex1 = new Exception("My Inner Exception 2");
			var ex2 = new Exception("My Exception 1", ex1);

			SerializableException originalException = new SerializableException(ex2);

			// Save the full ToString() value, including the exception message and stack trace.

			var rawBytes = originalException.SerializeException();
			SerializableException newException = rawBytes.DeSerializeException();

			string originalExceptionAsString = originalException.ToString();
			string newExceptionAsString = newException.ToString();

			// Double-check that the exception message and stack trace (owned by the base Exception) are preserved
			Assert.AreEqual(originalExceptionAsString, newExceptionAsString);
		}
Exemple #7
0
            public override bool Send(string fileName, Stream file, Report report, SerializableException exception)
            {
                try
                {
                    report.CustomInfo = new BugReportExtraInfo();
                    var data = string.Concat("<BugReport>", report.ToString(), exception.ToString(), "</BugReport>");

                    var compressed = CompressionTools.BrotliCompress(data);

                    using var s = Program.GetHttpClient();
                    var result = s.PostAsync(new Uri($"SendCrashReport?userId={Properties.Settings.Default.MiscUserId}&data={Convert.ToBase64String(compressed)}", UriKind.Relative), null).Result;
                    result.EnsureSuccessStatusCode();
                }
                catch (Exception e)
                {
                    Console.WriteLine("Failed to send crash report: " + e);
                    return(false);
                }
                return(true);
            }
Exemple #8
0
        public void ToString_should_be_same_from_round_trip(string testName, Action action)
        {
            using (ApprovalResults.ForScenario(testName))
            {
                string message = string.Empty;
                string xml     = string.Empty;
                try
                {
                    action();
                }
                catch (Exception ex)
                {
                    xml = new SerializableException(ex).ToXmlString();
                }

                SerializableException exception = SerializableException.FromXmlString(xml);

                Approvals.Verify(Sanitize(exception.ToString()));
            }
        }
Exemple #9
0
        public string Build(SerializableException exception, string exceptionInfo, string?environmentInfo, string?additionalInfo)
        {
            if (exception is null)
            {
                throw new ArgumentNullException(nameof(exception));
            }

            StringBuilder sb = new();

            sb.Append($"template=bug_report.yml");
            sb.Append($"&labels={Uri.EscapeDataString("type: NBug")}");
            sb.Append($"&about={Uri.EscapeDataString(environmentInfo)}");

            StringBuilder exceptionDetails = new();

            if (!string.IsNullOrEmpty(exceptionInfo))
            {
                // Tests may be run on VMs, and AppendLine() could be either \r\n or \n
                exceptionDetails.Append('\n');
                exceptionDetails.Append(exceptionInfo);
                exceptionDetails.Append('\n');
            }

            exceptionDetails.Append("```\n");
            exceptionDetails.Append(exception.ToString());
            exceptionDetails.Append('\n');
            exceptionDetails.Append("```\n");
            exceptionDetails.Append('\n');

            if (!string.IsNullOrWhiteSpace(additionalInfo))
            {
                exceptionDetails.Append(additionalInfo.Trim());
                exceptionDetails.Append('\n');
            }

            sb.Append($"&description={Uri.EscapeDataString(exceptionDetails.ToString())}");

            return(sb.ToString());
        }
        public static void Can_Serialize_An_Exception()
        {
            NUnitUtils.PrintTestName();

            Stopwatch sw = Stopwatch.StartNew();

            var ex1 = new Exception("My Inner Exception 2");
            var ex2 = new Exception("My Exception 1", ex1);

            var originalException = new SerializableException(ex2);

            // Save the full ToString() value, including the exception message and stack trace.

            var rawBytes     = originalException.SerializeException();
            var newException = rawBytes.DeSerializeException();

            var originalExceptionAsString = originalException.ToString();
            var newExceptionAsString      = newException.ToString();

            // Double-check that the exception message and stack trace (owned by the base Exception) are preserved
            Assert.AreEqual(originalExceptionAsString, newExceptionAsString);

            NUnitUtils.PrintElapsedTime(sw.Elapsed);
        }
Exemple #11
0
        public override bool Send(string fileName, Stream file, Report report, SerializableException exception)
        {
            if (string.IsNullOrEmpty(Username) || Username.Trim().Length == 0)
            {
                throw new ArgumentNullException("Username");
            }

            if (string.IsNullOrEmpty(Password) || Password.Trim().Length == 0)
            {
                throw new ArgumentNullException("Password");
            }

            if (string.IsNullOrEmpty(Url) || Url.Trim().Length == 0)
            {
                throw new ArgumentNullException("Url");
            }

            if (ProjectId <= 0)
            {
                throw new ArgumentNullException("ProjectId");
            }

            if (string.IsNullOrEmpty(Category) || Category.Trim().Length == 0)
            {
                throw new ArgumentNullException("Category");
            }

            if (string.IsNullOrEmpty(Description) || Description.Trim().Length == 0)
            {
                Description = exception.ToString();
            }

            if (string.IsNullOrEmpty(Summary) || Summary.Trim().Length == 0)
            {
                Summary = report.GeneralInfo.ExceptionMessage + " @ " + report.GeneralInfo.TargetSite;
            }

            if (string.IsNullOrEmpty(AdditionalInformation) || AdditionalInformation.Trim().Length == 0)
            {
                AdditionalInformation = report.ToString();
            }

            var service = new MantisConnectService(new BasicHttpBinding(), new EndpointAddress(Url));
            var user    = service.mc_login(Username, Password);

            Logger.Info(String.Format("Successfully logged in to Mantis bug tracker as {0}", user.account_data.real_name));
            var issue = new IssueData();

            issue.date_submitted          = DateTime.Now;
            issue.date_submittedSpecified = true;
            issue.version  = report.GeneralInfo.HostApplicationVersion;
            issue.os       = Environment.OSVersion.ToString();
            issue.os_build = Environment.OSVersion.Version.ToString();
            issue.platform = Environment.OSVersion.Platform.ToString();
            issue.reporter = user.account_data;
            issue.project  = new ObjectRef()
            {
                id = ProjectId.ToString(CultureInfo.InvariantCulture), name = String.Empty
            };
            issue.category               = Category;
            issue.summary                = Summary;
            issue.description            = Description;
            issue.additional_information = AdditionalInformation;
            issue.steps_to_reproduce     = StepsToReproduce;
            issue.severity               = new ObjectRef()
            {
                id = Severity.ToString(CultureInfo.InvariantCulture), name = Severity.ToString(CultureInfo.InvariantCulture)
            };
            issue.status = new ObjectRef()
            {
                id = Status.ToString(CultureInfo.InvariantCulture), name = Status.ToString(CultureInfo.InvariantCulture)
            };
            bool success = false;

            if (AddVersionIfNotExists)
            {
                var versions = service.mc_project_get_versions(Username, Password, ProjectId.ToString(CultureInfo.InvariantCulture));
                if (versions.Count() == 0 ||
                    !versions.Any(x => x.name == report.GeneralInfo.HostApplicationVersion.ToString(CultureInfo.InvariantCulture)))
                {
                    var version = new ProjectVersionData
                    {
                        name                = report.GeneralInfo.HostApplicationVersion.ToString(CultureInfo.InvariantCulture),
                        project_id          = ProjectId.ToString(CultureInfo.InvariantCulture),
                        released            = true,
                        releasedSpecified   = true,
                        date_order          = DateTime.Now,
                        date_orderSpecified = true,
                        description         = "Added by NBug"
                    };
                    var versionId = service.mc_project_version_add(Username, Password, version);
                    Logger.Info(String.Format("Successfully added new version id {0} to Mantis bug tracker", versionId));
                }
            }

            int bugId;

            Int32.TryParse(service.mc_issue_add(Username, Password, issue), out bugId);

            if (bugId > 0)
            {
                Logger.Info(String.Format("Successfully added new issue id {0} to Mantis bug tracker", bugId));
                success = true;
                if (SendAttachment)
                {
                    if (file != null && file.Length > 0)
                    {
                        if (!SuccessIfAttachmentFails)
                        {
                            success = false;
                        }
                        try
                        {
                            var attachment = new byte[file.Length];
                            file.Position = 0;
                            file.Read(attachment, 0, Convert.ToInt32(file.Length));
                            var attachmentId = service.mc_issue_attachment_add(Username, Password, bugId.ToString(CultureInfo.InvariantCulture), fileName, "application/zip", attachment);
                            Logger.Info(String.Format("Successfully added attachment id {0} for isssue id {1} to Mantis bug tracker", attachmentId, bugId));
                            success = true;
                        }
                        catch (Exception ex)
                        {
                            Logger.Error(String.Format("Failed to upload attachment with issue id {0} to Mantis bug tracker{1}{2}", bugId, Environment.NewLine, ex.Message));
                            if (!SuccessIfAttachmentFails)
                            {
                                throw;
                            }
                        }
                    }
                }
            }

            return(success);
        }
Exemple #12
0
        public string Build(SerializableException exception, string?environmentInfo, string?additionalInfo)
        {
            if (exception is null)
            {
                throw new ArgumentNullException(nameof(exception));
            }

            var sb = new StringBuilder();

            sb.AppendLine(@"<!--
    :warning: Review existing issues to see whether someone else has already reported your issue.
-->

:warning: The sections below must be filled in and this text must be removed or the issue will be closed.

## Current behaviour

<!-- Be as specific and detailed as possible to help us identify your issue. -->


## Expected behaviour


## Steps to reproduce

<!-- Take some time to try and reproduce the issue, then explain how to do so here. -->


## Error Details");
            sb.AppendLine("```");
            sb.AppendLine(exception.ToString());
            sb.AppendLine("```");
            sb.AppendLine();
            sb.AppendLine();

            if (!string.IsNullOrWhiteSpace(additionalInfo))
            {
                sb.AppendLine("## Additional information");
                sb.AppendLine(additionalInfo.Trim());
                sb.AppendLine();
                sb.AppendLine();
            }

            try
            {
                sb.AppendLine("## Environment");

                if (!string.IsNullOrWhiteSpace(environmentInfo))
                {
                    sb.AppendLine(environmentInfo);
                }
                else
                {
                    sb.AppendLine("System information is not supplied");
                }
            }
            catch (Exception ex)
            {
                sb.AppendLine("Failed to retrieve system information.");
                sb.AppendLine("Exception:");
                sb.AppendLine("```");
                sb.AppendLine(ex.ToString());
                sb.AppendLine("```");
            }

            return(sb.ToString());
        }