Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Tagged as

Go to top

Collect and Compare Log Statistics using LogJoin

, 22 Oct 2013
The LogJoin tool helps to collect any unstructured data from text files and join it to a simple table representation for easy analysis.
/*
 * Copyright (c) 2013, Yuriy Nelipovich
 * 
 * If you find this code useful or in case of any questions, suggestions
 * bug reports, donation, please email me: dev.yuriy.n@gmail.com
 */

using System.Collections.Generic;
using System.Configuration;
using System.Linq;

namespace LogJoin.Config
{
    /// <summary>
    /// Config section that contains all parameters for the application
    /// </summary>
    public class Parameters : ConfigurationSection
    {
        [ConfigurationProperty("expressions")]
        [ConfigurationCollection(typeof (Expression), AddItemName = "expr")]
        public ExpressionCollection ExpressionsCollection
        {
            get { return (ExpressionCollection) this["expressions"]; }
        }

        public IEnumerable<Expression> Expressions
        {
            get { return this.ExpressionsCollection.Cast<Expression>(); }
        }

        [ConfigurationProperty("inputs")]
        [ConfigurationCollection(typeof (InputAttributes), AddItemName = "input")]
        public InputCollection InputsCollection
        {
            get { return (InputCollection) this["inputs"]; }
        }

        public IEnumerable<InputAttributes> Inputs
        {
            get { return this.InputsCollection.Cast<InputAttributes>(); }
        }

        [ConfigurationProperty("output", IsRequired = true)]
        public ConfigurationTextElement<string> OutputFilePathElement
        {
            get { return (ConfigurationTextElement<string>) this["output"]; }
            set { this["output"] = value; }
        }

        public string OutputFilePath
        {
            get { return this.OutputFilePathElement.Value; }
        }

        [ConfigurationProperty("outputDelimiter", IsRequired = true)]
        public ConfigurationTextElement<string> OutputValuesDelimiterElement
        {
            get { return (ConfigurationTextElement<string>) this["outputDelimiter"]; }
            set { this["outputDelimiter"] = value; }
        }

        public string OutputValuesDelimiter
        {
            get { return this.OutputValuesDelimiterElement.Value; }
        }

        /// <summary>
        /// Assembles a regular expression from its parts using substitutions
        /// </summary>
        /// <param name="name">name of the expression to assemble</param>
        /// <returns></returns>
        public Expression BuildRegEx(string name)
        {
            var initialExpr = this.Expressions.Single(e => e.Name == name);
            var previous = this.Expressions.TakeWhile(e => e.Name != name)
                               .ToDictionary(e => e.Name, e => this.BuildRegEx(e.Name));
            var result = previous.Aggregate(initialExpr.Value,
                                            (current, p) =>
                                            current.Replace(string.Format("%%{0}%%", p.Key), p.Value.Value));
            return new Expression {Name = initialExpr.Name, Value = result, IsMultiline = initialExpr.IsMultiline};
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The BSD License

Share

About the Author

Yuriy Nelipovich
Software Developer CactusSoft
Belarus Belarus
No Biography provided

| Advertise | Privacy | Mobile
Web03 | 2.8.140926.1 | Last Updated 22 Oct 2013
Article Copyright 2013 by Yuriy Nelipovich
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid