/// <summary> /// Registers the entity class. /// </summary> /// <param name="type">Type of the entity.</param> /// <exception cref="RegistrationException"> /// Unable to register type that is not marked with Entity attribute. /// </exception> /// <exception cref="EntityException"> /// One of the properties had its type specified as a file, but it was not a /// string. /// </exception> /// <exception cref="EntityException"> /// One of the properties had its type specified as a vector, but it was not a /// vector type. /// </exception> /// <exception cref="EntityException"> /// One of the properties was registered with invalid type. /// </exception> public static void Register(Type type) { EntityAttribute attribute; if (!type.TryGetAttribute(out attribute)) { #if DEBUG throw new RegistrationException("Unable to register type that is not marked with Entity attribute."); #else return; #endif } // Register class. EntityRegister.Types.Add(attribute.Name, type); Native.EntityInterop.RegisterEntityClass ( new EntityRegistrationParams { name = attribute.Name, category = attribute.Category, flags = attribute.Flags, editorHelper = attribute.EditorHelper, editorIcon = attribute.Icon, properties = EntityRegister.GetProperties(type) } ); }
/// <summary> /// Creates the native page. /// </summary> /// <param name="pageType">Type of the page.</param> /// <param name="verifyPageValidity">if set to <c>true</c> verify the page validity.</param> /// <returns>The created page object.</returns> protected override IPage CreateNativePage(Type pageType, bool verifyPageValidity) { var webDriver = this.driver.Value; // Check to see if a frames reference exists, and switch if needed PageNavigationAttribute navigationAttribute; if (pageType.TryGetAttribute(out navigationAttribute) && !string.IsNullOrWhiteSpace(navigationAttribute.FrameName)) { webDriver.SwitchTo().Frame(navigationAttribute.FrameName); this.switchedContext = true; } else if (this.switchedContext) { webDriver.SwitchTo().DefaultContent(); this.switchedContext = false; } Func<IWebDriver, IBrowser, Action<object>, object> pageBuildMethod; if (!this.pageCache.TryGetValue(pageType, out pageBuildMethod)) { pageBuildMethod = pageBuilder.CreatePage(pageType); this.pageCache.Add(pageType, pageBuildMethod); } var nativePage = pageBuildMethod(webDriver, this, null); return new SeleniumPage(nativePage) { ExecuteWithElementLocateTimeout = this.ExecuteWithElementLocateTimeout, EvaluateWithElementLocateTimeout = this.EvaluateWithElementLocateTimeout }; }
bool TryGetGamemodeParams(ref IScriptRegistrationParams registrationParams, Type type) { var gamemodeRegistrationParams = new GameRulesRegistrationParams(); GameRulesAttribute gamemodeAttribute; if (type.TryGetAttribute(out gamemodeAttribute)) { if (!string.IsNullOrEmpty(gamemodeAttribute.Name)) gamemodeRegistrationParams.name = gamemodeAttribute.Name; gamemodeRegistrationParams.defaultGamemode = gamemodeAttribute.Default; } registrationParams = gamemodeRegistrationParams; return true; }
bool TryGetEntityParams(ref IScriptRegistrationParams registrationParams, Type type) { var entityRegistrationParams = new EntityRegistrationParams(); //LoadFlowNode(ref script, true); BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance; var folders = type.GetNestedTypes(flags).Where(x => x.ContainsAttribute<EditorPropertyFolderAttribute>()); var members = type.GetMembers(flags); var entityProperties = new List<object>(); EntityProperty property; members.ForEach(member => { if (TryGetProperty(member, out property)) entityProperties.Add(property); }); folders.ForEach(folder => { folder.GetMembers().ForEach(member => { if (TryGetProperty(member, out property)) { property.folder = folder.Name; entityProperties.Add(property); } }); }); entityRegistrationParams.properties = entityProperties.ToArray(); EntityAttribute entAttribute; if (type.TryGetAttribute(out entAttribute)) { entityRegistrationParams.name = entAttribute.Name; var curType = type; var entType = typeof(Entity); while (curType != entType) { if (type.TryGetAttribute(out entAttribute)) { // don't override if the type before this (or earlier) changed it. if(entityRegistrationParams.category == null) entityRegistrationParams.category = entAttribute.Category; if(entityRegistrationParams.editorHelper == null) entityRegistrationParams.editorHelper = entAttribute.EditorHelper; if(entityRegistrationParams.editorIcon == null) entityRegistrationParams.editorIcon = entAttribute.Icon; if(entityRegistrationParams.flags == EntityClassFlags.Default) entityRegistrationParams.flags = entAttribute.Flags; } curType = curType.BaseType; } } registrationParams = entityRegistrationParams; return true; }
bool TryGetFlowNodeParams(ref IScriptRegistrationParams registrationParams, Type type) { if (!type.GetMembers().Any(member => member.ContainsAttribute<PortAttribute>())) return false; var nodeRegistrationParams = new FlowNodeRegistrationParams(); FlowNodeAttribute nodeInfo; if (type.TryGetAttribute(out nodeInfo)) { if (!string.IsNullOrEmpty(nodeInfo.UICategory)) nodeRegistrationParams.category = nodeInfo.UICategory; if (!string.IsNullOrEmpty(nodeInfo.Name)) nodeRegistrationParams.name = nodeInfo.Name; } registrationParams = nodeRegistrationParams; return true; }
/// <summary> /// Gets the page URL via the page attributes. /// </summary> /// <param name="browser">The browser.</param> /// <param name="pageType">Type of the page.</param> /// <returns> /// The URL stricture from the page. /// </returns> /// <exception cref="PageNavigationException">No PageAttribute or PageNavigationAttribute exists on type: {0}</exception> /// <exception cref="PageNavigationException">Thrown if the page is not able to navigate to.</exception> private static UriStructure GetPageUriInternal(IBrowser browser, Type pageType) { PageNavigationAttribute pageNavigationAttribute; if (pageType.TryGetAttribute(out pageNavigationAttribute)) { return new UriStructure(pageNavigationAttribute.Url, pageNavigationAttribute.IsAbsoluteUrl, pageNavigationAttribute.UrlTemplate); } var browserUri = browser.GetUriForPageType(pageType); if (!string.IsNullOrWhiteSpace(browserUri)) { return new UriStructure(browserUri, false); } throw new PageNavigationException("No PageNavigationAttribute exists on type: {0}", pageType.Name); }
/// <summary> /// Creates the native page. /// </summary> /// <param name="pageType">Type of the page.</param> /// <returns>The internal document.</returns> private HtmlDocument CreateNativePage(Type pageType) { Func<UITestControl, IBrowser, Action<HtmlControl>, HtmlDocument> function; if (!this.pageCache.TryGetValue(pageType, out function)) { function = PageBuilder<UITestControl, HtmlDocument>.CreateElement(pageType); this.pageCache.Add(pageType, function); } UITestControl parentElement = this.window.Value; // Check to see if a frames reference exists var isFrameDocument = false; PageNavigationAttribute navigationAttribute; if (pageType.TryGetAttribute(out navigationAttribute) && !string.IsNullOrWhiteSpace(navigationAttribute.FrameName)) { Func<UITestControl, HtmlFrame> frameFunction; if (!this.frameCache.Value.TryGetValue(navigationAttribute.FrameName, out frameFunction)) { throw new PageNavigationException( "Cannot locate frame with ID '{0}' for page '{1}'", navigationAttribute.FrameName, pageType.Name); } parentElement = frameFunction(parentElement); isFrameDocument = true; if (parentElement == null) { throw new PageNavigationException( "Cannot load frame with ID '{0}' for page '{1}'. The property that matched the frame did not return a parent document.", navigationAttribute.FrameName, pageType.Name); } } var documentElement = function(parentElement, this, null); if (isFrameDocument) { // Set properties that are relevant to the frame. documentElement.SearchProperties[HtmlDocument.PropertyNames.FrameDocument] = "True"; documentElement.SearchProperties[HtmlDocument.PropertyNames.RedirectingPage] = "False"; } return documentElement; }
/// <summary> /// Creates a new <see cref="HistorianAdapter"/>. /// </summary> /// <param name="type"><see cref="Type"/> of historian adapter.</param> public HistorianAdapter(Type type) { m_type = type; DescriptionAttribute descriptionAttribute; if (m_type.TryGetAttribute(out descriptionAttribute)) m_description = descriptionAttribute.Description; else m_description = m_type.FullName; }
private void build(Type tableType, String prefix) { //GET the Table Attribute var attr = tableType.TryGetAttribute<System.Data.Linq.Mapping.TableAttribute>(); if (attr == null) { throw new Gale.Exception.GaleException("API007", tableType.Name); } //Set Table metadata this._type = tableType; this._name = tableType.Name; this._key = attr.Name; this._prefix = prefix; }
/// <summary> /// Gets a description of the given type. This method will search for a /// <see cref="DescriptionAttribute"/> using reflection. If none is found, /// it will default to the <see cref="Type.FullName"/> of the type. /// </summary> /// <param name="type">The type for which a description is found.</param> /// <returns> /// Either the description as defined by a <see cref="DescriptionAttribute"/> /// or else the <see cref="Type.FullName"/> of the parameter - then <c>true</c> /// if the description attribute existed (and was defined); else <c>false</c>. /// </returns> private static Tuple<string, bool> GetDescription(Type type) { DescriptionAttribute descriptionAttribute; if (type.TryGetAttribute(out descriptionAttribute)) { // Treat null or empty string like there was no description if (string.IsNullOrWhiteSpace(descriptionAttribute.Description)) return Tuple.Create(type.FullName, false); return Tuple.Create(descriptionAttribute.Description, true); } return Tuple.Create(type.FullName, false); }
// Static Methods /// <summary> /// Gets the editor browsable state of the given type. This method will /// search for a <see cref="EditorBrowsableAttribute"/> using reflection. /// If none is found, it will default to <see cref="EditorBrowsableState.Always"/>. /// </summary> /// <param name="type">The type for which an editor browsable state is found.</param> /// <returns> /// Either the editor browsable state as defined by an <see cref="EditorBrowsableAttribute"/> /// or else <see cref="EditorBrowsableState.Always"/>. /// </returns> private static EditorBrowsableState GetEditorBrowsableState(Type type) { EditorBrowsableAttribute editorBrowsableAttribute; if (type.TryGetAttribute(out editorBrowsableAttribute)) return editorBrowsableAttribute.State; return EditorBrowsableState.Always; }
internal EntityRegisterParams GetRegistrationConfig(Type type) { EntityAttribute entityAttribute = null; if(type.TryGetAttribute<EntityAttribute>(out entityAttribute)) { return new EntityRegisterParams(type.Name, entityAttribute.Category, entityAttribute.EditorHelper, entityAttribute.Icon, entityAttribute.Flags); } return new EntityRegisterParams(type.Name, "Default", "", "", EntityClassFlags.Default); }