<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>UI Automation</title><link>https://community.telligent.com/community/11/w/developer-training/65054/ui-automation</link><description /><dc:language>en-US</dc:language><generator>14.0.0.586 14</generator><item><title>UI Automation</title><link>https://community.telligent.com/community/11/w/developer-training/65054/ui-automation</link><pubDate>Thu, 20 Jun 2019 20:13:47 GMT</pubDate><guid isPermaLink="false">3eb9e8c8-b276-4b2b-ad1c-588239dce1c5</guid><dc:creator>Ben Tiedt</dc:creator><comments>https://community.telligent.com/community/11/w/developer-training/65054/ui-automation#comments</comments><description>Current Revision posted to Developer Training by Ben Tiedt on 06/20/2019 20:13:47&lt;br /&gt;
&lt;p&gt;When developing custom extensions using [[Plugins|plugins]], it is often beneficial to install UI components as part of the installation of the extension making use of the [[api-documentation:IInstallablePlugin Plugin Type|IInstallallablePlugin]] interface and the UI automation API.&lt;/p&gt;
&lt;p&gt;[toc]&lt;/p&gt;
&lt;h2&gt;&lt;a id="What_is_the_UI_Automation_API" name="What_is_the_UI_Automation_API"&gt;&lt;/a&gt;What is the UI Automation API&lt;/h2&gt;
&lt;p&gt;The UI automation API is set of APIs made available to [[Plugins|plugins]] via the [[api-documentation:In-Process API Documentation|in-process API]]&amp;nbsp;to enable the automated adjustment of UI components. Specifically, it includes the following services and constants:&lt;/p&gt;
&lt;h3&gt;&lt;a id="Services" name="Services"&gt;&lt;/a&gt;Services&lt;/h3&gt;
&lt;h4&gt;&lt;a id="api-documentation_ContentFragments_In-Process_API_ServiceContentFragments" name="api-documentation_ContentFragments_In-Process_API_ServiceContentFragments"&gt;&lt;/a&gt;[[api-documentation:ContentFragments In-Process API Service|ContentFragments]]&lt;/h4&gt;
&lt;p&gt;Enable/disable widgets, identify widgets to other UI automation APIs, translate widgets, and automate&amp;nbsp;widget upgrading (see [[Managing Widget Source and Distribution]]).&lt;/p&gt;
&lt;h4&gt;&lt;a id="api-documentation_FactoryDefaultScriptedContentFragmentProviderFiles_In-Process_API_ServiceFactoryDefaultScriptedContentFragmentProviderFiles" name="api-documentation_FactoryDefaultScriptedContentFragmentProviderFiles_In-Process_API_ServiceFactoryDefaultScriptedContentFragmentProviderFiles"&gt;&lt;/a&gt;[[api-documentation:FactoryDefaultScriptedContentFragmentProviderFiles In-Process API Service|FactoryDefaultScriptedContentFragmentProviderFiles]]&lt;/h4&gt;
&lt;p&gt;Add/update, delete, and detect factory default widget provider source files and attachments to install files associated to a factory default widget provider ([[api-documentation:IScriptedContentFragmentFactoryDefaultProvider Plugin Type|IScriptedContentFragmentFactoryDefaultProvider]] plugin). For the recommended approach to deploy factory default widgets, see [[Managing Widget Source and Distribution]].&lt;/p&gt;
&lt;h4&gt;&lt;a id="api-documentation_ThemeFiles_In-Process_API_ServiceThemeFiles" name="api-documentation_ThemeFiles_In-Process_API_ServiceThemeFiles"&gt;&lt;/a&gt;[[api-documentation:ThemeFiles In-Process API Service|ThemeFiles]]&lt;/h4&gt;
&lt;p&gt;Add/update and detect embedded theme files.&lt;/p&gt;
&lt;h4&gt;&lt;a id="api-documentation_ThemeFooterContentFragments_In-Process_API_ServiceThemeFooterContentFragments" name="api-documentation_ThemeFooterContentFragments_In-Process_API_ServiceThemeFooterContentFragments"&gt;&lt;/a&gt;[[api-documentation:ThemeFooterContentFragments In-Process API Service|ThemeFooterContentFragments]]&lt;/h4&gt;
&lt;p&gt;List, insert, replace, and delete widgets within theme footers.&lt;/p&gt;
&lt;h4&gt;&lt;a id="api-documentation_ThemeFooters_In-Process_API_ServiceThemeFooters" name="api-documentation_ThemeFooters_In-Process_API_ServiceThemeFooters"&gt;&lt;/a&gt;[[api-documentation:ThemeFooters In-Process API Service|ThemeFooters]]&lt;/h4&gt;
&lt;p&gt;Add, edit, delete, and detect theme footers.&lt;/p&gt;
&lt;h4&gt;&lt;a id="api-documentation_ThemeHeaderContentFragments_In-Process_API_ServiceThemeHeaderContentFragments" name="api-documentation_ThemeHeaderContentFragments_In-Process_API_ServiceThemeHeaderContentFragments"&gt;&lt;/a&gt;[[api-documentation:ThemeHeaderContentFragments In-Process API Service|ThemeHeaderContentFragments]]&lt;/h4&gt;
&lt;p&gt;List, insert, replace, and delete widgets within theme headers.&lt;/p&gt;
&lt;h4&gt;&lt;a id="api-documentation_ThemeHeaders_In-Process_API_ServiceThemeHeaders" name="api-documentation_ThemeHeaders_In-Process_API_ServiceThemeHeaders"&gt;&lt;/a&gt;[[api-documentation:ThemeHeaders In-Process API Service|ThemeHeaders]]&lt;/h4&gt;
&lt;p&gt;Add, edit, delete, and detect theme headers.&lt;/p&gt;
&lt;h4&gt;&lt;a id="api-documentation_ThemePageContentFragments_In-Process_API_ServiceThemePageContentFragments" name="api-documentation_ThemePageContentFragments_In-Process_API_ServiceThemePageContentFragments"&gt;&lt;/a&gt;[[api-documentation:ThemePageContentFragments In-Process API Service|ThemePageContentFragments]]&lt;/h4&gt;
&lt;p&gt;List, insert, replace, and delete widgets within theme pages.&lt;/p&gt;
&lt;h4&gt;&lt;a id="api-documentation_ThemePages_In-Process_API_ServiceThemePages" name="api-documentation_ThemePages_In-Process_API_ServiceThemePages"&gt;&lt;/a&gt;[[api-documentation:ThemePages In-Process API Service|ThemePages]]&lt;/h4&gt;
&lt;p&gt;Add, edit, delete, and detect theme pages.&lt;/p&gt;
&lt;h4&gt;&lt;a id="api-documentation_Themes_In-Process_API_ServiceThemes" name="api-documentation_Themes_In-Process_API_ServiceThemes"&gt;&lt;/a&gt;[[api-documentation:Themes In-Process API Service|Themes]]&lt;/h4&gt;
&lt;p&gt;List themes for a specific theme type.&lt;/p&gt;
&lt;h3&gt;&lt;a id="Constants" name="Constants"&gt;&lt;/a&gt;Constants&lt;/h3&gt;
&lt;p&gt;The following APIs provide constants for use with UI automation services:&lt;/p&gt;
&lt;h4&gt;&lt;a id="api-documentation_ContentFragmentWrappingFormats_In-Process_API_ServiceContentFragmentWrappingFormats" name="api-documentation_ContentFragmentWrappingFormats_In-Process_API_ServiceContentFragmentWrappingFormats"&gt;&lt;/a&gt;[[api-documentation:ContentFragmentWrappingFormats In-Process API Service|ContentFragmentWrappingFormats]]&lt;/h4&gt;
&lt;p&gt;Constants for platform-defined widget wrapping formats for use with content-fragment-related services.&lt;/p&gt;
&lt;h4&gt;&lt;a id="api-documentation_LayoutRegions_In-Process_API_ServiceLayoutRegions" name="api-documentation_LayoutRegions_In-Process_API_ServiceLayoutRegions"&gt;&lt;/a&gt;[[api-documentation:LayoutRegions In-Process API Service|LayoutRegions]]&lt;/h4&gt;
&lt;p&gt;Constants for platform-defined layout regions for use with widget placement in content-fragment-related services.&lt;/p&gt;
&lt;h4&gt;&lt;a id="api-documentation_ThemeableApplicationIds_In-Process_API_ServiceThemeableApplicationIds" name="api-documentation_ThemeableApplicationIds_In-Process_API_ServiceThemeableApplicationIds"&gt;&lt;/a&gt;[[api-documentation:ThemeableApplicationIds In-Process API Service|ThemeableApplicationIds]]&lt;/h4&gt;
&lt;p&gt;Constant for identifying the site application identifier.&amp;nbsp;&lt;/p&gt;
&lt;h4&gt;&lt;a id="api-documentation_ThemeProperties_In-Process_API_ServiceThemeProperties" name="api-documentation_ThemeProperties_In-Process_API_ServiceThemeProperties"&gt;&lt;/a&gt;[[api-documentation:ThemeProperties In-Process API Service|ThemeProperties]]&lt;/h4&gt;
&lt;p&gt;Constants for theme properties used to interact with the ThemeFiles service.&lt;/p&gt;
&lt;h4&gt;&lt;a id="api-documentation_ThemeTypes_In-Process_API_ServiceThemeTypes" name="api-documentation_ThemeTypes_In-Process_API_ServiceThemeTypes"&gt;&lt;/a&gt;[[api-documentation:ThemeTypes In-Process API Service|ThemeTypes]]&lt;/h4&gt;
&lt;p&gt;Constants for the platform-defined theme types to be used with other UI automation APIs.&lt;/p&gt;
&lt;h2&gt;&lt;a id="Using_the_UI_Automation_API" name="Using_the_UI_Automation_API"&gt;&lt;/a&gt;Using the UI Automation API&lt;/h2&gt;
&lt;p&gt;There are a few common situations where you&amp;#39;d use the UI automation API:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A custom application or custom functionality defines new pages (see [[Page Definition and URL Routing]]) and wants to include theme-specific variants of the new pages to simplify installation. For this, use the&amp;nbsp;[[api-documentation:ThemeHeaders In-Process API Service|ThemeHeaders]],&amp;nbsp;[[api-documentation:ThemePages In-Process API Service|ThemePages]], and&amp;nbsp;[[api-documentation:ThemeFooters In-Process API Service|ThemeFooters]]&amp;nbsp;APIs.&lt;/li&gt;
&lt;li&gt;A set of custom functionality implemented as a set of custom widgets (via an&amp;nbsp;[[api-documentation:IScriptedContentFragmentFactoryDefaultProvider Plugin Type|IScriptedContentFragmentFactoryDefaultProvider]]) needs to install the source widget files as part of the plugin representing the custom functionality. For this, see [[Managing Widget Source and Distribution]].&lt;/li&gt;
&lt;li&gt;A custom application with custom widgets needs to install one or more custom widgets on existing pages. For this, use the &lt;a href="/training/w/developer90/52476.ui-automation/edit/ThemeHeaderContentFragments"&gt;ThemeHeaderContentFragments&lt;/a&gt;, [[api-documentation:ThemePageContentFragments In-Process API Service|ThemePageContentFragments]], and [[api-documentation:ThemeFooterContentFragments In-Process API Service|ThemeFooterContentFragments]] APIs.&lt;/li&gt;
&lt;li&gt;A CSS file should be programmatically installed in the theme, either for general customization (perhaps as part of an automated deployment process) or as part of a custom application. For this, see the [[api-documentation:ThemeFiles In-Process API Service|ThemeFiles]] API and the example, Installing a CSS File, below.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;&lt;a id="Sample_Installing_a_CSS_File" name="Sample_Installing_a_CSS_File"&gt;&lt;/a&gt;Sample: Installing a CSS File&lt;/h2&gt;
&lt;p&gt;In this sample, a hard-coded CSS file will be installed in the site theme. This is a common scenario when deploying widgets through&amp;nbsp;an&amp;nbsp;[[api-documentation:IScriptedContentFragmentFactoryDefaultProvider Plugin Type|IScriptedContentFragmentFactoryDefaultProvider]]&amp;nbsp;(see [[Managing Widget Source and Distribution]]) when the widgets share a common CSS or LESS file.&lt;/p&gt;
&lt;p&gt;To integrate with the platform via code and access the [[api-documentation:In-Process API Documentation|In-Process API]], the example will implement the [[api-documentation:IPlugin Plugin Type|IPlugin interface]]&amp;nbsp;in a public class named InstallCssFile. To ensure that the CSS file is only installed when it needs to be (when the plugin is first enabled or when a new version is installed), the &lt;code&gt;InstallCssFile&lt;/code&gt; class also implements the [[api-documentation:IInstallablePlugin Plugin Type|IInstallablePlugin interface]]. To implement the class, the project will need to reference the Telligent.Evolution.Api and Telligent.Evolution.Components DLLs.&lt;/p&gt;
&lt;p&gt;The full source is at the bottom of this page, but the key usage of the UI Automation API occurs in the &lt;code&gt;Install()&lt;/code&gt; and &lt;code&gt;Uninstall()&lt;/code&gt; methods:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="csharp"&gt;public void Install(Version lastInstalledVersion)
{
    foreach (var theme in Themes.List(ThemeTypes.Site))
    {
        ThemeFiles.AddUpdateFactoryDefault(
            theme, 
            ThemeProperties.StyleSheetFiles, 
            _fileName, 
            _fileStream, 
            (int)_fileStream.Length, 
            new CssThemeFileOptions
            {
                ApplyToModals = true,
                ApplyToNonModals = true
            });

        ThemeFiles.AddUpdate(
            theme, 
            ThemeableApplicationIds.Site, 
            ThemeProperties.StyleSheetFiles, 
            _fileName, 
            _fileStream, 
            (int)_fileStream.Length, 
            new CssThemeFileOptions
            {
                ApplyToModals = true,
                ApplyToNonModals = true
            }
            );
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;In &lt;code&gt;Install()&lt;/code&gt;, the plugin loops on each available site theme (using the [[api-documentation:ThemeTypes In-Process API Service|ThemeTypes]] and [[api-documentation:Themes In-Process API Service|Themes]] APIs). For each theme, it installs a factory default version of the CSS file and the same file into the current contextual version of the site theme (using the [[api-documentation:ThemeTypes In-Process API Service|ThemeFiles]], [[api-documentation:ThemeProperties In-Process API Service|ThemeProperties]], and [[api-documentation:ThemeableApplicationIds In-Process API Service|ThemeableApplicationIds]] APIs). When installing CSS files into the &lt;code&gt;ThemeProperties.StyleSheetFiles&lt;/code&gt; theme property, CSS options can be defined using [[api-documentation:CssThemeFileOptions In-Process API Supplementary Type|CssThemeFileOptions]]. In this example, the plugin identifies that the file should be rendered on modal and non-modal pages of the theme.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="csharp"&gt;public void Uninstall()
{
    foreach (var theme in Themes.List(ThemeTypes.Site))
    {
        ThemeFiles.RemoveFactoryDefault(theme, ThemeProperties.StyleSheetFiles, _fileName);
        ThemeFiles.Remove(theme, ThemeableApplicationIds.Site, ThemeProperties.StyleSheetFiles, _fileName);
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;When uninstalling, the &lt;code&gt;Uninstall()&lt;/code&gt; method is called and the plugin again loops on the available themes and removes the installed CSS file from the factory default and contextual implementation of each theme.&lt;/p&gt;
&lt;p&gt;The full source of this sample is below:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://community.telligent.com/cfs-file/__key/communityserver-wikis-components-files/00-00-00-12-83/InstallCssFile_2E00_cs"&gt;community.telligent.com/.../InstallCssFile_2E00_cs&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;
</description></item></channel></rss>