/// <summary>
        /// Writes the supplied <see cref="ISyndicationResource"/> to the specified <see cref="HttpContext"/> response stream and sets the appropriate headers.
        /// </summary>
        /// <param name="context">
        ///     An <see cref="HttpContext"/> object that provides references to the intrinsic server objects
        ///     (for example, <b>Request</b>, <b>Response</b>, <b>Session</b>, and <b>Server</b>) used to service HTTP requests.
        /// </param>
        /// <param name="resource">The <see cref="ISyndicationResource"/> to be written to the response stream.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="context"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="resource"/> is a null reference (Nothing in Visual Basic).</exception>
        private void WriteResource(HttpContext context, ISyndicationResource resource)
        {
            //------------------------------------------------------------
            //	Validate parameters
            //------------------------------------------------------------
            Guard.ArgumentNotNull(context, "context");
            Guard.ArgumentNotNull(resource, "resource");

            //------------------------------------------------------------
            //	Process conditional GET information if present
            //  (If conditions met, handler execution stops.)
            //------------------------------------------------------------
            SyndicationResourceHandler.ProcessConditionalGetInformation(context, resource);

            //------------------------------------------------------------
            //	Modify response meta-data information
            //------------------------------------------------------------
            context.Response.ContentType = SyndicationResourceHandler.ContentFormatAsMimeType(resource.Format);
            context.Response.AppendHeader("Content-Disposition", SyndicationResourceHandler.GetContentDisposition(resource.Format));

            //------------------------------------------------------------
            //	Save XML representation of resource to output stream
            //------------------------------------------------------------
            SyndicationResourceSaveSettings settings = new SyndicationResourceSaveSettings();

            settings.AutoDetectExtensions = true;
            settings.MinimizeOutputSize   = false;

            resource.Save(context.Response.OutputStream, settings);

            //------------------------------------------------------------
            //	Modify response caching expiration information
            //------------------------------------------------------------
            this.ModifyCacheExpiration(context);
        }
예제 #2
0
파일: RssResult.cs 프로젝트: dpawatts/zeus
        protected override void WriteXml(ControllerContext context)
        {
            RssFeed feed = new RssFeed();
            feed.Channel.Title = Feed.Title;
            feed.Channel.Link = GetLink(Feed.Url);
            feed.Channel.Description = Feed.Tagline;
            feed.Channel.PublicationDate = Feed.Published;
            feed.Channel.LastBuildDate = DateTime.Now;
            feed.Channel.Generator = "Zeus CMS";
            feed.Channel.ManagingEditor = Feed.Author;

            foreach (ISyndicatable syndicatable in Feed.Items)
            {
                RssItem item = new RssItem();
                item.Title = syndicatable.Title;
                item.Link = GetLink(syndicatable.Url);
                item.Description = syndicatable.Summary;
                item.PublicationDate = syndicatable.Published;
                feed.Channel.AddItem(item);
            }

            SyndicationResourceSaveSettings settings = new SyndicationResourceSaveSettings
            {
                CharacterEncoding = new UTF8Encoding(false)
            };

            feed.Save(context.HttpContext.Response.OutputStream, settings);
        }
        /// <summary>
        /// Saves the syndication resource to the specified <see cref="XmlWriter"/> and <see cref="SyndicationResourceSaveSettings"/>.
        /// </summary>
        /// <param name="writer">The <b>XmlWriter</b> to which you want to save the syndication resource.</param>
        /// <param name="settings">The <see cref="SyndicationResourceSaveSettings"/> object used to configure the persistance of the <see cref="AtomEntry"/> instance.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="writer"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="settings"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="XmlException">The operation would not result in well formed XML for the syndication resource.</exception>
        public new void Save(XmlWriter writer, SyndicationResourceSaveSettings settings)
        {
            Guard.ArgumentNotNull(writer, "writer");
            Guard.ArgumentNotNull(settings, "settings");

            List <ISyndicationExtension> list = new List <ISyndicationExtension>(this.Extensions);

            if (this.EditedOn != DateTime.MinValue)
            {
                if (!list.Exists(AtomPublishingEditedSyndicationExtension.MatchByType))
                {
                    AtomPublishingEditedSyndicationExtension editedExtension = new AtomPublishingEditedSyndicationExtension();
                    editedExtension.Context.EditedOn = this.EditedOn;
                    this.AddExtension(editedExtension);
                }
            }

            if (this.IsDraft)
            {
                if (!list.Exists(AtomPublishingControlSyndicationExtension.MatchByType))
                {
                    AtomPublishingControlSyndicationExtension controlExtension = new AtomPublishingControlSyndicationExtension();
                    controlExtension.Context.IsDraft = this.IsDraft;
                    this.AddExtension(controlExtension);
                }
            }

            base.Save(writer, settings);
        }
예제 #4
0
        public override void ExecuteResult(ControllerContext context)
        {
            context.HttpContext.Response.ContentType = "application/rss+xml";
            SyndicationResourceSaveSettings settings = new SyndicationResourceSaveSettings();

            settings.CharacterEncoding = new UTF8Encoding(false);
            Feed.Save(context.HttpContext.Response.OutputStream, settings);
        }
예제 #5
0
        /// <summary>
        /// Saves the syndication resource to the specified <see cref="XmlWriter"/> using the supplied <see cref="SyndicationResourceSaveSettings"/>.
        /// </summary>
        /// <param name="writer">The <b>XmlWriter</b> to which you want to save the syndication resource.</param>
        /// <param name="settings">The <see cref="SyndicationResourceSaveSettings"/> object used to configure the persistance of the <see cref="MyCustomRssFeed"/> instance.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="writer"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="settings"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="XmlException">The operation would not result in well formed XML for the syndication resource.</exception>
        public void Save(XmlWriter writer, SyndicationResourceSaveSettings settings)
        {
            Guard.ArgumentNotNull(writer, "writer");
            Guard.ArgumentNotNull(settings, "settings");
            writer.WriteStartElement("rss");
            writer.WriteAttributeString("version", this.Version.ToString());

            //  Code to write XML representation of custom syndication resource to the supplied writer would go here

            writer.WriteEndElement();
        }
예제 #6
0
        /// <summary>
        /// Saves the syndication resource to the specified <see cref="Stream"/>.
        /// </summary>
        /// <param name="stream">The <b>Stream</b> to which you want to save the syndication resource.</param>
        /// <param name="settings">The <see cref="SyndicationResourceSaveSettings"/> object used to configure the persistance of the <see cref="MyCustomRssFeed"/> instance. This value can be <b>null</b>.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="stream"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="XmlException">The operation would not result in well formed XML for the syndication resource.</exception>
        public void Save(Stream stream, SyndicationResourceSaveSettings settings)
        {
            Guard.ArgumentNotNull(stream, "stream");

            if (settings == null)
            {
                settings = new SyndicationResourceSaveSettings();
            }
            XmlWriterSettings writerSettings = new XmlWriterSettings();

            writerSettings.OmitXmlDeclaration = false;
            writerSettings.Indent             = !settings.MinimizeOutputSize;
            writerSettings.Encoding           = settings.CharacterEncoding;

            using (XmlWriter writer = XmlWriter.Create(stream, writerSettings))
            {
                this.Save(writer, settings);
            }
        }
예제 #7
0
        /// <summary>
        /// Adds the supplied <see cref="ISyndicationResource"/> to the data store using the specifed <see cref="Guid"/>.
        /// </summary>
        /// <param name="resourceKey">A <see cref="Guid"/> that represents the globally unique identifier for the <paramref name="resource"/>.</param>
        /// <param name="resource">The <see cref="ISyndicationResource"/> to be added to the data store.</param>
        /// <returns>A <see cref="SyndicationResourceCreateStatus"/> enumeration value that indicates the result of the adding the syndication resource to the data store.</returns>
        private SyndicationResourceCreateStatus ResourceAdd(Guid resourceKey, ISyndicationResource resource)
        {
            Guard.ArgumentNotNull(resource, "resource");

            if (this.ResourceKeyExists(resourceKey))
            {
                return(SyndicationResourceCreateStatus.DuplicateProviderResourceKey);
            }

            string resourceFilePath = this.BuildResourcePath(resourceKey, resource.Format);

            using (FileStream stream = new FileStream(resourceFilePath, FileMode.Create, FileAccess.Write))
            {
                SyndicationResourceSaveSettings settings = new SyndicationResourceSaveSettings();
                settings.AutoDetectExtensions = true;
                settings.MinimizeOutputSize   = false;

                resource.Save(stream, settings);
            }

            return(SyndicationResourceCreateStatus.Success);
        }
예제 #8
0
        /// <summary>
        /// Saves the syndication resource to the specified <see cref="XmlWriter"/> and <see cref="SyndicationResourceSaveSettings"/>.
        /// </summary>
        /// <param name="writer">The <b>XmlWriter</b> to which you want to save the syndication resource.</param>
        /// <param name="settings">The <see cref="SyndicationResourceSaveSettings"/> object used to configure the persistance of the <see cref="AtomEntry"/> instance.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="writer"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="settings"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="XmlException">The operation would not result in well formed XML for the syndication resource.</exception>
        public new void Save(XmlWriter writer, SyndicationResourceSaveSettings settings)
        {
            //------------------------------------------------------------
            //	Validate parameter
            //------------------------------------------------------------
            Guard.ArgumentNotNull(writer, "writer");
            Guard.ArgumentNotNull(settings, "settings");

            //------------------------------------------------------------
            //	Modify syndication extensions based on properties
            //------------------------------------------------------------
            List <ISyndicationExtension> list = new List <ISyndicationExtension>(this.Extensions);

            if (this.EditedOn != DateTime.MinValue)
            {
                if (!list.Exists(AtomPublishingEditedSyndicationExtension.MatchByType))
                {
                    AtomPublishingEditedSyndicationExtension editedExtension = new AtomPublishingEditedSyndicationExtension();
                    editedExtension.Context.EditedOn = this.EditedOn;
                    this.AddExtension(editedExtension);
                }
            }

            if (this.IsDraft)
            {
                if (!list.Exists(AtomPublishingControlSyndicationExtension.MatchByType))
                {
                    AtomPublishingControlSyndicationExtension controlExtension = new AtomPublishingControlSyndicationExtension();
                    controlExtension.Context.IsDraft = this.IsDraft;
                    this.AddExtension(controlExtension);
                }
            }

            //------------------------------------------------------------
            //	Save member resource
            //------------------------------------------------------------
            base.Save(writer, settings);
        }
예제 #9
0
        /// <summary>
        /// Updates the supplied <see cref="ISyndicationResource"/> within the data store that has the specifed <see cref="Guid"/>.
        /// </summary>
        /// <param name="resourceKey">A <see cref="Guid"/> that represents the globally unique identifier of the resource to be updated.</param>
        /// <param name="resource">A <see cref="ISyndicationResource"/> object that represents the updated information for the resource to be updated.</param>
        /// <remarks>
        ///     If there is no resource for the specified <paramref name="resourceKey"/>, no modification to the data store occurs.
        /// </remarks>
        private void ResourceUpdate(Guid resourceKey, ISyndicationResource resource)
        {
            Guard.ArgumentNotNull(resource, "resource");

            if (!this.ResourceKeyExists(resourceKey))
            {
                return;
            }

            string resourceFilePath = this.BuildResourcePath(resourceKey, resource.Format);

            if (File.Exists(resourceFilePath))
            {
                using (FileStream stream = new FileStream(resourceFilePath, FileMode.Create, FileAccess.Write))
                {
                    SyndicationResourceSaveSettings settings = new SyndicationResourceSaveSettings();
                    settings.AutoDetectExtensions = true;
                    settings.MinimizeOutputSize   = false;

                    resource.Save(stream, settings);
                }
            }
        }
예제 #10
0
파일: AtomEntry.cs 프로젝트: Jiyuu/Argotic
        /// <summary>
        /// Saves the syndication resource to the specified <see cref="XmlWriter"/> and <see cref="SyndicationResourceSaveSettings"/>.
        /// </summary>
        /// <param name="writer">The <b>XmlWriter</b> to which you want to save the syndication resource.</param>
        /// <param name="settings">The <see cref="SyndicationResourceSaveSettings"/> object used to configure the persistance of the <see cref="AtomEntry"/> instance.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="writer"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="settings"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="XmlException">The operation would not result in well formed XML for the syndication resource.</exception>
        public void Save(XmlWriter writer, SyndicationResourceSaveSettings settings)
        {
            //------------------------------------------------------------
            //	Validate parameter
            //------------------------------------------------------------
            Guard.ArgumentNotNull(writer, "writer");
            Guard.ArgumentNotNull(settings, "settings");

            //------------------------------------------------------------
            //	Save entry
            //------------------------------------------------------------
            writer.WriteStartElement("entry", AtomUtility.AtomNamespace);

            if (settings.AutoDetectExtensions)
            {
                SyndicationExtensionAdapter.FillExtensionTypes(this, settings.SupportedExtensions);

                if(this.Content != null)
                {
                    SyndicationExtensionAdapter.FillExtensionTypes(this.Content, settings.SupportedExtensions);
                }
                if (this.Id != null)
                {
                    SyndicationExtensionAdapter.FillExtensionTypes(this.Id, settings.SupportedExtensions);
                }
                if (this.Rights != null)
                {
                    SyndicationExtensionAdapter.FillExtensionTypes(this.Rights, settings.SupportedExtensions);
                }
                if (this.Source != null)
                {
                    SyndicationExtensionAdapter.FillExtensionTypes(this.Source, settings.SupportedExtensions);
                }
                if (this.Summary != null)
                {
                    SyndicationExtensionAdapter.FillExtensionTypes(this.Summary, settings.SupportedExtensions);
                }
                if (this.Title != null)
                {
                    SyndicationExtensionAdapter.FillExtensionTypes(this.Title, settings.SupportedExtensions);
                }

                foreach (AtomPersonConstruct author in this.Authors)
                {
                    SyndicationExtensionAdapter.FillExtensionTypes(author, settings.SupportedExtensions);
                }
                foreach (AtomCategory category in this.Categories)
                {
                    SyndicationExtensionAdapter.FillExtensionTypes(category, settings.SupportedExtensions);
                }
                foreach (AtomPersonConstruct contributor in this.Contributors)
                {
                    SyndicationExtensionAdapter.FillExtensionTypes(contributor, settings.SupportedExtensions);
                }
                foreach (AtomLink link in this.Links)
                {
                    SyndicationExtensionAdapter.FillExtensionTypes(link, settings.SupportedExtensions);
                }
            }
            SyndicationExtensionAdapter.WriteXmlNamespaceDeclarations(settings.SupportedExtensions, writer);

            AtomUtility.WriteCommonObjectAttributes(this, writer);

            if (this.Id != null)
            {
                this.Id.WriteTo(writer);
            }
            if (this.Title != null)
            {
                this.Title.WriteTo(writer, "title");
            }
            if (this.UpdatedOn != DateTime.MinValue)
            {
                writer.WriteElementString("updated", AtomUtility.AtomNamespace, SyndicationDateTimeUtility.ToRfc3339DateTime(this.UpdatedOn));
            }

            this.WriteEntryOptionals(writer);
            this.WriteEntryCollections(writer);

            //------------------------------------------------------------
            //	Write the syndication extensions of the current instance
            //------------------------------------------------------------
            SyndicationExtensionAdapter.WriteExtensionsTo(this.Extensions, writer);

            writer.WriteEndElement();
        }
