문제

BugTracker.net의 문서 페이지를 읽습니다
BugTracker.net API 문서나는 Get 또는 Post를 사용해야한다는 것을 깨달았습니다. 나는 궁금했다 :

  • C# 응용 프로그램 (또는 vb.net)에서 BugTracker.net에 버그를 쉽게 제출하는 데 사용할 수있는 라이브러리가 있습니까?
    또는,
  • 라이브러리가없는 경우. get 또는 post를 사용하여 BugTracker.net에 버그를 제출할 수있는 방법은 무엇입니까?
도움이 되었습니까?

해결책 3

답변 해 주셔서 감사합니다. 웹에서 귀하의 답변 및 기타 리소스를 사용하여 BugTracker.net에 새 버그를 제출하는 방법을 구성했습니다.
이 메소드는 성공 또는 실패를 나타내는 부울 값을 반환하고 상태가있는 사용자에게 메시지를 표시합니다.
이 동작은 귀하의 요구에 맞게 변경 될 수 있습니다. 이 방법은 포스트 메소드를 사용하여 주석에 긴 텍스트를 제출하는 데 도움이되는 버그를 제출합니다 (주석에 로그 파일의 내용을 제출하려고했는데 작동했습니다).

코드는 다음과 같습니다.

public bool SubmitBugToBugTracker(string serverName,
                                        bool useProxy,
                                        string proxyHost,
                                        int proxyPort,
                                        string userName,
                                        string password,
                                        string description,
                                        string comment,
                                        int projectId)
    {
        if (!serverName.EndsWith(@"/"))
        {
            serverName += @"/";
        }
        string requestUrl = serverName + "insert_bug.aspx";
        string requestMethod = "POST";
        string requestContentType = "application/x-www-form-urlencoded";
        string requestParameters = "username=" + userName
                                  + "&password=" + password
                                  + "&short_desc=" + description
                                  + "&comment=" + comment
                                  + "&projectid=" + projectId;
        // POST parameters (postvars)
        byte[] buffer = Encoding.ASCII.GetBytes(requestParameters);
        // Initialisation
        HttpWebRequest WebReq = (HttpWebRequest)WebRequest.Create(requestUrl);
        // Add proxy info if used.
        if (useProxy)
        {
            WebReq.Proxy = new WebProxy(proxyHost, proxyPort);
        }

        // Method is POST
        WebReq.Method = requestMethod;
        // ContentType, for the postvars.
        WebReq.ContentType = requestContentType;
        // Length of the buffer (postvars) is used as contentlength.
        WebReq.ContentLength = buffer.Length;
        // Open a stream for writing the postvars
        Stream PostData = WebReq.GetRequestStream();
        //Now we write, and afterwards, we close. Closing is always important!
        PostData.Write(buffer, 0, buffer.Length);
        PostData.Close();
        // Get the response handle, we have no true response yet!
        HttpWebResponse WebResp = (HttpWebResponse)WebReq.GetResponse();
        // Read the response (the string)
        Stream Answer = WebResp.GetResponseStream();
        StreamReader _Answer = new StreamReader(Answer);
        string responseStream = _Answer.ReadToEnd();

        // Find out if bug submission was successfull.
        if (responseStream.StartsWith("OK:"))
        {
            MessageBox.Show("Bug submitted successfully.");
            return true;
        }
        else if (responseStream.StartsWith("ERROR:"))
        {
            MessageBox.Show("Error occured. Bug hasn't been submitted.\nError Message: " + responseStream);
            return false;
        }
        else
        {
            MessageBox.Show("Error occured. Bug hasn't been submitted.\nError Message: " + responseStream);
            return false;
        }
    }

다른 팁

이 간단한 예를 확인하십시오 문서에서 .NET을 사용하여 게시물 요청을 만드는 방법 BugTracker.net API 요구 사항에 따라 게시되는 변수를 설정하십시오.

아래는 POP3 서버에서 이메일을 읽은 다음 insert_bug.aspx 페이지에 버그로 제출되는 BugTracker.net 서비스의 코드입니다. 그러나 이것이 복잡 할 필요는 없습니다.

이 URL을 호출하는 것만으로도 작동합니다.

http:\\YOUR-HOST\insert_bug.aspx?username=YOU&password=YOUR-PASSWORD&short_desc=This+is+a+bug

