Esempio n. 1
0
        public Trip(string fileName)
        {
            string        stringUnit    = "";
            int           lineNumber    = 0;
            List <string> unitsFromLine = new List <string>();

            Lines = new TripLines();

            IEnumerable <string> fileStrings = File.ReadAllLines(fileName);

            foreach (var line in fileStrings)
            {
                lineNumber += 1;
                if (lineNumber == 2 || lineNumber > 3)
                {
                    for (int i = 0; i < line.Length; i++)
                    {
                        char symbol = line[i];
                        if (symbol == ';')
                        {
                            unitsFromLine.Add(stringUnit);
                            stringUnit = "";
                        }
                        else if (i == line.Length - 1)
                        {
                            stringUnit += line[i];
                            unitsFromLine.Add(stringUnit);
                            stringUnit = "";
                        }
                        else
                        {
                            stringUnit += line[i];
                        }
                    }
                    if (lineNumber == 2)
                    {
                        Header = new TripHeader(unitsFromLine);
                        unitsFromLine.Clear();
                    }
                    else
                    {
                        Lines.Add(new Order(unitsFromLine));
                    }
                }
            }
        }
Esempio n. 2
0
        public void Test(string fileName)
        {
            string               stringUnit    = "";
            char                 symbol        = new char();
            int                  lineNumber    = 0;
            List <string>        unitsFromLine = new List <string>();
            IEnumerable <string> fileStrings   = File.ReadAllLines(fileName);
            TripLines            tripLines     = new TripLines();

            foreach (var line in fileStrings)
            {
                lineNumber += 1;
                if (lineNumber == 2)    // || lineNumber > 3)
                {
                    //Console.WriteLine(line);
                    for (int i = 0; i < line.Length; i++)
                    {
                        symbol = line[i];
                        //Console.WriteLine($"symbol = {symbol}, line.Length = {line.Length}, i = {i}");
                        if (symbol == ';')
                        {
                            unitsFromLine.Add(stringUnit);
                            stringUnit = "";
                        }
                        else if (i == line.Length - 1)
                        {
                            stringUnit += line[i];
                            unitsFromLine.Add(stringUnit);
                            stringUnit = "";
                        }
                        else
                        {
                            stringUnit += line[i];
                        }
                    }
                    TripHeader header = new TripHeader(unitsFromLine);
                    SaveHeader(header);
                }
                else if (lineNumber > 3)
                {
                    unitsFromLine.Clear();
                    //Console.WriteLine(line.Count());
                    //Console.WriteLine(line);
                    for (int i = 0; i < line.Length; i++)
                    {
                        symbol = line[i];
                        //Console.WriteLine($"symbol = {symbol}, line.Length = {line.Length}, i = {i}");
                        if (symbol == ';')
                        {
                            //Console.WriteLine(stringUnit);
                            unitsFromLine.Add(stringUnit);
                            stringUnit = "";
                        }
                        else if (i == line.Length - 1)
                        {
                            stringUnit += line[i];
                            //Console.WriteLine(stringUnit);
                            unitsFromLine.Add(stringUnit);
                            stringUnit = "";
                        }
                        else
                        {
                            stringUnit += line[i];
                        }
                    }
                    tripLines.Add(new Order(unitsFromLine));
                }
            }
        }