Esempio n. 1
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;
        }
Esempio n. 2
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);
        }
Esempio n. 3
0
 public string mc_issue_add(string username, string password, IssueData issue)
 {
     return(Channel.mc_issue_add(username, password, issue));
 }