예제 #11
0
        /// <summary>
        /// Saves the syndication resource to the specified <see cref="XmlWriter"/> and <see cref="SyndicationResourceSaveSettings"/>.
        /// </summary>
        /// <param name="writer">The <b>XmlWriter</b> to which you want to save the syndication resource.</param>
        /// <param name="settings">The <see cref="SyndicationResourceSaveSettings"/> object used to configure the persistance of the <see cref="AtomCategoryDocument"/> instance.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="writer"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="settings"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="XmlException">The operation would not result in well formed XML for the syndication resource.</exception>
        public void Save(XmlWriter writer, SyndicationResourceSaveSettings settings)
        {
            //------------------------------------------------------------
            //	Validate parameter
            //------------------------------------------------------------
            Guard.ArgumentNotNull(writer, "writer");
            Guard.ArgumentNotNull(settings, "settings");

            //------------------------------------------------------------
            //	Save document
            //------------------------------------------------------------
            writer.WriteStartElement("categories", AtomUtility.AtomPublishingNamespace);
            // writer.WriteAttributeString("version", this.Version.ToString());

            if (settings.AutoDetectExtensions)
            {
                SyndicationExtensionAdapter.FillExtensionTypes(this, settings.SupportedExtensions);

                foreach (AtomCategory category in this.Categories)
                {
                    SyndicationExtensionAdapter.FillExtensionTypes(category, settings.SupportedExtensions);
                }
            }
            SyndicationExtensionAdapter.WriteXmlNamespaceDeclarations(settings.SupportedExtensions, writer);

            AtomUtility.WriteCommonObjectAttributes(this, writer);

            if (this.IsFixed)
            {
                writer.WriteAttributeString("fixed", "yes");
            }

            if (this.Scheme != null)
            {
                writer.WriteAttributeString("scheme", this.Scheme.ToString());
            }

            if (this.Uri != null)
            {
                writer.WriteAttributeString("href", this.Uri.ToString());
            }

            foreach (AtomCategory category in this.Categories)
            {
                category.WriteTo(writer);
            }

            //------------------------------------------------------------
            //	Write the syndication extensions of the current instance
            //------------------------------------------------------------
            SyndicationExtensionAdapter.WriteExtensionsTo(this.Extensions, writer);

            writer.WriteEndElement();
        }
예제 #12
0
        /// <summary>
        /// Saves the syndication resource to the specified <see cref="XmlWriter"/> and <see cref="SyndicationResourceSaveSettings"/>.
        /// </summary>
        /// <param name="writer">The <b>XmlWriter</b> to which you want to save the syndication resource.</param>
        /// <param name="settings">The <see cref="SyndicationResourceSaveSettings"/> object used to configure the persistance of the <see cref="AtomServiceDocument"/> instance.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="writer"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="settings"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="XmlException">The operation would not result in well formed XML for the syndication resource.</exception>
        public void Save(XmlWriter writer, SyndicationResourceSaveSettings settings)
        {
            //------------------------------------------------------------
            //	Validate parameter
            //------------------------------------------------------------
            Guard.ArgumentNotNull(writer, "writer");
            Guard.ArgumentNotNull(settings, "settings");

            //------------------------------------------------------------
            //	Save document
            //------------------------------------------------------------
            writer.WriteStartElement("service", AtomUtility.AtomPublishingNamespace);
            // writer.WriteAttributeString("version", this.Version.ToString());

            if (settings.AutoDetectExtensions)
            {
                SyndicationExtensionAdapter.FillExtensionTypes(this, settings.SupportedExtensions);

                foreach (AtomWorkspace workspace in this.Workspaces)
                {
                    SyndicationExtensionAdapter.FillExtensionTypes(workspace, settings.SupportedExtensions);
                }
            }
            SyndicationExtensionAdapter.WriteXmlNamespaceDeclarations(settings.SupportedExtensions, writer);

            AtomUtility.WriteCommonObjectAttributes(this, writer);

            foreach (AtomWorkspace workspace in this.Workspaces)
            {
                workspace.WriteTo(writer);
            }

            //------------------------------------------------------------
            //	Write the syndication extensions of the current instance
            //------------------------------------------------------------
            SyndicationExtensionAdapter.WriteExtensionsTo(this.Extensions, writer);

            writer.WriteEndElement();
        }
예제 #13
0
파일: RssFeed.cs 프로젝트: Jiyuu/Argotic
        /// <summary>
        /// Saves the syndication resource to the specified <see cref="Stream"/>.
        /// </summary>
        /// <param name="stream">The <b>Stream</b> to which you want to save the syndication resource.</param>
        /// <param name="settings">The <see cref="SyndicationResourceSaveSettings"/> object used to configure the persistance of the <see cref="RssFeed"/> instance. This value can be <b>null</b>.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="stream"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="XmlException">The operation would not result in well formed XML for the syndication resource.</exception>
        public void Save(Stream stream, SyndicationResourceSaveSettings settings)
        {
            //------------------------------------------------------------
            //	Validate parameter
            //------------------------------------------------------------
            Guard.ArgumentNotNull(stream, "stream");

            if (settings == null)
            {
                settings    = new SyndicationResourceSaveSettings();
            }

            //------------------------------------------------------------
            //	Create XmlWriter against supplied stream to save feed
            //------------------------------------------------------------
            XmlWriterSettings writerSettings    = new XmlWriterSettings();
            writerSettings.OmitXmlDeclaration   = false;
            writerSettings.Indent               = !settings.MinimizeOutputSize;
            writerSettings.Encoding             = settings.CharacterEncoding;

            using (XmlWriter writer = XmlWriter.Create(stream, writerSettings))
            {
                this.Save(writer, settings);
            }
        }