더 복잡한 코드 :


            string post_data = "username=" + HttpUtility.UrlEncode(ServiceUsername)
                + "&password=" + HttpUtility.UrlEncode(ServicePassword)
                + "&projectid=" + Convert.ToString(projectid)
                + "&from=" + HttpUtility.UrlEncode(from)
                + "&short_desc=" + HttpUtility.UrlEncode(subject)
                + "&message=" + HttpUtility.UrlEncode(message);

            byte[] bytes = Encoding.UTF8.GetBytes(post_data);


            // send request to web server
            HttpWebResponse res = null;
            try
            {
                HttpWebRequest req = (HttpWebRequest) System.Net.WebRequest.Create(Url);


                req.Credentials = CredentialCache.DefaultCredentials;
                req.PreAuthenticate = true; 

                //req.Timeout = 200; // maybe?
                //req.KeepAlive = false; // maybe?

                req.Method = "POST";
                req.ContentType= "application/x-www-form-urlencoded";
                req.ContentLength=bytes.Length;
                Stream request_stream = req.GetRequestStream();
                request_stream.Write(bytes,0,bytes.Length);
                request_stream.Close();
                res = (HttpWebResponse) req.GetResponse();
            }
            catch (Exception e)
            {
                write_line("HttpWebRequest error url=" + Url);
                write_line(e);
            }

            // examine response

            if (res != null) {

                int http_status = (int) res.StatusCode;
                write_line (Convert.ToString(http_status));

                string http_response_header = res.Headers["BTNET"];
                res.Close();

                if (http_response_header != null)
                {
                    write_line (http_response_header);

                    // only delete message from pop3 server if we
                    // know we stored in on the web server ok
                    if (MessageInputFile == ""
                    && http_status == 200
                    && DeleteMessagesOnServer == "1"
                    && http_response_header.IndexOf("OK") == 0)
                    {
                        write_line ("sending POP3 command DELE");
                        write_line (client.DELE (message_number));
                    }
                }
                else
                {
                    write_line("BTNET HTTP header not found.  Skipping the delete of the email from the server.");
                    write_line("Incrementing total error count");
                    total_error_count++;
                }
            }
            else
            {
                write_line("No response from web server.  Skipping the delete of the email from the server.");
                write_line("Incrementing total error count");
                total_error_count++;
            }

나는 그 방법을 사용하고 있었지만 제출 된 버그와 함께 비밀번호를 보내는 것을 좋아하지 않았습니다. 여러 가지 이유로 LDAP 인증이 아닌 내부 BugTracker 비밀번호 시스템을 사용하고 있으므로 BugTracker 암호는 알려지지 않습니다. 제 경우에는 모든 사용자가 버그를 제출할 권한이 있으며 로그인은 LAN ID입니다. 따라서 응용 프로그램의 인증 된 인스턴스에서보고 된 문제를 수집하고 문제를보고하는 프로젝트 ID, 프로그램 및 클래스를 캡처 한 후 버그 트래커 DB에 저장된 절차를 호출하여 항목을 직접 삽입합니다.

물론 부정적인 점은 데이터베이스에 직접적으로 이루어지고 잠재적으로 향후 업그레이드 문제를 일으킬 수 있지만 현재 우리에게는 잘 작동한다는 것입니다.

(SQL2005/2008)

CREATE PROCEDURE [dbo].[Add_Bug]
@strUsername as varchar(20) = '', 
@intProjID as integer = 0,
@strSubject as varchar(200),
@strComment as text
AS
    BEGIN
SET NOCOUNT ON;

declare @us_id as integer
declare @us_org as integer
declare @st_id as integer
declare @priority as integer
declare @category as integer
declare @errorreturn as integer
declare @assigneduser as integer

declare @newbugid as integer

if (@intProjID = 0 or RTRIM(@strUsername) = '') 
    RETURN -1

set @priority = 3 -- default to LOW
set @category = 1 -- default to bug

-- look up us_id, us_org from users where us_username = 'lanid'

set @us_id = 0

BEGIN TRY

    BEGIN TRANSACTION

    select @us_id = us_id, @us_org = us_org from BugTracker.dbo.users 
    where us_username = @strUsername

    if (@@ROWCOUNT = 0 or @us_id = 0 )
    BEGIN
        -- set to default values to allow entry anyway
        -- if not found default to the autobug reporter
                    -- this is a separate account created just for these reports
        set @us_id = 36     
        set @us_org = 6     
    END

    select @assigneduser = pj_default_user from projects 
                    where pj_id = @intProjID and 
        pj_auto_assign_default_user = 1

    if (@@ROWCOUNT <> 1)
        set @assigneduser = NULL

    -- get default status as st_id from statuses where st_default = 1

    select @st_id = st_id from BugTracker.dbo.statuses where st_default = 1 

    -- now insert the bug and post comments

    insert into bugs (bg_short_desc, bg_reported_user, bg_reported_date,
            bg_status, bg_priority, bg_org, bg_category, bg_project,                     
            bg_assigned_to_user, bg_last_updated_user, bg_last_updated_date) 
    values ( @strSubject, @us_id, getdate(), @st_id, @priority, @us_org,
            @category, @intProjID, @assigneduser, @us_id, getdate())

    if @@ERROR <> 0
        BEGIN
        ROLLBACK TRANSACTION
        END
    ELSE
        BEGIN

        select @newbugid = @@IDENTITY

        insert into bug_posts (bp_bug, bp_type, bp_user, bp_date,
                    bp_comment, bp_hidden_from_external_users)
        values (@newbugid, 'comment', @us_id, getdate(), @strComment, 0)

        if @@ERROR <> 0
            ROLLBACK TRANSACTION
        END
END TRY

BEGIN CATCH
    ROLLBACK TRANSACTION
    RETURN -2
END CATCH   

IF (@@TRANCOUNT > 0)
    COMMIT TRANSACTION

RETURN @newbugid

END
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top