Exemplo n.º 1
0
        public void Apply(PageRouteModel model)
        {
            var pageName = model.ViewEnginePath.Trim('/');
            var tokenizer = new StringTokenizer(pageName, new[] { '/' });
            int count = tokenizer.Count(), pathIndex = 0;

            for (var i = 0; i < count; i++)
            {
                var segment = tokenizer.ElementAt(i);

                if ("Pages" == segment)
                {
                    if (i < 2 || i == count - 1)
                    {
                        return;
                    }

                    foreach (var selector in model.Selectors)
                    {
                        selector.AttributeRouteModel.SuppressLinkGeneration = true;
                    }

                    var module = tokenizer.ElementAt(i - 1).Value;

                    var template = pageName.Substring(pathIndex - (module.Length + 1));

                    model.Selectors.Add(new SelectorModel
                    {
                        AttributeRouteModel = new AttributeRouteModel
                        {
                            Template = template,
                            Name     = template.Replace('/', '.')
                        }
                    });

                    var extensionManager = _httpContextAccessor.HttpContext.RequestServices.GetService <IExtensionManager>();
                    var name             = extensionManager.GetExtension(module).Manifest.Name;

                    if (!String.IsNullOrWhiteSpace(name))
                    {
                        module = name;
                    }

                    template = module + pageName.Substring(pathIndex + "Pages".Length);

                    model.Selectors.Add(new SelectorModel
                    {
                        AttributeRouteModel = new AttributeRouteModel
                        {
                            Template = template,
                            Name     = template.Replace('/', '.')
                        }
                    });

                    break;
                }

                pathIndex += segment.Length + 1;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Main function for parsing process
        /// </summary>
        /// <param name="text">text to parse</param>
        /// <param name="baseForeColor">base Font color</param>
        /// <param name="baseFont">base font</param>
        /// <param name="fontSize">base font size</param>
        /// <param name="aligment">base textaligment</param>
        /// <param name="fontStyle"> base font style etc. Regular, Bold</param>
        /// <returns>Formatted text block that contains the whole structure</returns>
        public static FormattedTextBlock Parse(string text, Color baseForeColor, string baseFont, float fontSize, FontStyle fontStyle, ContentAlignment aligment)
        {
            if (string.IsNullOrEmpty(text))
            {
                return(new FormattedTextBlock());
            }

            Stack <FormattedText.HTMLLikeListType> lastListType = new Stack <FormattedText.HTMLLikeListType>();

            lastListType.Push(FormattedText.HTMLLikeListType.None);
            text = text.Replace("\\<", "&lt;").Replace("\\>", "&gt;").Replace("\r\n", "<br>").Replace("\n", "<br>");

            //prepare initially block
            FormattedTextBlock textBlock             = new FormattedTextBlock();
            FormattedText      previousFormattedText = new FormattedText();//this is a base item for creating HTML

            previousFormattedText.FontColor        = baseForeColor;
            previousFormattedText.FontName         = baseFont;
            previousFormattedText.FontSize         = fontSize;
            previousFormattedText.ContentAlignment = aligment;
            previousFormattedText.FontStyle        = fontStyle;

            //create tokens
            StringTokenizer tokenizer   = new StringTokenizer(text, "<");
            int             count       = tokenizer.Count();
            bool            hasOpenTag  = text.IndexOf("<") > -1;
            TextLine        currentLine = new TextLine();

            textBlock.Lines.Add(currentLine);
            bool shouldProduceNewLine = false;

            TinyHTMLParsersData parsersData = new TinyHTMLParsersData();

            //enumerate tokens
            for (int i = 0; i < count; ++i)
            {
                FormattedText currentItem = ProcessToken(ref previousFormattedText, tokenizer, hasOpenTag, parsersData, ref shouldProduceNewLine);

                if (!string.IsNullOrEmpty(currentItem.HtmlTag) &&
                    currentItem.HtmlTag.Length >= 1 && shouldProduceNewLine)
                {
                    currentLine = new TextLine();
                    textBlock.Lines.Add(currentLine);
                    if (currentItem.HtmlTag.Length >= 2)
                    {
                        currentItem.HtmlTag = currentItem.HtmlTag.TrimEnd(' ').Trim('/');
                    }

                    shouldProduceNewLine = (!string.IsNullOrEmpty(currentItem.text) && currentItem.text.Trim().Length == 0);
                }

                currentLine.List.Add(currentItem);
                previousFormattedText = new FormattedText(currentItem);
            }

            return(textBlock);
        }
Exemplo n.º 3
0
        public static FormattedTextBlock Parse(
            string text,
            Color baseForeColor,
            string baseFont,
            float fontSize,
            FontStyle fontStyle,
            ContentAlignment aligment)
        {
            if (string.IsNullOrEmpty(text))
            {
                return(new FormattedTextBlock());
            }
            new Stack <FormattedText.HTMLLikeListType>().Push(FormattedText.HTMLLikeListType.None);
            text = text.Replace("\\", "[CDATA[\\]]");
            text = text.Replace("\\<", "&lt;");
            text = text.Replace("\\>", "&gt;");
            text = text.Replace("\r\n", "<br>");
            text = text.Replace("\n", "<br>");
            FormattedTextBlock formattedTextBlock = new FormattedTextBlock();
            FormattedText      prevItem           = new FormattedText();

            prevItem.FontColor        = baseForeColor;
            prevItem.FontName         = baseFont;
            prevItem.FontSize         = fontSize;
            prevItem.ContentAlignment = aligment;
            prevItem.FontStyle        = fontStyle;
            StringTokenizer tokenizer  = new StringTokenizer(text, "<");
            int             num        = tokenizer.Count();
            bool            hasOpenTag = text.IndexOf("<") > -1;
            TextLine        textLine   = new TextLine();

            formattedTextBlock.Lines.Add(textLine);
            bool shouldProduceNewLine = false;

            TinyHTMLParsers.TinyHTMLParsersData parserData = new TinyHTMLParsers.TinyHTMLParsersData();
            for (int index = 0; index < num; ++index)
            {
                FormattedText prototypeFormattedText = TinyHTMLParsers.ProcessToken(ref prevItem, tokenizer, hasOpenTag, parserData, ref shouldProduceNewLine);
                if (!string.IsNullOrEmpty(prototypeFormattedText.HtmlTag) && prototypeFormattedText.HtmlTag.Length >= 1 && shouldProduceNewLine)
                {
                    textLine = new TextLine();
                    formattedTextBlock.Lines.Add(textLine);
                    if (prototypeFormattedText.HtmlTag.Length >= 2)
                    {
                        prototypeFormattedText.HtmlTag = prototypeFormattedText.HtmlTag.TrimEnd(' ').Trim('/');
                    }
                    shouldProduceNewLine = !string.IsNullOrEmpty(prototypeFormattedText.text) && prototypeFormattedText.text.Trim().Length == 0;
                }
                textLine.List.Add(prototypeFormattedText);
                prevItem = new FormattedText(prototypeFormattedText);
            }
            return(formattedTextBlock);
        }
Exemplo n.º 4
0
    public static (bool Valid, string Message) IsDocumentIdValid(this string documentId)
    {
        const string syntax = "[{container}:]{path}[/{path}...]";

        if (documentId.IsEmpty())
        {
            return(false, "Id required");
        }

        IReadOnlyList <IToken> tokens = new StringTokenizer()
                                        .Add(":", "/")
                                        .Parse(documentId);

        int containerSymbolCount = tokens.Count(x => x.Value == ":");

        if (containerSymbolCount > 1)
        {
            return(false, $"Invalid container, cannot have more then one ':', {syntax}");
        }
        if (containerSymbolCount == 1 && (tokens.Count <= 1 || tokens[1].Value != ":"))
        {
            return(false, $"Invalid container, {syntax}");
        }
        if (containerSymbolCount == 0 && tokens.Where(filterSyntax).Count() == 0)
        {
            return(false, $"No path, {syntax}");
        }
        if (tokens.Last().Value == ":")
        {
            return(false, $"Cannot end with ':', {syntax}");
        }
        if (tokens.Last().Value == "/")
        {
            return(false, $"Cannot end with '/', {syntax}");
        }

        string?error = tokens
                       .Where(filterSyntax)
                       .Select(x => testVector(x.Value))
                       .FirstOrDefault(x => x != null);

        return(error != null ? (false, error) : (true, String.Empty));
Exemplo n.º 5
0
        public void Apply(PageRouteModel model)
        {
            var pageName = model.ViewEnginePath.Trim('/');
            var tokenizer = new StringTokenizer(pageName, new[] { '/' });
            int count = tokenizer.Count(), pathIndex = 0;

            for (var i = 0; i < count; i++)
            {
                var segment = tokenizer.ElementAt(i);

                if ("Pages" == segment)
                {
                    if (i < 2 || i == count - 1)
                    {
                        return;
                    }

                    foreach (var selector in model.Selectors)
                    {
                        selector.AttributeRouteModel.SuppressLinkGeneration = true;
                    }

                    var module = tokenizer.ElementAt(i - 1).Value;

                    var template = pageName.Substring(pathIndex - (module.Length + 1));

                    model.Selectors.Add(new SelectorModel
                    {
                        AttributeRouteModel = new AttributeRouteModel
                        {
                            Template = template,
                            Name     = template.Replace('/', '.')
                        }
                    });

                    var name = _hostingEnvironment.GetModule(module).ModuleInfo.Name;

                    if (!String.IsNullOrWhiteSpace(name))
                    {
                        module = name;
                    }

                    if (module != Application.ModuleName)
                    {
                        template = module + pageName.Substring(pathIndex + "Pages".Length);
                    }
                    else
                    {
                        template = pageName.Substring(pathIndex + "Pages".Length + 1);
                    }


                    model.Selectors.Add(new SelectorModel
                    {
                        AttributeRouteModel = new AttributeRouteModel
                        {
                            Template = template,
                            Name     = template.Replace('/', '.')
                        }
                    });

                    break;
                }

                pathIndex += segment.Length + 1;
            }
        }