示例#1
0
        /// <summary>
        ///		Interpreta las cabeceras de un archivo OPML
        /// </summary>
        private void ParseHead(MLNodesCollection nodes, OPMLChannel channel)
        {
            foreach (MLNode node in nodes)
            {
                switch (node.Name)
                {
                case OPMLConstTags.cnsttitle:
                    channel.Title = node.Value;
                    break;

                case OPMLConstTags.cnstStrDateCreated:
                    channel.DateCreated = node.Value.GetDateTime(DateTime.Now);
                    break;

                case OPMLConstTags.cnstStrDateModified:
                    channel.DateModified = node.Value.GetDateTime(DateTime.Now);
                    break;

                case OPMLConstTags.cnstStrOwnerName:
                    channel.OwnerName = node.Value;
                    break;

                case OPMLConstTags.cnstStrOwnerEMail:
                    channel.OwnerEMail = node.Value;
                    break;
                }
            }
        }
示例#2
0
        /// <summary>
        ///		Interpreta un archivo
        /// </summary>
        public OPMLChannel Parse(string fileName)
        {
            OPMLChannel channel = null;
            MLFile      fileML  = new XMLParser().Load(fileName);

            // Lee los datos
            if (fileML != null)
            {
                foreach (MLNode node in fileML.Nodes)
                {
                    if (node.Name == OPMLConstTags.cnstStrRoot)
                    {
                        // Crea el objeto
                        channel = new OPMLChannel();
                        // Carga los datos
                        foreach (MLNode channelML in node.Nodes)
                        {
                            switch (channelML.Name)
                            {
                            case OPMLConstTags.cnstStrHead:
                                ParseHead(channelML.Nodes, channel);
                                break;

                            case OPMLConstTags.cnstbody:
                                ParseEntries(channelML.Nodes, channel.Entries);
                                break;
                            }
                        }
                    }
                }
            }
            // Devuelve los datos del canal
            return(channel);
        }
示例#3
0
        /// <summary>
        ///		Graba un archivo OPML con los datos actuales
        /// </summary>
        internal void Save(BlogReaderManager manager, string fileName)
        {
            OPMLChannel channel = new OPMLChannel();

            // Asigna las propiedades
            channel.Title = "Archivo creado con Bau Studio";
            // Añade las carpetas
            foreach (Model.FolderModel folder in manager.File.Folders)
            {
                AddFolder(folder, channel.Entries);
            }
            // Añade los blogs
            foreach (Model.BlogModel blog in manager.File.Blogs)
            {
                AddBlog(blog, channel.Entries);
            }
            // Graba el archivo
            LibHelper.Files.HelperFiles.MakePath(System.IO.Path.GetDirectoryName(fileName));
            new OPMLWriter().Save(channel, fileName);
        }
示例#4
0
        /// <summary>
        ///		Obtiene el builder XML de un objeto Atom
        /// </summary>
        private MLFile GetFile(OPMLChannel channel)
        {
            MLFile file = new MLFile();
            MLNode node = file.Nodes.Add(OPMLConstTags.cnstStrRoot);
            MLNode nodeHeader;

            // Añade la cabecera
            node.Attributes.Add("version", "1.1");
            // Cabecera
            nodeHeader = node.Nodes.Add(OPMLConstTags.cnstStrHead);
            // Obtiene el XML de los datos
            nodeHeader.Nodes.Add(OPMLConstTags.cnsttitle, channel.Title);
            nodeHeader.Nodes.Add(OPMLConstTags.cnstStrDateCreated,
                                 DateTimeHelper.ToStringRfc822(channel.DateCreated));
            nodeHeader.Nodes.Add(OPMLConstTags.cnstStrDateModified,
                                 DateTimeHelper.ToStringRfc822(channel.DateModified));
            nodeHeader.Nodes.Add(OPMLConstTags.cnstStrOwnerName, channel.OwnerName);
            nodeHeader.Nodes.Add(OPMLConstTags.cnstStrOwnerEMail, channel.OwnerEMail);
            // Obtiene el XML de los elementos
            AddEntries(node.Nodes.Add(OPMLConstTags.cnstbody), channel.Entries);
            // Devuelve los datos
            return(file);
        }
示例#5
0
 /// <summary>
 ///		Graba los datos de un objeto OPML en un archivo XML
 /// </summary>
 public void Save(OPMLChannel channel, string fileName)
 {
     new XMLWriter().Save(fileName, GetFile(channel));
 }
示例#6
0
 /// <summary>
 ///		Obtiene el XML de un canal RSS
 /// </summary>
 public string GetXML(OPMLChannel channel)
 {
     return(GetFile(channel).ToString());
 }