Exemplo n.º 1
0
        public XDoc StockChart(
            [DekiExtParam("stock ticker symbol")] string symbol
            )
        {
            // check keys
            string app = Config["finance-app-id"].AsText;
            string sig = Config["finance-sig"].AsText;

            if (string.IsNullOrEmpty(app) || string.IsNullOrEmpty(sig))
            {
                return(new XDoc("html").Start("body").Start("span").Attr("style", "color:red;font-weight:bold;").Value("The Yahoo! Finance Application ID or Signature are missing").End().End());
            }

            // create control
            symbol = symbol.ToUpperInvariant();
            XDoc result = new XDoc("html").Start("body").Start("iframe")
                          .Attr("allowtransparency", "true")
                          .Attr("marginwidth", "0")
                          .Attr("marginheight", "0")
                          .Attr("hspace", "0")
                          .Attr("vspace", "0")
                          .Attr("frameborder", "0")
                          .Attr("scrolling", "no")
                          .Attr("src", string.Format("http://api.finance.yahoo.com/instrument/1.0/{0}/badge;chart=1y;quote/HTML?AppID={1}&sig={2}", XUri.EncodeSegment(symbol), XUri.EncodeQuery(app), XUri.EncodeQuery(sig)))
                          .Attr("width", "200px")
                          .Attr("height", "390px")
                          .Start("a").Attr("href", "http://finance.yahoo.com").Value("Yahoo! Finance").End()
                          .Elem("br")
                          .Start("a").Attr("href", "http://finance.yahoo.com/q?s=^GSPC/").Value("Quote for ^GSPC").End()
                          .End().End();

            return(result);
        }
Exemplo n.º 2
0
 public void EncodeQuery()
 {
     Assert.AreEqual("a^b|c", XUri.EncodeQuery("a^b|c"));
 }
Exemplo n.º 3
0
        /// <summary>
        /// Retrieves the title as a ui uri segment (ui urls can be used to access pages by pre-pending the ui host).  The output is db encoded.
        /// Ex. "index.php?title=User:Admin/MyPage", "User:Admin/MyPage"
        /// </summary>
        public string AsUiUriPath(bool forceUseIndexPhp)
        {
            string path;
            string dbPath = XUri.Decode(AsUnprefixedDbPath());

            if (forceUseIndexPhp)
            {
                path = INDEX_PHP_TITLE + AppendFilenameQueryAnchor(NSAndPathToString(Namespace, XUri.EncodeQuery(dbPath).Replace("+", "%2b")), true);
            }
            else
            {
                // returns the title in a wiki ui consumable form
                StringBuilder pathBuilder = new StringBuilder();
                string[]      segments    = AsDbSegments(dbPath);
                bool          useIndexPhp = false;
                foreach (string segment in segments)
                {
                    if (-1 < segment.IndexOfAny(INDEX_PHP_CHARS))
                    {
                        useIndexPhp = true;
                        break;
                    }
                    if (0 < pathBuilder.Length)
                    {
                        pathBuilder.Append("/");
                    }
                    pathBuilder.Append(XUri.EncodeSegment(segment));
                }
                if (useIndexPhp)
                {
                    path = INDEX_PHP_TITLE + AppendFilenameQueryAnchor(NSAndPathToString(Namespace, XUri.EncodeQuery(dbPath).Replace("+", "%2b")), true);
                }
                else
                {
                    path = AppendFilenameQueryAnchor(NSAndPathToString(Namespace, pathBuilder.ToString().Replace("?", "%3f")), false);
                }
            }

            // URL encode ?'s so they don't get confused for the query and add the filename, anchor and query
            return(path);
        }