public override void VisitControl(ResolvedControl control) { ISeleniumGenerator generator; if (generators.TryGetValue(control.Metadata.Type, out generator)) { var helperDefinition = HelperDefinitionsStack.Peek(); // generate the content var context = new SeleniumGeneratorContext() { Control = control, UsedNames = helperDefinition.UsedNames, Visitor = this }; if (generator.CanAddDeclarations(helperDefinition, context)) { generator.AddDeclarations(helperDefinition, context); return; } } base.VisitControl(control); }
public override void VisitControl(ResolvedControl control) { var err = validator.Validate(control); Errors.AddRange(err); base.VisitControl(control); }
public override void VisitControl(ResolvedControl control) { if (control.Metadata.Type == typeof(Content)) { Visit(control, control.Content, base.VisitControl); return; } base.VisitControl(control); }
public override void VisitControl(ResolvedControl control) { Matcher.PushControl(control); foreach (var style in Matcher.GetMatchingStyles()) { style.ApplyStyle(control, configuration); } base.VisitControl(control); Matcher.PopControl(); }
public static string GetValueOrNull(this ResolvedControl control, IPropertyDescriptor property) { IAbstractPropertySetter value; if (!control.TryGetProperty(property, out value) || !(value is ResolvedPropertyValue)) { return(null); } return(((ResolvedPropertyValue)value).Value?.ToString()); }
public ResolvedPropertySetter GetPropertySetter(ResolvedControl resolvedControl, DotvvmConfiguration configuration) { var resolvedInnerControl = new ResolvedControl(metadata, null, resolvedControl.DataContextTypeStack); innerControlStyle.Applicator.ApplyStyle(resolvedInnerControl, configuration); return(new ResolvedPropertyControlCollection(dotvvmProperty, new List <ResolvedControl> { resolvedInnerControl })); }
public static ResolvedPropertyBinding GetValueBindingOrNull(this ResolvedControl control, IPropertyDescriptor property) { IAbstractPropertySetter binding; if (!control.TryGetProperty(property, out binding)) { return(null); } return(binding as ResolvedPropertyBinding); }
public void ApplyStyle(ResolvedControl control, DotvvmConfiguration configuration) { try { action(control, configuration); } catch (Exception ex) { control.DothtmlNode.AddError($"Could not apply styles: {ex}"); } }
public override void VisitControl(ResolvedControl control) { var selector = TryGetNameFromProperty(control, UITests.NameProperty); if (selector != null) { selectors.Add(selector); } base.VisitControl(control); }
public static string GetValue(this ResolvedControl control, IPropertyDescriptor property) { IAbstractPropertySetter value; if (!control.TryGetProperty(property, out value) || !(value is ResolvedPropertyValue)) { throw new CodeValidationException(string.Format(ValidationErrorMessages.MissingPropertyError, control.Metadata.Type.Name, property.Name)); } return(((ResolvedPropertyValue)value).Value?.ToString()); }
/// <summary> /// Processes the HTML element that represents a new object. /// </summary> private ResolvedControl ProcessObjectElement(DothtmlElementNode element, DataContextStack dataContext) { object[] constructorParameters; var controlMetadata = controlResolver.ResolveControl(element.TagPrefix, element.TagName, out constructorParameters); var control = new ResolvedControl(controlMetadata, element, dataContext) { ContructorParameters = constructorParameters }; var dataContextAttribute = element.Attributes.FirstOrDefault(a => a.AttributeName == "DataContext"); if (dataContextAttribute != null) { ProcessAttribute(dataContextAttribute, control, dataContext); } if (control.Properties.ContainsKey(DotvvmBindableObject.DataContextProperty) && control.Properties[DotvvmBindableObject.DataContextProperty] is ResolvedPropertyBinding) { dataContext = new DataContextStack( ((ResolvedPropertyBinding)control.Properties[DotvvmBindableObject.DataContextProperty]).Binding.GetExpression().Type, dataContext); control.DataContextTypeStack = dataContext; } if (controlMetadata.DataContextConstraint != null && !controlMetadata.DataContextConstraint.IsAssignableFrom(dataContext.DataContextType)) { throw new DotvvmCompilationException($"The control '{controlMetadata.Name}' requires a DataContext of type '{controlMetadata.DataContextConstraint.FullName}'!", element.Tokens); } // set properties from attributes foreach (var attribute in element.Attributes.Where(a => a.AttributeName != "DataContext")) { ProcessAttribute(attribute, control, dataContext); } var typeChange = DataContextChangeAttribute.GetDataContextExpression(dataContext, control); if (typeChange != null) { dataContext = new DataContextStack(typeChange, dataContext); } ProcessControlContent(element.Content, control); // check required properties var missingProperties = control.Metadata.Properties.Values.Where(p => p.MarkupOptions.Required && !control.Properties.ContainsKey(p)); if (missingProperties.Any()) { throw new DotvvmCompilationException($"The control '{ control.Metadata.Name }' is missing required properties: { string.Join(", ", missingProperties.Select(p => "'" + p.Name + "'")) }.", control.DothtmlNode.Tokens); } return(control); }
protected virtual void ApplyStyle(ResolvedControl control, DotvvmConfiguration configuration) { if (SetProperties != null) { foreach (var prop in SetProperties) { if (!control.Properties.ContainsKey(prop.Key) || prop.Value.Append) { control.SetProperty(prop.Value.Value, prop.Value.Append, out string error); } } } }
/// <summary> /// Processes the element which contains property value. /// </summary> private ResolvedPropertySetter ProcessElementProperty(ResolvedControl control, DotvvmProperty property, IEnumerable <DothtmlNode> elementContent) { var dataContext = control.DataContextTypeStack; var typeChange = DataContextChangeAttribute.GetDataContextExpression(dataContext, control, property); if (typeChange != null) { dataContext = new DataContextStack(typeChange, dataContext); } // the element is a property if (IsTemplateProperty(property)) { // template return(new ResolvedPropertyTemplate(property, ProcessTemplate(elementContent, dataContext))); } else if (IsCollectionProperty(property)) { // collection of elements var collection = FilterNodes <DothtmlElementNode>(elementContent, property) .Select(childObject => ProcessObjectElement(childObject, dataContext)); return(new ResolvedPropertyControlCollection(property, collection.ToList())); } else if (property.PropertyType == typeof(string)) { // string property var strings = FilterNodes <DothtmlLiteralNode>(elementContent, property); var value = string.Concat(strings.Select(s => s.Value)); return(new ResolvedPropertyValue(property, value)); } else if (IsControlProperty(property)) { // new object var children = FilterNodes <DothtmlElementNode>(elementContent, property).ToList(); if (children.Count > 1) { throw new DotvvmCompilationException($"The property '{property.MarkupOptions.Name}' can have only one child element!"); } else if (children.Count == 1) { return(new ResolvedPropertyControl(property, ProcessObjectElement(children[0], dataContext))); } else { return(new ResolvedPropertyControl(property, null)); } } else { throw new DotvvmCompilationException($"The property '{property.FullName}' is not supported!"); } }
public virtual void VisitControl(ResolvedControl control) { DefaultVisit(control); }