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()
        {
            TestInit();

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

            Assert.IsTrue(allControls.Any(c => c.DisplayText == "dot:TextBox"));
        }
        public void MetadataControlResolver_ReloadAllControls_PropertyMetadata()
        {
            TestInit();

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

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

            var itemTemplateProperty = resolver.GetMetadata("dot:Repeater").Properties.FirstOrDefault(p => p.Name == "ItemTemplate");
            Assert.IsTrue(itemTemplateProperty.IsTemplate);
            Assert.IsTrue(itemTemplateProperty.IsElement);
        }
Esempio n. 4
0
 public DothtmlCompletionSource(DothtmlCompletionSourceProvider sourceProvider, DothtmlParser parser, 
     DothtmlClassifier classifier, ITextBuffer textBuffer, VisualStudioWorkspace workspace, 
     IGlyphService glyphService, DTE2 dte, DotvvmConfigurationProvider 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;
 }
        private void FixElement(StringBuilder edit, MetadataControlResolver metadataControlResolver, ITextBuffer textBuffer, DothtmlElementNode 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<DothtmlElementNode>())
                {
                    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 ICompletionSource TryCreateCompletionSource(ITextBuffer textBuffer)
        {
            return textBuffer.Properties.GetOrCreateSingletonProperty(() =>
            {
                var classifierProvider = new DothtmlClassifierProvider()
                {
                    Registry = Registry
                };

                ConfigurationProvider = new DotvvmConfigurationProvider();
                MetadataControlResolver = new MetadataControlResolver();

                WatchWorkspaceChanges();

                Parser = new DothtmlParser();
                Classifier = (DothtmlClassifier)classifierProvider.GetClassifier(textBuffer);

                return new DothtmlCompletionSource(this, Parser, Classifier, textBuffer,
                    Workspace, GlyphService, CompletionHelper.DTE, ConfigurationProvider, MetadataControlResolver);
            });
        }
        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_AttributeProperty()
        {
            TestInit();

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

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

            Assert.IsNotNull(control);
            Assert.IsNull(property);        // the property cannot be used as element
        }
        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", "dot:Repeater", "ItemTemplate" }, out control, out property);

            Assert.IsNotNull(control);
            Assert.IsNotNull(property);
        }
        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"));
        }