コード例 #1
0
ファイル: HttpHelper.cs プロジェクト: clarencemorse/myzilla
        public string PostAttachment( Attachment objAtt, string url)
        {
            string result = string.Empty  ;

               try
               {
               string postURL = String.Concat(url, ATTACHMENT_PAGE);

               MultipartForm mPost = new MultipartForm(postURL , _userID );

               mPost.SetField("bugid", objAtt.BugId.ToString());
               mPost.SetField("action", "insert");
               mPost.SetField("description", objAtt.Description);
               mPost.SetField("contenttypemethod", "list");
               mPost.SetField("contenttypeselection", objAtt.ContentType);
               mPost.SetField("contenttypeentry", string.Empty);
               mPost.SetField("comment", objAtt.Comment);
               mPost.FileContentType = objAtt.ContentType;

               mPost.SendFile(objAtt.FileName);

               result = mPost.ResponseText.ToString();
               }
               catch (Exception ex)
               {
               MyLogger.WriteWithStack(ex.Message, "PostToUrlWhenLogOn", LoggingCategory.Exception);

               throw;
               }

               return result ;
        }
コード例 #2
0
ファイル: BugHandling.cs プロジェクト: clarencemorse/myzilla
        public void PostAttachment(Attachment attachment, out string errorMessage)
        {
            errorMessage = string.Empty;

            TDSettings.ConnectionRow connection = MyZillaSettingsDataSet.GetInstance().GetConnectionById(_connectionId);

            string myZillaUrl = connection.URL;

            MyZilla.BL.Utils.HttpHelper httpDialog = new HttpHelper(_connectionId, connection.Charset);

            try
            {
                string result = httpDialog.PostAttachment(attachment , myZillaUrl );

                string token = "";
                int startToken = result.IndexOf("token");
                if (startToken > 0)
                {
                    int stopTokenEntry = result.Substring(startToken).IndexOf(">");
                    if (stopTokenEntry > 0)
                    {
                        string res = result.Substring(startToken, stopTokenEntry);
                        if (!string.IsNullOrEmpty(res))
                        {
                            if (res.Contains("value="))
                            {
                                token = res.Substring(res.IndexOf("value=") + "value=".Length);
                                token = token.Replace("\"", "");
                            }
                        }
                    }
                }

                if (!string.IsNullOrEmpty(token))
                    attachment.Token = token;

                if (result.IndexOf("Changes Submitted") >= 0)
                {
                    errorMessage = string.Empty;
                }
                else
                {
                    int pos1 = result.IndexOf("<title>");
                    int pos2 = result.IndexOf("</title>");

                    errorMessage = result.Substring(pos1 +"<title>".Length, pos2 -( pos1 -1  + "</title>".Length ));
                }

            }
            catch (Exception ex)
            {
                errorMessage = ex.Message;
            }
        }
