track google chorme URL - c#

I want to get url of all tabs I found this code
this code give me tabs title only please tell me how I get all tabs url
var automationElements = AutomationElement.FromHandle(proc.MainWindowHandle);
// Find `New Tab` element
var propCondNewTab = new PropertyCondition(AutomationElement.NameProperty, "New Tab");
var elemNewTab = automationElements.FindFirst(TreeScope.Descendants, propCondNewTab);
// Get parent of `New Tab` element
var treeWalker = TreeWalker.ControlViewWalker;
var elemTabStrip = treeWalker.GetParent(elemNewTab);
// Loop through all tabs
var tabItemCondition = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.TabItem);
foreach (AutomationElement tabItem in elemTabStrip.FindAll(TreeScope.Children, tabItemCondition)) {
var nameProperty = tabItem.GetCurrentPropertyValue(AutomationElement.NameProperty);
Debug.WriteLine("title: " + nameProperty.ToString());
}

Related

How to create Toast Notification with custom icon and custom app name?

I'm trying to create a Windows Toast Notification with .Net C#. While this, I would like to change the notification icon and the app name in the attribution area (header) of the notification.
I'm able to place a notification with a custom "App name" like shown here:
I do this with this code:
var toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02);
var stringElements = toastXml.GetElementsByTagName("text");
stringElements[0].AppendChild(toastXml.CreateTextNode("Title"));
stringElements[1].AppendChild(toastXml.CreateTextNode("Message"));
ToastNotification toast = new(toastXml);
ToastNotificationManager.CreateToastNotifier("App name").Show(toast);
But I don't find a solution, how to place an icon left from "App name".
The solution can't be to modify the toast on a different way, since it only changes the visual or action elements. But not the attribute area:
How can I show an icon in the attribute area?
To set the icon in the attribution area you can set it directly.
var toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02);
var stringElements = toastXml.GetElementsByTagName("text");
stringElements[0].AppendChild(toastXml.CreateTextNode("Title"));
stringElements[1].AppendChild(toastXml.CreateTextNode("Message"));
ToastNotification toast = new(toastXml);
// here you set your icon
toast.attribution.icon = new ToastImageSource("path to your image");
ToastNotificationManager.CreateToastNotifier("App name").Show(toast);
To set the icon in the title you can change the created toast.
var toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02);
var stringElements = toastXml.GetElementsByTagName("text");
stringElements[0].AppendChild(toastXml.CreateTextNode("Title"));
stringElements[1].AppendChild(toastXml.CreateTextNode("Message"));
ToastNotification toast = new(toastXml);
// Here you can change the visual element of the toast
// don't know which image will be correct. Can't test at the moment
toast.Visual.TileLarge.HintRemoveMargin = true;
toast.Visual.TileSmall.HintRemoveMargin = true;
toast.Visual.TileMedium.HintRemoveMargin = true;
toast.Visual.TileLarge.Branding = ToastBranding.Logo;
toast.Visual.TileSmall.Branding = ToastBranding.Logo;
toast.Visual.TileMedium.Branding = ToastBranding.Logo;
toast.Visual.TileLarge.AppLogoOverride = new ToastAppLogo();
toast.Visual.TileSmall.AppLogoOverride = new ToastAppLogo();
toast.Visual.TileMedium.AppLogoOverride = new ToastAppLogo();
toast.Visual.TileLarge.AppLogoOverride.Crop = new ToastAppLogoCrop(0, 0, 1, 1);
toast.Visual.TileSmall.AppLogoOverride.Crop = new ToastAppLogoCrop(0, 0, 1, 1);
toast.Visual.TileMedium.AppLogoOverride.Crop = new ToastAppLogoCrop(0, 0, 1, 1);
toast.Visual.TileLarge.AppLogoOverride.Source = new ToastImageSource("file:///C:/path/to/your/icon");
toast.Visual.TileSmall.AppLogoOverride.Source = new ToastImageSource("file:///C:/path/to/your/icon");
toast.Visual.TileMedium.AppLogoOverride.Source = new ToastImageSource("file:///C:/path/to/your/icon");
ToastNotificationManager.CreateToastNotifier("App name").Show(toast);
Additionally you can set an appLogoOverlay which is displayed in the title area
// get hte ToastGeneric toast content
XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastGeneric);
// here you get the visual element of the toast
XmlNodeList toastVisualElements = toastXml.GetElementsByTagName("visual");
// to add an icon you need app logo overlay
XmlElement appLogoOverlay = toastXml.CreateElement("appLogoOverlay");
// here you set the source of the overlay
appLogoOverlay.SetAttribute("src", "path to your icon");
// here you can add style attributes
appLogoOverlay.SetAttribute("hint-crop", "circle");
toastVisualElements[0].AppendChild(appLogoOverlay);
var stringElements = toastXml.GetElementsByTagName("text");
stringElements[0].AppendChild(toastXml.CreateTextNode("Title"));
stringElements[1].AppendChild(toastXml.CreateTextNode("Message"));
ToastNotification toast = new(toastXml);
ToastNotificationManager.CreateToastNotifier("App name").Show(toast);

