PathElementGenerator Code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Collections;
using System.Text.RegularExpressions;
namespace PathElementGenerator
{
    class Program
    {
        static void Main(string[] args)
        {
            string responseFilePath = @"C:\Users\saikatd\jakarta-jmeter-2.5\jakarta-jmeter-2.5\bin";
            string processedIdentifiersFilePath = @"C:\Users\saikatd\SSTE\ProcessedIdentifiers.txt";
            List<string> pathElements = new List<string>();
            List<string> fileList = GetFileList(responseFilePath, @"*.html", 1);
            //Read each response file and try to match regular expressions from ProcessedIdentifiers.txt
            for (int i = 0; i < fileList.Count; i++)
            {
                string html = File.ReadAllText(fileList[i]);
                //Read the regular expression from ProcessedIdentifiers.txt
                StreamReader sr = new StreamReader(processedIdentifiersFilePath);
                for (string str = sr.ReadLine(); str != null; str = sr.ReadLine())
                {
                    if (IsMatchSuccess(html, GetRightIdentifier(str)))
                    {
                        if (pathElements.Count == 0)
                        {
                            pathElements.Add(GetLeftIdentifier(str));
                        }
                        else
                        {
                            if (pathElements[pathElements.Count - 1].ToString() != GetLeftIdentifier(str))
                            {
                                pathElements.Add(GetLeftIdentifier(str));
                            }
                        }
                        break;
                    }
                }
                sr.Close();
            }
            Console.WriteLine("Path Elements");
            Console.WriteLine("=============");
            Console.Write("UseCase_pathElements =");
            for (int i = 0; i < pathElements.Count; i++)
            {
                Console.Write(" " + pathElements[i].Replace("_identifier", ""));
            }
            Console.WriteLine();
        }
        public static bool IsMatchSuccess(string str, string expr)
        {
            Match m = Regex.Match(str, expr);
            return (m.Success);
        }
        public static List<string> GetFileList(string sourceDirectory, string fileExtension, int sizeInBytes)
        {
            List<string> fileList = new List<string>();
            DirectoryInfo di = new DirectoryInfo(sourceDirectory);
            FileInfo[] fiArr = di.GetFiles(fileExtension, SearchOption.AllDirectories);
            foreach (FileInfo file in fiArr)
            {
                if (file.Length > sizeInBytes)
                {
                    fileList.Add(file.FullName);
                }
            }
            return fileList;
        }
        public static string GetLeftIdentifier(string text)
        {
            string leftIdentifier = "";
            Regex reg = new Regex("=");
            string[] stringArray = reg.Split(text, 2);
            if (stringArray.Length < 2 || text.StartsWith("#"))
            {
                return text;
            }
            leftIdentifier = stringArray[0];
            leftIdentifier = leftIdentifier.Trim();
            return leftIdentifier;
        }
        public static string GetRightIdentifier(string text)
        {
            string rightIdentifier = "";
            Regex reg = new Regex("=");
            string[] stringArray = reg.Split(text, 2);
            if (stringArray.Length < 2 || text.StartsWith("#"))
            {
                return text;
            }
            rightIdentifier = stringArray[1];
            rightIdentifier = rightIdentifier.Trim();
            return rightIdentifier;
        }
    }
}
Advertisements
This entry was posted in Information Technology. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s