示例#1
0
        public override string OnLinkOpen(LinkElement element)
        {
            switch (element.Link.Type)
            {
            case LinkType.Command:
                CommandLink command = (CommandLink)element.Link;
                return(this.prefix.Peek() + "command=" + command.Command + "\n");

            case LinkType.Window:
                WindowLink el = (WindowLink)element.Link;
                Formatter  f  = new TextFormatter(this.prefix.Peek() + "| ");
                return(f.Format(el.Element));

            case LinkType.Item:
                ItemLink item = (ItemLink)element.Link;
                return(this.prefix.Peek() +
                       "lid=" + item.LowID.ToString() +
                       " hid=" + item.HighID.ToString() +
                       " ql=" + item.Quality.ToString() + "\n");

            case LinkType.User:
                UserLink user = (UserLink)element.Link;
                return(this.prefix.Peek() + "character=" + user.Character + "\n");

            case LinkType.Other:
                OtherLink other = (OtherLink)element.Link;
                return(this.prefix.Peek() + "uri=" + other.Uri.ToString() + "\n");

            case LinkType.Invalid:
                InvalidLink invalid = (InvalidLink)element.Link;
                return(this.prefix.Peek() + "uri=" + invalid.Raw + "\n");

            default:
                return(this.prefix.Peek() +
                       "unknown LinkType: " +
                       element.Link.Type.ToString() + "\n");
            }
        }
示例#2
0
        public override string OnLinkOpen(LinkElement element)
        {
            // Transform link
            string href  = "";
            string title = "";

            switch (element.Link.Type)
            {
            case LinkType.Command:
                CommandLink command = (CommandLink)element.Link;
                href  = "chatcmd://" + HttpUtility.UrlEncode(command.Command);
                title = Web.EscapeHtml(command.Command);
                break;

            case LinkType.Window:
                WindowLink window = (WindowLink)element.Link;
                href = "text://" + this._cache.CacheElement(window.Element).ToString();
                break;

            case LinkType.Item:
                ItemLink item = (ItemLink)element.Link;
                href = string.Format("itemref://{0}/{1}/{2}",
                                     item.LowID, item.HighID, item.Quality);
                title = href;
                break;

            case LinkType.Entity:
                EntityLink entity = (EntityLink)element.Link;
                href = string.Format("itemid://{0}/{1}",
                                     entity.TypeID, entity.InstanceID);
                title = href;
                break;

            case LinkType.User:
                UserLink user = (UserLink)element.Link;
                href  = "character://" + HttpUtility.UrlEncode(user.Character);
                title = Web.EscapeHtml(user.Character);
                break;

            case LinkType.Other:
                OtherLink other = (OtherLink)element.Link;
                href  = other.Uri.ToString();
                title = Web.EscapeHtml(href);
                break;

            case LinkType.Invalid:
                InvalidLink invalid = (InvalidLink)element.Link;
                href  = "";    // Leave link empty as it's potentially harmfull
                title = Web.EscapeHtml(invalid.Raw);
                break;
            }
            // Handle 'no-style' links
            string style = "";

            if (!element.Stylized)
            {
                // Find parent color
                Color   color  = null;
                Element parent = element;
                if (this._style != TextStyle.Strip)
                {
                    while ((parent = parent.Parent) != null)
                    {
                        if (parent.Type != ElementType.Color)
                        {
                            continue;
                        }
                        color = ((ColorElement)parent).Color;
                        break;
                    }
                }
                // Transform color into a html style
                if (color != null)
                {
                    if (this._style == TextStyle.Invert)
                    {
                        color = _invert(color);
                    }
                    style = string.Format(
                        " class=\"NoStyle\" style=\"color: #{0:X2}{1:X2}{2:X2}\"",
                        color.Red, color.Green, color.Blue);
                }
                else
                {
                    style = " class=\"NoStyle\"";
                }
            }
            return(string.Format("<a href=\"{0}\" title=\"{1}\"{2}>", href, Web.EscapeHtml(title), style));
        }
示例#3
0
        protected Element CreateLinkElement(OpenNode node)
        {
            // Valid link?
            string href = node.GetAttribute("href");

            if (string.IsNullOrEmpty(href) || !href.Contains("://"))
            {
                return(new ContainerElement());
            }
            // Parse link
            int index = href.IndexOf("://");

            if (index <= 0)
            {
                return(new ContainerElement());
            }
            string  type          = href.Substring(0, index).ToLower();
            string  argument      = href.Substring(index + 3);
            Link    link          = null;
            Element windowElement = null;
            // Verify header
            Regex validCharacters = new Regex("^[a-zA-Z]+$");

            if (!validCharacters.IsMatch(type) || argument.Length == 0)
            {
                // Invalid link
                link = new InvalidLink(href);
            }
            else
            {
                // Generate link
                switch (type)
                {
                case "text":
                    windowElement = Parse(argument);
                    if (windowElement == null)
                    {
                        break;
                    }
                    link = new WindowLink(windowElement);
                    break;

                case "charref":
                    index = argument.IndexOf("/");
                    if (index < 0)
                    {
                        break;
                    }
                    index = argument.IndexOf("/", index + 1);
                    if (index <= 0)
                    {
                        break;
                    }
                    argument      = argument.Substring(index + 1);
                    windowElement = Parse(argument);
                    if (windowElement == null)
                    {
                        break;
                    }
                    link = new WindowLink(windowElement);
                    break;

                case "itemref":
                    string[] itemParts = argument.Split('/');
                    if (itemParts.Length != 3)
                    {
                        break;
                    }
                    uint lowId, highId, ql;
                    if (!uint.TryParse(itemParts[0], out lowId))
                    {
                        break;
                    }
                    if (!uint.TryParse(itemParts[1], out highId))
                    {
                        break;
                    }
                    if (!uint.TryParse(itemParts[2], out ql))
                    {
                        break;
                    }
                    link = new ItemLink(lowId, highId, ql);
                    break;

                case "itemid":
                    string[] entityParts = argument.Split('/');
                    // itemid:// can come with 4 arguments, but we have no use for the last 2
                    if (entityParts.Length != 2 && entityParts.Length != 4)
                    {
                        break;
                    }
                    uint typeId, instanceId;
                    if (!uint.TryParse(entityParts[0], out typeId))
                    {
                        break;
                    }
                    if (!uint.TryParse(entityParts[1], out instanceId))
                    {
                        break;
                    }
                    link = new EntityLink(typeId, instanceId);
                    break;

                case "chatcmd":
                    link = new CommandLink(argument);
                    break;

                case "user":
                    link = new UserLink(argument);
                    break;

                default:
                    try
                    {
                        // Attempt to create an 'OtherLink'
                        // this operation will throw an exception if the 'href' is significantly malformed
                        link = new OtherLink(href);
                    }
                    catch (UriFormatException)
                    {
                        // The 'href' is malformed, store as InvalidLink
                        link = new InvalidLink(href);
                    }
                    break;
                }
            }
            if (link == null)
            {
                return(new ContainerElement());
            }
            string style = node.GetAttribute("style");

            if (style != null)
            {
                style = style.Replace(" ", "").ToLower();
                if (!style.Contains("text-decoration:none"))
                {
                    style = null;
                }
            }
            return(new LinkElement(link, style == null));
        }
示例#4
0
        public void ButtonWindowLinkCommand()
        {
            WindowLink windowLink = new WindowLink();

            windowLink.ShowDialog();
        }
示例#5
0
        public override string OnLinkOpen(LinkElement element)
        {
            string href  = "";
            string style = "";

            switch (element.Link.Type)
            {
            case LinkType.Command:
                CommandLink command = (CommandLink)element.Link;
                href = "chatcmd://" + Web.EscapeHtml(command.Command);
                break;

            case LinkType.Window:
                WindowLink window = (WindowLink)element.Link;
                Formatter  f      = null;
                if (this.Style == AomlFormatterStyle.DoubleQuote)
                {
                    f = new AomlFormatter(AomlFormatterStyle.SingleQuote);
                }
                else
                {
                    f = new PlainTextFormatter();
                }
                href = "text://" + f.Format(window.Element);
                break;

            case LinkType.Item:
                ItemLink item = (ItemLink)element.Link;
                href = string.Format("itemref://{0}/{1}/{2}",
                                     item.LowID,
                                     item.HighID,
                                     item.Quality);
                break;

            case LinkType.Entity:
                EntityLink entity = (EntityLink)element.Link;
                href = string.Format("itemid://{0}/{1}",
                                     entity.TypeID,
                                     entity.InstanceID);
                break;

            case LinkType.User:
                UserLink user = (UserLink)element.Link;
                href = "user://" + Web.EscapeHtml(user.Character);
                break;

            case LinkType.Other:
                OtherLink other = (OtherLink)element.Link;
                href = other.Uri.ToString();
                break;

            case LinkType.Invalid:
                href = "";     // Leave empty as it's potentially harmful
                break;
            }
            if (!element.Stylized)
            {
                style = string.Format(" style={0}text-decoration:none{0}", this.Quote);
            }
            return(string.Format("<a href={0}{1}{0}{2}>",
                                 this.Quote,
                                 href,
                                 style));
        }