예제 #14
0
파일: RssFeed.cs 프로젝트: Jiyuu/Argotic
        /// <summary>
        /// Saves the syndication resource to the specified <see cref="XmlWriter"/> using the supplied <see cref="SyndicationResourceSaveSettings"/>.
        /// </summary>
        /// <param name="writer">The <b>XmlWriter</b> to which you want to save the syndication resource.</param>
        /// <param name="settings">The <see cref="SyndicationResourceSaveSettings"/> object used to configure the persistance of the <see cref="RssFeed"/> instance.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="writer"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="settings"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="XmlException">The operation would not result in well formed XML for the syndication resource.</exception>
        public void Save(XmlWriter writer, SyndicationResourceSaveSettings settings)
        {
            //------------------------------------------------------------
            //	Validate parameter
            //------------------------------------------------------------
            Guard.ArgumentNotNull(writer, "writer");
            Guard.ArgumentNotNull(settings, "settings");

            //------------------------------------------------------------
            //	Save feed
            //------------------------------------------------------------
            writer.WriteStartElement("rss");
            writer.WriteAttributeString("version", this.Version.ToString());

            if (this.Channel != null && this.Channel.SelfLink != null)
            {
                writer.WriteAttributeString("xmlns", "atom", null, "http://www.w3.org/2005/Atom");
            }

            if (settings.AutoDetectExtensions)
            {
                SyndicationExtensionAdapter.FillExtensionTypes(this, settings.SupportedExtensions);
                SyndicationExtensionAdapter.FillExtensionTypes(this.Channel, settings.SupportedExtensions);
                if (this.Channel.Cloud != null)
                {
                    SyndicationExtensionAdapter.FillExtensionTypes(this.Channel.Cloud, settings.SupportedExtensions);
                }
                if (this.Channel.Image != null)
                {
                    SyndicationExtensionAdapter.FillExtensionTypes(this.Channel.Image, settings.SupportedExtensions);
                }
                if (this.Channel.TextInput != null)
                {
                    SyndicationExtensionAdapter.FillExtensionTypes(this.Channel.TextInput, settings.SupportedExtensions);
                }

                foreach (RssCategory category in this.Channel.Categories)
                {
                    SyndicationExtensionAdapter.FillExtensionTypes(category, settings.SupportedExtensions);
                }
                foreach (RssItem item in this.Channel.Items)
                {
                    SyndicationExtensionAdapter.FillExtensionTypes(item, settings.SupportedExtensions);

                    if (item.Guid != null)
                    {
                        SyndicationExtensionAdapter.FillExtensionTypes(item.Guid, settings.SupportedExtensions);
                    }
                    if (item.Source != null)
                    {
                        SyndicationExtensionAdapter.FillExtensionTypes(item.Source, settings.SupportedExtensions);
                    }

                    foreach (RssCategory category in item.Categories)
                    {
                        SyndicationExtensionAdapter.FillExtensionTypes(category, settings.SupportedExtensions);
                    }
                    foreach (RssEnclosure enclosure in item.Enclosures)
                    {
                        SyndicationExtensionAdapter.FillExtensionTypes(enclosure, settings.SupportedExtensions);
                    }
                }
            }

            SyndicationExtensionAdapter.WriteXmlNamespaceDeclarations(settings.SupportedExtensions, writer);

            if (this.Channel != null)
            {
                this.Channel.WriteTo(writer);
            }

            //------------------------------------------------------------
            //	Write the syndication extensions of the current instance
            //------------------------------------------------------------
            SyndicationExtensionAdapter.WriteExtensionsTo(this.Extensions, writer);

            writer.WriteEndElement();
        }
예제 #15
0
        /// <summary>
        /// Saves the syndication resource to the specified <see cref="XmlWriter"/> and <see cref="SyndicationResourceSaveSettings"/>.
        /// </summary>
        /// <param name="writer">The <b>XmlWriter</b> to which you want to save the syndication resource.</param>
        /// <param name="settings">The <see cref="SyndicationResourceSaveSettings"/> object used to configure the persistance of the <see cref="OpmlDocument"/> instance.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="writer"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="settings"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="XmlException">The operation would not result in well formed XML for the syndication resource.</exception>
        public void Save(XmlWriter writer, SyndicationResourceSaveSettings settings)
        {
            //------------------------------------------------------------
            //	Validate parameter
            //------------------------------------------------------------
            Guard.ArgumentNotNull(writer, "writer");
            Guard.ArgumentNotNull(settings, "settings");

            //------------------------------------------------------------
            //	Save document
            //------------------------------------------------------------
            writer.WriteStartElement("opml");
            writer.WriteAttributeString("version", this.Version.ToString());

            if (settings.AutoDetectExtensions)
            {
                SyndicationExtensionAdapter.FillExtensionTypes(this, settings.SupportedExtensions);

                if(this.Head != null)
                {
                    SyndicationExtensionAdapter.FillExtensionTypes(this.Head, settings.SupportedExtensions);
                }

                foreach (OpmlOutline outline in this.Outlines)
                {
                    SyndicationExtensionAdapter.FillExtensionTypes(outline, settings.SupportedExtensions);

                    foreach (OpmlOutline childOutline in outline.Outlines)
                    {
                        SyndicationExtensionAdapter.FillExtensionTypes(childOutline, settings.SupportedExtensions);
                    }
                }
            }
            SyndicationExtensionAdapter.WriteXmlNamespaceDeclarations(settings.SupportedExtensions, writer);

            if(this.Head != null)
            {
                this.Head.WriteTo(writer);
            }

            //------------------------------------------------------------
            //	Write the syndication extensions of the current instance
            //------------------------------------------------------------
            SyndicationExtensionAdapter.WriteExtensionsTo(this.Extensions, writer);

            writer.WriteStartElement("body");
            foreach(OpmlOutline outline in this.Outlines)
            {
                outline.WriteTo(writer);
            }
            writer.WriteEndElement();

            writer.WriteEndElement();
        }