コード例 #3
0
ファイル: BugHandling.cs プロジェクト: clarencemorse/myzilla
        /// <summary>
        /// Walks through the node element and fills a bug object
        /// </summary>
        /// <param name="BugNode"></param>
        /// <returns></returns>
        private static Bug GetBug(XmlNode BugNode)
        {
            Bug bugResult = new Bug();

            XmlElement bugElement = (XmlElement)BugNode;

            try{

                if (bugElement.HasAttributes)
                {
                    string errorMessage = bugElement.Attributes["error"].InnerText;

                    if (!string.IsNullOrEmpty(errorMessage))
                    {
                        bugResult.ErrorMessage = errorMessage;

                        return bugResult;
                    }
                }

                string comment = string.Empty;

                #region Get object properties

                if (bugElement.GetElementsByTagName("alias").Count == 1)
                {
                    bugResult.Alias = bugElement.GetElementsByTagName("alias")[0].InnerText;
                }

                bugResult.Id = int.Parse(bugElement.GetElementsByTagName("bug_id")[0].InnerText);

                bugResult.Product = bugElement.GetElementsByTagName("product")[0].InnerText;

                bugResult.Component = bugElement.GetElementsByTagName("component")[0].InnerText;

                bugResult.Status = bugElement.GetElementsByTagName("bug_status")[0].InnerText;

                bugResult.AssignedTo = bugElement.GetElementsByTagName("assigned_to")[0].InnerText;

                if (bugElement.GetElementsByTagName("bug_file_loc").Count == 1)
                {

                    bugResult.Url = bugElement.GetElementsByTagName("bug_file_loc")[0].InnerText;
                }

                if (bugElement.GetElementsByTagName("short_desc").Count == 1)
                {

                    bugResult.FullSummary = bugElement.GetElementsByTagName("short_desc")[0].InnerText;

                    bugResult.Summary = bugResult.FullSummary.Substring(0, Math.Min(bugResult.FullSummary.Length, 60));
                }

                if (bugElement.GetElementsByTagName("rep_platform").Count == 1)
                {

                    bugResult.Hardware = bugElement.GetElementsByTagName("rep_platform")[0].InnerText;
                }

                if (bugElement.GetElementsByTagName("op_sys").Count == 1)
                {

                    bugResult.OS = bugElement.GetElementsByTagName("op_sys")[0].InnerText;
                }

                if (bugElement.GetElementsByTagName("version").Count == 1)
                {

                    bugResult.Version = bugElement.GetElementsByTagName("version")[0].InnerText;
                }

                if (bugElement.GetElementsByTagName("priority").Count == 1)
                {

                    bugResult.Priority = bugElement.GetElementsByTagName("priority")[0].InnerText;
                }

                if (bugElement.GetElementsByTagName("bug_severity").Count == 1)
                {

                    bugResult.Severity = bugElement.GetElementsByTagName("bug_severity")[0].InnerText;
                }

                if (bugElement.GetElementsByTagName("reporter").Count == 1)
                {

                    bugResult.Reporter = bugElement.GetElementsByTagName("reporter")[0].InnerText;
                }

                if (bugElement.GetElementsByTagName("clasification").Count == 1)
                {

                    bugResult.Classification = bugElement.GetElementsByTagName("clasification")[0].InnerText;
                }

                //result.Created
                string dateAsString = bugElement.GetElementsByTagName("creation_ts")[0].InnerText;
                DateTime value;

                //prevent wrond date parsing by removing PST, PDT, CET ...
                //(some database datetime values particularity) with  empty string
                Regex dateFieldEnding = new Regex(@" [A-Z]+", RegexOptions.IgnoreCase);

                dateAsString = dateFieldEnding.Replace(dateAsString, string.Empty);

                bool success = DateTime.TryParse(dateAsString, out value);

                if (success)
                    bugResult.Created = value;

                //read bug CHANGED date
                dateAsString = bugElement.GetElementsByTagName("delta_ts")[0].InnerText;

                dateAsString = dateFieldEnding.Replace(dateAsString, string.Empty);

                success = DateTime.TryParse(dateAsString, out value);

                if (success)
                {
                    bugResult.Changed = value;
                }

                if (bugElement.GetElementsByTagName("resolution").Count == 1)
                {

                    bugResult.Resolution = bugElement.GetElementsByTagName("resolution")[0].InnerText;
                }

                if (bugElement.GetElementsByTagName("target_milestone").Count == 1)
                {

                    bugResult.Milestone = bugElement.GetElementsByTagName("target_milestone")[0].InnerText;
                }

                if (bugElement.GetElementsByTagName("status_whiteboard").Count == 1)
                {

                    bugResult.StatusWhiteboard = bugElement.GetElementsByTagName("status_whiteboard")[0].InnerText;
                }

                if (bugElement.GetElementsByTagName("dependson").Count == 1)
                {

                    bugResult.DependsOn = bugElement.GetElementsByTagName("dependson")[0].InnerText;
                }

                if (bugElement.GetElementsByTagName("token").Count >= 1)
                {

                    bugResult.Token = bugElement.GetElementsByTagName("token")[0].InnerText;
                }

                if (bugElement.GetElementsByTagName("blocked").Count == 1)
                {

                    bugResult.Blocks = bugElement.GetElementsByTagName("blocked")[0].InnerText;
                }

                if (bugElement.GetElementsByTagName("cc").Count >= 1)
                {
                    for (int i = 0; i < bugElement.GetElementsByTagName("cc").Count; i++)
                    {
                        string strCC = bugElement.GetElementsByTagName("cc")[i].InnerText;

                        if (!string.IsNullOrEmpty(strCC))
                        {
                            bugResult.CC.Add(strCC);

                        }
                    }

                }

                //getting comments (first comment is the long description): "Description" is the label from the web interface
                int nrOfComments = bugElement.GetElementsByTagName("who").Count;
                for (int i = 0; i < nrOfComments; i++)
                {
                    comment = String.Empty;
                    comment = bugElement.GetElementsByTagName("who")[i].InnerText;
                    comment += " , " + bugElement.GetElementsByTagName("bug_when")[i].InnerText;
                    comment += " , " + bugElement.GetElementsByTagName("thetext")[i].InnerText.Replace("System.Collections.Generic.List`1[System.String]", String.Empty);

                    bugResult.Comment.Add(comment);
                }

                //getting comments (first comment is the long description): "Description" is the label from the web interface
                int nrOfAttachments = bugElement.GetElementsByTagName("attachment").Count;
                for (int i = 0; i < nrOfAttachments; i++)
                {
                    Attachment newAttachment = new Attachment();

                    newAttachment.AttachmentId = int.Parse(bugElement.GetElementsByTagName("attachid")[i].InnerText);

                    //replace PST(some database datetime values particularity) with  empty string
                    string attachmentCreatedOn = bugElement.GetElementsByTagName("date")[i].InnerText;

                    attachmentCreatedOn = dateFieldEnding.Replace(attachmentCreatedOn, string.Empty);

                    success = DateTime.TryParse(attachmentCreatedOn, out value);

                    if (success)
                        newAttachment.Created = DateTime.Parse(attachmentCreatedOn);

                    newAttachment.Description = bugElement.GetElementsByTagName("desc")[i].InnerText;
                    if (bugElement.GetElementsByTagName("ctype")[i] != null)
                    {
                        newAttachment.ContentType = bugElement.GetElementsByTagName("ctype")[i].InnerText;
                    }
                    if (bugElement.GetElementsByTagName("type")[i] != null)
                    {
                        newAttachment.ContentType = bugElement.GetElementsByTagName("type")[i].InnerText;
                    }
                    if (bugElement.GetElementsByTagName("size")[i] != null)
                    {
                        newAttachment.Size = long.Parse(bugElement.GetElementsByTagName("size")[i].InnerText);
                    }
                    if (bugElement.GetElementsByTagName("filename")[i] != null)
                    {
                        newAttachment.FileName = bugElement.GetElementsByTagName("filename")[i].InnerText;
                    }

                    newAttachment.Operation = AttachmentOperation.Unchanged;

                    bugResult.Attachments.Add(newAttachment);
                }

                #endregion
            }catch(Exception ex){
                bugResult.ErrorMessage = ex.Message;

                MyLogger.WriteWithStack(ex.Message, "GetBug", LoggingCategory.Exception);
            }

            return bugResult;
        }
