Beispiel #1
0
        private LookupList GetTagLookupList(AspNetTag tag)
        {
            List <Type> controlTypes = GetTagControlTypes(tag);

            List <LookupListItem> lookupItems =
                new List <LookupListItem>();

            foreach (Type type in controlTypes)
            {
                LookupListItem item = GetItem(type);
                item.Category = QuickSharp.CodeAssist.Constants.WEBCONTROL;
                item.MenuItems.Clear();
                lookupItems.Add(item);
            }

            string insertionTemplate =
                String.Format("{0}>",
                              QuickSharp.CodeAssist.Constants.
                              INSERTION_TEMPLATE_TEXT_PLACEHOLDER);

            if (!tag.ClosingTag)
            {
                insertionTemplate = String.Format(
                    "{0} ID=\"{1}\" runat=\"server\"></{2}:{0}>",
                    QuickSharp.CodeAssist.Constants.
                    INSERTION_TEMPLATE_TEXT_PLACEHOLDER,
                    QuickSharp.CodeAssist.Constants.
                    INSERTION_TEMPLATE_CPOS_PLACEHOLDER,
                    tag.TagPrefix);
            }

            return(new LookupList(
                       tag.LookAhead, lookupItems, insertionTemplate));
        }
Beispiel #2
0
        private AspNetTag GetAspNetTag(string text)
        {
            text = CSharpFormattingTools.RemoveUnwantedText(text);

            string[] split1 = text.Split('<');
            string[] split2 = split1[split1.Length - 1].Split('>');
            string   tag    = split2[0];

            AspNetTag aspNetTag = new AspNetTag(text);

            if (split2.Length > 1)
            {
                return(null);
            }

            /*
             * Check tag is ASP.NET and get the type.
             */

            Regex re = new Regex(@"^/?(\w+):(\w*)(\s*)");
            Match m  = re.Match(tag);

            if (m.Success)
            {
                aspNetTag.TagPrefix      = m.Groups[1].Value;
                aspNetTag.LookAhead      = m.Groups[2].Value;
                aspNetTag.ClosingTag     = tag.StartsWith("/");
                aspNetTag.WantAttributes =
                    m.Groups[3].Value != String.Empty;

                return(aspNetTag);
            }

            return(null);
        }
Beispiel #3
0
        private List <Type> GetTagControlTypes(AspNetTag tag)
        {
            List <String> namespaceList = new List <String>();

            foreach (TagNamespace tn in GetTagNamespaces())
            {
                if (tn.TagPrefix == tag.TagPrefix &&
                    !namespaceList.Contains(tn.Namespace))
                {
                    namespaceList.Add(tn.Namespace);
                }
            }

            return(GetNamespaceControlTypes(namespaceList));
        }
Beispiel #4
0
 public async Task <IActionResult> OnPostCreateAsync(string tag)
 {
     if (!string.IsNullOrEmpty(tag))
     {
         if (!_context.AspNetTag.Any(t => t.Tag == tag))
         {
             AspNetTag aspNetTag = new AspNetTag()
             {
                 Tag = tag
             };
             _context.AspNetTag.Add(aspNetTag);
             _context.SaveChanges();
             StatusMessage = "Тег успешно добавлен!";
             return(RedirectToPage("./Tags"));
         }
         else
         {
             StatusMessage = "Тэг с таким же названием уже существует!";
             return(Page());
         }
     }
     StatusMessage = "Ошибка при добавлении тега!";
     return(Page());
 }
Beispiel #5
0
 private LookupList GetTagItemLookupList(AspNetTag tag)
 {
     return(null);
 }
