Exemple #1
0
        public bool leerArchivo(string path, Documento data)
        {
            string archivo = IOArchivos.leerArchivo(path);

            bool   tag      = false;
            bool   tagColor = false;
            string color    = "";

            foreach (char c in archivo)
            {
                //Identificar si hay un tag de color
                if (c == '<')
                {
                    tag   = true;
                    color = "";
                }
                //Identificar cual es el color
                else if (c == '=')
                {
                    if (color == "color")
                    {
                        color    = "";
                        tagColor = true;
                        tag      = false;
                    }
                }
                else if (c == '>')
                {
                    tagColor = false;
                }
                else if (tag)
                {
                    color += c;
                }
                else if (tagColor)
                {
                    color += c;
                }
                else
                {
                    Console.WriteLine(color);
                    System.Drawing.Color color1;
                    switch (color)
                    {
                    case "Red":
                        color1 = System.Drawing.Color.Red;
                        break;

                    case "Green":
                        color1 = System.Drawing.Color.Green;
                        break;

                    case "Blue":
                        color1 = System.Drawing.Color.Blue;
                        break;

                    case "Black":
                        color1 = System.Drawing.Color.Black;
                        break;

                    case "Yellow":
                        color1 = System.Drawing.Color.Yellow;
                        break;

                    default:
                        color1 = System.Drawing.Color.Black;
                        break;
                    }
                    Caracter caracter;
                    if (c == '\t')
                    {
                        caracter = new Caracter(' ', color1);
                    }
                    else
                    {
                        caracter = new Caracter(c, color1);
                    }
                    data.Caracteres.Add(caracter);
                }
            }
            return(true);
        }
        public bool leerArchivo(string path, Documento data)
        {
            int    counter = 0;
            string line;
            string color = "White";
            string texto;
            int    tamaño;

            // Read the file and display it line by line.
            System.IO.StreamReader file =
                new System.IO.StreamReader(path);
            while ((line = file.ReadLine()) != null)
            {
                if ((line[0] != '{') & (line[0] != '}') & (line != "\"Glosario\":"))
                {
                    if (line.Substring(0, 7).Equals("\"color\""))
                    {
                        color  = "";
                        tamaño = line.Length - 2;
                        for (int i = 9; i != tamaño; i++)
                        {
                            color += line[i];
                        }
                        Console.WriteLine(color);
                    }
                    else
                    {
                        texto  = "";
                        tamaño = line.Length - 2;
                        for (int i = 9; i != tamaño; i++)
                        {
                            texto += line[i];
                        }
                        Console.WriteLine(texto);
                        System.Drawing.Color color1;
                        switch (color)
                        {
                        case "Red":
                            color1 = System.Drawing.Color.Red;
                            break;

                        case "Green":
                            color1 = System.Drawing.Color.Green;
                            break;

                        case "Blue":
                            color1 = System.Drawing.Color.Blue;
                            break;

                        case "Black":
                            color1 = System.Drawing.Color.Black;
                            break;

                        case "Yellow":
                            color1 = System.Drawing.Color.Yellow;
                            break;

                        default:
                            color1 = System.Drawing.Color.Black;
                            break;
                        }
                        Caracter caracter;
                        foreach (Char c in texto)
                        {
                            caracter = new Caracter(c, color1);
                            data.Caracteres.Add(caracter);
                        }
                    }
                }
                System.Console.WriteLine(line);
                counter++;
            }

            file.Close();
            System.Console.WriteLine("There were {0} lines.", counter);
            return(true);
        }