示例#1
0
        private async void postCommentButton_Click(object sender, RoutedEventArgs e)
        {
            progressRing.Visibility = Visibility.Visible;
            var name    = NameText.Text;
            var email   = MailText.Text;
            var content = CommentText.Text;

            string template = "post_id={0}&name={1}&email={2}&content={3}";
            string postData = string.Format(template, post_id, name, email, content);

            byte[]     byteArray = Encoding.UTF8.GetBytes(postData);
            WebRequest request   = HttpWebRequest.Create(App.BLOG_URL + "?json=submit_comment");

            request.Method      = "POST";
            request.ContentType = "application/x-www-form-urlencoded";
            Stream dataStream = await request.GetRequestStreamAsync();

            await dataStream.WriteAsync(byteArray, 0, byteArray.Length);

            try
            {
                WebResponse response = await request.GetResponseAsync();

                dataStream = response.GetResponseStream();
                StreamReader reader             = new StreamReader(dataStream);
                string       responseFromServer = await reader.ReadToEndAsync();

                var deserialized_response = JsonConvert.DeserializeObject <ServerResponse>(responseFromServer);
                if (deserialized_response.status != "error")
                {
                    StatusBlock.Foreground  = new SolidColorBrush(Colors.Green);
                    StatusBlock.Text        = "Comment posted!";
                    progressRing.Visibility = Visibility.Collapsed;
                }
                else
                {
                    StatusBlock.Foreground  = new SolidColorBrush(Colors.Red);
                    StatusBlock.Text        = deserialized_response.error;
                    progressRing.Visibility = Visibility.Collapsed;
                }
            }
            catch (Exception ex)
            {
                StatusBlock.Foreground  = new SolidColorBrush(Colors.Red);
                StatusBlock.Text        = "An error occurred. Please try again.";
                progressRing.Visibility = Visibility.Collapsed;
            }
            FeedDataSource feedDataSource = (FeedDataSource)App.Current.Resources["feedDataSource"];

            if (feedDataSource != null)
            {
                await feedDataSource.GetFeedsAsync();
            }
            if (post_title != null)
            {
                LoadState(post_title, null);
            }
        }
示例#2
0
        /// <summary>
        /// Populates the page with content passed during navigation.  Any saved state is also
        /// provided when recreating a page from a prior session.
        /// </summary>
        /// <param name="navigationParameter">The parameter value passed to
        /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested.
        /// </param>
        /// <param name="pageState">A dictionary of state preserved by this page during an earlier
        /// session.  This will be null the first time a page is visited.</param>
        protected async override void LoadState(Object navigationParameter, Dictionary <String, Object> pageState)
        {
            pageTitle.Text = "Articles tagged \"" + App.page_title + "\"";
            navParam       = navigationParameter.ToString();
            ViewCommentsButton.Visibility = Visibility.Collapsed;
            progressRing.Visibility       = Visibility.Visible;
            Windows.UI.Xaml.Media.Animation.Storyboard sb =
                this.FindName("PopInStoryBoard") as Windows.UI.Xaml.Media.Animation.Storyboard;
            if (sb != null)
            {
                sb.Begin();
            }

            // TODO: Assign a bindable group to this.DefaultViewModel["Group"]
            // TODO: Assign a collection of bindable items to this.DefaultViewModel["Items"]
            FeedDataSource feedDataSource = (FeedDataSource)App.Current.Resources["feedDataSource"];

            if (feedDataSource != null)
            {
                await feedDataSource.GetFeedsAsync("tag", navigationParameter.ToString());
            }
            RootObject feedData = FeedDataSource.GetFeed();

            if (feedData != null)
            {
                this.DefaultViewModel["Feed"]  = feedData;
                this.DefaultViewModel["Items"] = feedData.posts;
            }

            if (pageState == null)
            {
                // When this is a new page, select the first item automatically unless logical page
                // navigation is being used (see the logical page navigation #region below.)
                if (!this.UsingLogicalPageNavigation() && this.itemsViewSource.View != null)
                {
                    this.itemsViewSource.View.MoveCurrentToFirst();
                }
                else
                {
                    //this.itemsViewSource.View.MoveCurrentToPosition(-1);
                }
            }
            else
            {
                // Restore the previously saved state associated with this page
                if (pageState.ContainsKey("SelectedItem") && this.itemsViewSource.View != null)
                {
                    // TODO: Invoke this.itemsViewSource.View.MoveCurrentTo() with the selected
                    //       item as specified by the value of pageState["SelectedItem"]
                    string itemTitle    = (string)pageState["SelectedItem"];
                    Post   selectedItem = FeedDataSource.GetItem(itemTitle);
                    this.itemsViewSource.View.MoveCurrentTo(selectedItem);
                }
            }
            ViewCommentsButton.Visibility = Visibility.Visible;
            progressRing.Visibility       = Visibility.Collapsed;
        }
示例#3
0
            public async void Execute(object param)
            {
                FeedDataSource feedDataSource = (FeedDataSource)App.Current.Resources["feedDataSource"];

                if (feedDataSource == null)
                {
                    return;
                }

                //Shouldn't need this now, but I'll leave it here
                ProgressRing filter_ring = new ProgressRing();

                filter_ring.IsActive = true;
                Flyout flyout = new Flyout();

                flyout.PlacementTarget = sender as UIElement;
                flyout.Placement       = PlacementMode.Top;
                flyout.HostMargin      = new Thickness(0);
                Border b = new Border();

                b.Width        = 20;
                b.Height       = 20;
                b.Child        = filter_ring;
                flyout.Content = b;
                flyout.IsOpen  = true;

                Menu menu = new Menu();

                menu.MaxHeight = 300;

                switch (type)
                {
                case "category":
                    foreach (Category item in feedDataSource.CategoryList.categories)
                    {
                        ToggleMenuItem menuItem = new ToggleMenuItem();
                        menuItem.Text    = item.title;
                        menuItem.Command = new MenuCategoryCommand(item.slug, item.title);
                        menu.Items.Add(menuItem);
                    }
                    break;

                case "tag":
                default:
                    foreach (Tag item in feedDataSource.TagList.tags)
                    {
                        ToggleMenuItem menuItem = new ToggleMenuItem();
                        menuItem.Text    = item.title;
                        menuItem.Command = new MenuTagCommand(item.slug, item.title);
                        menu.Items.Add(menuItem);
                    }
                    break;
                }

                flyout.Content = menu;
            }
示例#4
0
        /// <summary>
        /// Populates the page with content passed during navigation.  Any saved state is also
        /// provided when recreating a page from a prior session.
        /// </summary>
        /// <param name="navigationParameter">The parameter value passed to
        /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested.
        /// </param>
        /// <param name="pageState">A dictionary of state preserved by this page during an earlier
        /// session.  This will be null the first time a page is visited.</param>
        protected override void LoadState(Object navigationParameter, Dictionary <String, Object> pageState)
        {
            string itemTitle = (string)navigationParameter;

            post_title = itemTitle;
            Post feedItem = FeedDataSource.GetItem(itemTitle);

            post_id = feedItem.id;
            if (feedItem != null)
            {
                this.DataContext = feedItem;
                foreach (Comment comment in feedItem.comments)
                {
                    HtmlDocument html = new HtmlDocument();
                    html.LoadHtml(comment.content);
                    comment.content = HtmlEntity.DeEntitize(html.DocumentNode.InnerText);
                }
                this.commentsListView.ItemsSource = feedItem.comments;
            }
        }