public void ProcessingParserUserFilterFailTest()
        {
            var parser = new ProcessingParser(new BaseFilter[] { new UserFilter(new string[] { "bob" }) },
                                              new IBlacklist[] { new KeywordBlacklist(new string[] { "pie" }, "redacted") });

            var result = parser.RunLineCheck("1448470905", "fred", "Hi, there how are you");

            Assert.That(result[0].Equals(""));
            Assert.That(result[1].Equals(""));
            Assert.That(result[2].Equals(""));
        }
        public static MetaData Parse([NotNull] XmlNode metaDataNode, [NotNull] XmlNamespaceManager manager)
        {
            Guard.NotNull(metaDataNode, nameof(metaDataNode));
            Guard.NotNull(manager, nameof(manager));

            var manifest = new MetaData();

            var acqNode = metaDataNode.SelectMetaDataObjectByID("acquisitionPeriod");

            manifest.AcquisitionPeriod = AcquisitionPeriodParser.Parse(acqNode, manager);

            var gpiNode = metaDataNode.SelectMetaDataObjectByID("generalProductInformation");

            manifest.GeneralProductInformation = GeneralProductInformationParser.Parse(gpiNode, manager);

            var mfsNode = metaDataNode.SelectMetaDataObjectByID("measurementFrameSet");

            if (mfsNode != null)
            {
                manifest.MeasurementFrameSet = MeasurementFrameParser.Parse(mfsNode, manager);
            }

            var morNode = metaDataNode.SelectMetaDataObjectByID("measurementOrbitReference");

            manifest.MeasurementOrbitReference = MeasurementOrbitReferenceParser.Parse(morNode, manager);

            var platformNode = metaDataNode.SelectMetaDataObjectByID("platform");

            manifest.Platform = PlatformParser.Parse(platformNode, manager);

            var processingNode = metaDataNode.SelectMetaDataObjectByID("processing");

            manifest.Processing = ProcessingParser.Parse(processingNode, manager);

            return(manifest);
        }
Esempio n. 3
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.");
            }
        }