Exemple #1
0
        public static List <JiraIssue> GetCurrentJiras()
        {
            // Make sure we suppress the login
            List <string> jirakeys = new List <string>();

            foreach (string url in BrowserHelper.GetBrowserUrls())
            {
                if (url == null)
                {
                    continue;
                }
                MatchCollection jiraKeyMatch = JIRA_KEY_REGEX.Matches(url);
                if (jiraKeyMatch != null && jiraKeyMatch.Count > 0)
                {
                    string jiraKey = jiraKeyMatch[0].Groups[1].Value;
                    jirakeys.Add(jiraKey);
                }
            }
            if (!string.IsNullOrEmpty(config.LastUsedJira) && !jirakeys.Contains(config.LastUsedJira))
            {
                jirakeys.Add(config.LastUsedJira);
            }
            if (jirakeys.Count > 0)
            {
                List <JiraIssue> jiraIssues = new List <JiraIssue>();
                foreach (string jiraKey in jirakeys)
                {
                    try {
                        JiraIssue issue = JiraPlugin.Instance.JiraConnector.getIssue(jiraKey);
                        if (issue != null)
                        {
                            jiraIssues.Add(issue);
                        }
                    } catch {}
                }
                if (jiraIssues.Count > 0)
                {
                    return(jiraIssues);
                }
            }
            return(null);
        }
Exemple #2
0
        public static List <Confluence.Page> GetCurrentPages()
        {
            List <Confluence.Page> pages = new List <Confluence.Page>();
            Regex pageIdRegex            = new Regex(@"pageId=(\d+)");
            Regex spacePageRegex         = new Regex(@"\/display\/([^\/]+)\/([^#]+)");

            foreach (string browserurl in BrowserHelper.GetBrowserUrls())
            {
                string url = null;
                try {
                    url = Uri.UnescapeDataString(browserurl).Replace("+", " ");
                } catch {
                    LOG.WarnFormat("Error processing URL: {0}", browserurl);
                    continue;
                }
                MatchCollection pageIdMatch = pageIdRegex.Matches(url);
                if (pageIdMatch != null && pageIdMatch.Count > 0)
                {
                    long pageId = long.Parse(pageIdMatch[0].Groups[1].Value);
                    try {
                        bool pageDouble = false;
                        foreach (Confluence.Page page in pages)
                        {
                            if (page.id == pageId)
                            {
                                pageDouble = true;
                                LOG.DebugFormat("Skipping double page with ID {0}", pageId);
                                break;
                            }
                        }
                        if (!pageDouble)
                        {
                            Confluence.Page page = ConfluencePlugin.ConfluenceConnector.getPage(pageId);
                            LOG.DebugFormat("Adding page {0}", page.Title);
                            pages.Add(page);
                        }
                        continue;
                    } catch (Exception ex) {
                        // Preventing security problems
                        LOG.DebugFormat("Couldn't get page details for PageID {0}", pageId);
                        LOG.Warn(ex);
                    }
                }
                MatchCollection spacePageMatch = spacePageRegex.Matches(url);
                if (spacePageMatch != null && spacePageMatch.Count > 0)
                {
                    if (spacePageMatch[0].Groups.Count >= 2)
                    {
                        string space = spacePageMatch[0].Groups[1].Value;
                        string title = spacePageMatch[0].Groups[2].Value;
                        if (string.IsNullOrEmpty(title) || string.IsNullOrEmpty(space))
                        {
                            continue;
                        }
                        if (title.EndsWith("#"))
                        {
                            title = title.Substring(0, title.Length - 1);
                        }
                        try {
                            bool pageDouble = false;
                            foreach (Confluence.Page page in pages)
                            {
                                if (page.Title.Equals(title))
                                {
                                    LOG.DebugFormat("Skipping double page with title {0}", title);
                                    pageDouble = true;
                                    break;
                                }
                            }
                            if (!pageDouble)
                            {
                                Confluence.Page page = ConfluencePlugin.ConfluenceConnector.getPage(space, title);
                                LOG.DebugFormat("Adding page {0}", page.Title);
                                pages.Add(page);
                            }
                            continue;
                        } catch (Exception ex) {
                            // Preventing security problems
                            LOG.DebugFormat("Couldn't get page details for space {0} / title {1}", space, title);
                            LOG.Warn(ex);
                        }
                    }
                }
            }
            return(pages);
        }