Esempio n. 1
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;
                }
            }
        }