public static async Task AddPage(string url)
        {
            JsonObject json = await accountManager.makeJsonPageRequest(url);

            if (json != null)
            {
                JsonObject pageinfo = json.GetNamedObject("data");
                JsonArray  links    = pageinfo.GetNamedArray("children");

                //string srt = links.GetObjectAt(0).GetNamedObject("data").GetNamedString("subreddit");
                string sr = url.Substring(24, url.Length - 29);
                //srimg = "http://thumbs.reddit.com/" + srt + ".png";

                string          srimg    = "Assets/reddit_logo.png";
                SampleDataGroup LinkPage = new SampleDataGroup(url, sr, "", srimg, "/r/all");
                //add http request to grab subreddit link
                for (uint i = 0; i < links.Count; i++)
                {
                    JsonObject Data  = links.GetObjectAt(i).GetNamedObject("data");
                    string     title = Data.GetNamedString("title");
                    string     id    = Data.GetNamedString("id");
                    id = links.GetObjectAt(i).GetNamedString("kind") + "_" + id;
                    string   author      = Data.GetNamedString("author");
                    string   thumbnail   = Data.GetNamedString("thumbnail");
                    string   permalink   = Data.GetNamedString("permalink");
                    string   selftext    = Data.GetNamedString("selftext");
                    string   subreddit   = Data.GetNamedString("subreddit");
                    int      numcomments = (int)Data.GetNamedNumber("num_comments");
                    DateTime date        = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
                    double   sec         = Data.GetNamedNumber("created_utc");
                    date = date.AddSeconds(sec);


                    string linkurl = Data.GetNamedString("url");
                    //string selftext = links.GetObjectAt(i).GetNamedObject("data").GetNamedString("permalink");
                    int score = int.Parse(Data.GetNamedNumber("score").ToString());

                    SampleDataItem ans = new SampleDataItem(id, title, author, thumbnail, permalink, selftext, LinkPage, permalink, linkurl, score, subreddit, date, numcomments);
                    if (thumbnail == "" || selftext != "")
                    {
                        ans.NeedImg = false;
                    }

                    // await ParseComments(ans);

                    LinkPage.Items.Add(ans);
                    if (SampleDataItem.isFVImageSource(ans.Url) && ans.FvImage != null)
                    {
                        LinkPage.Images.Add(ans);
                    }
                }

                SampleDataSource._sampleDataSource.AllGroups.Add(LinkPage);
            }
            else
            {
                //show the user that the page wasn't valid
            }
        }
        public static async Task ParseCommentsAsync(SampleDataItem sditem)
        {
            string comments = "http://www.reddit.com" + sditem.Permalink + ".json";

            JsonArray json = await accountManager.makeJsonCommentRequest(comments);

            JsonArray commentlist = json.GetObjectAt(1).GetNamedObject("data").GetNamedArray("children");
            string    op          = json.GetObjectAt(0).GetNamedObject("data").GetNamedArray("children").GetObjectAt(0).GetNamedObject("data").GetNamedString("author");

            sditem.Comments = xJArraytoCommentList(commentlist, -2, op);
        }
 public static async Task AddChildren(SampleDataItem sditem, ObservableCollection <Comment> list)
 {
     foreach (var item in list)
     {
         sditem.aComments.Add(item);
         if (item.children != null && item.children.Count > 0)
         {
             await SampleDataSource.AddChildren(sditem, item.children);
         }
     }
     //sditem.Comments.Clear();
 }
        //String uniqueId, String title, String subtitle, String imagePath, String description, String content, SampleDataGroup group
        //String uniqueId, String title, String subtitle, String imagePath, String description

        public static async Task ExtendPageAsync(SampleDataGroup sg)
        {
            string url = sg.Items.Last().UniqueId;

            url = "http://www.reddit.com/r/" + sg.Title + "/.json?count=25&after=" + url;


            JsonObject json = await accountManager.makeJsonPageRequest(url);

            JsonObject pageinfo = json.GetNamedObject("data");
            JsonArray  links    = pageinfo.GetNamedArray("children");

            //add http request to grab subreddit link
            for (uint i = 0; i < links.Count; i++)
            {
                JsonObject Data  = links.GetObjectAt(i).GetNamedObject("data");
                string     title = Data.GetNamedString("title");
                string     id    = Data.GetNamedString("id");
                id = links.GetObjectAt(i).GetNamedString("kind") + "_" + id;
                string   author      = Data.GetNamedString("author");
                string   thumbnail   = Data.GetNamedString("thumbnail");
                string   permalink   = Data.GetNamedString("permalink");
                string   selftext    = Data.GetNamedString("selftext");
                string   subreddit   = Data.GetNamedString("subreddit");
                int      numcomments = (int)Data.GetNamedNumber("num_comments");
                DateTime date        = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
                double   sec         = Data.GetNamedNumber("created_utc");
                date = date.AddSeconds(sec);


                string linkurl = Data.GetNamedString("url");
                //string selftext = links.GetObjectAt(i).GetNamedObject("data").GetNamedString("permalink");
                int score = int.Parse(Data.GetNamedNumber("score").ToString());

                SampleDataItem ans = new SampleDataItem(id, title, author, thumbnail, permalink, selftext, sg, permalink, linkurl, score, subreddit, date, numcomments);
                if (thumbnail == "" || selftext != "")
                {
                    ans.NeedImg = false;
                }
                sg.Items.Add(ans);
                if (SampleDataItem.isFVImageSource(ans.Url) && ans.FvImage != null)
                {
                    sg.Images.Add(ans);
                }
            }
        }
Exemple #5
0
        private async void SaveAsImageInPicturesLibrary(Data.SampleDataItem sditem)
        {
            if (sditem != null)
            {
                var client = new HttpClient();
                HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, sditem.Url);
                var response = await client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead);

                var filename            = sditem.Url.Substring(sditem.Url.LastIndexOf('/') + 1);
                Task <StorageFile> task = GetFileIfExistsAsync(KnownFolders.PicturesLibrary, filename);
                StorageFile        file = await task;

                if (file == null)
                {
                    var imageFile = await KnownFolders.PicturesLibrary.CreateFileAsync(filename, CreationCollisionOption.ReplaceExisting);

                    var fs = await imageFile.OpenAsync(FileAccessMode.ReadWrite);

                    var writer = new DataWriter(fs.GetOutputStreamAt(0));
                    writer.WriteBytes(await response.Content.ReadAsByteArrayAsync());
                    await writer.StoreAsync();

                    writer.DetachStream();
                    await fs.FlushAsync();

                    //var dialog = new MessageDialog("The image is successfully saved in \"Pictures Library\".","Saving Image");
                    //await dialog.ShowAsync();
                    SavingTextBox.Text  = "Saved";
                    bottomAppBar.IsOpen = false;
                    await Task.Delay(3000);

                    //SavingStoryboard.Begin();
                }
                else
                {
                    var dialog = new MessageDialog("The image is already saved in \"Pictures Library\".",
                                                   "Saving Image");
                    await dialog.ShowAsync();
                }
            }

            SavingTextBox.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            SavingTextBox.Text       = "Saving...";
            bottomAppBar.IsOpen      = false;
        }