示例#1
0
        public PostRoot GetPost()
        {
            string   post = GetPostData();
            PostRoot pr   = JsonConvert.DeserializeObject <PostRoot>(post);

            return(pr);
        }
        public IActionResult Index()
        {
            PostRoot pr       = new PostRoot();
            PostData basePath = pr.data.children[0].data;
            string   title    = basePath.title;
            string   image    = basePath.thumbnail;
            string   url      = "reddit.com" + basePath.permalink;

            RedditTrimmedModel rtm = new RedditTrimmedModel();

            rtm.Title    = title;
            rtm.ImageUrl = image;
            rtm.LinkUrl  = url;
            return(View(rtm));
        }
示例#3
0
        private void webClient_OpenReadCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            if (e.Cancelled)
            {
                return;
            }
            Dispatcher.BeginInvoke(() =>
            {
                value          = JsonConvert.DeserializeObject <PostRoot>(e.Result);
                var caption    = value.post.title.Split('.', '!', '?');
                tbCaption.Text = caption[0];
                // Need some smarter trim here, for O.Henry for example
                if (caption.Length > 1)
                {
                    tbCaptionAuthor.Text = value.post.title.Replace(caption[0], "").Trim(new char[] { '.', '!', '?' });
                }
                //if (NavigationContext.QueryString["b"] != null)
                //{
                //    value.post.content = "<div style='background-color:black;color:white;margin:0;padding:0'>" + value.post.content + "</div>";
                //ContentWebBrowser.Background = new SolidColorBrush(Colors.Black);
                //}

                ShowReadDuration(value.post.content);
                ContentWebBrowser.NavigateToString(InjectedString(value.post.content));
                pi.IsVisible = false;

                // Save downloaded story to HISTORY
                StoryRepository.AddNewStory(value.post.title,
                                            DateTime.Parse(value.post.date),
                                            value.post.url,
                                            value.post.content, false, null);

                ApplicationBarMenuItem mi = ApplicationBar.MenuItems[1] as ApplicationBarMenuItem;
                if (mi != null)
                {
                    mi.Text = StoryRepository.CheckStoryTitle(value.post.title, true) ? RemoveFromFavoritsString : AddToFavoritsString;
                }
            });
        }
示例#4
0
        void DetailsView_Loaded(object sender, RoutedEventArgs e)
        {
            string itemURL = "";
            string randURI = "";
            string title   = "";

            pi.IsIndeterminate = true;
            pi.IsVisible       = true;
            SystemTray.SetProgressIndicator(this, pi);

            if (NavigationContext.QueryString.TryGetValue("title", out title))
            {
                var story = StoryRepository.GetSingleStoryByTitle(title);
                if (story != null && !story.Details.Contains("[..."))
                {
                    value            = new PostRoot();
                    value.post       = new Post();
                    value.post.title = story.Title;
                    value.post.url   = story.Link;
                    ContentWebBrowser.NavigateToString(InjectedString(story.Details));
                    pi.IsVisible = false;
                    var caption = story.Title.Split(new char[] { '.', '!', '?' });

                    tbCaption.Text = caption[0];
                    // Need some smarter trim here, for O.Henry for example
                    if (caption.Length > 1)
                    {
                        tbCaptionAuthor.Text = value.post.title.Replace(caption[0], "").Trim(new char[] { '.', '!', '?' });
                    }
                    return;
                }
            }
            wc = new WebClient();
            wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(webClient_OpenReadCompleted);

            if (NavigationContext.QueryString.TryGetValue("item", out itemURL))
            {
                itemURL = HttpUtility.UrlDecode(itemURL);

                try
                {
                    wc.DownloadStringAsync(new Uri(itemURL + "?json=1"));
                }
                catch (Exception exception)
                {
                    BugSenseHandler.Instance.LogError(exception);
                    pi.IsVisible = false;
                }
            }
            if (NavigationContext.QueryString.TryGetValue("randURI", out randURI))
            {
                try
                {
                    string         tURL    = HttpUtility.UrlDecode(randURI);
                    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri(HttpUtility.UrlDecode(randURI)));
                    request.Method = "HEAD";
                    request.AllowReadStreamBuffering = false;
                    // Start the asynchronous request.


                    request.BeginGetResponse(new AsyncCallback(GetResponseCallback), request);
                }
                catch (Exception exception)
                {
                    BugSenseHandler.Instance.LogError(exception);
                    pi.IsVisible = false;
                }
            }
        }
示例#5
0
        private static string FastConvertExtendedASCII(string HTML)
        {
            char[] s = HTML.ToCharArray();

            // Getting number of characters to be converted
            // and calculate extra space
            int n = 0;
            int value;

            foreach (char c in s)
            {
                if ((value = Convert.ToInt32(c)) > 127)
                {
                    if (value > 9999)
                    {
                        n += 7;
                    }
                    else if (value > 999)
                    {
                        n += 6;
                    }
                    else
                    {
                        n += 5;
                    }
                }
            }

            // To avoid new string instantiating
            // allocate memory buffer for final string
            char[] res = new char[HTML.Length + n];

            // Conversion
            int       i = 0;
            int       div;
            const int zero = (int)'0';

            foreach (char c in s)
            {
                if ((value = Convert.ToInt32(c)) > 127)
                {
                    res[i++] = '&';
                    res[i++] = '#';

                    if (value > 9999)
                    {
                        div = 10000;
                    }
                    else if (value > 999)
                    {
                        div = 1000;
                    }
                    else
                    {
                        div = 100;
                    }

                    while (div > 0)
                    {
                        res[i++] = (char)(zero + value / div);
                        value   %= div;
                        div     /= 10;
                    }

                    res[i++] = ';';
                }
                else
                {
                    res[i] = c;
                    i++;
                }
            }

            return(new string(res));
        }