예제 #16
0
        /// <summary>
        /// Saves the syndication resource to the specified <see cref="XmlWriter"/> and <see cref="SyndicationResourceSaveSettings"/>.
        /// </summary>
        /// <param name="writer">The <b>XmlWriter</b> to which you want to save the syndication resource.</param>
        /// <param name="settings">The <see cref="SyndicationResourceSaveSettings"/> object used to configure the persistance of the <see cref="ApmlDocument"/> instance.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="writer"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="settings"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="XmlException">The operation would not result in well formed XML for the syndication resource.</exception>
        public void Save(XmlWriter writer, SyndicationResourceSaveSettings settings)
        {
            //------------------------------------------------------------
            //	Validate parameter
            //------------------------------------------------------------
            Guard.ArgumentNotNull(writer, "writer");
            Guard.ArgumentNotNull(settings, "settings");

            //------------------------------------------------------------
            //	Save document
            //------------------------------------------------------------
            writer.WriteStartElement("APML", ApmlUtility.ApmlNamespace);
            writer.WriteAttributeString("version", this.Version.ToString());

            if (settings.AutoDetectExtensions)
            {
                SyndicationExtensionAdapter.FillExtensionTypes(this, settings.SupportedExtensions);

                if (this.Head != null)
                {
                    SyndicationExtensionAdapter.FillExtensionTypes(this.Head, settings.SupportedExtensions);
                }

                foreach (ApmlApplication application in this.Applications)
                {
                    SyndicationExtensionAdapter.FillExtensionTypes(application, settings.SupportedExtensions);
                }

                foreach (ApmlProfile profile in this.Profiles)
                {
                    SyndicationExtensionAdapter.FillExtensionTypes(profile, settings.SupportedExtensions);

                    foreach (ApmlConcept explicitConcept in profile.ExplicitConcepts)
                    {
                        SyndicationExtensionAdapter.FillExtensionTypes(explicitConcept, settings.SupportedExtensions);
                    }

                    foreach (ApmlSource explicitSource in profile.ExplicitSources)
                    {
                        SyndicationExtensionAdapter.FillExtensionTypes(explicitSource, settings.SupportedExtensions);

                        foreach (ApmlAuthor explicitAuthor in explicitSource.Authors)
                        {
                            SyndicationExtensionAdapter.FillExtensionTypes(explicitAuthor, settings.SupportedExtensions);
                        }
                    }

                    foreach (ApmlConcept implicitConcept in profile.ImplicitConcepts)
                    {
                        SyndicationExtensionAdapter.FillExtensionTypes(implicitConcept, settings.SupportedExtensions);
                    }

                    foreach (ApmlSource implicitSource in profile.ImplicitSources)
                    {
                        SyndicationExtensionAdapter.FillExtensionTypes(implicitSource, settings.SupportedExtensions);

                        foreach (ApmlAuthor implicitAuthor in implicitSource.Authors)
                        {
                            SyndicationExtensionAdapter.FillExtensionTypes(implicitAuthor, settings.SupportedExtensions);
                        }
                    }
                }
            }
            SyndicationExtensionAdapter.WriteXmlNamespaceDeclarations(settings.SupportedExtensions, writer);

            this.Head.WriteTo(writer);

            writer.WriteStartElement("Body", ApmlUtility.ApmlNamespace);
            writer.WriteAttributeString("defaultprofile", this.DefaultProfileName);

            foreach(ApmlProfile profile in this.Profiles)
            {
                profile.WriteTo(writer);
            }

            if(this.Applications.Count > 0)
            {
                writer.WriteStartElement("Applications", ApmlUtility.ApmlNamespace);
                foreach (ApmlApplication application in this.Applications)
                {
                    application.WriteTo(writer);
                }
                writer.WriteEndElement();
            }

            writer.WriteEndElement();

            //------------------------------------------------------------
            //	Write the syndication extensions of the current instance
            //------------------------------------------------------------
            SyndicationExtensionAdapter.WriteExtensionsTo(this.Extensions, writer);

            writer.WriteEndElement();
        }
예제 #17
0
        public override void ExecuteItemSequence(string groupByValue, IEnumerable <Tuple <ITaskItem, ITaskItem, ITaskItem> > items)
        {
            var feed = new AtomFeed
            {
                Id        = new AtomId(new Uri(FeedId)),
                Title     = new AtomTextConstruct(FeedTitle ?? ""),
                UpdatedOn = DateTime.Now,
            };

            if (!string.IsNullOrWhiteSpace(FeedRights))
            {
                feed.Rights = new AtomTextConstruct(FeedRights);
            }

            if (!string.IsNullOrWhiteSpace(FeedIcon))
            {
                feed.Icon = new AtomIcon(new Uri(FeedIcon));
            }

            if (!string.IsNullOrWhiteSpace(FeedLogo))
            {
                feed.Logo = new AtomLogo(new Uri(FeedLogo));
            }

            if (!string.IsNullOrWhiteSpace(FeedSubtitle))
            {
                feed.Subtitle = new AtomTextConstruct(FeedSubtitle);
            }


            if (!string.IsNullOrWhiteSpace(FeedAuthors))
            {
                foreach (string author in FeedAuthors.Split(';').Select(item => item.Trim()))
                {
                    feed.Authors.Add(new AtomPersonConstruct(author));
                }
            }

            if (!string.IsNullOrWhiteSpace(FeedContributors))
            {
                foreach (string contributor in FeedContributors.Split(';').Select(item => item.Trim()))
                {
                    feed.Contributors.Add(new AtomPersonConstruct(contributor));
                }
            }

            if (!string.IsNullOrWhiteSpace(FeedCategories))
            {
                foreach (string category in FeedCategories.Split(';').Select(item => item.Trim()))
                {
                    feed.Categories.Add(new AtomCategory(category));
                }
            }

            if (FeedLinkRelationSelf != null)
            {
                var selfLink = new AtomLink
                {
                    Relation = "self",
                    Uri      = new Uri(FeedLinkRelationSelf)
                };
                feed.Links.Add(selfLink);
            }

            foreach (Tuple <ITaskItem, ITaskItem, ITaskItem> tuple in items.OrderByDescending(item => item.Item2.GetTimestamp()))
            {
                ITaskItem modelInput   = tuple.Item1;
                ITaskItem receiptInput = tuple.Item2;
                ITaskItem contentInput = tuple.Item3;

                modelInput.LoadCustomMetadata();

                DateTime receiptModified = receiptInput.GetTimestamp();
                var      entry           = new AtomEntry
                {
                    Id        = new AtomId(new Uri(modelInput.GetMetadata(EntryIdSelector ?? "Uri"))),
                    Title     = new AtomTextConstruct(modelInput.GetMetadata(EntryTitleSelector ?? "Title")),
                    UpdatedOn = receiptModified,
                    Summary   = new AtomTextConstruct(modelInput.GetMetadata(EntrySummarySelector ?? "Summary")),
                };

                if (string.IsNullOrWhiteSpace(entry.Title.Content))
                {
                    entry.Title.Content = tuple.Item1.ItemSpec;
                }
                if (string.IsNullOrWhiteSpace(entry.Summary.Content))
                {
                    entry.Summary.Content = entry.Title.Content;
                }

                if (contentInput.Exists())
                {
                    if (string.IsNullOrWhiteSpace(EntryContentEncoding))
                    {
                        entry.Content = new AtomContent(contentInput.ReadAllText());
                    }
                    else
                    {
                        entry.Content = new AtomContent(contentInput.ReadAllText(), EntryContentEncoding);
                    }

                    if (!string.IsNullOrWhiteSpace(EntryContentType))
                    {
                        entry.Content.ContentType = EntryContentType;
                    }
                }

                var alternateLink = new AtomLink
                {
                    Relation = "alternate",
                    Uri      = new Uri(modelInput.GetMetadata(EntryLinkAlternateSelector ?? "Uri"))
                };
                entry.Links.Add(alternateLink);
                feed.AddEntry(entry);
            }
            using (FileStream stream = File.OpenWrite(Output.ItemSpec))
            {
                SyndicationResourceSaveSettings s = new SyndicationResourceSaveSettings()
                {
                    CharacterEncoding = Encoding.UTF8
                };
                feed.Save(stream, s);
            }
        }
