Ejemplo n.º 1
0
        /// <summary>
        /// Plots reddit post based on Post Id
        /// </summary>
        /// <param name="dimstyle">object containing dim scales based on the bounding box drawn by user</param>
        /// <param name="id">Reddit Post ID</param>
        /// <returns></returns>
        public static string PlotPost(EntityData dimstyle, string id)
        {
            string result = "OK";

            try
            {
                RedditSharp.Things.Post post = (RedditSharp.Things.Post)PostIds.GetPost(id);
                if (IsLinkedImg(post.Url.AbsoluteUri))
                {
                    //Will insert imageif link is a direct link to the image
                    string filename = GetImage(post.Url.AbsoluteUri);
                    DrawEntity.DrawImg(dimstyle.origin, filename, "REDDIT.IMGS", dimstyle.yLength * .05, dimstyle.yLength * .05);
                }
                //if it's only a link to imgur page...
                List <string> imgurLinks = GetImgurImgs(post.Url.AbsoluteUri);
                for (int i = 0; i < imgurLinks.Count; i++)
                {
                    Point3d imgLocation = new Point3d(dimstyle.origin.X + (i * (dimstyle.cornerBase.X - dimstyle.origin.X)), dimstyle.origin.Y, 0);
                    double  heightNWith = dimstyle.yLength * 0.025; //Basing height and with on the height of the border drawn by user. if width & height are seperated then img will be distorted
                    string  image       = GetImage(imgurLinks[i]);
                    DrawEntity.DrawImg(imgLocation, image, "REDDIT.IMGS", heightNWith, heightNWith);
                }
                RedditSharp.Reddit reddit = new RedditSharp.Reddit();
                if (post != null)
                {
                    //Post generated looks like this with indentation
                    int     i                  = -1; //Multiplier to help to align text in the Y axis.
                    double  yTextLocation      = dimstyle.origin.Y;
                    double  mtextActualHeight  = (dimstyle.yLength * .0025);
                    Point2d subHeadingLocation = new Point2d(dimstyle.origin.X, dimstyle.origin.Y);
                    foreach (var comment in post.Comments.Take(50))
                    {
                        Tuple <double, double> widthHeight;                                // A*C*T*U*A*L width & height of the mtext created
                        yTextLocation -= (mtextActualHeight - (dimstyle.yLength * .0025)); //adds height padding
                        Point2d commentLocation = new Point2d(dimstyle.origin.X, yTextLocation);
                        widthHeight = DrawEntity.DrawText(commentLocation, dimstyle.commentsSize, dimstyle.textWidth, comment.Body, "REDDIT.COMMENTS", 7);

                        mtextActualHeight  = widthHeight.Item2;
                        subHeadingLocation = new Point2d(dimstyle.origin.X, yTextLocation - mtextActualHeight);
                        string subHeading = string.Format("By:{0} | Upvotes: {1} | Submitted: {2}",
                                                          comment.Author, comment.Upvotes, post.Created.ToString());
                        DrawEntity.DrawText(subHeadingLocation, dimstyle.subCommentsSize, dimstyle.textWidth, subHeading, "REDDIT.COMMENTS.SUBHEADINGS", 251);
                        i--;
                        foreach (var subcomment in comment.Comments.Take(20))
                        {
                            yTextLocation     -= (mtextActualHeight - (dimstyle.yLength * .0025)); //adds height padding
                            commentLocation    = new Point2d(dimstyle.origin.X + ((dimstyle.cornerBase.X - dimstyle.origin.X) * 0.025), yTextLocation);
                            widthHeight        = DrawEntity.DrawText(commentLocation, (dimstyle.commentsSize * 0.75), dimstyle.textWidth, subcomment.Body, "REDDIT.COMMENTS", 7);
                            mtextActualHeight  = widthHeight.Item2;
                            subHeadingLocation = new Point2d(dimstyle.origin.X + ((dimstyle.cornerBase.X - dimstyle.origin.X) * 0.025), yTextLocation - mtextActualHeight);
                            subHeading         = string.Format("By:{0} | Upvotes: {1} | Submitted: {2}",
                                                               subcomment.Author, subcomment.Upvotes, subcomment.Created.ToString());
                            DrawEntity.DrawText(subHeadingLocation, (dimstyle.subCommentsSize * 0.75), dimstyle.textWidth, subHeading, "REDDIT.COMMENTS.SUBHEADINGS", 251);
                            i--;
                            foreach (var subsubcomment in subcomment.Comments.Take(15))
                            {
                                yTextLocation     -= (mtextActualHeight - (dimstyle.yLength * .0025)); //adds height padding
                                commentLocation    = new Point2d(dimstyle.origin.X + ((dimstyle.cornerBase.X - dimstyle.origin.X) * 0.05), yTextLocation);
                                widthHeight        = DrawEntity.DrawText(commentLocation, (dimstyle.commentsSize * 0.5), dimstyle.textWidth, subsubcomment.Body, "REDDIT.COMMENTS", 7);
                                mtextActualHeight  = widthHeight.Item2;
                                subHeadingLocation = new Point2d(dimstyle.origin.X + ((dimstyle.cornerBase.X - dimstyle.origin.X) * 0.05), yTextLocation - mtextActualHeight);
                                subHeading         = string.Format("By:{0} | Upvotes: {1} | Submitted: {2}", subsubcomment.Author, subsubcomment.Upvotes, subsubcomment.Created.ToString());
                                DrawEntity.DrawText(subHeadingLocation, (dimstyle.subCommentsSize * 0.5), dimstyle.textWidth, subHeading, "REDDIT.COMMENTS.SUBHEADINGS", 251);
                                i--;
                                foreach (var subsubsubcomment in subsubcomment.Comments.Take(10))
                                {
                                    yTextLocation     -= (mtextActualHeight - (dimstyle.yLength * .0025)); //adds height padding
                                    commentLocation    = new Point2d(dimstyle.origin.X + ((dimstyle.cornerBase.X - dimstyle.origin.X) * 0.075), yTextLocation);
                                    widthHeight        = DrawEntity.DrawText(commentLocation, (dimstyle.commentsSize * .25), dimstyle.textWidth, subsubsubcomment.Body, "REDDIT.COMMENTS", 7);
                                    mtextActualHeight  = widthHeight.Item2;
                                    subHeadingLocation = new Point2d(dimstyle.origin.X + ((dimstyle.cornerBase.X - dimstyle.origin.X) * 0.075), yTextLocation - mtextActualHeight);
                                    subHeading         = string.Format("By:{0} | Upvotes: {1} | Submitted: {2}", subsubsubcomment.Author, subsubsubcomment.Upvotes, subsubsubcomment.Created.ToString());
                                    DrawEntity.DrawText(subHeadingLocation, (dimstyle.subCommentsSize * 0.25), dimstyle.textWidth, subHeading, "REDDIT.COMMENTS.SUBHEADINGS", 251);
                                    i--;
                                }
                            }
                        }
                    }
                    Point3d endPt = new Point3d(dimstyle.cornerBase.X - ((dimstyle.cornerBase.X - dimstyle.origin.X) / 2), subHeadingLocation.Y - (subHeadingLocation.Y * 0.0025), 0);
                    DrawEntity.DrawBox(dimstyle.origin, endPt, "REDDIT.BORDER", 20);
                    DrawEntity.DrawDim(dimstyle.origin, new Point3d(endPt.X, dimstyle.origin.Y, 0), "POST ID : " + id, "REDDIT.COMMENTS", dimstyle.subHeadingTxtSize, 1.005);
                }
            }
            catch (Exception e)
            {
                System.Windows.MessageBox.Show(e.Message);
                result = "FAILED";
            }
            return(result);
        }