/// <summary>
        /// GenerateReport from the conversation
        /// </summary>
        /// <param name="conversation"> <see cref="Conversation"> variable used for the report </param>
        /// <returns> the conversation with the generated report </returns>
        public Conversation GenerateReport(Conversation conversation)
        {
            // CHECK if theres any messages to be reported
            if (conversation.Messages.Count() == 0)
            {
                // No messages, report this where the rankings would be

                // INITIALISE an IList of type string, called empty list
                IList <string> emptyList = new List <string>();
                emptyList.Add("No users to be ranked");
                // INSANTIATE a new ConversationReport, passing into the constructor
                // the returns of the MostActive method and the MostActiveList method
                ConversationReport conversationReportEmpty = new ConversationReport(
                    "No users to report",
                    emptyList);
                // SET the Conversation parameters report
                conversation.Report = conversationReportEmpty;

                return(conversation);
            }
            else
            {
                // INSANTIATE a new ConversationReport, passing into the constructor
                // the returns of the MostActive method and the MostActiveList method
                ConversationReport conversationReport = new ConversationReport(
                    MostActive(conversation.Messages.ToList()),
                    MostActiveList(conversation.Messages.ToList()));
                // SET the Conversation parameters report
                conversation.Report = conversationReport;

                return(conversation);
            }
        }
Exemple #2
0
        /// <summary>
        /// Helper method to read the conversation from <paramref name="inputFilePath"/>.
        /// </summary>
        /// <param name="inputFilePath">
        /// The input file path.
        /// </param>
        /// <returns>
        /// A <see cref="Conversation"/> model representing the conversation.
        /// </returns>
        /// <exception cref="ArgumentException">
        /// Thrown when the input file could not be found.
        /// </exception>
        /// <exception cref="Exception">
        /// Thrown when something else went wrong.
        /// </exception>
        ///



        public Conversation ReadConversation(string inputFilePath, BaseFilter[] filters, IBlacklist[] blacklists, bool generateReport = false)
        {
            try
            {
                var reader = new StreamReader(new FileStream(inputFilePath, FileMode.Open, FileAccess.Read),
                                              Encoding.ASCII);
                var messages         = new List <Message>();
                var conversationName = reader.ReadLine();


                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    var split            = line.Split(' ');
                    var messageInfo      = new string[3];
                    var processingParser = new ProcessingParser(filters, blacklists);

                    if (split[1].Length <= 0)
                    {
                        throw new InvalidUserIdException("Invalid User ID, Check input");
                    }

                    if (split.Length <= 2)
                    {
                        throw new MessageFormatException("Empty or Incorrectly formatted Message, Check input");
                    }

                    messageInfo[0] = split[0];
                    messageInfo[1] = split[1];
                    messageInfo[2] = line.Substring(split[0].Length + split[1].Length + 1).Trim();
                    messageInfo    = processingParser.RunLineCheck(messageInfo[0], messageInfo[1], messageInfo[2]);

                    //if timestamp is empty, then message didn't pass through filter or blacklist
                    if (messageInfo[0] != "")
                    {
                        messages.Add(new Message(DateTimeOffset.FromUnixTimeSeconds(Convert.ToInt64(messageInfo[0])), messageInfo[1], messageInfo[2]));
                    }
                }

                if (generateReport)
                {
                    var reported = new ConversationReport(conversationName, messages);

                    reported.GenerateReportData();
                    reported.SortDataAscending();
                    return(reported);
                }
                else
                {
                    return(new Conversation(conversationName, messages));
                }
            }
            catch (FormatException)
            {
                throw new Exception("Incorrect Unix Format, Please Check input");
            }
            catch (FileNotFoundException)
            {
                throw new ArgumentException("The file was not found.");
            }
            catch (IOException)
            {
                throw new Exception("Something went wrong in the IO.");
            }
        }