コード例 #4
0
        private void btnAddAttachment_Click(object sender, EventArgs e)
        {
            try
            {
                bool isValid = CheckConditions();

                if (isValid == true)
                {
                    this.Cursor = Cursors.WaitCursor;

                    string contentType = Utils.GetFileContentType(txtFile.Text);

                    this.NewAttachment = new Attachment(_bugID, txtFile.Text, txtDescription.Text, contentType, txtComment.Text);

                    System.IO.FileInfo fileInfo = new System.IO.FileInfo(txtFile.Text);

                    this.NewAttachment.Size = fileInfo.Length;

                    if (_postWhenAdding == true)
                    {

                        string errorMessage = string.Empty;
                        // post attachment
                        IBugBSI bugProvider = (IBugBSI)BLControllerFactory.GetRegisteredConcreteFactory(this.connectionId);

                        bugProvider.PostAttachment(this.NewAttachment, out errorMessage);

                        if (!String.IsNullOrEmpty(errorMessage))
                        {
                            string strMessage = string.Format(Messages.ErrPostFile, txtFile.Text);

                            MessageBox.Show(this, strMessage + Environment.NewLine + errorMessage, Messages.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);

                            this.NewAttachment = null;
                        }
                        else
                        {
                            this.Close();
                        }
                    }
                    else
                    {
                        // no code here.
                        this.Close();
                    }

                }
            }

            catch (Exception ex)
            {
                MyLogger.Write(ex, "btnAddAttachment_Click", LoggingCategory.Exception);

                this.NewAttachment = null;

                MessageBox.Show(this, ex.Message, Messages.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);

            }
            finally {
                this.Cursor = Cursors.Default;
            }
        }