Beispiel #6
0
        public virtual LookupList GetLookupList(ScintillaEditForm document)
        {
            /*
             * Read controls, assemblies and namespaces from the web.config.
             */

            ReadWebConfig();

            /*
             * Refresh the master namespace lists.
             */

            UpdateLists();

            /*
             * Colorize the ASP.NET tags. This just looks for
             * strings that look like tags, there is no attempt
             * to recognize them as valid types so no Code Assist
             * functionality is required.
             */

            Colorize(document);

            /*
             * Prepare the search content and target for
             * the code assist lookup. Get the full source
             * and the source up to the caret position.
             */

            string text = document.GetContent() as string;

            /*
             * Save all the content. Unlike the C# code
             * provider we are also interested in content after
             * the caret. (This is because of a shortcut in the
             * code provider where we treat the current scope as
             * only existing before the caret. We can mostly get
             * away with it in normal code but not here.)
             */

            _fullSource = text;

            /*
             * Now we have the source see if there are any extra
             * assemblies declared in the page.
             */

            AddDeclaredAssemblies(text);

            /*
             * Call the appropriate lookup provider.
             */

            int currentPos = document.Editor.CurrentPos;

            /*
             * Because scriptlets and directives have similar syntax,
             * directive check must come before the scriptlet test.
             */

            if (IsCodeSection(text, currentPos))            // <script runat="server">
            {
                return(GetCodeSectionLookupList(document, text));
            }
            else if (IsDirectiveSection(text, currentPos))  // <%@
            {
                return(GetDirectiveSectionLookupList(text, currentPos));
            }
            else if (IsScriptletSection(text, currentPos))  // <% or <%=
            {
                return(GetCodeSectionLookupList(document, text));
            }
            else // In a tag
            {
                text = text.Substring(0, currentPos);

                /*
                 * Look for a dollar expression (e.g. "<%$ AppSettings:MyVal " )
                 */

                Regex re    = new Regex(@"<%\$\s*(\w*)(:)?(\w*)(\s*)$");
                Match match = re.Match(text);

                if (match.Success)
                {
                    return(GetDollarExpressionLookupList(match));
                }

                /*
                 * Look for tags or tag attributes.
                 */

                AspNetTag tag = GetAspNetTag(text);

                if (tag != null)
                {
                    if (tag.WantAttributes)
                    {
                        return(GetTagAttributesLookupList(tag));
                    }
                    else
                    {
                        return(GetTagLookupList(tag));
                    }
                }
                else
                {
                    return(xhtmlProvider.GetXhtmlLookupList(document));
                }
            }
        }
Beispiel #7
0
        private LookupList GetTagAttributesLookupList(AspNetTag tag)
        {
            string controlName = tag.LookAhead.ToLower();
            Type   controlType = null;

            foreach (Type t in GetTagControlTypes(tag))
            {
                if (controlName == t.Name.ToLower())
                {
                    controlType = t;
                    break;
                }
            }

            if (controlType == null)
            {
                return(null);
            }

            /*
             * Get the public properties.
             */

            List <LookupListItem> items = new List <LookupListItem>();

            BindingFlags flags =
                BindingFlags.Public |
                BindingFlags.FlattenHierarchy |
                BindingFlags.Instance;

            List <String> foundNames = new List <String>();

            foreach (MethodInfo mi in controlType.GetMethods(flags))
            {
                if (!mi.Name.StartsWith("set_") &&
                    !mi.Name.StartsWith("add_"))
                {
                    continue;
                }

                string name = mi.Name.Substring(4);

                if (mi.Name.StartsWith("add_"))
                {
                    name = "On" + name;
                }

                if (foundNames.Contains(name))
                {
                    continue;
                }
                foundNames.Add(name);

                LookupListItem li = new LookupListItem();
                li.DisplayText = name;
                li.InsertText  = name;
                li.Category    = QuickSharp.CodeAssist.Constants.PROPERTIES;

                items.Add(li);
            }

            /*
             * Get the lookahead.
             */

            string lookAhead = String.Empty;

            string[] split = tag.Context.Split(' ');
            if (split[split.Length - 1] != String.Empty)
            {
                lookAhead = split[split.Length - 1];
            }

            lookAhead = lookAhead.Trim();

            string insertionTemplate = String.Format("{0}=\"{1}\"",
                                                     QuickSharp.CodeAssist.Constants.
                                                     INSERTION_TEMPLATE_TEXT_PLACEHOLDER,
                                                     QuickSharp.CodeAssist.Constants.
                                                     INSERTION_TEMPLATE_CPOS_PLACEHOLDER);

            return(new LookupList(lookAhead, items, insertionTemplate));
        }