Example #1
0
        public void TestGetViewParamFromUrl()
        {
            S1Resource.ParserFactory = new DZParserFactory(null);
            S1Resource.HostList      = new List <string> {
                "http://220.196.42.167/2b/", "http://bbs.saraba1st.com/2b/"
            };
            string s0      = "http://220.196.42.167/2b/read-htm-tid-785763-page-54.html";
            string s1      = "http://bbs.saraba1st.com/2b/read-htm-tid-785763-page-54.html";
            string s2      = "http://bbs.saraba1st.com/2b/read.php?tid=785763&page=54#20636585";
            string s3      = "http://bbs.saraba1st.com/2b/simple/?t785763_54.html";
            string s4      = "http://bbs.saraba1st.com/2b/read-htm-tid-785763.html";
            string s5      = "http://bbs.saraba1st.com/2b/read.php?tid=785763";
            string s6      = "http://bbs.saraba1st.com/2b/simple/?t785763.html";
            string s7      = "http://bbs.saraba1st.com/2b/thread-785763-54-1.html";
            string expect  = "?ID=785763&Page=54";
            string expect2 = "?ID=785763";

            Assert.AreEqual(expect, S1Resource.GetThreadParamFromUrl(s0));
            Assert.AreEqual(expect, S1Resource.GetThreadParamFromUrl(s1));
            Assert.AreEqual(expect2, S1Resource.GetThreadParamFromUrl(s4));
            Assert.AreEqual(expect, S1Resource.GetThreadParamFromUrl(s2));
            Assert.AreEqual(expect2, S1Resource.GetThreadParamFromUrl(s5));
            Assert.AreEqual(expect, S1Resource.GetThreadParamFromUrl(s3));
            Assert.AreEqual(expect2, S1Resource.GetThreadParamFromUrl(s6));
            Assert.AreEqual(expect, S1Resource.GetThreadParamFromUrl(s7));
        }
Example #2
0
        private static Inline BuildLink(HtmlElement item)
        {
            Hyperlink link  = new Hyperlink();
            var       url   = item.Attributes["href"];
            var       aText = item.PlainText();

            if (url == null || aText.Length == 0)
            {
                return(link);
            }

            if (url.ToLower().StartsWith("mailto:"))
            {
                link.Click += (o, e) =>
                {
                    EmailComposeTask emailComposeTask = new EmailComposeTask();

                    emailComposeTask.To = url.Substring(url.IndexOf(':') + 1);

                    emailComposeTask.Show();
                };
            }

            S1Resource.GetAbsoluteUrl(ref url);
            var viewParam = S1Resource.GetThreadParamFromUrl(url);

            if (viewParam != null)
            {
                Run header = new Run();
                header.Text      = "<s1: ";
                header.FontStyle = FontStyles.Italic;
                link.Inlines.Add(header);
                link.Inlines.Add(aText);
                link.Inlines.Add("> ");
                link.NavigateUri = new Uri("/Views/PostView.xaml" + viewParam, UriKind.Relative);
            }
            else
            {
                try
                {
                    link.NavigateUri = new Uri(url);
                    link.TargetName  = "_blank";
                }
                catch (Exception) { };
                link.Inlines.Add(aText);
            }
            link.FontSize   = SettingView.ContentFontSize * .85;
            link.Foreground = (Brush)Application.Current.Resources["PhoneAccentBrush"];

            return(link);
        }