Exemplo n.º 1
0
        /// <summary>
        /// Loads the parser object described in the assembly path and class name.
        /// </summary>
        /// <param name="assemblyName">Path to the assembly containing the listener class.</param>
        /// <param name="className">Name of the listener class in the assembly.</param>
        /// <param name="log">The log file descriptor object.</param>
        /// <returns>A new log Parser object.</returns>
        /// <exception cref="ParseCodeException">
        /// Thrown when a valid IParseListener object cannot be created.
        /// </exception>
        public static BaseParser LoadParser(string assemblyName, string className, LogFile log)
        {
            Assembly assembly = Assembly.Load(AssemblyName.GetAssemblyName(assemblyName));

            if (assembly == null)
            {
                throw new ParseCodeException(string.Format("Assembly {0} not loaded", assemblyName));
            }

            Type type = assembly.GetType(className, true);

            if (type == null)
            {
                throw new ParseCodeException(string.Format("{0} not found in assembly: {1}", className, assemblyName));
            }

            BaseParser baseParser = Activator.CreateInstance(type, new object[] { log }) as BaseParser;

            if (baseParser == null)
            {
                throw new ParseCodeException(string.Format("{0} does not inherit from BaseParser", type.Name));
            }

            return(baseParser);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Blender"/> class.
        /// </summary>
        /// <param name="parser">The parser used to parse the log text.</param>
        /// <param name="subscribers">The subscribers.</param>
        /// <param name="logContent">All lines of text, contained in the log, to be parsed.</param>
        /// <exception cref="System.ArgumentNullException">
        /// Throws when "log" or "parser" or "logContent" are null.
        /// </exception>
        public Blender(BaseParser parser, IList <IParseListener> subscribers, IList <string> logContent)
        {
            BaseParser       = parser;
            this.Subscribers = subscribers;
            this.LogContent  = logContent;
            if (BaseParser == null)
            {
                throw new ArgumentNullException("parser");
            }

            if (this.LogContent == null)
            {
                throw new ArgumentNullException("logContent");
            }

            this.SubscribeListeners();
        }
Exemplo n.º 3
0
        // ReSharper restore ValueParameterNotUsed

        /// <summary>
        /// Parses the log file text.
        /// </summary>
        /// <returns>
        /// A list of LogEntry objects.
        /// </returns>
        public IList <LogEntry> Parse()
        {
            this.OnParseStarted(new LogEventArgs(BaseParser.Log));
            if (this.IsParsed())
            {
                this.OnNoParse(new NoParseEventArgs(BaseParser.Log));
                this.OnParseEnded(new LogEventArgs(BaseParser.Log));

                return(new List <LogEntry>());
            }

            IList <LogEntry> logEntries = BaseParser.Parse(this.LogContent);

            this.OnParseEnded(new LogEventArgs(BaseParser.Log));

            return(logEntries);
        }