Get chrome tab title and URL c# for all the active and minimized

I am working on an application what will read chrome, firefox and IE browsing history. With the help of this article, I can able to get chrome's history using sqlite but when chrome is not running. So I have read the opened tabs of browser and store them into database. To achieve this I modified this code and now i am able to get all the tab title and active tab url as well title of active window.
Here is the code
public class BrowserHistoryBO
{
public string BrowserName { get; set; }
public string URL { get; set; }
public string Title { get; set; }
public bool IsDelete { get; set; }
public bool IsCurrent { get; set; }
}
public void GetGoogleHistory()
{
List<BrowserHistoryBO> listBH = new List<BrowserHistoryBO>();
List<string> listTempBH = new List<string>();
string currentTitle = string.Empty;
string url = string.Empty;
Process[] procsChrome = Process.GetProcessesByName("chrome").Where(us => us.MainWindowHandle != IntPtr.Zero).ToArray();
foreach (Process chrome in procsChrome)
{
AutomationElement element = AutomationElement.FromHandle(chrome.MainWindowHandle);
if (element == null)
{ }
AutomationElementCollection edits5 = element.FindAll(TreeScope.Subtree, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit));
AutomationElement edit = edits5[0];
//Current tab URL
url = ((ValuePattern)edit.GetCurrentPattern(ValuePattern.Pattern)).Current.Value as string;
//Current tab title
currentTitle = chrome.MainWindowTitle.Replace(" - Google Chrome", "");
if (url != string.Empty && currentTitle != string.Empty && currentTitle != "New Tab")
{
//check whether current tab already in list
var result = listBH.FirstOrDefault(us => us.Title == currentTitle);
//if yes then add/update url
if (result != null)
{
result.URL = url;
result.IsCurrent = true;
}
//If no then add new tab to the list
else
{
listBH.Add(new BrowserHistoryBO
{
Title = currentTitle,
URL = url,
IsDelete = false,
IsCurrent = true
});
}
}
AutomationElement elm = AutomationElement.FromHandle(chrome.MainWindowHandle);
AutomationElement elmUrlBar = elm.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, "Address and search bar"));
Condition condNewTab = new PropertyCondition(AutomationElement.NameProperty, "New Tab");
TreeWalker tWalker = TreeWalker.ControlViewWalker;
AutomationElement elemNewTab = elm.FindFirst(TreeScope.Descendants, condNewTab);
AutomationElement elemTabStrip = tWalker.GetParent(elemNewTab);
Condition tabItemCondition = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.TabItem);
if ((elemNewTab == null))
{
return;
}
//get all the child's title
foreach (AutomationElement tabItem in elemTabStrip.FindAll(TreeScope.Children, tabItemCondition))
{
listTempBH.Add(tabItem.Current.Name);
}
var lookup = new List<string>(listBH.Select(x => x.Title));//Get stored Title
var lookupClosedTab = lookup.Except(listTempBH).ToList();//get closed tab
var newTab = listTempBH.Except(lookup).ToList();
//find closed tab
foreach (var item in lookupClosedTab)
{
var ct = listBH.Where(us => us.Title == item).FirstOrDefault();
ct.IsDelete = true;
}
//below code will add new opened tab to list
foreach (var item in newTab)
{
listBH.Add(new BrowserHistoryBO
{
Title = item,
URL = "",
IsDelete = false,
IsCurrent = false
});
}
}
}
This code works fine when Tabs are opened same window and with incognito mode also, But when there are more than one window is open or all the windows are minimized, this code returns only title of single window.
I found this answer and modified code that uses List ChromeWindows = WindowsFinder("Chrome_WidgetWin_1", "chrome"); but it returns only title of all window.
Please help me to find all minimized, active and opened tabs Title and URL.
Pardon me for grammatical mistakes

