/// <summary> /// Outputs a string ready for RSS /// </summary> /// <returns>A string formatted for RSS</returns> public override string ToString() { StringBuilder ItemString = new StringBuilder(); ItemString.Append("<item><title>").Append(Title).Append("</title>\r\n<link>") .Append(Link).Append("</link>\r\n<author>").Append(Author) .Append("</author>\r\n"); foreach (string Category in Categories) { ItemString.Append("<category>").Append(Category).Append("</category>\r\n"); } ItemString.Append("<pubDate>").Append(PubDate.ToString("r", CultureInfo.InvariantCulture)).Append("</pubDate>\r\n"); if (Enclosure != null) { ItemString.Append(Enclosure.ToString()); } if (Thumbnail != null) { ItemString.Append(Thumbnail.ToString()); } ItemString.Append("<description><![CDATA[").Append(Description).Append("]]></description>\r\n"); if (GUID != null) { ItemString.Append(GUID.ToString()); } ItemString.Append("<itunes:subtitle>").Append(Title).Append("</itunes:subtitle>"); ItemString.Append("<itunes:summary><![CDATA[").Append(Description).Append("]]></itunes:summary>"); ItemString.Append("</item>\r\n"); return(ItemString.ToString()); }
public int CompareTo(Item other) { if (other == null) { return(1); } return(PubDate.CompareTo(other.PubDate)); }
protected override void WriteElementExtensions(XmlWriter writer, string version) { WriteFeedElement(writer, "link", Link); WriteFeedElement(writer, "Title", Title.Text); WriteFeedElement(writer, "Description", HtmlSafe(Summary.Text)); WriteFeedElement(writer, "PubDate", PubDate.ToLongDateString()); WriteFeedElement(writer, "Guid", Guid); WriteFeedElement(writer, "Encoded", HtmlSafe(Encoded)); }
public XElement ToXml() { XElement RetVal = new XElement("item"); RetVal.SetElementValue("link", Link.ToString()); RetVal.SetElementValue("title", Title); RetVal.SetElementValue("description", Description); RetVal.SetElementValue("pubDate", PubDate.ToString("yyyy-MM-dd HH:mm:ss")); RetVal.Add(Enclosure.ToXml()); return(RetVal); }
public void WriteXml(XmlWriter writer) { XmlSerializerNamespaces ns = new XmlSerializerNamespaces(); ns.Add("", ""); writer.WriteElementString("episodeType", Namespaces.ITunes, EpisodeType.ToString()); if (Episode.HasValue) { writer.WriteElementString("episode", Namespaces.ITunes, Episode.Value.ToString()); } if (Season.HasValue) { writer.WriteElementString("season", Namespaces.ITunes, Season.Value.ToString()); } writer.WriteElementString("title", Title); if (!string.IsNullOrWhiteSpace(Subtitle)) { writer.WriteElementString("subtitle", Namespaces.ITunes, Subtitle); } /* * These nodes will be populated with the Description property */ writer.WriteElementString("description", Description); writer.WriteElementString("summary", Namespaces.ITunes, Description); if (!string.IsNullOrWhiteSpace(DescriptionEncoded)) { writer.WriteStartElement("encoded", Namespaces.Content); writer.WriteCData(DescriptionEncoded); writer.WriteEndElement(); } writer.WriteElementString("author", Namespaces.ITunes, Author); XmlSerializerNamespaces ns2 = new XmlSerializerNamespaces(); ns2.Add("itunes", Namespaces.ITunes); new XmlSerializer(typeof(Image)).Serialize(writer, Image, ns2); writer.WriteElementString("link", Link); new XmlSerializer(typeof(Enclosure)).Serialize(writer, Enclosure, ns); writer.WriteElementString("guid", Guid); writer.WriteElementString("pubDate", PubDate.ToUniversalTime().ToString("ddd, dd MMM yyyy HH:mm:ss +0000")); writer.WriteElementString("duration", Namespaces.ITunes, Duration.ToString()); writer.WriteElementString("explicit", Namespaces.ITunes, Explicit ? "true" : "false"); }
/// <summary> /// Creates an item element with page info /// </summary> /// <returns>Returns <see cref="XElement"/> that represents an item tag in the yandex turbo feed.</returns> public XElement ToXElement() { return(new XElement( "item", new XAttribute("turbo", Turbo), new XElement("link", Link), new XElement(_turboYandexNamespace + "source", Source), new XElement(_turboYandexNamespace + "topic", Topic), new XElement("pubDate", PubDate.ToString("R")), new XElement("author", Author), Related?.ToXElement(), new XElement(_turboYandexNamespace + "content", new XCData(Content)))); }
public WbTime?TryParsePubDate() { if (PubDate == null || PubDate.StartsWith('?')) { return(null); } if (DateTime.TryParse(PubDate, out var v)) { return(WbTime.FromDateTime(v, WikibaseTimePrecision.Day)); } var year = Convert.ToInt16(PubDate); return(WbTime.FromDateTime(new DateTime(year, 1, 1, 0, 0, 0, DateTimeKind.Utc), WikibaseTimePrecision.Year)); }
public XmlDocument GenerateXML() { var doc = new XmlDocument(); var rss = doc.Begin("rss"); rss.Attributes = new Dictionary <string, string>() { { "version", "2.0" }, { "xmlns:content", "http://purl.org/rss/1.0/modules/content/" }, { "xmlns:wfw", "http://wellformedweb.org/CommentAPI/" }, { "xmlns:dc", "http://purl.org/dc/elements/1.1/" }, { "xmlns:wp", "http://wordpress.org/export/1.2/" }, { "xmlns:excerpt", "http://wordpress.org/export/1.2/excerpt/" } }; var channel = rss.Add("channel"); channel.Add("title", Title).Up() .Add("link", Link).Up() .Add("description").CData(Description).Up() .Add("language", "en").Up() .Add("wp:wxr_version", "1.1").Up() .Add("generator", "hughesoft.com").Up() .Add("pubDate", PubDate.ToString()).Up() .Add("wp:base_site_url", BaseUrl).Up() .Add("wp:base_blog_url", BlogUrl); foreach (var tag in Posts.SelectMany(x => x.Tags)) { channel.Add("wp:tag") .Add("wp:tag_slug", tag.Slug).Up() .Add("wp:tag_name").CData(tag.Name); } foreach (var cat in Posts.SelectMany(x => x.Categories)) { channel.Add("wp:category") .Add("wp:category_nicename", cat.NiceName).Up() .Add("wp:cat_name").CData(cat.Name).Up() .Add("wp:category_parent", cat.Parent); } foreach (var post in Posts) { channel.Children.Add(post.GenerateXML()); } return(doc); }
public override int GetHashCode() { unchecked { var hashCode = RegNumber; hashCode = (hashCode * 397) ^ (Country != null ? Country.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (Inventors != null ? Inventors.GetHashCode() : 0); hashCode = (hashCode * 397) ^ AppDate.GetHashCode(); hashCode = (hashCode * 397) ^ PubDate.GetHashCode(); hashCode = (hashCode * 397) ^ (Name != null ? Name.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (Note != null ? Note.GetHashCode() : 0); hashCode = (hashCode * 397) ^ CountPages; return(hashCode); } }
public XElement ToXml() { XElement RetVal = new XElement("item"); RetVal.SetElementValue("link", Link.ToString()); RetVal.SetElementValue("title", Title); RetVal.SetElementValue("description", Description); RetVal.SetElementValue("pubDate", PubDate.ToString("yyyy-MM-dd HH:mm:ss")); RetVal.SetAttributeValue("isread", IsRead); if (Enclosure != null) { RetVal.Add(Enclosure.ToXml()); } return(RetVal); }
public override string ToString() { StringBuilder sb = new StringBuilder(); sb.AppendLine(" <item>"); sb.AppendLine($" <title>{Title}</title>"); sb.AppendLine($" <guid isPermaLink=\"false\">{Guid}</guid>"); sb.AppendLine($" <pubDate>{(PubDate.ToString("ddd',' d MMM yyyy HH':'mm':'ss", new CultureInfo("en-US")) + " " + PubDate.ToString("zzzz").Replace(":", ""))}</pubDate>"); sb.AppendLine($" <category>{Category}</category>"); sb.AppendLine($" <link>{Link}</link>"); sb.AppendLine($" <description><![CDATA[{Description}]]></description>"); sb.Append(" </item>"); return(sb.ToString()); }
public void Save() { string file = Path.Combine(_folder, ID + ".xml"); XDocument doc = new XDocument( new XElement("post", new XElement("title", Title), new XElement("slug", Slug), new XElement("pubDate", PubDate.ToString("yyyy-MM-dd HH:mm:ss")), new XElement("content", Content), new XElement("ispublished", IsPublished), new XElement("categories", string.Empty), new XElement("comments", string.Empty) )); XElement categories = doc.XPathSelectElement("post/categories"); foreach (string category in Categories) { categories.Add(new XElement("category", category)); } XElement comments = doc.XPathSelectElement("post/comments"); foreach (Comment comment in Comments) { comments.Add( new XElement("comment", new XElement("author", comment.Author), new XElement("email", comment.Email), new XElement("website", comment.Website), new XElement("ip", comment.Ip), new XElement("userAgent", comment.UserAgent), new XElement("date", comment.PubDate.ToString("yyyy-MM-dd HH:m:ss")), new XElement("content", comment.Content), new XAttribute("isAdmin", comment.IsAdmin), new XAttribute("id", comment.ID) )); } if (!File.Exists(file)) // New post { Post.Posts.Insert(0, this); Post.Posts.Sort((p1, p2) => p2.PubDate.CompareTo(p1.PubDate)); } doc.Save(file); }
/// <summary> /// 生成XML操作实例 /// </summary> /// <returns></returns> public IO.XmlHelper CreateXml() { var rssXmlWr = new DoNet.Common.IO.XmlHelper();//XML读写 rssXmlWr.CreateNewXML(RssDoc.XmlHeader); //结点属性集合 var attributeDic = new Dictionary <string, string>(); attributeDic.Add("version", RssDoc.Version); //创建根结点rss var rssRoot = rssXmlWr.CreateNewNode(null, XmlNodeType.Element, "rss", attributeDic); //创建频道 var channcel = rssXmlWr.CreateNewNode(rssRoot, XmlNodeType.Element, "channel"); CreateNode("title", Title, rssXmlWr, channcel);//写入标题 CreateNode("link", Link, rssXmlWr, channcel); if (!string.IsNullOrWhiteSpace(Logo)) { CreateNode("image", string.Format("<url>{0}</url>", Logo), rssXmlWr, channcel); } CreateNode("description", Description, rssXmlWr, channcel); CreateNode("language", Language, rssXmlWr, channcel); if (PubDate != DateTime.MinValue && PubDate != DateTime.MaxValue) { CreateNode("pubDate", PubDate.ToString("yyyy/MM/dd HH:mm:ss"), rssXmlWr, channcel); } //var ci = new CultureInfo("en-us"); if (LastBuildDate != DateTime.MinValue && LastBuildDate != DateTime.MaxValue) { CreateNode("lastBuildDate", this.LastBuildDate.ToString("yyyy/MM/dd HH:mm:ss"), rssXmlWr, channcel); } CreateNode("docs", Docs, rssXmlWr, channcel); CreateNode("generator", Generator, rssXmlWr, channcel); CreateNode("managingEditor", ManagingEditor, rssXmlWr, channcel); CreateNode("webMaster", WebMaster, rssXmlWr, channcel); CreateNode("ttl", Items.Count.ToString(), rssXmlWr, channcel); foreach (var item in Items) { CreateRssItem(item, rssXmlWr, channcel); } return(rssXmlWr); }
public void PrintSingleTitle() { Console.WriteLine($"{String.Format("{0, -10}", "Title_Id")}" + $"{String.Format("{0, -40}", "Title")} " + $"{String.Format("{0, -20}", "ISBN")} " + $"{String.Format("{0, -25}", "Author")} " + $"{String.Format("{0, -25}", "Publisher")} " + $"{String.Format("{0, -20}", "Genre")} " + $"{String.Format("{0, -20}", "Published Date")} " + $"Price"); // print a line StringBuilder sbLine = new StringBuilder(); for (int i = 0; i < 180; i++) { sbLine.Append('='); } Console.WriteLine(sbLine); // truncate too long title string shortTitle = Title1; if (shortTitle.Length > 35) { shortTitle = shortTitle.Substring(0, 35); } // format ISBN string fIsbn = Isbn.Substring(0, 3) + '-' + Isbn.Substring(3); Console.WriteLine($"{String.Format("{0, -10}", TitleId)}" + $"{String.Format("{0, -40}", shortTitle)} " + $"{String.Format("{0, -20}", fIsbn)} " + $"{String.Format("{0, -25}", Author)} " + $"{String.Format("{0, -25}", Publisher)} " + $"{String.Format("{0, -20}", Genre)} " + $"{String.Format("{0, -20}", PubDate.ToShortDateString())} " + $"{"$ " + String.Format("{0, 5}", String.Format("{0:n2}", Price))}"); }
public override string ToString() { // truncate too long title string shortTitle = Title1; if (shortTitle.Length > 35) { shortTitle = shortTitle.Substring(0, 35); } // format ISBN string fIsbn = Isbn.Substring(0, 3) + '-' + Isbn.Substring(3); return($"{String.Format("{0, -10}", TitleId)}" + $"{String.Format("{0, -40}", shortTitle)} " + $"{String.Format("{0, -20}", fIsbn)} " + $"{String.Format("{0, -25}", Author)} " + $"{String.Format("{0, -25}", Publisher)} " + $"{String.Format("{0, -20}", Genre)} " + $"{String.Format("{0, -20}", PubDate.ToShortDateString())} " + $"{"$ " + String.Format("{0, 5}", String.Format("{0:n2}", Price))}"); }
/// <summary> /// Converts the channel to a string /// </summary> /// <returns>The channel as a string</returns> public override string ToString() { StringBuilder ChannelString = new StringBuilder(); ChannelString.Append("<channel>"); ChannelString.Append("<title>").Append(Title).Append("</title>\r\n"); ChannelString.Append("<link>").Append(Link).Append("</link>\r\n"); ChannelString.Append("<atom:link xmlns:atom=\"http://www.w3.org/2005/Atom\" rel=\"self\" href=\"").Append(Link).Append("\" type=\"application/rss+xml\" />"); ChannelString.Append("<description><![CDATA[").Append(Description).Append("]]></description>\r\n"); ChannelString.Append("<language>").Append(Language).Append("</language>\r\n"); ChannelString.Append("<copyright>").Append(Copyright).Append("</copyright>\r\n"); ChannelString.Append("<webMaster>").Append(WebMaster).Append("</webMaster>\r\n"); ChannelString.Append("<pubDate>").Append(PubDate.ToString("Ddd, dd MMM yyyy HH':'mm':'ss", CultureInfo.InvariantCulture)).Append("</pubDate>\r\n"); ChannelString.Append("<itunes:explicit>").Append((Explicit ? "yes" : "no")).Append("</itunes:explicit>"); ChannelString.Append("<itunes:subtitle>").Append(Title).Append("</itunes:subtitle>"); ChannelString.Append("<itunes:summary><![CDATA[").Append(Description).Append("]]></itunes:summary>"); foreach (string Category in Categories) { ChannelString.Append("<category>").Append(Category).Append("</category>\r\n"); ChannelString.Append("<itunes:category text=\"").Append(Category).Append("\" />\r\n"); } ChannelString.Append("<docs>").Append(Docs).Append("</docs>\r\n"); ChannelString.Append("<ttl>").Append(TTL.ToString(CultureInfo.InvariantCulture)).Append("</ttl>\r\n"); if (!string.IsNullOrEmpty(ImageUrl)) { ChannelString.Append("<image><url>").Append(ImageUrl).Append("</url>\r\n<title>").Append(Title).Append("</title>\r\n<link>").Append(Link).Append("</link>\r\n</image>\r\n"); } foreach (Item CurrentItem in Items) { ChannelString.Append(CurrentItem.ToString()); } ChannelString.Append("</channel>\r\n"); return(ChannelString.ToString()); }
protected bool Equals(Patent other) { return(RegNumber == other.RegNumber && string.Equals(Country, other.Country) && Equals(Inventors, other.Inventors) && AppDate.Equals(other.AppDate) && PubDate.Equals(other.PubDate) && string.Equals(Name, other.Name) && string.Equals(Note, other.Note) && CountPages == other.CountPages); }
public string GetLink() { return("/{0}/{1}".FormatWith(PubDate.ToString("yyyy/MM", CultureInfo.InvariantCulture), TitleSlug)); }
public bool AreCommentsOpen(int commentsCloseAfterDays) { return(PubDate.AddDays(commentsCloseAfterDays) >= DateTime.UtcNow.ToLocalTime()); }
string GetJornalDateDMY() { var comps = PubDate.Split('_'); return($"{comps[2]}/{comps[1]}/{comps[0]}"); }
public bool AreCommentsOpen(int commentsCloseAfterDays) => PubDate.AddDays(commentsCloseAfterDays) >= DateTime.UtcNow;
/// <summary> /// Simple display /// </summary> /// <returns>[Title]: [Description] ([Date]) \r\n [Body]</returns> public override string ToString() { return(String.Format("{0}: {1} ({2}) {3} {4}", Title, Description, PubDate.ToShortDateString(), Environment.NewLine, Body)); }