2016-03-08 52 views
1

我試圖重新打開使用MantisConnect解決或關閉的螳螂問題 我已經成功地更改了未解決/已關閉問題的狀態,但是當問題是這兩個問題之一時,以下例外:使用MantisConnect恢復螳螂問題

System.ServiceModel.ProtocolException 

與消息:

有與從網絡接收到的XML的問題。 有關更多詳細信息,請參閱內部例外。

與內異常:

System.Xml.XmlException 

隨着消息:

在聲明的編碼 'ISO-8859-1' 不匹配文件「的編碼UTF- 8' 。

我使用update命令在這裏做介紹的更新:https://www.mantisbt.org/bugs/api/soap/mantisconnect.php?wsdl

得到了我的mantisconnect代碼從GitHub這裏: https://github.com/mantishub/MantisDotNetClient

有趣的是,這些變化對其他國家和即使是已解決和已關閉狀態的工作,異常只會在問題已解決或關閉時拋出 我無法在mantisconnect中找到任何其他命令來重新打開問題,任何人都有一個想法。

編輯: 螳螂的問題,我在我的評論談論票:https://mantisbt.org/bugs/view.php?id=16579

+0

服務器日誌中有任何東西嗎?聽起來像是在服務器端觸發錯誤,可能是因爲缺少重新開放問題的權限 –

+0

由於我們的IT團隊採用了令人敬畏的安全措施,所以不幸的是,此時不具備對這些日誌的訪問權限。我希望儘快改變這一點。我在一兩天前遇到過mantisConnect錯誤跟蹤問題,我相信這個問題正在討論中。我會盡快發佈。與此同時,我相信這是我的錯誤(我打開票的方式),因爲我嘗試上傳mantisconnect時附帶的fileName已存在於螳螂問題 – ImP

+0

