private JiraIssueModel CookIssue(MailItem currentMail)
        {
            var issue = new JiraIssueModel();
            var desc  = GetBodyDescription(currentMail.Body);

            if (String.IsNullOrWhiteSpace(desc))
            {
                issue.IsIssue = false;
            }
            var    match   = m_RegexSummary.Match(currentMail.Subject);
            string summary = match.Success ? match.Value : currentMail.Subject;

            IdentfierDescriptor assignee = null;
            var firstRecipient           = currentMail.Recipients.OfType <Recipient>().FirstOrDefault();

            if (firstRecipient != null && firstRecipient.Resolve())
            {
                try
                {
                    var     addressEntry = firstRecipient.AddressEntry;
                    dynamic shortName    = addressEntry.GetExchangeUser();
                    assignee = new IdentfierDescriptor {
                        Name = shortName.Alias
                    };
                }
                catch (Exception)
                {
                    assignee = null;
                }
            }

            var fields = new Fields
            {
                Summary     = summary,
                Description = CookIssueField("description", desc),
                Assignee    = CookIssueField("assignee", assignee),
                IssueType   = new IdentfierDescriptor()
                {
                    Name = CurrentSelectedIssueType == null ? "Case" : CurrentSelectedIssueType.Name
                },
                Project = new IdentfierDescriptor()
                {
                    ID = CurrentAssignProject.ID
                },
                Reporter = CookIssueField("reporter", new IdentfierDescriptor {
                    Name = JiraUserAuth.User
                }),
                Priority = CookIssueField("priority", new IdentfierDescriptor()
                {
                    ID = "3"
                }),
            };

            issue.Fields = fields;
            return(issue);
        }
 private String CreateIssueToJira(JiraIssueModel issue)
 {
     if (JiraUserAuth != null && issue != null)
     {
         String errMsg;
         String requiredValue;
         IsCurrentIssueRequiredFieldsValueNull(out requiredValue);
         if (!JiraOperator.CreateIssue(issue, out errMsg, requiredValue))
         {
             return(errMsg);
         }
         return(String.Empty);
     }
     return("User authorization info is empty");
 }
        public Boolean CreateIssue(JiraIssueModel issue, out String errMsg, String extraData = null)
        {
            if (String.IsNullOrWhiteSpace(m_CurrentCookie) && User != null)
            {
                if (!UserAuth(User, out m_CurrentCookie, out errMsg))
                {
                    return(false);
                }
            }

            string jiraUri = BaseJiraUrl + "/rest/api/2/issue";

            try
            {
                String postData = Utils.Object2Json(issue);
                if (!String.IsNullOrWhiteSpace(extraData))
                {
                    var lastPosition = postData.LastIndexOf(',');
                    postData = postData.Insert(lastPosition, "," + extraData);
                }

                var response = Utils.CreatePostHttpResponse(jiraUri, postData, 30000, null, Encoding.UTF8, m_CurrentCookie);
                if (response != null)
                {
                    using (var stream = response.GetResponseStream())
                    {
                        if (stream != null)
                        {
                            using (var sr = new StreamReader(stream))
                            {
                                var resString = sr.ReadToEnd();
                                if (resString.Contains("id"))
                                {
                                    errMsg = String.Empty;
                                    return(true);
                                }
                                var error = Utils.Json2Object <JiraErrorModel>(resString);
                                if (error != null)
                                {
                                    errMsg = String.Join(Environment.NewLine, error.ErrorMessages.ToArray());
                                    return(false);
                                }
                            }
                        }
                    }
                }
                errMsg = "Connect failed.";
                return(false);
            }
            catch (WebException e)
            {
                if (e.Response != null)
                {
                    using (var stream = e.Response.GetResponseStream())
                    {
                        if (stream != null)
                        {
                            using (var sr = new StreamReader(stream))
                            {
                                var resString = sr.ReadToEnd();
                                var error     = Utils.Json2Object <JiraErrorModel>(resString);
                                if (error.ErrorMessages == null || error.ErrorMessages.Count == 0)
                                {
                                    errMsg = error.Errors != null?String.Join(";", error.Errors.Values) : "Bad Request";
                                }
                                else
                                {
                                    errMsg = String.Join("\r\n", error.ErrorMessages.ToArray());
                                }
                                return(false);
                            }
                        }
                    }
                }
                errMsg = e.Message;
                return(false);
            }
            catch (Exception e)
            {
                errMsg = e.Message;
                return(false);
            }
        }
        public Boolean CreateIssue(JiraIssueModel issue, out String errMsg, String extraData = null)
        {
            if (String.IsNullOrWhiteSpace(m_CurrentCookie) && User != null)
            {
                if (!UserAuth(User, out m_CurrentCookie, out errMsg))
                {
                    return false;
                }
            }

            string jiraUri = BaseJiraUrl + "/rest/api/2/issue";
            try
            {
                String postData = Utils.Object2Json(issue);
                if (!String.IsNullOrWhiteSpace(extraData))
                {
                    var lastPosition = postData.LastIndexOf(',');
                    postData = postData.Insert(lastPosition, "," + extraData);
                }

                var response = Utils.CreatePostHttpResponse(jiraUri, postData, 30000, null, Encoding.UTF8, m_CurrentCookie);
                if (response != null)
                {
                    using (var stream = response.GetResponseStream())
                    {
                        if (stream != null)
                        {
                            using (var sr = new StreamReader(stream))
                            {
                                var resString = sr.ReadToEnd();
                                if (resString.Contains("id"))
                                {
                                    errMsg = String.Empty;
                                    return true;
                                }
                                var error = Utils.Json2Object<JiraErrorModel>(resString);
                                if (error != null)
                                {
                                    errMsg = String.Join(Environment.NewLine, error.ErrorMessages.ToArray());
                                    return false;
                                }
                            }
                        }
                    }
                }
                errMsg = "Connect failed.";
                return false;
            }
            catch (WebException e)
            {
                if (e.Response != null)
                {
                    using (var stream = e.Response.GetResponseStream())
                    {
                        if (stream != null)
                        {
                            using (var sr = new StreamReader(stream))
                            {
                                var resString = sr.ReadToEnd();
                                var error = Utils.Json2Object<JiraErrorModel>(resString);
                                if (error.ErrorMessages == null || error.ErrorMessages.Count == 0)
                                {
                                    errMsg = error.Errors != null ? String.Join(";", error.Errors.Values) : "Bad Request";
                                }
                                else
                                {
                                    errMsg = String.Join("\r\n", error.ErrorMessages.ToArray());
                                }
                                return false;
                            }
                        }
                    }
                }
                errMsg = e.Message;
                return false;
            }
            catch (Exception e)
            {
                errMsg = e.Message;
                return false;
            }
        }