예제 #18
0
        /// <summary>
        /// Saves the syndication resource to the specified <see cref="XmlWriter"/> and <see cref="SyndicationResourceSaveSettings"/>.
        /// </summary>
        /// <param name="writer">The <b>XmlWriter</b> to which you want to save the syndication resource.</param>
        /// <param name="settings">The <see cref="SyndicationResourceSaveSettings"/> object used to configure the persistance of the <see cref="RsdDocument"/> instance.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="writer"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="settings"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="XmlException">The operation would not result in well formed XML for the syndication resource.</exception>
        public void Save(XmlWriter writer, SyndicationResourceSaveSettings settings)
        {
            //------------------------------------------------------------
            //	Validate parameter
            //------------------------------------------------------------
            Guard.ArgumentNotNull(writer, "writer");
            Guard.ArgumentNotNull(settings, "settings");

            //------------------------------------------------------------
            //	Save document
            //------------------------------------------------------------
            writer.WriteStartElement("rsd", RsdUtility.RsdNamespace);
            writer.WriteAttributeString("version", this.Version.ToString());

            if (settings.AutoDetectExtensions)
            {
                SyndicationExtensionAdapter.FillExtensionTypes(this, settings.SupportedExtensions);

                foreach(RsdApplicationInterface api in this.Interfaces)
                {
                    SyndicationExtensionAdapter.FillExtensionTypes(api, settings.SupportedExtensions);
                }
            }
            SyndicationExtensionAdapter.WriteXmlNamespaceDeclarations(settings.SupportedExtensions, writer);

            writer.WriteStartElement("service", RsdUtility.RsdNamespace);

            if(!String.IsNullOrEmpty(this.EngineName))
            {
                writer.WriteElementString("engineName", RsdUtility.RsdNamespace, this.EngineName);
            }

            if (this.EngineLink != null)
            {
                writer.WriteElementString("engineLink", RsdUtility.RsdNamespace, this.EngineLink.ToString());
            }

            if (this.Homepage != null)
            {
                writer.WriteElementString("homePageLink", RsdUtility.RsdNamespace, this.Homepage.ToString());
            }

            writer.WriteStartElement("apis", RsdUtility.RsdNamespace);
            foreach(RsdApplicationInterface api in this.Interfaces)
            {
                api.WriteTo(writer);
            }
            writer.WriteEndElement();

            writer.WriteEndElement();

            //------------------------------------------------------------
            //	Write the syndication extensions of the current instance
            //------------------------------------------------------------
            SyndicationExtensionAdapter.WriteExtensionsTo(this.Extensions, writer);

            writer.WriteEndElement();
        }
예제 #19
0
        /// <summary>
        /// Fills the supported extensions collection of the supplied <see cref="SyndicationResourceSaveSettings"/> object based on syndication extensions present in the current instance hierarchy.
        /// </summary>
        /// <param name="settings">The <see cref="SyndicationResourceSaveSettings"/> object whose <see cref="SyndicationResourceSaveSettings.SupportedExtensions"/> collection is to be filled.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="settings"/> is a null reference (Nothing in Visual Basic).</exception>
        private void FillExtensionTypes(SyndicationResourceSaveSettings settings)
        {
            //------------------------------------------------------------
            //	Validate parameter
            //------------------------------------------------------------
            Guard.ArgumentNotNull(settings, "settings");

            //------------------------------------------------------------
            //	Fill supported extensions based on current syndication extensions
            //------------------------------------------------------------
            SyndicationExtensionAdapter.FillExtensionTypes(this, settings.SupportedExtensions);

            if (this.Subtitle != null)
            {
                SyndicationExtensionAdapter.FillExtensionTypes(this.Subtitle, settings.SupportedExtensions);
            }
            if (this.Title != null)
            {
                SyndicationExtensionAdapter.FillExtensionTypes(this.Title, settings.SupportedExtensions);
            }

            foreach (BlogMLAuthor author in this.Authors)
            {
                SyndicationExtensionAdapter.FillExtensionTypes(author, settings.SupportedExtensions);

                if (author.Title != null)
                {
                    SyndicationExtensionAdapter.FillExtensionTypes(author.Title, settings.SupportedExtensions);
                }
            }

            foreach (BlogMLCategory category in this.Categories)
            {
                SyndicationExtensionAdapter.FillExtensionTypes(category, settings.SupportedExtensions);

                if (category.Title != null)
                {
                    SyndicationExtensionAdapter.FillExtensionTypes(category.Title, settings.SupportedExtensions);
                }
            }

            foreach (BlogMLPost post in this.Posts)
            {
                SyndicationExtensionAdapter.FillExtensionTypes(post, settings.SupportedExtensions);

                if (post.Content != null)
                {
                    SyndicationExtensionAdapter.FillExtensionTypes(post.Content, settings.SupportedExtensions);
                }
                if (post.Excerpt != null)
                {
                    SyndicationExtensionAdapter.FillExtensionTypes(post.Excerpt, settings.SupportedExtensions);
                }
                if (post.Name != null)
                {
                    SyndicationExtensionAdapter.FillExtensionTypes(post.Name, settings.SupportedExtensions);
                }
                if (post.Title != null)
                {
                    SyndicationExtensionAdapter.FillExtensionTypes(post.Title, settings.SupportedExtensions);
                }

                foreach (BlogMLAttachment attachment in post.Attachments)
                {
                    SyndicationExtensionAdapter.FillExtensionTypes(attachment, settings.SupportedExtensions);
                }

                foreach (BlogMLComment comment in post.Comments)
                {
                    SyndicationExtensionAdapter.FillExtensionTypes(comment, settings.SupportedExtensions);

                    if (comment.Content != null)
                    {
                        SyndicationExtensionAdapter.FillExtensionTypes(comment.Content, settings.SupportedExtensions);
                    }
                    if (comment.Title != null)
                    {
                        SyndicationExtensionAdapter.FillExtensionTypes(comment.Title, settings.SupportedExtensions);
                    }
                }

                foreach (BlogMLTrackback trackback in post.Trackbacks)
                {
                    SyndicationExtensionAdapter.FillExtensionTypes(trackback, settings.SupportedExtensions);
                }
            }
        }
