public async Task OnChannelDisconnectedAsync(AtomChannel channel) { foreach (var plugin in this._plugins) { await plugin.OnChannelDisconnectedAsync(channel); } }
public async Task OnChannelMessageReceivedAsync(AtomChannel channel, AtomMessage message) { foreach (var plugin in this._plugins) { await plugin.OnChannelMessageReceivedAsync(channel, message); } }
/// <summary> /// Obtiene un canal Atom a partir de los datos de un archivo, si es un archivo RSS o RDF lo convierte a Atom /// </summary> public async Task <AtomChannel> DownloadAsync(string url) { AtomChannel channel = null; // Descarga el archivo try { string fileName = System.IO.Path.GetTempFileName(); // Descarga el archivo LibCommonHelper.Files.HelperFiles.SaveTextFile(fileName, await new HttpWebClient().HttpGetAsync(url)); // Carga los datos if (System.IO.File.Exists(fileName)) { channel = Load(fileName); } // Elimina el archivo System.IO.File.Delete(fileName); } catch (Exception exception) { throw new Exceptions.FeedException(Exceptions.FeedException.ExceptionType.DownloadError, "Error en la descarga. Url: " + url, exception); } // Si ha llegado hasta aquí es porque desconoce el tipo de archivo return(channel); }
/// <summary> /// Obtiene el builder XML de un objeto Atom /// </summary> private MLFile GetFile(AtomChannel channel) { MLFile file = new MLFile(); MLNode node; // Añade la cabecera node = file.Nodes.Add(AtomConstTags.cnstStrChannelRoot); node.Attributes.Add("xmlns", "http://purl.org/atom/ns#"); node.NameSpaces.AddRange(channel.Extensions.GetNameSpaces(channel)); node.Attributes.Add("version", "0.3"); // Obtiene el XML de los datos node.Nodes.Add(AtomConstTags.cnstStrChannelId, channel.ID); AddText(node, AtomConstTags.cnstStrChannelTitle, channel.Title); AddText(node, AtomConstTags.cnstStrChannelTagline, channel.TagLine); AddText(node, AtomConstTags.cnstsubTitle, channel.Subtitle); node.Nodes.Add(AtomConstTags.cnsticon, channel.Icon); node.Nodes.Add(AtomConstTags.cnstStrLogo, channel.Logo); AddRights(node, channel.Rights); AddGenerator(node, channel.Generator); node.Nodes.Add(AtomConstTags.cnstStrChannelConvertLineBreaks, channel.ConvertLineBreaks); AddText(node, AtomConstTags.cnstStrChannelInfo, channel.Info); AddLinks(node, channel.Links); AddDate(node, AtomConstTags.cnstStrItemModified, channel.LastUpdated); AddCategories(node, channel.Categories); // Obtiene el XML de las extensiones channel.Extensions.AddNodesExtension(node); // Obtiene el XML de los elementos AddItems(node, channel.Entries); // Devuelve los datos return(file); }
public override Stream OnChannelCreatingStream(AtomChannel channel, Stream stream) { var sslStream = new SslStream(stream); sslStream.AuthenticateAsServer(this._certificate); return(sslStream); }
public Stream OnChannelCreatingStream(AtomChannel channel, Stream stream) { foreach (var plugin in this._plugins) { stream = plugin.OnChannelCreatingStream(channel, stream); } return(stream); }
internal NetsyChannel(AtomChannel atomChannel, IPackageSerializer packageSerializer, NetsyConnectionHelper.HandlerRegistry handlerRegistry) { Guard.NotNull(atomChannel, nameof(atomChannel)); Guard.NotNull(packageSerializer, nameof(packageSerializer)); Guard.NotNull(handlerRegistry, nameof(handlerRegistry)); this._atomChannel = atomChannel; this._atomChannel.MessageReceived += this.AtomChannelOnMessageReceived; this._connectionHelper = new NetsyConnectionHelper(packageSerializer, atomChannel.SendMessageAsync, handlerRegistry); this.Data = new Dictionary <string, object>(); }
/// <summary> /// Convierte un archivo RDF en un archivo Atom /// </summary> public AtomChannel Convert(RDFChannel rdf) { AtomChannel channel = new AtomChannel(); // Convierte los datos del canal channel.ID = new Guid().ToString(); channel.Title = ConvertText(rdf.Title); channel.Info = ConvertText(rdf.Description); channel.Subtitle = ConvertText(""); channel.Links.Add(ConvertLink(rdf.Link, AtomLink.AtomLinkType.Self)); // Añade las extensiones ConvertExtension(rdf.Extensions, channel.Extensions); // Añade las entradas ConvertEntries(rdf, channel); // Devuelve el objeto Atom return(channel); }
/// <summary> /// Interpreta los datos de un archivo XML /// </summary> public AtomChannel Parse(MLFile fileML) { AtomChannel channel = ParseRSS(fileML); // Si no se ha cargado desde un archivo RSS, se carga desde un archivo RDF if (channel == null) { channel = ParseRDF(fileML); } // Si no se ha cargado desde un archivo RSS, se carga desde un archivo Atom if (channel == null) { channel = new AtomParser().Parse(fileML); } // Devuelve los datos return(channel); }
/// <summary> /// Añade los mensajes a las cuentas /// </summary> private EntriesModelCollection AddMessages(BlogModel blog, AtomChannel channel) { EntriesModelCollection downloaded = new EntriesModelCollection(); // Graba las entradas nuevas foreach (AtomEntry entry in channel.Entries) { if (entry.Links != null && entry.Links.Count > 0 && !entry.Links[0].Href.IsEmpty() && !blog.Entries.ExistsURL(entry.Links[0].Href)) { EntryModel blogEntry = new EntryModel(); // Asigna el blog blogEntry.Blog = blog; // Asigna los datos a la entrada blogEntry.Name = entry.Title.Content; blogEntry.Content = entry.Content.Content; blogEntry.URL = entry.Links[0].Href; blogEntry.UrlEnclosure = GetUrlAttachment(entry.Links); blogEntry.DownloadFileName = GetDownloadFileName(blog, blogEntry.UrlEnclosure); if (entry.Authors != null && entry.Authors.Count > 0) { blogEntry.Author = entry.Authors[0].Name; } blogEntry.DatePublish = entry.DatePublished; blogEntry.Status = EntryModel.StatusEntry.NotRead; // Lanza el evento de descarga de una entrada RaiseEvent(blogEntry); // Añade la entrada al blog y a la lista de elementos descargados blog.Entries.Add(blogEntry); downloaded.Add(blogEntry); } } // Si se ha añadido algo, graba las entradas if (downloaded.Count > 0) { // Cambia el número de elementos no leídos blog.NumberNotRead = blog.Entries.GetNumberNotRead(); // Graba las entradas new Bussiness.Blogs.EntryBussiness().Save(blog, _blogManager.Configuration.PathBlogs); } // Devuelve los elementos descargados return(downloaded); }
/// <summary> /// Convierte un archivo RSS en un archivo Atom /// </summary> public RSSChannel Convert(AtomChannel channel) { RSSChannel rss = new RSSChannel(); // Convierte los datos del canal rss.Title = channel.Title.Content; rss.Generator = channel.Generator.Name; rss.Description = channel.Info.Content; if (channel.Links.Count > 0) { rss.Link = channel.Links[0].Href; } rss.LastBuildDate = channel.LastUpdated; // Añade las extensiones ConvertExtension(channel.Extensions, rss.Extensions); // Añade las entradas ConvertEntries(channel, rss); // Devuelve el objeto Atom return(rss); }
/// <summary> /// Interpreta un archivo XML /// </summary> public AtomChannel Parse(MLFile fileML) { AtomChannel channel = null; // Recorre los nodos del documento if (fileML != null) { foreach (MLNode node in fileML.Nodes) { if (node.Name.Equals(AtomConstTags.cnstStrChannelRoot)) { // Crea el objeto channel = new AtomChannel(); // Lee los datos ParseChannel(node, channel); } } } // Devuelve el objeto Atom return(channel); }
/// <summary> /// Convierte las entradas Atom en entradas RSS /// </summary> private void ConvertEntries(AtomChannel channel, RSSChannel rss) { foreach (AtomEntry channelEntry in channel.Entries) { RSSEntry rssEntry = new RSSEntry(); // Convierte los datos de la entrada rssEntry.GUID.ID = channelEntry.ID; rssEntry.Title = channelEntry.Title.Content; rssEntry.Content = channelEntry.Content.Content; rssEntry.DateCreated = channelEntry.DatePublished; // Vínculos if (channelEntry.Links.Count > 0) { rssEntry.Link = channelEntry.Links[0].Href; } foreach (AtomLink channelLink in channelEntry.Links) { if (channelLink.LinkType.Equals("enclosure")) { rssEntry.Enclosures.Add(ConvertLink(channelLink)); } } // Autores foreach (AtomPeople channelAuthor in channelEntry.Authors) { rssEntry.Authors.Add(new RSSAuthor(channelAuthor.Name)); } // Categorías foreach (AtomCategory channelCategory in channelEntry.Categories) { rssEntry.Categories.Add(new RSSCategory(channelCategory.Name)); } // Convierte las extensiones ConvertExtension(channelEntry.Extensions, rssEntry.Extensions); // Añade la entrada al objeto Atom rss.Entries.Add(rssEntry); } }
/// <summary> /// Convierte un archivo RSS en un archivo Atom /// </summary> public AtomChannel Convert(RSSChannel rss) { AtomChannel channel = new AtomChannel(); // Convierte los datos del canal channel.ID = new Guid().ToString(); channel.Title = ConvertText(rss.Title); channel.Generator = ConvertGenerator(rss.Generator); channel.ConvertLineBreaks = true; channel.Info = ConvertText(rss.Description); channel.Subtitle = ConvertText(""); channel.Links.Add(ConvertLink(rss.Link, AtomLink.AtomLinkType.Self)); channel.LastUpdated = rss.LastBuildDate; channel.Icon = rss.Logo.Url; channel.Logo = rss.Logo.Url; // Añade las extensiones ConvertExtension(rss.Extensions, channel.Extensions); // Añade las entradas ConvertEntries(rss, channel); // Devuelve el objeto Atom return(channel); }
/// <summary> /// Convierte las entradas RDF en entradas Atom /// </summary> private void ConvertEntries(RDFChannel rdf, AtomChannel channel) { foreach (RDFEntry rdfEntry in rdf.Entries) { AtomEntry channelEntry = new AtomEntry(); // Convierte los datos de la entrada channelEntry.ID = rdfEntry.ID; channelEntry.Title = ConvertText(rdfEntry.Title); channelEntry.Content = ConvertText(rdfEntry.Content); channelEntry.DateIssued = rdfEntry.DateCreated; channelEntry.DateCreated = rdfEntry.DateCreated; channelEntry.DateModified = rdfEntry.DateCreated; channelEntry.DateUpdated = rdfEntry.DateCreated; channelEntry.DatePublished = rdfEntry.DateCreated; // Vínculos channelEntry.Links.Add(ConvertLink(rdfEntry.Link, AtomLink.AtomLinkType.Self)); // Convierte las extensiones ConvertExtension(rdfEntry.Extensions, channelEntry.Extensions); // Añade la entrada al objeto Atom channel.Entries.Add(channelEntry); } }
/// <summary> /// Convierte las entradas RSS en entradas Atom /// </summary> private void ConvertEntries(RSSChannel rss, AtomChannel channel) { foreach (RSSEntry rssEntry in rss.Entries) { AtomEntry channelEntry = new AtomEntry(); // Convierte los datos de la entrada channelEntry.ID = rssEntry.ID; channelEntry.Title = ConvertText(rssEntry.Title); channelEntry.Content = ConvertText(rssEntry.Content); channelEntry.DateIssued = rssEntry.DateCreated; channelEntry.DateCreated = rssEntry.DateCreated; channelEntry.DateModified = rssEntry.DateCreated; channelEntry.DateUpdated = rssEntry.DateCreated; channelEntry.DatePublished = rssEntry.DateCreated; // Vínculos channelEntry.Links.Add(ConvertLink(rssEntry.Link, AtomLink.AtomLinkType.Self)); foreach (RSSEnclosure rssEnclosure in rssEntry.Enclosures) { channelEntry.Links.Add(ConvertLink(rssEnclosure)); } // Autores foreach (RSSAuthor rssAuthor in rssEntry.Authors) { channelEntry.Authors.Add(ConvertAuthor(rssAuthor)); } // Categorías foreach (RSSCategory rssCategory in rssEntry.Categories) { channelEntry.Categories.Add(ConvertCategory(rssCategory)); } // Convierte las extensiones ConvertExtension(rssEntry.Extensions, channelEntry.Extensions); // Añade la entrada al objeto Atom channel.Entries.Add(channelEntry); } }
public virtual Task OnChannelConnectedAsync(AtomChannel channel) { return(Task.CompletedTask); }
/// <summary> /// Interpreta una entrada de un archivo Atom /// </summary> private AtomEntry ParseEntry(MLNode objMLEntry, AtomChannel channel) { AtomEntry entry = new AtomEntry(); // Recorre los nodos foreach (MLNode node in objMLEntry.Nodes) { switch (node.Name) { case AtomConstTags.cnstStrItemID: entry.ID = node.Value; break; case AtomConstTags.cnstStrItemTitle: entry.Title = ParseText(node); break; case AtomConstTags.cnstStrItemContent: entry.Content = ParseText(node); break; case AtomConstTags.cnstStrSummary: entry.Summary = ParseText(node); break; case AtomConstTags.cnstStrItemIssued: entry.DateIssued = node.Value.GetDateTime(DateTime.MinValue); break; case AtomConstTags.cnstStrItemModified: entry.DateModified = node.Value.GetDateTime(DateTime.MinValue); break; case AtomConstTags.cnstStrItemCreated: entry.DateCreated = node.Value.GetDateTime(DateTime.MinValue); break; case AtomConstTags.cnstStrItemUpdated: entry.DateUpdated = node.Value.GetDateTime(DateTime.MinValue); break; case AtomConstTags.cnstStrItemPublished: entry.DatePublished = node.Value.GetDateTime(DateTime.MinValue); break; case AtomConstTags.cnstStrItemLink: entry.Links.Add(ParseLink(node)); break; case AtomConstTags.cnstStrItemAuthor: entry.Authors.Add(ParsePeople(node)); break; case AtomConstTags.cnstStrItemContributor: entry.Contributors.Add(ParsePeople(node)); break; case AtomConstTags.cnstStrChannelCategory: entry.Categories.Add(ParseCategory(node)); break; case AtomConstTags.cnstsource: entry.Source = ParseSource(node); break; case AtomConstTags.cnstStrRights: entry.Rights = ParseRights(node); break; default: entry.Extensions.Parse(node, entry, channel.Dictionary); break; } } // Actualiza la fecha de creación if (entry.DateCreated.Date == DateTime.MinValue.Date) { entry.DateCreated = entry.DatePublished; if (entry.DateCreated.Date == DateTime.MinValue.Date) { entry.DateCreated = DateTime.Now; } } // Devuelve la entrada return(entry); }
/// <summary> /// Interpreta los datos del canal /// </summary> private void ParseChannel(MLNode node, AtomChannel channel) { foreach (MLNode child in node.Nodes) { switch (child.Name) { case AtomConstTags.cnstStrChannelId: channel.ID = child.Value; break; case AtomConstTags.cnstStrChannelTitle: channel.Title = ParseText(child); break; case AtomConstTags.cnstStrChannelTagline: channel.TagLine = ParseText(child); break; case AtomConstTags.cnstsubTitle: channel.Subtitle = ParseText(child); break; case AtomConstTags.cnsticon: channel.Icon = child.Value; break; case AtomConstTags.cnstStrLogo: channel.Logo = child.Value; break; case AtomConstTags.cnstStrRights: channel.Rights = ParseRights(child); break; case AtomConstTags.cnstStrChannelGenerator: channel.Generator = ParseGenerator(child); break; case AtomConstTags.cnstStrChannelConvertLineBreaks: channel.ConvertLineBreaks = child.Value.GetBool(false); break; case AtomConstTags.cnstStrChannelInfo: channel.Info = ParseText(child); break; case AtomConstTags.cnstStrItemLink: channel.Links.Add(ParseLink(child)); break; case AtomConstTags.cnstStrItemModified: channel.LastUpdated = child.Value.GetDateTime(DateTime.Now); break; case AtomConstTags.cnstStrChannelCategory: channel.Categories.Add(ParseCategory(child)); break; case AtomConstTags.cnstStrItemRoot: channel.Entries.Add(ParseEntry(child, channel)); break; default: channel.Extensions.Parse(child, channel, channel.Dictionary); break; } } }
public virtual Task OnChannelSendingMessageAsync(AtomChannel channel, AtomMessage message) { return(Task.CompletedTask); }
public virtual Task OnChannelMessageReceivedAsync(AtomChannel channel, AtomMessage message) { return(Task.CompletedTask); }
public virtual Stream OnChannelCreatingStream(AtomChannel channel, Stream stream) { return(stream); }
/// <summary> /// Graba los datos de un objeto Atom en un archivo XML /// </summary> public void Save(AtomChannel channel, string fileName) { new XMLWriter().Save(fileName, GetFile(channel)); }
/// <summary> /// Obtiene el XML de un canal Atom /// </summary> public string GetXML(AtomChannel channel) { return(GetFile(channel).ToString()); }