@ RobertMunteanu我用查爾斯來監視交通,發現以下回應:acces denied,issue is readonly。然而,我可以在螳螂本身重新開放這個問題。這對應於[問題](https://wiki.mantisbt.org/bugs/view.php?id=16579)我發現 – ImP

回答

0

由於是螳螂API在我導航使用WebRequests的網站,並從螳螂散裝UP_STATUS功能解決了這個問題的錯誤。它很髒,但它的工作原理。

class MantisWebRequest 
{ 
    public string Password { private get; set; } 
    public string Username { private get; set; } 

    public CookieContainer CookieContainer { get; private set; } 
    public StreamReader Reader { get; private set; } 
    public Stream DataStream { get; private set; } 
    public WebResponse Response { get; private set; } 
    public HttpWebRequest Request { get; private set; } 
    public string Page { get; private set; } 
    public MantisWebRequest(string username, string password) 
    { 
     Username = username; 
     Password = password; 
     CookieContainer = new CookieContainer(); 
    } 

    public void Connect(string cookieName = null) 
    { 
     string loginurl = "http://mantispageurl/login.php"; 
     // Create a request using a URL that can receive a post. 
     Request = (HttpWebRequest)System.Net.WebRequest.Create(loginurl); 
     // Set the Method property of the request to POST. 
     Request.Method = "POST"; 
     Request.KeepAlive = true; 

     if (cookieName != null) 
      CookieContainer.Add(new Cookie(cookieName, Username, "/", new Uri(loginurl).Host)); 
     Request.CookieContainer = CookieContainer; 

     // Create POST data and convert it to a byte array. Modify this line accordingly 
     string postData = String.Format("username={0}&password={1}&secure_session=on", Username, Password); 

     byte[] byteArray = Encoding.UTF8.GetBytes(postData); 
     // Set the ContentType property of the WebRequest. 
     Request.ContentType = "application/x-www-form-urlencoded"; 
     // Set the ContentLength property of the WebRequest. 
     Request.ContentLength = byteArray.Length; 
     // Get the request stream. 
     DataStream = Request.GetRequestStream(); 
     // Write the data to the request stream. 
     DataStream.Write(byteArray, 0, byteArray.Length); 
     // Close the Stream object. 
     DataStream.Close(); 
     // Get the response. 
     Response = Request.GetResponse(); 
     // Get the stream containing content returned by the server. 
     DataStream = Response.GetResponseStream(); 
     // Open the stream using a StreamReader for easy access. 
     Reader = new StreamReader(DataStream); 
     // Read the content. 
     Page = Reader.ReadToEnd(); 

     // Clean up the streams. 
     Reader.Close(); 
     DataStream.Close(); 
     Response.Close(); 


    } 

    private void POST(string url, string postData) 
    { 
     Request = (HttpWebRequest)System.Net.WebRequest.Create(url); 
     Request.Method = "POST"; 
     Request.KeepAlive = true; 
     Request.CookieContainer = CookieContainer; 

     byte[] byteArray = Encoding.UTF8.GetBytes(postData); 
     // Set the ContentType property of the WebRequest. 
     Request.ContentType = "application/x-www-form-urlencoded"; 
     // Set the ContentLength property of the WebRequest. 
     Request.ContentLength = byteArray.Length; 
     // Get the request stream. 
     DataStream = Request.GetRequestStream(); 
     // Write the data to the request stream. 
     DataStream.Write(byteArray, 0, byteArray.Length); 
     // Close the Stream object. 
     DataStream.Close(); 
     Response = Request.GetResponse(); 
     // Get the stream containing content returned by the server. 
     DataStream = Response.GetResponseStream(); 
     // Open the stream using a StreamReader for easy access. 
     Reader = new StreamReader(DataStream); 
     // Read the content. 
     Page = Reader.ReadToEnd(); 

     // Clean up the streams. 
     Reader.Close(); 
     DataStream.Close(); 
     Response.Close(); 
    } 

    private void POST(string url, string postData, string tokenName) 
    { 
     string token = GetToken(tokenName); 

     Request = (HttpWebRequest)System.Net.WebRequest.Create(url); 
     Request.Method = "POST"; 
     Request.KeepAlive = true; 
     Request.CookieContainer = CookieContainer; 

     postData = string.Format("{0}={1}&{2}", tokenName, token, postData); 

     byte[] byteArray = Encoding.UTF8.GetBytes(postData); 
     // Set the ContentType property of the WebRequest. 
     Request.ContentType = "application/x-www-form-urlencoded"; 
     // Set the ContentLength property of the WebRequest. 
     Request.ContentLength = byteArray.Length; 
     // Get the request stream. 
     DataStream = Request.GetRequestStream(); 
     // Write the data to the request stream. 
     DataStream.Write(byteArray, 0, byteArray.Length); 
     // Close the Stream object. 
     DataStream.Close(); 
     Response = Request.GetResponse(); 
     // Get the stream containing content returned by the server. 
     DataStream = Response.GetResponseStream(); 
     // Open the stream using a StreamReader for easy access. 
     Reader = new StreamReader(DataStream); 
     // Read the content. 
     Page = Reader.ReadToEnd(); 

     // Clean up the streams. 
     Reader.Close(); 
     DataStream.Close(); 
     Response.Close(); 
    } 

    private void GET(string url) 
    { 


     Request = (HttpWebRequest)System.Net.WebRequest.Create(url); 
     Request.Method = "GET"; 
     Request.CookieContainer = CookieContainer; 

     Response = Request.GetResponse(); 
     // Get the stream containing content returned by the server. 
     DataStream = Response.GetResponseStream(); 
     // Open the stream using a StreamReader for easy access. 
     Reader = new StreamReader(DataStream); 
     // Read the content. 
     Page = Reader.ReadToEnd(); 

     // Clean up the streams. 
     Reader.Close(); 
     DataStream.Close(); 
     Response.Close(); 

    } 

    private string GetToken(string tokenName) 
    { 
     int tokenIndex = Page.IndexOf(tokenName); 
     int endindex = tokenIndex + Page.Substring(tokenIndex).IndexOf(">", StringComparison.Ordinal); 
     int startindex = Page.Substring(0, tokenIndex).LastIndexOf("<", StringComparison.Ordinal); 
     string input = Page.Substring(startindex, endindex - startindex + 1); 

     string valuestring = "value=\""; 
     int tokenIndex2 = input.IndexOf(valuestring, StringComparison.Ordinal); 
     int endindex2 = tokenIndex2 + valuestring.Length + input.Substring(tokenIndex2 + valuestring.Length).IndexOf("\"", StringComparison.Ordinal); 
     int startindex2 = tokenIndex2 + valuestring.Length; 
     string output = input.Substring(startindex2, endindex2 - startindex2); 

     return output; 
    } 

    public void UpdateStatus(int[] issueIds, int statusId) 
    { 
     string tokenName = "bug_actiongroup_UP_STATUS_token"; 
     string formUrl = GetUpdateStatusUrl(issueIds); 
     string formPostDataUrl = "http://mantispageurl/bug_actiongroup.php"; 
     string formPostData = GetUpdateStatusPostData(issueIds, statusId); 

     GET(formUrl); 
     POST(formPostDataUrl, formPostData, tokenName); 
    } 

    private string GetUpdateStatusUrl(int[] issueIds) 
    { 
     string postData = "?"; 
     foreach (var issueId in issueIds) 
     { 
      postData = string.Format("{0}&bug_arr%5B%5D={1}", postData, issueId); 
     } 
     postData = String.Format("{0}&action=UP_STATUS", postData); 

     return "http://mantispageurl/bug_actiongroup_page.php" + postData; 
    } 

    private string GetUpdateStatusPostData(int[] issueIds, int statusId) 
    { 
     string postData = "action=UP_STATUS"; 
     foreach (var issueId in issueIds) 
     { 
      postData = string.Format("{0}&bug_arr%5B%5D={1}", postData, issueId); 
     } 
     postData = String.Format("{0}&status={1}&bugnote_text=", postData, statusId); 

     return postData; 

    }