public void MetadataControlResolver_AttachedPropertyEnumValues()
        {
            TestInit();

            var resolver = new MetadataControlResolver();
            var values = resolver.GetControlAttributeValues(context, new List<string>() { "html" }, "RenderSettings.Mode");

            Assert.IsTrue(values.Any(v => v.DisplayText == "Server"));
            Assert.IsTrue(values.Any(v => v.DisplayText == "Client"));
        }
        public void MetadataControlResolver_ElementContext_ElementProperty()
        {
            TestInit();

            var resolver = new MetadataControlResolver();
            var allControls = resolver.ReloadAllControls(context);

            ControlMetadata control;
            ControlPropertyMetadata property;
            resolver.GetElementContext(new List<string>() { "html", "body", "rw:Repeater", "ItemTemplate" }, out control, out property);

            Assert.IsNotNull(control);
            Assert.IsNotNull(property);
        }
        public void MetadataControlResolver_ElementContext_AttributeProperty()
        {
            TestInit();

            var resolver = new MetadataControlResolver();
            var allControls = resolver.ReloadAllControls(context);

            ControlMetadata control;
            ControlPropertyMetadata property;
            resolver.GetElementContext(new List<string>() { "html", "body", "rw:Repeater", "WrapperTagName" }, out control, out property);

            Assert.IsNotNull(control);
            Assert.IsNull(property);        // the property cannot be used as element
        }
Example #4
0
 public RwHtmlCompletionSource(RwHtmlCompletionSourceProvider sourceProvider, RwHtmlParser parser, 
     RwHtmlClassifier classifier, ITextBuffer textBuffer, VisualStudioWorkspace workspace, 
     IGlyphService glyphService, DTE2 dte, RedwoodConfigurationProvider configurationProvider,
     MetadataControlResolver metadataControlResolver)
 {
     this.sourceProvider = sourceProvider;
     this.textBuffer = textBuffer;
     this.classifier = classifier;
     this.parser = parser;
     this.workspace = workspace;
     this.glyphService = glyphService;
     this.dte = dte;
     this.configurationProvider = configurationProvider;
     this.MetadataControlResolver = metadataControlResolver;
 }
        public ICompletionSource TryCreateCompletionSource(ITextBuffer textBuffer)
        {
            return textBuffer.Properties.GetOrCreateSingletonProperty(() =>
            {
                var classifierProvider = new RwHtmlClassifierProvider()
                {
                    Registry = Registry
                };

                ConfigurationProvider = new RedwoodConfigurationProvider();
                MetadataControlResolver = new MetadataControlResolver();

                WatchWorkspaceChanges();

                Parser = new RwHtmlParser();
                Classifier = (RwHtmlClassifier)classifierProvider.GetClassifier(textBuffer);

                return new RwHtmlCompletionSource(this, Parser, Classifier, textBuffer,
                    Workspace, GlyphService, CompletionHelper.DTE, ConfigurationProvider, MetadataControlResolver);
            });
        }
        private void FixElement(StringBuilder edit, MetadataControlResolver metadataControlResolver, ITextBuffer textBuffer, RwHtmlElementNode element)
        {
            // fix element name
            var metadata = metadataControlResolver.GetMetadata(element.FullTagName);
            if (metadata != null)
            {
                // we have found the metadata for the control
                if (metadata.FullTagName != element.FullTagName)
                {
                    // the used name differs from the correct, fix the tag name
                    edit.SetRange(element.TagPrefixToken.StartPosition, element.TagPrefixToken.Length, metadata.TagPrefix);
                    edit.SetRange(element.TagNameToken.StartPosition, element.TagNameToken.Length, metadata.TagName);

                    if (element.CorrespondingEndTag != null)
                    {
                        edit.SetRange(element.CorrespondingEndTag.TagPrefixToken.StartPosition, element.CorrespondingEndTag.TagPrefixToken.Length, metadata.TagPrefix);
                        edit.SetRange(element.CorrespondingEndTag.TagNameToken.StartPosition, element.CorrespondingEndTag.TagNameToken.Length, metadata.TagName);
                    }
                }

                // fix attribute names
                foreach (var attribute in element.Attributes)
                {
                    var property = metadata.GetProperty(attribute.AttributeName);
                    if (property != null && property.Name != attribute.AttributeName)
                    {
                        // the used name differs from the correct, fix the tag name
                        edit.SetRange(attribute.AttributeNameToken.StartPosition, attribute.AttributeNameToken.Length, property.Name);
                    }
                }

                // fix property elements
                foreach (var child in element.Content.OfType<RwHtmlElementNode>())
                {
                    var property = metadata.GetProperty(child.FullTagName);
                    if (property != null && property.IsElement && property.Name != child.FullTagName)
                    {
                        // the used name differs from the correct, fix the tag name
                        edit.SetRange(child.TagNameToken.StartPosition, child.TagNameToken.Length, property.Name);
                        if (child.CorrespondingEndTag != null)
                        {
                            edit.SetRange(child.CorrespondingEndTag.TagNameToken.StartPosition, child.CorrespondingEndTag.TagNameToken.Length, property.Name);
                        }
                    }
                }
            }
        }
        public void MetadataControlResolver_ElementContext_HtmlGenericControl()
        {
            TestInit();

            var resolver = new MetadataControlResolver();
            var allControls = resolver.ReloadAllControls(context);

            ControlMetadata control;
            ControlPropertyMetadata property;
            resolver.GetElementContext(new List<string>() { "html" }, out control, out property);

            Assert.IsNotNull(control);
            Assert.IsNull(property);

            Assert.IsTrue(control.Properties.Any(p => p.Name == "Visible"));
            Assert.IsTrue(control.Properties.Any(p => p.Name == "DataContext"));
        }
        public void MetadataControlResolver_ReloadAttachedProperties()
        {
            TestInit();

            var resolver = new MetadataControlResolver();
            var attachedProperties = resolver.GetAttachedPropertyNames(context);

            Assert.IsTrue(attachedProperties.Any(c => c.DisplayText == "RenderSettings.Mode"));
        }
        public void MetadataControlResolver_ReloadAllControls_PropertyMetadata()
        {
            TestInit();

            var resolver = new MetadataControlResolver();
            var allControls = resolver.ReloadAllControls(context);

            var repeater = allControls.FirstOrDefault(c => c.DisplayText == "rw:Repeater");

            var itemTemplateProperty = resolver.GetMetadata("rw:Repeater").Properties.FirstOrDefault(p => p.Name == "ItemTemplate");
            Assert.IsTrue(itemTemplateProperty.IsTemplate);
            Assert.IsTrue(itemTemplateProperty.IsElement);
        }
        public void MetadataControlResolver_ReloadAllControls()
        {
            TestInit();

            var resolver = new MetadataControlResolver();
            var allControls = resolver.ReloadAllControls(context);

            Assert.IsTrue(allControls.Any(c => c.DisplayText == "rw:TextBox"));
        }