Exemplo n.º 1
0
        public LogData getData(String sourceFile)
        {
            LogData       logData     = new LogData();
            File          file        = new File();
            DataSection   dataSection = new DataSection();
            List <String> myData      = new List <String>();


            String[] terms = sourceFile.Split('\\');
            file.Name = terms[terms.Length - 1];


            using (StreamReader sr = new StreamReader(sourceFile))
            {
                String line;
                while ((line = sr.ReadLine()) != null)
                {
                    if (line.Equals("[Code]"))
                    {
                        file.Code = dataSection.ParamList = sr.ReadLine();
                    }

                    if (line.Equals("[Description]"))
                    {
                        file.Description = sr.ReadLine();
                    }

                    if (line.Equals("[Data]"))
                    {
                        while ((line = sr.ReadLine()) != null)
                        {
                            myData.Add(line);
                        }
                        break;
                    }
                }
            }

            dataSection.Data = myData;
            logData.File     = new List <File>();
            logData.File.Add(file);
            logData.DataSection = dataSection;
            return(logData);
        }
Exemplo n.º 2
0
        public LogData mergeLogData(List <LogData> logDatas)
        {
            LogData     logData     = new LogData();
            DataSection dataSection = new DataSection();

            logData.File = new List <File>();
            List <string> tempData = new List <string>();

            dataSection.Data = new List <string>();
            Dictionary <int, List <String> > keysMap   = new Dictionary <int, List <String> >();
            Dictionary <String, String>      valuesMap = new Dictionary <String, String>();

            for (int i = 0; i < logDatas.Count; i++)
            {
                File file = new File();
                file = logDatas[i].File[0];
                logData.File.Add(file);

                dataSection.ParamList += logDatas[i].DataSection.ParamList + ",";

                List <String> keys = new List <String>();

                for (int j = 0; j < logDatas[i].DataSection.Data.Count; j++)
                {
                    String[] terms = logDatas[i].DataSection.Data[j].Split(',');
                    keys.Add(terms[0]);
                    if (valuesMap.ContainsKey(terms[0]))
                    {
                        String valToAdd;
                        if (i > 1)
                        {
                            valToAdd = valuesMap[terms[0]] + "," + terms[1];
                        }
                        else
                        {
                            valToAdd = valuesMap[terms[0]] + terms[1];
                        }

                        valuesMap.Remove(terms[0]);
                        valuesMap.Add(terms[0], valToAdd);
                    }
                    else
                    {
                        if (i > 0)
                        {
                            valuesMap.Add(terms[0], "," + terms[1]);
                        }
                        else
                        {
                            valuesMap.Add(terms[0], terms[1] + ",");
                        }
                    }
                }
                keysMap.Add(i, keys);
            }

            dataSection.ParamList = dataSection.ParamList.Substring(0, dataSection.ParamList.Length - 1);
            dataSection.Data      = mergeData(keysMap, valuesMap);
            logData.DataSection   = dataSection;
            return(logData);
        }