BlogEngine.Core.SyndicationGenerator.GetPermaLink C# (CSharp) Méthode

GetPermaLink() private static méthode

Creates a Uri that represents the peramlink for the supplied IPublishable.
/// The is a null reference (Nothing in Visual Basic). ///
private static GetPermaLink ( IPublishable publishable ) : Uri
publishable IPublishable /// The used to generate the permalink for. ///
Résultat System.Uri
        private static Uri GetPermaLink(IPublishable publishable)
        {
            var post = publishable as Post;
            return post != null ? post.PermaLink : publishable.AbsoluteLink;
        }

Usage Example

Exemple #1
0
        /// <summary>
        /// Writes the Atom feed entry element information to the specified <see cref="XmlWriter"/> using the supplied <see cref="Page"/>.
        /// </summary>
        /// <param name="writer">The <see cref="XmlWriter"/> to write feed entry element information to.</param>
        /// <param name="publishable">The <see cref="IPublishable"/> used to generate feed entry content.</param>
        private static void WriteAtomEntry(XmlWriter writer, IPublishable publishable)
        {
            Post    post    = publishable as Post;
            Comment comment = publishable as Comment;

            //------------------------------------------------------------
            //	Raise serving event
            //------------------------------------------------------------
            ServingEventArgs arg = new ServingEventArgs(publishable.Content, ServingLocation.Feed);

            publishable.OnServing(arg);
            if (arg.Cancel)
            {
                return;
            }

            //------------------------------------------------------------
            //	Modify publishable content to make references absolute
            //------------------------------------------------------------
            string content = ConvertPathsToAbsolute(arg.Body);

            writer.WriteStartElement("entry");
            //------------------------------------------------------------
            //	Write required entry elements
            //------------------------------------------------------------
            writer.WriteElementString("id", Utils.ConvertToAbsolute(publishable.RelativeLink).ToString());
            writer.WriteElementString("title", publishable.Title);
            writer.WriteElementString("updated", SyndicationGenerator.ToW3CDateTime(publishable.DateCreated.ToUniversalTime()));

            //------------------------------------------------------------
            //	Write recommended entry elements
            //------------------------------------------------------------
            writer.WriteStartElement("link");
            writer.WriteAttributeString("rel", "self");
            writer.WriteAttributeString("href", SyndicationGenerator.GetPermaLink(publishable).ToString());
            writer.WriteEndElement();

            writer.WriteStartElement("link");
            writer.WriteAttributeString("href", Utils.ConvertToAbsolute(publishable.RelativeLink).ToString());
            writer.WriteEndElement();

            writer.WriteStartElement("author");
            writer.WriteElementString("name", publishable.Author);
            writer.WriteEndElement();

            writer.WriteStartElement("summary");
            writer.WriteAttributeString("type", "html");
            writer.WriteString(content);
            writer.WriteEndElement();

            //------------------------------------------------------------
            //	Write optional entry elements
            //------------------------------------------------------------
            writer.WriteElementString("published", SyndicationGenerator.ToW3CDateTime(publishable.DateCreated.ToUniversalTime()));

            writer.WriteStartElement("link");
            writer.WriteAttributeString("rel", "related");
            writer.WriteAttributeString("href", String.Concat(Utils.ConvertToAbsolute(publishable.RelativeLink).ToString(), "#comment"));
            writer.WriteEndElement();

            //------------------------------------------------------------
            //	Write enclosure tag for podcasting support
            //------------------------------------------------------------
            if (BlogSettings.Instance.EnableEnclosures)
            {
                string encloser = GetEnclosure(content);
                if (!string.IsNullOrEmpty(encloser))
                {
                    writer.WriteRaw(encloser);
                }
            }

            //------------------------------------------------------------
            //	Write entry category elements
            //------------------------------------------------------------
            if (publishable.Categories != null)
            {
                foreach (Category category in publishable.Categories)
                {
                    writer.WriteStartElement("category");
                    writer.WriteAttributeString("term", category.Title);
                    writer.WriteEndElement();
                }
            }

            //------------------------------------------------------------
            //	Write Dublin Core syndication extension elements
            //------------------------------------------------------------
            if (!String.IsNullOrEmpty(publishable.Author))
            {
                writer.WriteElementString("dc", "publisher", "http://purl.org/dc/elements/1.1/", publishable.Author);
            }
            if (!String.IsNullOrEmpty(publishable.Description))
            {
                writer.WriteElementString("dc", "description", "http://purl.org/dc/elements/1.1/", publishable.Description);
            }

            //------------------------------------------------------------
            //	Write pingback syndication extension elements
            //------------------------------------------------------------
            Uri pingbackServer;

            if (Uri.TryCreate(String.Concat(Utils.AbsoluteWebRoot.ToString().TrimEnd('/'), "/pingback.axd"), UriKind.RelativeOrAbsolute, out pingbackServer))
            {
                writer.WriteElementString("pingback", "server", "http://madskills.com/public/xml/rss/module/pingback/", pingbackServer.ToString());
                writer.WriteElementString("pingback", "target", "http://madskills.com/public/xml/rss/module/pingback/", SyndicationGenerator.GetPermaLink(publishable).ToString());
            }

            //------------------------------------------------------------
            //	Write slash syndication extension elements
            //------------------------------------------------------------
            if (post != null && post.Comments != null)
            {
                writer.WriteElementString("slash", "comments", "http://purl.org/rss/1.0/modules/slash/", post.Comments.Count.ToString(CultureInfo.InvariantCulture));
            }

            //------------------------------------------------------------
            //	Write trackback syndication extension elements
            //------------------------------------------------------------
            if (post != null && post.TrackbackLink != null)
            {
                writer.WriteElementString("trackback", "ping", "http://madskills.com/public/xml/rss/module/trackback/", post.TrackbackLink.ToString());
            }

            //------------------------------------------------------------
            //	Write well-formed web syndication extension elements
            //------------------------------------------------------------
            writer.WriteElementString("wfw", "comment", "http://wellformedweb.org/CommentAPI/", String.Concat(Utils.ConvertToAbsolute(publishable.RelativeLink).ToString(), "#comment"));
            writer.WriteElementString("wfw", "commentRss", "http://wellformedweb.org/CommentAPI/", Utils.AbsoluteWebRoot.ToString().TrimEnd('/') + "/syndication.axd?post=" + publishable.Id.ToString());

            //------------------------------------------------------------
            //	Write </entry> element
            //------------------------------------------------------------
            writer.WriteEndElement();
        }
All Usage Examples Of BlogEngine.Core.SyndicationGenerator::GetPermaLink