пятница, 27 декабря 2013 г.

C# PropsAppReader - чтение файла формата "tag1...\tag1"

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.IO;

namespace Solution.Framework
{
    class PropsAppReader
    {
        string fileName;
        string[] fileText;
        
        
        public PropsAppReader(string f_fileName)
        {
            this.fileName = f_fileName;
            fileText= File.ReadAllLines(f_fileName);
        }

        public string GetValueByParamName(string paramName)      
        {
            string sPattern = "(?<=<" + paramName + ">)(.*)(?=</" + paramName + ">)";
            string OneString = "";

            foreach (string s in fileText)
                OneString += s;


            return Regex.Match(OneString, sPattern).Value.ToString().Trim();
        }


        public string[] GetAllText()
        {
            return fileText;
        }
    }
}


Использование класса Solution:

...

PropsAppReader scriptManager = new PropsAppReader(file_path);


string val1 = PropsAppReader.GetValueByParamName("tag1-name")

string val2 = PropsAppReader.GetValueByParamName("tag2-name")
...
string valN = PropsAppReader.GetValueByParamName("tagN-name")
...


Структура файла:

<tag1-name>Tag1_value</tag1-name>
<tag2-name>Tag2_value</tag2-name>
...
<tagN-name>TagN_value</tagN-name>

Комментариев нет:

Отправить комментарий

Docker. Первые контейнеры

Источник:  php.dragomano.ru Структура каталогов: ~/develop/web/project/                  nginx/      - сервис web-сервера                php...