예제 #20
0
        /// <summary>
        /// Saves the syndication resource to the specified <see cref="XmlWriter"/> and <see cref="SyndicationResourceSaveSettings"/>.
        /// </summary>
        /// <param name="writer">The <b>XmlWriter</b> to which you want to save the syndication resource.</param>
        /// <param name="settings">The <see cref="SyndicationResourceSaveSettings"/> object used to configure the persistance of the <see cref="BlogMLDocument"/> instance.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="writer"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="settings"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="XmlException">The operation would not result in well formed XML for the syndication resource.</exception>
        public void Save(XmlWriter writer, SyndicationResourceSaveSettings settings)
        {
            //------------------------------------------------------------
            //	Validate parameters
            //------------------------------------------------------------
            Guard.ArgumentNotNull(writer, "writer");
            Guard.ArgumentNotNull(settings, "settings");

            //------------------------------------------------------------
            //	Save document
            //------------------------------------------------------------
            writer.WriteStartElement("blog", BlogMLUtility.BlogMLNamespace);
            //writer.WriteAttributeString("version", this.Version.ToString());

            if (settings.AutoDetectExtensions)
            {
                this.FillExtensionTypes(settings);
            }
            SyndicationExtensionAdapter.WriteXmlNamespaceDeclarations(settings.SupportedExtensions, writer);

            if(this.GeneratedOn != DateTime.MinValue)
            {
                writer.WriteAttributeString("date-created", SyndicationDateTimeUtility.ToRfc3339DateTime(this.GeneratedOn));
            }

            if (this.RootUrl != null)
            {
                writer.WriteAttributeString("root-url", this.RootUrl.ToString());
            }

            if(this.Title != null)
            {
                this.Title.WriteTo(writer, "title");
            }

            if (this.Subtitle != null)
            {
                this.Subtitle.WriteTo(writer, "sub-title");
            }

            if(this.Authors.Count > 0)
            {
                writer.WriteStartElement("authors", BlogMLUtility.BlogMLNamespace);
                foreach (BlogMLAuthor author in this.Authors)
                {
                    author.WriteTo(writer);
                }
                writer.WriteEndElement();
            }

            if (this.ExtendedProperties.Count > 0)
            {
                writer.WriteStartElement("extended-properties", BlogMLUtility.BlogMLNamespace);
                foreach (string property in this.ExtendedProperties.Keys)
                {
                    writer.WriteStartElement("property", BlogMLUtility.BlogMLNamespace);
                    writer.WriteAttributeString("name", property);
                    writer.WriteAttributeString("value", this.ExtendedProperties[property]);
                    writer.WriteEndElement();
                }
                writer.WriteEndElement();
            }

            if (this.Categories.Count > 0)
            {
                writer.WriteStartElement("categories", BlogMLUtility.BlogMLNamespace);
                foreach (BlogMLCategory category in this.Categories)
                {
                    category.WriteTo(writer);
                }
                writer.WriteEndElement();
            }

            if (((Collection<BlogMLPost>)this.Posts).Count > 0)
            {
                writer.WriteStartElement("posts", BlogMLUtility.BlogMLNamespace);
                foreach (BlogMLPost post in this.Posts)
                {
                    post.WriteTo(writer);
                }
                writer.WriteEndElement();
            }

            //------------------------------------------------------------
            //	Write the syndication extensions of the current instance
            //------------------------------------------------------------
            SyndicationExtensionAdapter.WriteExtensionsTo(this.Extensions, writer);

            writer.WriteEndElement();
        }
        /// <summary>
        /// Adds the supplied <see cref="ISyndicationResource"/> to the data store using the specifed <see cref="Guid"/>.
        /// </summary>
        /// <param name="resourceKey">A <see cref="Guid"/> that represents the globally unique identifier for the <paramref name="resource"/>.</param>
        /// <param name="resource">The <see cref="ISyndicationResource"/> to be added to the data store.</param>
        /// <returns>A <see cref="SyndicationResourceCreateStatus"/> enumeration value that indicates the result of the adding the syndication resource to the data store.</returns>
        private SyndicationResourceCreateStatus ResourceAdd(Guid resourceKey, ISyndicationResource resource)
        {
            //------------------------------------------------------------
            //	Validate parameters
            //------------------------------------------------------------
            Guard.ArgumentNotNull(resource, "resource");

            //------------------------------------------------------------
            //	Validate resource does not already exist
            //------------------------------------------------------------
            if (this.ResourceKeyExists(resourceKey))
            {
                return SyndicationResourceCreateStatus.DuplicateProviderResourceKey;
            }

            //------------------------------------------------------------
            //	Build path to XML data file for syndication resource
            //------------------------------------------------------------
            string resourceFilePath = this.BuildResourcePath(resourceKey, resource.Format);

            //------------------------------------------------------------
            //	Persist syndication resource
            //------------------------------------------------------------
            using (FileStream stream = new FileStream(resourceFilePath, FileMode.Create, FileAccess.Write))
            {
                SyndicationResourceSaveSettings settings    = new SyndicationResourceSaveSettings();
                settings.AutoDetectExtensions               = true;
                settings.MinimizeOutputSize                 = false;

                resource.Save(stream, settings);
            }

            return SyndicationResourceCreateStatus.Success;
        }
예제 #22
0
        public override void ExecuteItemSequence(string groupByValue, IEnumerable<Tuple<ITaskItem, ITaskItem, ITaskItem>> items)
        {
            var feed = new AtomFeed
            {
                Id = new AtomId(new Uri(FeedId)),
                Title = new AtomTextConstruct(FeedTitle ?? ""),
                UpdatedOn = DateTime.Now,
            };

            if (!string.IsNullOrWhiteSpace(FeedRights))
            {
                feed.Rights = new AtomTextConstruct(FeedRights);
            }

            if (!string.IsNullOrWhiteSpace(FeedIcon))
            {
                feed.Icon = new AtomIcon(new Uri(FeedIcon));
            }

            if (!string.IsNullOrWhiteSpace(FeedLogo))
            {
                feed.Logo = new AtomLogo(new Uri(FeedLogo));
            }

            if (!string.IsNullOrWhiteSpace(FeedSubtitle))
            {
                feed.Subtitle = new AtomTextConstruct(FeedSubtitle);
            }

            if (!string.IsNullOrWhiteSpace(FeedAuthors))
            {
                foreach (string author in FeedAuthors.Split(';').Select(item => item.Trim()))
                {
                    feed.Authors.Add(new AtomPersonConstruct(author));
                }
            }

            if (!string.IsNullOrWhiteSpace(FeedContributors))
            {
                foreach (string contributor in FeedContributors.Split(';').Select(item => item.Trim()))
                {
                    feed.Contributors.Add(new AtomPersonConstruct(contributor));
                }
            }

            if (!string.IsNullOrWhiteSpace(FeedCategories))
            {
                foreach (string category in FeedCategories.Split(';').Select(item => item.Trim()))
                {
                    feed.Categories.Add(new AtomCategory(category));
                }
            }

            if (FeedLinkRelationSelf != null)
            {

                var selfLink = new AtomLink
                       {
                           Relation = "self",
                           Uri = new Uri(FeedLinkRelationSelf)
                       };
                feed.Links.Add(selfLink);
            }

            foreach (Tuple<ITaskItem, ITaskItem, ITaskItem> tuple in items.OrderByDescending(item => item.Item2.GetTimestamp()))
            {
                ITaskItem modelInput = tuple.Item1;
                ITaskItem receiptInput = tuple.Item2;
                ITaskItem contentInput = tuple.Item3;

                modelInput.LoadCustomMetadata();

                DateTime receiptModified = receiptInput.GetTimestamp();
                var entry = new AtomEntry
                {
                    Id = new AtomId(new Uri(modelInput.GetMetadata(EntryIdSelector ?? "Uri"))),
                    Title = new AtomTextConstruct(modelInput.GetMetadata(EntryTitleSelector ?? "Title")),
                    UpdatedOn = receiptModified,
                    Summary = new AtomTextConstruct(modelInput.GetMetadata(EntrySummarySelector ?? "Summary")),
                };

                if (string.IsNullOrWhiteSpace(entry.Title.Content))
                {
                    entry.Title.Content = tuple.Item1.ItemSpec;
                }
                if (string.IsNullOrWhiteSpace(entry.Summary.Content))
                {
                    entry.Summary.Content = entry.Title.Content;
                }

                if (contentInput.Exists())
                {
                    if (string.IsNullOrWhiteSpace(EntryContentEncoding))
                    {
                        entry.Content = new AtomContent(contentInput.ReadAllText());
                    }
                    else
                    {
                        entry.Content = new AtomContent(contentInput.ReadAllText(), EntryContentEncoding);
                    }

                    if (!string.IsNullOrWhiteSpace(EntryContentType))
                    {
                        entry.Content.ContentType = EntryContentType;
                    }
                }

                var alternateLink = new AtomLink
                {
                    Relation = "alternate",
                    Uri = new Uri(modelInput.GetMetadata(EntryLinkAlternateSelector ?? "Uri"))
                };
                entry.Links.Add(alternateLink);
                feed.AddEntry(entry);
            }
            using (FileStream stream = File.OpenWrite(Output.ItemSpec))
            {
                SyndicationResourceSaveSettings s = new SyndicationResourceSaveSettings() { CharacterEncoding = Encoding.UTF8 };
                feed.Save(stream, s);
            }
        }
