Ejemplo n.º 1
0
        public List <string> SimulateFeed(string UserFilePath, string TweetFilePath)
        {
            List <string> feedList = new List <string>();

            try
            {
                if (inputRetriever == null)
                {
                    throw new ArgumentNullException();
                }

                string userFileData = inputRetriever.GetData(UserFilePath);

                if (string.IsNullOrEmpty(userFileData) == true || validator.TryValidate(userFileData, ValidateOptions.UsASCII) == false)
                {
                    throw new Exception();
                }

                string tweetfileData = inputRetriever.GetData(TweetFilePath);

                if (string.IsNullOrEmpty(tweetfileData) == true || validator.TryValidate(tweetfileData, ValidateOptions.UsASCII) == false)
                {
                    throw new Exception();
                }

                IDictionary <string, string> users = null;
                string[] userlines = userFileData.Split(GlobalVar.NewLineArray, StringSplitOptions.RemoveEmptyEntries);
                foreach (var userline in userlines)
                {
                    users = userRepository.CreateFollowAssociationByLine(userline);
                }

                IDictionary <string, ArrayList> tweets = null;
                string[] tweetLines = tweetfileData.Split(GlobalVar.NewLineArray, StringSplitOptions.RemoveEmptyEntries);
                foreach (var tweetLine in tweetLines)
                {
                    tweets = tweetReposity.CreateUserTweetAssociation(tweetLine);
                }

                var usersList = users.GetDictionaryKeyValueToList();
                if (usersList == null)
                {
                    throw new ArgumentNullException();
                }

                foreach (var userKey in usersList)
                {
                    if (logger.TryLog($"{userKey}") == false)
                    {
                        throw new Exception();
                    }

                    IList <string> orderedTweetList = new List <string>();

                    ArrayList userTweetList;
                    if (tweets.TryGetValue(userKey, out userTweetList) == true)
                    {
                        foreach (var ts in userTweetList)
                        {
                            orderedTweetList.Add(string.Concat(ts.ToString(), Seperator, userKey));
                        }
                    }

                    string userFollowedKeys;
                    if (users.TryGetValue(userKey, out userFollowedKeys) == true)
                    {
                        foreach (var followedKey in userFollowedKeys.Split(GlobalVar.CommaCharArray))
                        {
                            ArrayList followedTweetList;
                            if (tweets.TryGetValue(followedKey, out followedTweetList) == true)
                            {
                                foreach (var followedTweet in followedTweetList)
                                {
                                    orderedTweetList.Add(string.Concat(followedTweet.ToString(), Seperator, followedKey));
                                }
                            }
                        }
                    }

                    foreach (var orderedTweet in orderedTweetList.OrderBy(x => x))
                    {
                        string tweetUser = orderedTweet.GetSubstringByKey(Seperator, SubstringOptions.AfterKey);
                        string userTWeet = orderedTweet.GetSubstringByKey(Seperator, SubstringOptions.BeforeKey).Substring(1);
                        logger.TryLog(CreateTweetFeed(tweetUser, userTWeet));
                        feedList.Add(CreateTweetFeed(tweetUser, userTWeet));
                    }
                }
            }
            catch (Exception e)
            {
                //Log an exception using the logger class
                logger.TryLog($"Exceptiong thrown : {e.ToString()}");
                feedList.Add($"Exceptiong thrown : {e.ToString()}");
            }
            return(feedList);
        }
Ejemplo n.º 2
0
        public string GetInputFromFile(string fileLocation)
        {
            var text = _documentRetreiver.GetData(fileLocation);

            return(text);
        }