Ejemplo n.º 1
0
        public int CompareTo(Object alpha)
        {
            if (alpha == null)
            {
                throw new ArgumentNullException();
            }

            Subreddit rightOp = alpha as Subreddit;

            if (rightOp != null)
            {
                return(Name.CompareTo(rightOp.Name));
            }
            else
            {
                throw new ArgumentException("[Subreddit]: CompareTo argument is not a name");
            }
        }
Ejemplo n.º 2
0
        /**
         * This function gets the awards for posts, comments, and replies. it toals and then
         * outputs them
         * Parameters: award-the string of silver,gold,or platinum to search for.
         */
        private void AwardOutput(string award)
        {
            bool silver, gold, platinum, replySearch;

            silver = gold = platinum = replySearch = false;

            uint postAwards, topCommentAwards, replyAwards;

            postAwards = topCommentAwards = replyAwards = 0;

            List <uint> postIDList        = new List <uint>();
            List <uint> commentIDList     = new List <uint>();
            List <uint> replyIDList       = new List <uint>();
            List <uint> replyIDSearchList = new List <uint>();


            Subreddit selectedSub = null;

            foreach (Subreddit sub in mySubReddits)                                                        //Find the selected subbreddit
            {
                if (sub.Name == subbredditAwardComboBox.GetItemText(subbredditAwardComboBox.SelectedItem)) //Found the seleceted subbreddit
                {
                    selectedSub = sub;
                    break;
                }
            }


            if (award == "Silver")//We are looking for silver
            {
                var Post_Query =
                    from N in myPosts
                    where N.SubId == selectedSub.Id
                    select N;

                foreach (Post post in Post_Query)//get the post awrds totaled
                {
                    postAwards += post.Silver;
                    postIDList.Add(post.PostID);
                }

                var Comment_Query =
                    from N in myComments
                    where postIDList.Contains(N.ParentID)
                    select N;

                foreach (Comment comment in Comment_Query)//get the top comments awards totaled
                {
                    topCommentAwards += comment.Silver;
                    commentIDList.Add(comment.CommentID);
                }

                var Reply_Query =
                    from N in myComments
                    where commentIDList.Contains(N.ParentID)
                    select N;

                foreach (Comment comment in Reply_Query) //Get the replies awards totaled
                {
                    replyAwards += comment.Silver;
                    replyIDList.Add(comment.CommentID);
                }

                if (replyIDList.Count > 0) //Do not search for replies if there are none
                {
                    replySearch = true;
                    while (replySearch)
                    {
                        replySearch = false;
                        foreach (Comment comment in myComments)            //search for comments to count the awards
                        {
                            foreach (uint ID in replyIDList)               //compare each ID to the comment
                            {
                                if (ID == comment.CommentID)               //If the id matches the comment
                                {
                                    replyAwards += comment.Silver;         //add the award to the total
                                    replySearch  = true;
                                    foreach (Comment search in myComments) //go through the comments and find any replies
                                    {
                                        if (search.ParentID == ID)         //add the items to be searched again
                                        {
                                            replyIDSearchList.Add(search.CommentID);
                                        }
                                    }
                                    break;
                                }
                            }
                        }
                        replyIDList.Clear();
                        replyIDList = replyIDSearchList;
                        replyIDSearchList.Clear();
                    }
                }
            }
            if (award == "Gold")
            {
                var Post_Query =
                    from N in myPosts
                    where N.SubId == selectedSub.Id
                    select N;

                foreach (Post post in Post_Query)//get the post awrds totaled
                {
                    postAwards += post.Gold;
                    postIDList.Add(post.PostID);
                }

                var Comment_Query =
                    from N in myComments
                    where postIDList.Contains(N.ParentID)
                    select N;

                foreach (Comment comment in Comment_Query)//get the top comments awards totaled
                {
                    topCommentAwards += comment.Gold;
                    commentIDList.Add(comment.CommentID);
                }

                var Reply_Query =
                    from N in myComments
                    where commentIDList.Contains(N.ParentID)
                    select N;

                foreach (Comment comment in Reply_Query) //Get the replies awards totaled
                {
                    replyAwards += comment.Gold;
                    replyIDList.Add(comment.CommentID);
                }

                if (replyIDList.Count > 0) //Do not search for replies if there are none
                {
                    replySearch = true;
                    while (replySearch)
                    {
                        replySearch = false;
                        foreach (Comment comment in myComments)            //search for comments to count the awards
                        {
                            foreach (uint ID in replyIDList)               //compare each ID to the comment
                            {
                                if (ID == comment.CommentID)               //If the id matches the comment
                                {
                                    replyAwards += comment.Gold;           //add the award to the total
                                    replySearch  = true;
                                    foreach (Comment search in myComments) //go through the comments and find any replies
                                    {
                                        if (search.ParentID == ID)         //add the items to be searched again
                                        {
                                            replyIDSearchList.Add(search.CommentID);
                                        }
                                    }
                                    break;
                                }
                            }
                        }
                        replyIDList.Clear();
                        replyIDList = replyIDSearchList;
                        replyIDSearchList.Clear();
                    }
                }
            }
            if (award == "Platinum")
            {
                var Post_Query =
                    from N in myPosts
                    where N.SubId == selectedSub.Id
                    select N;

                foreach (Post post in Post_Query)//get the post awrds totaled
                {
                    postAwards += post.Platinum;
                    postIDList.Add(post.PostID);
                }

                var Comment_Query =
                    from N in myComments
                    where postIDList.Contains(N.ParentID)
                    select N;

                foreach (Comment comment in Comment_Query)//get the top comments awards totaled
                {
                    topCommentAwards += comment.Platinum;
                    commentIDList.Add(comment.CommentID);
                }

                var Reply_Query =
                    from N in myComments
                    where commentIDList.Contains(N.ParentID)
                    select N;

                foreach (Comment comment in Reply_Query) //Get the replies awards totaled
                {
                    replyAwards += comment.Platinum;
                    replyIDList.Add(comment.CommentID);
                }

                if (replyIDList.Count > 0) //Do not search for replies if there are none
                {
                    replySearch = true;
                    while (replySearch)
                    {
                        replySearch = false;
                        foreach (Comment comment in myComments)            //search for comments to count the awards
                        {
                            foreach (uint ID in replyIDList)               //compare each ID to the comment
                            {
                                if (ID == comment.CommentID)               //If the id matches the comment
                                {
                                    replyAwards += comment.Platinum;       //add the award to the total
                                    replySearch  = true;
                                    foreach (Comment search in myComments) //go through the comments and find any replies
                                    {
                                        if (search.ParentID == ID)         //add the items to be searched again
                                        {
                                            replyIDSearchList.Add(search.CommentID);
                                        }
                                    }
                                    break;
                                }
                            }
                        }
                        replyIDList.Clear();
                        replyIDList = replyIDSearchList;
                        replyIDSearchList.Clear();
                    }
                }
            }

            OutputBox.Text += '\t' + award + "Awards for Posts are: " + postAwards.ToString() + '\n';
            OutputBox.Text += '\t' + award + "Awards for Top Comments are: " + topCommentAwards.ToString() + '\n';
            OutputBox.Text += '\t' + award + "Awards for Replies are: " + replyAwards.ToString() + "\n\n";
        }
Ejemplo n.º 3
0
        /**
         * This function gets and reads input from files provided to us.
         * Parameters: myPosts- a SortedSet of post objects to fill with post info
         *             myComments - a SortedSet of Comment objects to fill with comment info
         *             mySubreddits - Sorted set of Subreddit objects
         *             myUsers - Sorted set of user objects
         */
        static public void getFileInput()
        {
            string currentLine;

            string[] tokens;

            //This will read the post file and build the objects from there
            using (StreamReader inFile = new StreamReader("..//..//posts.txt"))
            {
                bool Locked;
                currentLine = inFile.ReadLine(); //prime the read
                while (currentLine != null)
                {
                    tokens = currentLine.Split('\t');

                    if (tokens[0] == "0")
                    {
                        Locked = false;
                    }
                    else
                    {
                        Locked = true;
                    }
                    //File structure
                    //Posts: Locked | ID | AuthorID | Title | Content | SubredditID | UpVotes | DownVotes | Weight | Year | Month | Day | Hour | Min | Sec | silver | gold | plstinum

                    string   dateString = tokens[9] + '-' + tokens[10] + '-' + tokens[11] + ' ' + tokens[12] + ':' + tokens[13] + ':' + tokens[14];
                    DateTime temp;
                    if (DateTime.TryParse(dateString, out temp)) //Makes sure the date converted successfully
                    {
                        Post postToAdd = new Post(               //build the post to add
                            Locked,                              //locked
                            UInt32.Parse(tokens[1]),             //postId
                            UInt32.Parse(tokens[2]),             //authorID
                            tokens[3],                           //title
                            tokens[4],                           //postContent
                            UInt32.Parse(tokens[5]),             //subHome
                            UInt32.Parse(tokens[6]),             //upvotes
                            UInt32.Parse(tokens[7]),             //downVotes
                            UInt32.Parse(tokens[8]),             //weight
                            temp,                                //dateTime,
                            UInt32.Parse(tokens[15]),            //Silver
                            UInt32.Parse(tokens[16]),            //Gold
                            UInt32.Parse(tokens[17])             //platinum
                            );

                        RedditQueries.myPosts.Add(postToAdd);
                    }
                    else //We failed to conver the date
                    {
                        Console.WriteLine("We didn't conver the date properly! QUIT (Handle this better)");
                        return;
                    }
                    currentLine = inFile.ReadLine(); //get the next line
                }
            }

            //This will read the comment file and build the objects from there
            using (StreamReader inFile = new StreamReader("..//..//comments.txt"))
            {
                currentLine = inFile.ReadLine(); //prime the read
                while (currentLine != null)
                {
                    tokens = currentLine.Split('\t');

                    string   dateString = tokens[6] + '-' + tokens[7] + '-' + tokens[8] + ' ' + tokens[9] + ':' + tokens[10] + ':' + tokens[11];
                    DateTime temp;
                    if (DateTime.TryParse(dateString, out temp)) //Make sure the date converted successfully
                    {
                        Comment commentToAdd = new Comment(      //build the comment to add
                            UInt32.Parse(tokens[0]),             //commentId
                            UInt32.Parse(tokens[1]),             //authorID
                            tokens[2],                           //content
                            UInt32.Parse(tokens[3]),             //parentID
                            UInt32.Parse(tokens[4]),             //upvotes
                            UInt32.Parse(tokens[5]),             //downVotes
                            temp,                                //dateTime
                            UInt32.Parse(tokens[12]),            //Silver
                            UInt32.Parse(tokens[13]),            //Gold
                            UInt32.Parse(tokens[14])             //platinum
                            );

                        RedditQueries.myComments.Add(commentToAdd);
                    }
                    else
                    {
                        Console.WriteLine("We didn't convert the date properly! QUIT (Handle this better)");
                        return;
                    }
                    currentLine = inFile.ReadLine(); //get the next line
                }
            }

            //This will read the the subreddit file and build the objects from them
            using (StreamReader inFile = new StreamReader("..//..//subreddits.txt"))
            {
                currentLine = inFile.ReadLine(); //prime the read
                while (currentLine != null)
                {
                    tokens = currentLine.Split('\t');

                    Subreddit newSub = new Subreddit( //build the subreddit
                        UInt32.Parse(tokens[0]),      //id
                        tokens[1],                    //name
                        UInt32.Parse(tokens[2]),      //Members
                        UInt32.Parse(tokens[3])       //Active
                        );

                    RedditQueries.mySubReddits.Add(newSub);

                    currentLine = inFile.ReadLine(); //get the next line
                }
            }

            //This will get the user information and store it in the user object
            using (StreamReader inFile = new StreamReader("..//..//users.txt"))
            {
                //Users: ID | UserType | Name | PasswordHash | PostScore | CommentScore | ModeratingSubs *
                currentLine = inFile.ReadLine(); //prime the read
                while (currentLine != null)
                {
                    tokens = currentLine.Split('\t');

                    List <string> moderating = new List <string>();

                    for (int i = 6; i < tokens.Length; ++i)
                    {
                        moderating.Add(tokens[i]);
                    }

                    User newUser = new User(     //build the user
                        UInt32.Parse(tokens[0]), //id
                        Int32.Parse(tokens[1]),  //user type
                        tokens[2],               //name
                        tokens[3],               //password hash
                        Int32.Parse(tokens[4]),  //postScore
                        Int32.Parse(tokens[5]),  //commentScore
                        moderating               //list of the moderating subs names
                        );

                    RedditQueries.myUsers.Add(newUser);

                    currentLine = inFile.ReadLine(); //get the next line
                }
            }
        }