Example #1
0
        /// <summary>
        ///		Interpreta el contenido de una sección
        /// </summary>
        private static string ParseContentSection(ParserLines objParser, string strBoundaryParent, string strBoundary, 
																							ref string strLastLine)
        {
            bool blnEnd = false;
            string strLine, strContent = "";

                // Lee el contenido
                    while (!blnEnd && !objParser.IsEof)
                      { // Lee la línea
                          strLine = objParser.ReadLine();
                        // Dependiendo de si estamos en una línea de boundary o en una línea de contenido
                          if (IsStartBoundary(strLine, strBoundary) || IsStartBoundary(strLine, strBoundaryParent))
                                    { // Guarda la última línea
                                            strLastLine = strLine;
                                        // Indica que ha terminado
                                            blnEnd = true;
                                    }
                                else
                                    { // Añade el salto de línea si es necesario
                                            if (!string.IsNullOrEmpty(strContent))
                                                strContent += "\r\n";
                                        // Añade la línea al contenido
                                            strContent += strLine;
                                    }
                      }
                // Devuelve el contenido de la sección
                    return strContent;
        }
Example #2
0
        /// <summary>
        ///		Interpreta las secciones hijo
        /// </summary>
        private static SectionsCollection ParseSectionsChild(string strBoundaryParent, ParserLines objParser,
																												 ref string strLastLine)
        {
            SectionsCollection objColSections = new SectionsCollection();
            string strLine;

                // Lee la primera línea (o recupera la anterior
                    if (!string.IsNullOrEmpty(strLastLine))
                        strLine = strLastLine;
                    else
                        strLine = objParser.ReadLine();
                // Quita las líneas anteriores al boundary si es necesario
                    if (!string.IsNullOrEmpty(strBoundaryParent) && !IsStartBoundary(strLine, strBoundaryParent))
                        { // Lee la siguiente línea
                                while (!objParser.IsEof && !IsStartBoundary(strLine, strBoundaryParent))
                                    strLine = objParser.ReadLine();
                        }
                // Si es la línea de boundary
                    if (IsStartBoundary(strLine, strBoundaryParent))
                        { bool blnEnd = false;

                                // Recorre las secciones hija
                                    while (!objParser.IsEof && !blnEnd)
                                        if (!string.IsNullOrEmpty(strLastLine) && IsEndBoundary(strLastLine, strBoundaryParent))
                                            blnEnd = true;
                                        else
                                            { Section objSection = ParseSection(objParser, strBoundaryParent, ref strLastLine);

                                                    // Añade la sección a la colección
                                                        objColSections.Add(objSection);
                                                    // Comprueba la última línea leída
                                                        if (IsEndBoundary(strLastLine, strBoundaryParent))
                                                            { // Vacía la última línea al ser un final de sección para pasar a la siguiente lectura
                                                                // sin una cadena de lectura atrasada (al fin y al cabo, la hemos tratado en el
                                                                // IsEndBoundary
                                                                    if (!objParser.IsEof)
                                                                        { strLastLine = objParser.ReadLine();
                                                                            if (strLastLine == "")
                                                                                strLastLine = objParser.ReadLine();
                                                                        }
                                                                    else
                                                                        strLastLine = "";
                                                                // Indica que es el final de sección
                                                                    blnEnd = true;
                                                            }
                                                        else if (objSection.ContentType.IsMultipart)
                                                            objSection.Sections.AddRange(ParseSectionsChild(objSection.ContentType.Boundary,
                                                                                                                                                            objParser, ref strLastLine));
                                            }
                        }
                    else
                      throw new Exception("Boundary mal formado");
                // Devuelve las secciones
                    return objColSections;
        }