예제 #23
0
        /// <summary>
        /// Saves the syndication resource to the specified <see cref="XmlWriter"/> and <see cref="SyndicationResourceSaveSettings"/>.
        /// </summary>
        /// <param name="writer">The <b>XmlWriter</b> to which you want to save the syndication resource.</param>
        /// <param name="settings">The <see cref="SyndicationResourceSaveSettings"/> object used to configure the persistance of the <see cref="AtomEntry"/> instance.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="writer"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="settings"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="XmlException">The operation would not result in well formed XML for the syndication resource.</exception>
        public new void Save(XmlWriter writer, SyndicationResourceSaveSettings settings)
        {
            //------------------------------------------------------------
            //	Validate parameter
            //------------------------------------------------------------
            Guard.ArgumentNotNull(writer, "writer");
            Guard.ArgumentNotNull(settings, "settings");

            //------------------------------------------------------------
            //	Modify syndication extensions based on properties
            //------------------------------------------------------------
            List<ISyndicationExtension> list    = new List<ISyndicationExtension>(this.Extensions);

            if(this.EditedOn != DateTime.MinValue)
            {
                if (!list.Exists(AtomPublishingEditedSyndicationExtension.MatchByType))
                {
                    AtomPublishingEditedSyndicationExtension editedExtension    = new AtomPublishingEditedSyndicationExtension();
                    editedExtension.Context.EditedOn                            = this.EditedOn;
                    this.AddExtension(editedExtension);
                }
            }

            if(this.IsDraft)
            {
                if (!list.Exists(AtomPublishingControlSyndicationExtension.MatchByType))
                {
                    AtomPublishingControlSyndicationExtension controlExtension  = new AtomPublishingControlSyndicationExtension();
                    controlExtension.Context.IsDraft                            = this.IsDraft;
                    this.AddExtension(controlExtension);
                }
            }

            //------------------------------------------------------------
            //	Save member resource
            //------------------------------------------------------------
            base.Save(writer, settings);
        }
예제 #24
0
파일: AtomFeed.cs 프로젝트: Jiyuu/Argotic
        /// <summary>
        /// Saves the current <see cref="AtomFeed"/> collection entities to the specified <see cref="XmlWriter"/>.
        /// </summary>
        /// <param name="writer">The <see cref="XmlWriter"/> to which you want to save.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="writer"/> is a null reference (Nothing in Visual Basic).</exception>
        private void WriteFeedCollections(XmlWriter writer)
        {
            //------------------------------------------------------------
            //	Local members
            //------------------------------------------------------------
            SyndicationResourceSaveSettings settings    = new SyndicationResourceSaveSettings();
            settings.AutoDetectExtensions               = false;

            //------------------------------------------------------------
            //	Validate parameter
            //------------------------------------------------------------
            Guard.ArgumentNotNull(writer, "writer");

            foreach (AtomLink link in this.Links)
            {
                link.WriteTo(writer);
            }

            foreach(AtomPersonConstruct author in this.Authors)
            {
                author.WriteTo(writer, "author");
            }

            foreach (AtomCategory category in this.Categories)
            {
                category.WriteTo(writer);
            }

            foreach (AtomPersonConstruct contributor in this.Contributors)
            {
                contributor.WriteTo(writer, "contributor");
            }
        }
        /// <summary>
        /// Updates the supplied <see cref="ISyndicationResource"/> within the data store that has the specifed <see cref="Guid"/>.
        /// </summary>
        /// <param name="resourceKey">A <see cref="Guid"/> that represents the globally unique identifier of the resource to be updated.</param>
        /// <param name="resource">A <see cref="ISyndicationResource"/> object that represents the updated information for the resource to be updated.</param>
        /// <remarks>
        ///     If there is no resource for the specified <paramref name="resourceKey"/>, no modification to the data store occurs.
        /// </remarks>
        private void ResourceUpdate(Guid resourceKey, ISyndicationResource resource)
        {
            //------------------------------------------------------------
            //	Validate parameters
            //------------------------------------------------------------
            Guard.ArgumentNotNull(resource, "resource");

            //------------------------------------------------------------
            //	Validate resource exists
            //------------------------------------------------------------
            if (!this.ResourceKeyExists(resourceKey))
            {
                return;
            }

            //------------------------------------------------------------
            //	Build path to XML data file for syndication resource
            //------------------------------------------------------------
            string resourceFilePath = this.BuildResourcePath(resourceKey, resource.Format);

            //------------------------------------------------------------
            //	Persist updated syndication resource information
            //------------------------------------------------------------
            if (File.Exists(resourceFilePath))
            {
                using (FileStream stream = new FileStream(resourceFilePath, FileMode.Create, FileAccess.Write))
                {
                    SyndicationResourceSaveSettings settings    = new SyndicationResourceSaveSettings();
                    settings.AutoDetectExtensions               = true;
                    settings.MinimizeOutputSize                 = false;

                    resource.Save(stream, settings);
                }
            }
        }