private static IEnumerable <string> GetBrowserUrls() { HashSet <string> urls = new HashSet <string>(); // FireFox foreach (WindowDetails window in WindowDetails.GetAllWindows("MozillaWindowClass")) { if (window.Text.Length == 0) { continue; } AutomationElement currentElement = AutomationElement.FromHandle(window.Handle); Condition conditionCustom = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Custom), new PropertyCondition(AutomationElement.IsOffscreenProperty, false)); for (int i = 5; i > 0 && currentElement != null; i--) { currentElement = currentElement.FindFirst(TreeScope.Children, conditionCustom); } if (currentElement == null) { continue; } Condition conditionDocument = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Document), new PropertyCondition(AutomationElement.IsOffscreenProperty, false)); AutomationElement docElement = currentElement.FindFirst(TreeScope.Children, conditionDocument); if (docElement == null) { continue; } foreach (AutomationPattern pattern in docElement.GetSupportedPatterns()) { if (pattern.ProgrammaticName != "ValuePatternIdentifiers.Pattern") { continue; } string url = (docElement.GetCurrentPattern(pattern) as ValuePattern).Current.Value.ToString(); if (!string.IsNullOrEmpty(url)) { urls.Add(url); break; } } } foreach (string url in IEHelper.GetIEUrls()) { urls.Add(url); } return(urls); }
public static List <JiraIssue> GetCurrentJiras() { // Make sure we suppress the login List <string> jirakeys = new List <string>(); foreach (string url in IEHelper.GetIEUrls()) { 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); }
public static List <Page> GetCurrentPages(ConfluenceConnector confluenceConnector) { var pages = new List <Page>(); var pageIdRegex = new Regex(@"pageId=(\d+)"); var spacePageRegex = new Regex(@"\/display\/([^\/]+)\/([^#]+)"); foreach (var browserurl in IEHelper.GetIEUrls().Distinct()) { string url; try { url = Uri.UnescapeDataString(browserurl).Replace("+", " "); } catch { Log.Warn().WriteLine("Error processing URL: {0}", browserurl); continue; } var pageIdMatch = pageIdRegex.Matches(url); if (pageIdMatch != null && pageIdMatch.Count > 0) { var pageId = long.Parse(pageIdMatch[0].Groups[1].Value); try { var pageDouble = false; foreach (var page in pages) { if (page.Id == pageId) { pageDouble = true; Log.Debug().WriteLine("Skipping double page with ID {0}", pageId); break; } } if (!pageDouble) { var page = confluenceConnector.GetPage(pageId); Log.Debug().WriteLine("Adding page {0}", page.Title); pages.Add(page); } continue; } catch (Exception ex) { // Preventing security problems Log.Debug().WriteLine("Couldn't get page details for PageID {0}", pageId); Log.Warn().WriteLine(ex); } } var spacePageMatch = spacePageRegex.Matches(url); if (spacePageMatch != null && spacePageMatch.Count > 0) { if (spacePageMatch[0].Groups.Count >= 2) { var space = spacePageMatch[0].Groups[1].Value; var 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 { var pageDouble = false; foreach (var page in pages) { if (page.Title.Equals(title)) { Log.Debug().WriteLine("Skipping double page with title {0}", title); pageDouble = true; break; } } if (!pageDouble) { var page = confluenceConnector.GetPage(space, title); Log.Debug().WriteLine("Adding page {0}", page.Title); pages.Add(page); } } catch (Exception ex) { // Preventing security problems Log.Debug().WriteLine("Couldn't get page details for space {0} / title {1}", space, title); Log.Warn().WriteLine(ex); } } } } return(pages); }