Creating Group Page Programmatically Sitefinity Backend

I've searched and I can't find any documentation on how to create a Group Page in the sitefinity API. I know how to create a page programmatically.
var pageDataId = Guid.NewGuid();
PageManager manager = PageManager.GetManager();
PageData pageData = null;
PageNode pageNode = null;
// Get the parent node Id
if (parentPageNodeId == Guid.Empty)
{
parentPageNodeId = SiteInitializer.CurrentFrontendRootNodeId;
}
PageNode parent = manager.GetPageNode(parentPageNodeId);
// Check whether exists
var initialPageNode = manager.GetPageNodes().Where(n => n.Id == pageId).SingleOrDefault();
if (initialPageNode != null)
{
return;
}
// Create the page
pageData = manager.CreatePageData(pageDataId);
pageData.HtmlTitle = pageName;
pageData.Title = pageName;
pageData.Description = pageName;
pageData.Culture = Thread.CurrentThread.CurrentCulture.ToString();
pageData.UiCulture = Thread.CurrentThread.CurrentUICulture.ToString();
pageNode = manager.CreatePage(parent, pageId, NodeType.Standard);
pageNode.Page = pageData;
pageNode.Name = pageName;
pageNode.Description = pageName;
pageNode.Title = pageName;
pageNode.UrlName = Regex.Replace(pageName.ToLower(), #"[^\w\-\!\$\'\(\)\=\#\d_]+", "-");
pageNode.ShowInNavigation = true;
pageNode.DateCreated = DateTime.UtcNow;
pageNode.LastModified = DateTime.UtcNow;
// Check whether home page
if (isHomePage)
{
SystemManager.CurrentContext.CurrentSite.SetHomePage(pageId);
}
manager.SaveChanges();
// Publish
var bag = new Dictionary<string, string>();
bag.Add("ContentType", typeof(PageNode).FullName);
WorkflowManager.MessageWorkflow(pageId, typeof(PageNode), null, "Publish", false, bag);
}
This creates a regular page. I've tried changing the NodeType from standard to NodeType.Group and leaving the rest of the code as is. However this throws an exception "The current page is not standard page." I've looked for pageNode properties to make the page a group page rather than a regular page but I can't find any. If anyone knows how to do this I would really appreciate it.
the exception is probably being thrown because you are attempting to create PageData for the created Group node. I believe that Group nodes do not have page data, but rather serve only to group other page nodes.
try removing the creation and assignment of the pageData to the PageGroup.Page property, and that should allow you to save the created page node.
Also if you install the sitefinity SDK there's a SampleUtilities class in the resources folder that has a lot of helper methods for creating pages, templates, etc that serves as a great reference point for working with the API.
I hope this is helpful!
This is some code that might help you:
// Define our new view
var templateIconView = new TemplateIconView { ID = TemplateIconViewControlId };
var pageManager = PageManager.GetManager();
pageManager.Provider.SuppressSecurityChecks = true;
// Get the root
var parentNode = pageManager.GetPageNode(SiteInitializer.SitefinityNodeId);
// Check whether exists
var initialPageNode = pageManager.GetPageNodes().SingleOrDefault(n => n.Id == AdditionalToolsPageId);
if (initialPageNode != null) {
pageManager.Delete(initialPageNode);
pageManager.SaveChanges();
}
var homePageNode = pageManager.GetPageNodes().SingleOrDefault(n => n.Id == HomePageId);
if (homePageNode != null) {
pageManager.Delete(homePageNode);
pageManager.SaveChanges();
}
// Create the Group Page Node
var groupPageNode = pageManager.CreatePage(parentNode, AdditionalToolsPageId, NodeType.Group);
groupPageNode.Name = "KonstruiTools";
groupPageNode.Description.SetString("Konstrui Tools", true);
groupPageNode.Title.SetString("Konstrui Tools", true);
groupPageNode.UrlName = Regex.Replace("Konstrui Tools", #"[^\w\-\!\$\'\(\)\=\#\d_]+", "-").ToLower();
groupPageNode.ShowInNavigation = true;
groupPageNode.DateCreated = DateTime.UtcNow;
groupPageNode.LastModified = DateTime.UtcNow;
pageManager.SaveChanges();
// Create the actual page PageData
var pageData = pageManager.CreatePageData(HomePageId);
pageData.HtmlTitle = "Configure Template Icons";
pageData.Title = "Configure Template Icons";
pageData.Description = "Configure Template Icons";
pageData.Culture = Thread.CurrentThread.CurrentCulture.ToString();
pageData.UiCulture = Thread.CurrentThread.CurrentUICulture.ToString();
pageData.EnableViewState = true;
pageData.EnableViewStateMac = true;
// Add our control to the page with default permissions
var control = pageManager.CreateControl<PageControl>(templateIconView, Constants.VALUE_DEFAULT_BACKEND_PLACEHOLDER);
pageManager.SetControlDefaultPermissions(control);
pageData.Controls.Add(control);
// Assign the Default Backend Template
pageData.Template = pageManager.GetTemplate(SiteInitializer.DefaultBackendTemplateId);
// Create the actual page PageNode
var pageNode = pageManager.CreatePage(groupPageNode, HomePageId, NodeType.Standard);
pageNode.Page = pageData;
pageNode.Name = "ConfigureTemplateIcons";
pageNode.Description = "Configure Template Icons";
pageNode.Title = "Configure Template Icons";
pageNode.UrlName = Regex.Replace("Configure Template Icons", #"[^\w\-\!\$\'\(\)\=\#\d_]+", "-").ToLower();
pageNode.ShowInNavigation = true;
pageNode.DateCreated = DateTime.UtcNow;
pageNode.LastModified = DateTime.UtcNow;
pageNode.RenderAsLink = true;
pageManager.SaveChanges();
// Publish
var bag = new Dictionary<string, string>();
bag.Add("ContentType", typeof(PageNode).FullName);
WorkflowManager.MessageWorkflow(HomePageId, typeof(PageNode), null, "Publish", false, bag);
pageManager.Provider.SuppressSecurityChecks = false;
This creates a grouppage inside the backend on rootlevel, wich holds another page with a control.
Here is what I ended up doing. It will create a group page under another group page which is exactly what I needed for my requirements.
var pageId = Guid.NewGuid();
PageManager manager = PageManager.GetManager();
PageNode pageNode = null;
//Find the modules section which will serve as the
//parent page.
string pageTitle = ConfigurationManager.AppSettings["ModulesSection"].ToString();
//Gets the actual Modules page.
var modulesNode = SitefinityHelper.GetPageNode(pageTitle);
if (modulesNode.Id == Guid.Empty)
{
modulesNode.Id = SiteInitializer.CurrentFrontendRootNodeId;
}
PageNode modulesPage = manager.GetPageNode(modulesNode.Id);
// Check whether exists
var initialPageNode = manager.GetPageNodes().Where(n => n.Id ==
pageId).SingleOrDefault();
if (initialPageNode != null)
{
return false;
}
//Creates the page under the Modules section as a Group Page.
pageNode = manager.CreatePage(modulesPage, pageId, NodeType.Group);
pageNode.Name = newModule.Name;
pageNode.Description = newModule.Description;
pageNode.Title = newModule.Name;
pageNode.UrlName = Regex.Replace(newModule.Name.ToLower(), #"[^\w\-\!\$\'\(\)\=\#\d_]+", "-");
pageNode.ShowInNavigation = true;
pageNode.DateCreated = DateTime.UtcNow;
pageNode.LastModified = DateTime.UtcNow;
manager.SaveChanges();e here
You can create Group page using fluent API. It's easy way given in fluent API
App.WorkWith()
.Page()
.CreateNewPageGroup()
.Do(x => x.Title = "Testpage2")
.Do(x => x.Name = "Testpage2")
.Do(x => x.UrlName = "testpage2")
.SaveChanges();

TreeViewId.SelectedNode.Depth Equivalent in Javasacript

In C# page i am getting TreeViewId.SelectedNode.Depth, while in javascript when i am trying to get depth of same treeView i am not getting the depth.
var treeViewData = window["<%=TreeViewMerchantId.ClientID%>" + "_Data"];
if (document.getElementById(treeViewData).selectedNodeID.value != "")
{
var selectedNode = document.getElementById(treeViewData).selectedNodeID.value;
var text = selectedNode.innerHTML;
var Depth = selectedNode.depth;
var Lable = selectedNode.level;
}

Getting full contents of a Datagrid using UIAutomation

I have need to retrieve all of the items in a Datagrid from an external application using UIAutomation. Currently, I can only retrieve (and view in UISpy) the visible items. Is there a way to cache all of the items in the Datagrid and then pull them? Here's the code:
static public ObservableCollection<Login> GetLogins()
{
ObservableCollection<Login> returnLogins = new ObservableCollection<Login>();
var id = System.Diagnostics.Process.GetProcessesByName("<Name here>")[0].Id;
var desktop = AutomationElement.RootElement;
var bw = AutomationElement.RootElement.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ProcessIdProperty, id));
var datagrid = bw.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.AutomationIdProperty, "lv"));
var loginLines = datagrid.FindAll(TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.DataItem));
foreach (AutomationElement loginLine in loginLines)
{
var loginInstance = new Login { IP = new IP() };
var loginLinesDetails = loginLine.FindAll(TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Custom));
for (var i = 0; i < loginLinesDetails.Count; i++)
{
var cacheRequest = new CacheRequest
{
AutomationElementMode = AutomationElementMode.None,
TreeFilter = Automation.RawViewCondition
};
cacheRequest.Add(AutomationElement.NameProperty);
cacheRequest.Add(AutomationElement.AutomationIdProperty);
cacheRequest.Push();
var targetText = loginLinesDetails[i].FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ClassNameProperty, "TextBlock"));
cacheRequest.Pop();
var myString = targetText.Cached.Name;
#region Determine data and write to return object
//Removed private information
#endregion
}
}
returnLogins.Add(loginInstance);
}
return returnLogins;
}
You can only retrieve the visible cells because you have table virtualization on.
Try disabling the virtualization (not always possible in all application but perhaps you want to move it into configuration and change it before testing)
I am 99% sure that this is not possible. UI Automation doesn't know about the data structures which are represented by the currently visible portion of a grid. It only sees what is visible. I think that you will have to page through the grid to get all the data (that is what I do).

Categories