/// <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); }
/// <summary> /// Gets a collection of all the resources in the data source that conform to the specified <see cref="SyndicationContentFormat"/>. /// </summary> /// <param name="format">A <see cref="SyndicationContentFormat"/> enumeration value that indicates the content format to filter resources by.</param> /// <returns> /// A <see cref="Collection{T}"/> of <see cref="ISyndicationResource"/> objects that represent the syndication resources that conform to the specified <paramref name="format"/>. /// </returns> private Collection <ISyndicationResource> ResourcesGet(SyndicationContentFormat format) { Collection <ISyndicationResource> resources = new Collection <ISyndicationResource>(); DirectoryInfo applicationDirectory = new DirectoryInfo(this.ApplicationPath); if (applicationDirectory.Exists) { FileInfo[] files = applicationDirectory.GetFiles(); foreach (FileInfo file in files) { if (file.Exists) { SyndicationContentFormat contentFormat = XmlSyndicationResourceProvider.ContentFormatByFileExtension(file.Extension); if (contentFormat == format) { using (FileStream stream = new FileStream(file.FullName, FileMode.Open, FileAccess.Read)) { ISyndicationResource resource = XmlSyndicationResourceProvider.BuildResource(contentFormat, stream); if (resource != null) { resources.Add(resource); } } } } } } return(resources); }
/// <summary> /// Modifies the <see cref="ISyndicationResource"/> to match the data source. /// </summary> /// <param name="resource">The Atom Publishing Protocol <see cref="ISyndicationResource"/> to be filled.</param> /// <param name="resourceMetadata">A <see cref="SyndicationResourceMetadata"/> object that represents the meta-data describing the <paramref name="resource"/>.</param> /// <exception cref="ArgumentNullException">The <paramref name="resource"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="resourceMetadata"/> is a null reference (Nothing in Visual Basic).</exception> private void FillAtomPublishingResource(ISyndicationResource resource, SyndicationResourceMetadata resourceMetadata) { //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(resource, "resource"); Guard.ArgumentNotNull(resourceMetadata, "resourceMetadata"); //------------------------------------------------------------ // Fill syndication resource using appropriate data adapter //------------------------------------------------------------ AtomCategoryDocument categoryDocument = resource as AtomCategoryDocument; AtomServiceDocument serviceDocument = resource as AtomServiceDocument; if (resourceMetadata.Version == new Version("1.0")) { AtomPublishing10SyndicationResourceAdapter atomPublishing10Adapter = new AtomPublishing10SyndicationResourceAdapter(this.Navigator, this.Settings); if (categoryDocument != null) { atomPublishing10Adapter.Fill(categoryDocument); } else if (serviceDocument != null) { atomPublishing10Adapter.Fill(serviceDocument); } } }
/// <summary> /// Retrieves a <see cref="ISyndicationResource"/> from the data store that has the specified key. /// </summary> /// <param name="resourceKey">A <see cref="Guid"/> that represents the globally unique identifier for the resource to be retrieved.</param> /// <returns> /// The <see cref="ISyndicationResource"/> that has the specified <paramref name="resourceKey"/>. /// If no resource exists for the specified <paramref name="resourceKey"/>, returns a <b>null</b> reference. /// </returns> private ISyndicationResource ResourceGet(Guid resourceKey) { ISyndicationResource resource = null; if (!this.ResourceKeyExists(resourceKey)) { return(null); } DirectoryInfo applicationDirectory = new DirectoryInfo(this.ApplicationPath); if (applicationDirectory.Exists) { FileInfo[] files = applicationDirectory.GetFiles(String.Format(null, "{0}.*", resourceKey.ToString())); if (files != null && files.Length == 1 && files[0].Exists) { using (FileStream stream = new FileStream(files[0].FullName, FileMode.Open, FileAccess.Read)) { SyndicationContentFormat format = XmlSyndicationResourceProvider.ContentFormatByFileExtension(files[0].Extension); if (format != SyndicationContentFormat.None) { resource = XmlSyndicationResourceProvider.BuildResource(format, stream); } } } } return(resource); }
//============================================================ // PUBLIC METHODS //============================================================ #region Fill(ISyndicationResource resource, SyndicationContentFormat format) /// <summary> /// Modifies the <see cref="ISyndicationResource"/> to match the data source. /// </summary> /// <param name="resource">The <see cref="ISyndicationResource"/> to be filled.</param> /// <param name="format">The <see cref="SyndicationContentFormat"/> enumeration value that indicates the type of syndication format that the <paramref name="resource"/> is expected to conform to.</param> /// <exception cref="ArgumentNullException">The <paramref name="resource"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentException">The <paramref name="format"/> is equal to <see cref="SyndicationContentFormat.None"/>.</exception> /// <exception cref="FormatException">The <paramref name="resource"/> data does not conform to the specified <paramref name="format"/>.</exception> public void Fill(ISyndicationResource resource, SyndicationContentFormat format) { //------------------------------------------------------------ // Validate parameters //------------------------------------------------------------ Guard.ArgumentNotNull(resource, "resource"); if (format == SyndicationContentFormat.None) { throw new ArgumentException(String.Format(null, "The specified syndication content format of {0} is invalid.", format), "format"); } //------------------------------------------------------------ // Extract syndication resource meta-data //------------------------------------------------------------ SyndicationResourceMetadata resourceMetadata = new SyndicationResourceMetadata(this.Navigator); //------------------------------------------------------------ // Verify resource conforms to specified format //------------------------------------------------------------ if (format != resourceMetadata.Format) { throw new FormatException(String.Format(null, "The supplied syndication resource has a content format of {0}, which does not match the expected content format of {1}.", resourceMetadata.Format, format)); } //------------------------------------------------------------ // Fill syndication resource using appropriate data adapter //------------------------------------------------------------ switch (format) { case SyndicationContentFormat.Atom: this.FillAtomResource(resource, resourceMetadata); break; } }
//============================================================ // PRIVATE METHODS //============================================================ #region FillAtomResource(ISyndicationResource resource, SyndicationResourceMetadata resourceMetadata) /// <summary> /// Modifies the <see cref="ISyndicationResource"/> to match the data source. /// </summary> /// <param name="resource">The Atom <see cref="ISyndicationResource"/> to be filled.</param> /// <param name="resourceMetadata">A <see cref="SyndicationResourceMetadata"/> object that represents the meta-data describing the <paramref name="resource"/>.</param> /// <exception cref="ArgumentNullException">The <paramref name="resource"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="resourceMetadata"/> is a null reference (Nothing in Visual Basic).</exception> private void FillAtomResource(ISyndicationResource resource, SyndicationResourceMetadata resourceMetadata) { //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(resource, "resource"); Guard.ArgumentNotNull(resourceMetadata, "resourceMetadata"); //------------------------------------------------------------ // Fill syndication resource using appropriate data adapter //------------------------------------------------------------ AtomFeed atomFeed = resource as AtomFeed; AtomEntry atomEntry = resource as AtomEntry; if (resourceMetadata.Version == new Version("1.0")) { Atom10SyndicationResourceAdapter atom10Adapter = new Atom10SyndicationResourceAdapter(this.Navigator, this.Settings); if (atomFeed != null) { atom10Adapter.Fill(atomFeed); } else if (atomEntry != null) { atom10Adapter.Fill(atomEntry); } } }
/// <summary> /// Modifies the <see cref="ISyndicationResource"/> to match the data source. /// </summary> /// <param name="resource">The Outline Processor Markup Language (OPML) <see cref="ISyndicationResource"/> to be filled.</param> /// <param name="resourceMetadata">A <see cref="SyndicationResourceMetadata"/> object that represents the meta-data describing the <paramref name="resource"/>.</param> /// <exception cref="ArgumentNullException">The <paramref name="resource"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="resourceMetadata"/> is a null reference (Nothing in Visual Basic).</exception> private void FillOpmlResource(ISyndicationResource resource, SyndicationResourceMetadata resourceMetadata) { //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(resource, "resource"); Guard.ArgumentNotNull(resourceMetadata, "resourceMetadata"); //------------------------------------------------------------ // Fill syndication resource using appropriate data adapter //------------------------------------------------------------ OpmlDocument opmlDocument = resource as OpmlDocument; Opml20SyndicationResourceAdapter opml20Adapter = new Opml20SyndicationResourceAdapter(this.Navigator, this.Settings); if (resourceMetadata.Version == new Version("2.0")) { opml20Adapter.Fill(opmlDocument); } if (resourceMetadata.Version == new Version("1.1")) { opml20Adapter.Fill(opmlDocument); } if (resourceMetadata.Version == new Version("1.0")) { opml20Adapter.Fill(opmlDocument); } }
/// <summary> /// Modifies the <see cref="ISyndicationResource"/> to match the data source. /// </summary> /// <param name="resource">The Really Simple Discovery (RSD) <see cref="ISyndicationResource"/> to be filled.</param> /// <param name="resourceMetadata">A <see cref="SyndicationResourceMetadata"/> object that represents the meta-data describing the <paramref name="resource"/>.</param> /// <exception cref="ArgumentNullException">The <paramref name="resource"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="resourceMetadata"/> is a null reference (Nothing in Visual Basic).</exception> private void FillRsdResource(ISyndicationResource resource, SyndicationResourceMetadata resourceMetadata) { //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(resource, "resource"); Guard.ArgumentNotNull(resourceMetadata, "resourceMetadata"); //------------------------------------------------------------ // Fill syndication resource using appropriate data adapter //------------------------------------------------------------ RsdDocument rsdDocument = resource as RsdDocument; if (resourceMetadata.Version == new Version("1.0")) { Rsd10SyndicationResourceAdapter rsd10Adapter = new Rsd10SyndicationResourceAdapter(this.Navigator, this.Settings); rsd10Adapter.Fill(rsdDocument); } if (resourceMetadata.Version == new Version("0.6")) { Rsd06SyndicationResourceAdapter rsd06Adapter = new Rsd06SyndicationResourceAdapter(this.Navigator, this.Settings); rsd06Adapter.Fill(rsdDocument); } }
/// <summary> /// Modifies the <see cref="ISyndicationResource"/> to match the data source. /// </summary> /// <param name="resource">The Atom <see cref="ISyndicationResource"/> to be filled.</param> /// <param name="resourceMetadata">A <see cref="SyndicationResourceMetadata"/> object that represents the meta-data describing the <paramref name="resource"/>.</param> /// <exception cref="ArgumentNullException">The <paramref name="resource"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="resourceMetadata"/> is a null reference (Nothing in Visual Basic).</exception> private void FillAtomResource(ISyndicationResource resource, SyndicationResourceMetadata resourceMetadata) { Guard.ArgumentNotNull(resource, "resource"); Guard.ArgumentNotNull(resourceMetadata, "resourceMetadata"); AtomFeed atomFeed = resource as AtomFeed; AtomEntry atomEntry = resource as AtomEntry; if (resourceMetadata.Version == new Version("1.0")) { Atom10SyndicationResourceAdapter atom10Adapter = new Atom10SyndicationResourceAdapter(this.Navigator, this.Settings); if (atomFeed != null) { atom10Adapter.Fill(atomFeed); } else if (atomEntry != null) { atom10Adapter.Fill(atomEntry); } } if (resourceMetadata.Version == new Version("0.3")) { Atom03SyndicationResourceAdapter atom03Adapter = new Atom03SyndicationResourceAdapter(this.Navigator, this.Settings); if (atomFeed != null) { atom03Adapter.Fill(atomFeed); } else if (atomEntry != null) { atom03Adapter.Fill(atomEntry); } } }
/// <summary> /// Asynchronous PUT to the server /// </summary> /// <param name="request">The request that identifies the resource within the syndication data source.</param> /// <param name="resource">The resource that should be created asynchronously.</param> public virtual AsyncRequest CreateAsync(SDataBaseRequest request, ISyndicationResource resource) { Guard.ArgumentNotNull(request, "request"); Guard.ArgumentNotNull(resource, "resource"); try { var url = new SDataUri(request.ToString()) { TrackingId = Guid.NewGuid().ToString() }.ToString(); var operation = new RequestOperation(HttpMethod.Post, resource); var response = ExecuteRequest(url, operation, MediaType.Xml); var tracking = response.Content as Tracking; if (tracking == null) { throw new SDataClientException("Unexpected content: " + response.Content); } return(new AsyncRequest(this, response.Location, tracking)); } catch (SDataClientException) { throw; } catch (Exception ex) { throw new SDataClientException(ex.Message, ex); } }
/// <summary> /// Modifies the <see cref="ISyndicationResource"/> to match the data source. /// </summary> /// <param name="resource">The <see cref="ISyndicationResource"/> to be filled.</param> /// <param name="format">The <see cref="SyndicationContentFormat"/> enumeration value that indicates the type of syndication format that the <paramref name="resource"/> is expected to conform to.</param> /// <exception cref="ArgumentNullException">The <paramref name="resource"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentException">The <paramref name="format"/> is equal to <see cref="SyndicationContentFormat.None"/>.</exception> /// <exception cref="FormatException">The <paramref name="resource"/> data does not conform to the specified <paramref name="format"/>.</exception> public void Fill(ISyndicationResource resource, SyndicationContentFormat format) { Guard.ArgumentNotNull(resource, "resource"); if (format == SyndicationContentFormat.None) { throw new ArgumentException(String.Format(null, "The specified syndication content format of {0} is invalid.", format), "format"); } SyndicationResourceMetadata resourceMetadata = new SyndicationResourceMetadata(this.Navigator); if (format != resourceMetadata.Format) { throw new FormatException(String.Format(null, "The supplied syndication resource has a content format of {0}, which does not match the expected content format of {1}.", resourceMetadata.Format, format)); } switch (format) { case SyndicationContentFormat.Apml: this.FillApmlResource(resource, resourceMetadata); break; case SyndicationContentFormat.Atom: this.FillAtomResource(resource, resourceMetadata); break; case SyndicationContentFormat.AtomCategoryDocument: this.FillAtomPublishingResource(resource, resourceMetadata); break; case SyndicationContentFormat.AtomServiceDocument: this.FillAtomPublishingResource(resource, resourceMetadata); break; case SyndicationContentFormat.BlogML: this.FillBlogMLResource(resource, resourceMetadata); break; case SyndicationContentFormat.Opml: this.FillOpmlResource(resource, resourceMetadata); break; case SyndicationContentFormat.Rsd: this.FillRsdResource(resource, resourceMetadata); break; case SyndicationContentFormat.Rss: this.FillRssResource(resource, resourceMetadata); break; } }
/// <summary> /// Gets a collection of all the resources in the data source in pages of data. /// </summary> /// <param name="pageIndex">The index of the page of results to return. <paramref name="pageIndex"/> is zero-based.</param> /// <param name="pageSize">The size of the page of results to return.</param> /// <param name="totalRecords">The total number of syndication resources in the data store.</param> /// <returns> /// A <see cref="Collection{T}"/> that contains a page of <see cref="ISyndicationResource"/> objects /// with a size of <paramref name="pageSize"/>, beginning at the page specified by <paramref name="pageIndex"/>. /// </returns> private Collection <ISyndicationResource> ResourcesGet(int pageIndex, int pageSize, out int totalRecords) { Collection <ISyndicationResource> resources = new Collection <ISyndicationResource>(); Collection <ISyndicationResource> pagedResources = new Collection <ISyndicationResource>(); DirectoryInfo applicationDirectory = new DirectoryInfo(this.ApplicationPath); if (applicationDirectory.Exists) { FileInfo[] files = applicationDirectory.GetFiles(); foreach (FileInfo file in files) { if (file.Exists) { SyndicationContentFormat format = XmlSyndicationResourceProvider.ContentFormatByFileExtension(file.Extension); if (format != SyndicationContentFormat.None) { using (FileStream stream = new FileStream(file.FullName, FileMode.Open, FileAccess.Read)) { ISyndicationResource resource = XmlSyndicationResourceProvider.BuildResource(format, stream); if (resource != null) { resources.Add(resource); } } } } } } totalRecords = resources.Count; if (pageSize > resources.Count) { pagedResources = new Collection <ISyndicationResource>(resources); } else { ISyndicationResource[] array = new ISyndicationResource[resources.Count]; resources.CopyTo(array, 0); int startIndex = (pageIndex == 0 ? 0 : (pageSize + pageIndex - 1)); for (int i = startIndex; i < pageSize; i++) { if (i > array.Length - 1) { break; } pagedResources.Add(array[i]); } } return(pagedResources); }
//============================================================ // PUBLIC METHODS //============================================================ #region ProcessRequest(HttpContext context) /// <summary> /// Enables processing of HTTP Web requests for syndicated content. /// </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> /// <exception cref="ArgumentNullException">The <paramref name="context"/> is a null reference (Nothing in Visual Basic).</exception> public void ProcessRequest(HttpContext context) { //------------------------------------------------------------ // Local members //------------------------------------------------------------ ISyndicationResource syndicationResource = null; //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(context, "context"); //------------------------------------------------------------ // Initialize handler state using query string parameters //------------------------------------------------------------ if (context.Request.QueryString["format"] != null && !String.IsNullOrEmpty(context.Request.QueryString["format"])) { SyndicationContentFormat format = SyndicationDiscoveryUtility.SyndicationContentFormatByName(context.Request.QueryString["format"]); if (format != SyndicationContentFormat.None) { this.Format = format; } } if (context.Request.QueryString["id"] != null && !String.IsNullOrEmpty(context.Request.QueryString["id"])) { this.Id = context.Request.QueryString["id"]; } //------------------------------------------------------------ // Get syndication resource using provider model //------------------------------------------------------------ if (this.Id != null) { syndicationResource = SyndicationManager.GetResource(this.Id); } else if (this.Format != SyndicationContentFormat.None) { Collection <ISyndicationResource> resources = SyndicationManager.GetResources(this.Format); if (resources != null && resources.Count > 0) { syndicationResource = resources[0]; } } //------------------------------------------------------------ // Write syndication resource data and header details //------------------------------------------------------------ if (syndicationResource != null) { this.WriteResource(context, syndicationResource); } }
/// <summary> /// Modifies the <see cref="ISyndicationResource"/> to match the data source. /// </summary> /// <param name="resource">The BlogML <see cref="ISyndicationResource"/> to be filled.</param> /// <param name="resourceMetadata">A <see cref="SyndicationResourceMetadata"/> object that represents the meta-data describing the <paramref name="resource"/>.</param> /// <exception cref="ArgumentNullException">The <paramref name="resource"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="resourceMetadata"/> is a null reference (Nothing in Visual Basic).</exception> private void FillBlogMLResource(ISyndicationResource resource, SyndicationResourceMetadata resourceMetadata) { Guard.ArgumentNotNull(resource, "resource"); Guard.ArgumentNotNull(resourceMetadata, "resourceMetadata"); BlogMLDocument blogMLDocument = resource as BlogMLDocument; BlogML20SyndicationResourceAdapter blogML20Adapter = new BlogML20SyndicationResourceAdapter(this.Navigator, this.Settings); if (resourceMetadata.Version == new Version("2.0")) { blogML20Adapter.Fill(blogMLDocument); } }
/// <summary> /// Modifies the <see cref="ISyndicationResource"/> to match the data source. /// </summary> /// <param name="resource">The Attention Profiling Markup Language (APML) <see cref="ISyndicationResource"/> to be filled.</param> /// <param name="resourceMetadata">A <see cref="SyndicationResourceMetadata"/> object that represents the meta-data describing the <paramref name="resource"/>.</param> /// <exception cref="ArgumentNullException">The <paramref name="resource"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="resourceMetadata"/> is a null reference (Nothing in Visual Basic).</exception> private void FillApmlResource(ISyndicationResource resource, SyndicationResourceMetadata resourceMetadata) { Guard.ArgumentNotNull(resource, "resource"); Guard.ArgumentNotNull(resourceMetadata, "resourceMetadata"); ApmlDocument apmlDocument = resource as ApmlDocument; if (resourceMetadata.Version == new Version("0.6")) { Apml06SyndicationResourceAdapter apml06Adapter = new Apml06SyndicationResourceAdapter(this.Navigator, this.Settings); apml06Adapter.Fill(apmlDocument); } }
/// <summary> /// Updates information about a syndication resource in the data source. /// </summary> /// <param name="providerResourceKey">The unique identifier that identifies the resource to be updated.</param> /// <param name="resource"> /// An object that implements the <see cref="ISyndicationResource"/> interface that represents the updated information for the resource. /// </param> /// <exception cref="ArgumentNullException">The <paramref name="providerResourceKey"/> 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> /// <exception cref="ArgumentException">The <paramref name="providerResourceKey"/> does not represent a valid <see cref="System.Guid"/> structure.</exception> public override void UpdateResource(Object providerResourceKey, ISyndicationResource resource) { Guid resourceKey = Guid.Empty; Guard.ArgumentNotNull(providerResourceKey, "providerResourceKey"); Guard.ArgumentNotNull(resource, "resource"); if (!XmlSyndicationResourceProvider.TryParseGuid(providerResourceKey.ToString(), out resourceKey)) { throw new ArgumentException(String.Format(null, "The provider resource key of {0} does not represent a valid System.Guid structure.", providerResourceKey), "providerResourceKey"); } lock (providerSyncObject) { this.ResourceUpdate(resourceKey, resource); } }
/// <summary> /// Modifies the <see cref="ISyndicationResource"/> to match the data source. /// </summary> /// <param name="resource">The Really Simple Syndication (RSS) <see cref="ISyndicationResource"/> to be filled.</param> /// <param name="resourceMetadata">A <see cref="SyndicationResourceMetadata"/> object that represents the meta-data describing the <paramref name="resource"/>.</param> /// <exception cref="ArgumentNullException">The <paramref name="resource"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="resourceMetadata"/> is a null reference (Nothing in Visual Basic).</exception> private void FillRssResource(ISyndicationResource resource, SyndicationResourceMetadata resourceMetadata) { //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(resource, "resource"); Guard.ArgumentNotNull(resourceMetadata, "resourceMetadata"); //------------------------------------------------------------ // Fill syndication resource using appropriate data adapter //------------------------------------------------------------ RssFeed rssFeed = resource as RssFeed; if (resourceMetadata.Version == new Version("2.0")) { Rss20SyndicationResourceAdapter rss20Adapter = new Rss20SyndicationResourceAdapter(this.Navigator, this.Settings); rss20Adapter.Fill(rssFeed); } if (resourceMetadata.Version == new Version("1.0")) { Rss10SyndicationResourceAdapter rss10Adapter = new Rss10SyndicationResourceAdapter(this.Navigator, this.Settings); rss10Adapter.Fill(rssFeed); } if (resourceMetadata.Version == new Version("0.92")) { Rss092SyndicationResourceAdapter rss092Adapter = new Rss092SyndicationResourceAdapter(this.Navigator, this.Settings); rss092Adapter.Fill(rssFeed); } if (resourceMetadata.Version == new Version("0.91")) { Rss091SyndicationResourceAdapter rss091Adapter = new Rss091SyndicationResourceAdapter(this.Navigator, this.Settings); rss091Adapter.Fill(rssFeed); } if (resourceMetadata.Version == new Version("0.9")) { Rss090SyndicationResourceAdapter rss090Adapter = new Rss090SyndicationResourceAdapter(this.Navigator, this.Settings); rss090Adapter.Fill(rssFeed); } }
/// <summary> /// Modifies the <see cref="ISyndicationResource"/> to match the data source. /// </summary> /// <param name="resource">The Really Simple Discovery (RSD) <see cref="ISyndicationResource"/> to be filled.</param> /// <param name="resourceMetadata">A <see cref="SyndicationResourceMetadata"/> object that represents the meta-data describing the <paramref name="resource"/>.</param> /// <exception cref="ArgumentNullException">The <paramref name="resource"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="resourceMetadata"/> is a null reference (Nothing in Visual Basic).</exception> private void FillRsdResource(ISyndicationResource resource, SyndicationResourceMetadata resourceMetadata) { Guard.ArgumentNotNull(resource, "resource"); Guard.ArgumentNotNull(resourceMetadata, "resourceMetadata"); RsdDocument rsdDocument = resource as RsdDocument; if (resourceMetadata.Version == new Version("1.0")) { Rsd10SyndicationResourceAdapter rsd10Adapter = new Rsd10SyndicationResourceAdapter(this.Navigator, this.Settings); rsd10Adapter.Fill(rsdDocument); } if (resourceMetadata.Version == new Version("0.6")) { Rsd06SyndicationResourceAdapter rsd06Adapter = new Rsd06SyndicationResourceAdapter(this.Navigator, this.Settings); rsd06Adapter.Fill(rsdDocument); } }
/// <summary> /// Modifies the <see cref="ISyndicationResource"/> to match the data source. /// </summary> /// <param name="resource">The BlogML <see cref="ISyndicationResource"/> to be filled.</param> /// <param name="resourceMetadata">A <see cref="SyndicationResourceMetadata"/> object that represents the meta-data describing the <paramref name="resource"/>.</param> /// <exception cref="ArgumentNullException">The <paramref name="resource"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="resourceMetadata"/> is a null reference (Nothing in Visual Basic).</exception> private void FillBlogMLResource(ISyndicationResource resource, SyndicationResourceMetadata resourceMetadata) { //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(resource, "resource"); Guard.ArgumentNotNull(resourceMetadata, "resourceMetadata"); //------------------------------------------------------------ // Fill syndication resource using appropriate data adapter //------------------------------------------------------------ BlogMLDocument blogMLDocument = resource as BlogMLDocument; BlogML20SyndicationResourceAdapter blogML20Adapter = new BlogML20SyndicationResourceAdapter(this.Navigator, this.Settings); if (resourceMetadata.Version == new Version("2.0")) { blogML20Adapter.Fill(blogMLDocument); } }
//============================================================ // PRIVATE METHODS //============================================================ #region FillApmlResource(ISyndicationResource resource, SyndicationResourceMetadata resourceMetadata) /// <summary> /// Modifies the <see cref="ISyndicationResource"/> to match the data source. /// </summary> /// <param name="resource">The Attention Profiling Markup Language (APML) <see cref="ISyndicationResource"/> to be filled.</param> /// <param name="resourceMetadata">A <see cref="SyndicationResourceMetadata"/> object that represents the meta-data describing the <paramref name="resource"/>.</param> /// <exception cref="ArgumentNullException">The <paramref name="resource"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="resourceMetadata"/> is a null reference (Nothing in Visual Basic).</exception> private void FillApmlResource(ISyndicationResource resource, SyndicationResourceMetadata resourceMetadata) { //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(resource, "resource"); Guard.ArgumentNotNull(resourceMetadata, "resourceMetadata"); //------------------------------------------------------------ // Fill syndication resource using appropriate data adapter //------------------------------------------------------------ ApmlDocument apmlDocument = resource as ApmlDocument; if (resourceMetadata.Version == new Version("0.6")) { Apml06SyndicationResourceAdapter apml06Adapter = new Apml06SyndicationResourceAdapter(this.Navigator, this.Settings); apml06Adapter.Fill(apmlDocument); } }
/// <summary> /// Initialises a new instance of the <see cref="RequestOperation"/> class with /// the specified <see cref="AtomEntry"/> and method. /// </summary> /// <param name="method">One of the <see cref="HttpMethod"/> values</param> /// <param name="resource">The input resource involved in the operation.</param> public RequestOperation(HttpMethod method, ISyndicationResource resource) { if (resource == null) { if (method == HttpMethod.Post || method == HttpMethod.Put) { throw new InvalidOperationException("Content must be specified for POST and PUT requests"); } } else { if (method != HttpMethod.Post && method != HttpMethod.Put) { throw new InvalidOperationException("Content must only be specified for POST and PUT requests"); } } Method = method; Resource = resource; }
/// <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); }
/// <summary> /// Modifies the <see cref="ISyndicationResource"/> to match the data source. /// </summary> /// <param name="resource">The Outline Processor Markup Language (OPML) <see cref="ISyndicationResource"/> to be filled.</param> /// <param name="resourceMetadata">A <see cref="SyndicationResourceMetadata"/> object that represents the meta-data describing the <paramref name="resource"/>.</param> /// <exception cref="ArgumentNullException">The <paramref name="resource"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="resourceMetadata"/> is a null reference (Nothing in Visual Basic).</exception> private void FillOpmlResource(ISyndicationResource resource, SyndicationResourceMetadata resourceMetadata) { Guard.ArgumentNotNull(resource, "resource"); Guard.ArgumentNotNull(resourceMetadata, "resourceMetadata"); OpmlDocument opmlDocument = resource as OpmlDocument; Opml20SyndicationResourceAdapter opml20Adapter = new Opml20SyndicationResourceAdapter(this.Navigator, this.Settings); if (resourceMetadata.Version == new Version("2.0")) { opml20Adapter.Fill(opmlDocument); } if (resourceMetadata.Version == new Version("1.1")) { opml20Adapter.Fill(opmlDocument); } if (resourceMetadata.Version == new Version("1.0")) { opml20Adapter.Fill(opmlDocument); } }
/// <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); } } }
/// <summary> /// Modifies the <see cref="ISyndicationResource"/> to match the data source. /// </summary> /// <param name="resource">The Really Simple Syndication (RSS) <see cref="ISyndicationResource"/> to be filled.</param> /// <param name="resourceMetadata">A <see cref="SyndicationResourceMetadata"/> object that represents the meta-data describing the <paramref name="resource"/>.</param> /// <exception cref="ArgumentNullException">The <paramref name="resource"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="resourceMetadata"/> is a null reference (Nothing in Visual Basic).</exception> private void FillRssResource(ISyndicationResource resource, SyndicationResourceMetadata resourceMetadata) { Guard.ArgumentNotNull(resource, "resource"); Guard.ArgumentNotNull(resourceMetadata, "resourceMetadata"); RssFeed rssFeed = resource as RssFeed; if (resourceMetadata.Version == new Version("2.0")) { Rss20SyndicationResourceAdapter rss20Adapter = new Rss20SyndicationResourceAdapter(this.Navigator, this.Settings); rss20Adapter.Fill(rssFeed); } if (resourceMetadata.Version == new Version("1.0")) { Rss10SyndicationResourceAdapter rss10Adapter = new Rss10SyndicationResourceAdapter(this.Navigator, this.Settings); rss10Adapter.Fill(rssFeed); } if (resourceMetadata.Version == new Version("0.92")) { Rss092SyndicationResourceAdapter rss092Adapter = new Rss092SyndicationResourceAdapter(this.Navigator, this.Settings); rss092Adapter.Fill(rssFeed); } if (resourceMetadata.Version == new Version("0.91")) { Rss091SyndicationResourceAdapter rss091Adapter = new Rss091SyndicationResourceAdapter(this.Navigator, this.Settings); rss091Adapter.Fill(rssFeed); } if (resourceMetadata.Version == new Version("0.9")) { Rss090SyndicationResourceAdapter rss090Adapter = new Rss090SyndicationResourceAdapter(this.Navigator, this.Settings); rss090Adapter.Fill(rssFeed); } }
//============================================================ // PUBLIC METHODS //============================================================ #region CreateResource(ISyndicationResource resource, Object providerResourceKey) /// <summary> /// Adds a new syndication resource to the data source. /// </summary> /// <param name="providerResourceKey">The unique identifier that identifies the resource within the syndication data source.</param> /// <param name="resource">The <see cref="ISyndicationResource"/> to be created within the data source.</param> /// <returns>A <see cref="SyndicationResourceCreateStatus"/> enumeration value indicating whether the syndication resource was created successfully.</returns> /// <exception cref="ArgumentNullException">The <paramref name="providerResourceKey"/> 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> public static SyndicationResourceCreateStatus CreateResource(Object providerResourceKey, ISyndicationResource resource) { return(SyndicationManager.Provider.CreateResource(providerResourceKey, resource)); }
/// <summary> /// Gets a collection of all the resources in the data source in pages of data. /// </summary> /// <param name="pageIndex">The index of the page of results to return. <paramref name="pageIndex"/> is zero-based.</param> /// <param name="pageSize">The size of the page of results to return.</param> /// <param name="totalRecords">The total number of syndication resources in the data store.</param> /// <returns> /// A <see cref="Collection{T}"/> that contains a page of <see cref="ISyndicationResource"/> objects /// with a size of <paramref name="pageSize"/>, beginning at the page specified by <paramref name="pageIndex"/>. /// </returns> private Collection<ISyndicationResource> ResourcesGet(int pageIndex, int pageSize, out int totalRecords) { //------------------------------------------------------------ // Local members //------------------------------------------------------------ Collection<ISyndicationResource> resources = new Collection<ISyndicationResource>(); Collection<ISyndicationResource> pagedResources = new Collection<ISyndicationResource>(); //------------------------------------------------------------ // Load syndication resources from XML data store //------------------------------------------------------------ DirectoryInfo applicationDirectory = new DirectoryInfo(this.ApplicationPath); if (applicationDirectory.Exists) { FileInfo[] files = applicationDirectory.GetFiles(); foreach (FileInfo file in files) { if (file.Exists) { SyndicationContentFormat format = XmlSyndicationResourceProvider.ContentFormatByFileExtension(file.Extension); if (format != SyndicationContentFormat.None) { using (FileStream stream = new FileStream(file.FullName, FileMode.Open, FileAccess.Read)) { ISyndicationResource resource = XmlSyndicationResourceProvider.BuildResource(format, stream); if (resource != null) { resources.Add(resource); } } } } } } //------------------------------------------------------------ // Build paged syndication resources //------------------------------------------------------------ totalRecords = resources.Count; if (pageSize > resources.Count) { pagedResources = new Collection<ISyndicationResource>(resources); } else { ISyndicationResource[] array = new ISyndicationResource[resources.Count]; resources.CopyTo(array, 0); int startIndex = (pageIndex == 0 ? 0 : (pageSize + pageIndex - 1)); for (int i = startIndex; i < pageSize; i++) { if(i > array.Length - 1) { break; } pagedResources.Add(array[i]); } } return pagedResources; }
/// <summary> /// Updates information about a syndication resource in the data source. /// </summary> /// <param name="providerResourceKey">The unique identifier that identifies the resource to be updated.</param> /// <param name="resource"> /// An object that implements the <see cref="ISyndicationResource"/> interface that represents the updated information for the resource. /// </param> /// <exception cref="ArgumentNullException">The <paramref name="providerResourceKey"/> 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> /// <exception cref="ArgumentException">The <paramref name="providerResourceKey"/> does not represent a valid <see cref="System.Guid"/> structure.</exception> public override void UpdateResource(Object providerResourceKey, ISyndicationResource resource) { //------------------------------------------------------------ // Local members //------------------------------------------------------------ Guid resourceKey = Guid.Empty; //------------------------------------------------------------ // Validate parameters //------------------------------------------------------------ Guard.ArgumentNotNull(providerResourceKey, "providerResourceKey"); Guard.ArgumentNotNull(resource, "resource"); if (!XmlSyndicationResourceProvider.TryParseGuid(providerResourceKey.ToString(), out resourceKey)) { throw new ArgumentException(String.Format(null, "The provider resource key of {0} does not represent a valid System.Guid structure.", providerResourceKey), "providerResourceKey"); } //------------------------------------------------------------ // Update syndication resource within data store //------------------------------------------------------------ lock (providerSyncObject) { this.ResourceUpdate(resourceKey, resource); } }
/// <summary> /// Initializes a new instance of the <see cref="SDataRequest"/> class. /// </summary> public SDataRequest(string uri, HttpMethod method, ISyndicationResource resource) : this(uri, new RequestOperation(method, resource)) { }
/// <summary> /// Modifies the <see cref="ISyndicationResource"/> to match the data source. /// </summary> /// <param name="resource">The Atom <see cref="ISyndicationResource"/> to be filled.</param> /// <param name="resourceMetadata">A <see cref="SyndicationResourceMetadata"/> object that represents the meta-data describing the <paramref name="resource"/>.</param> /// <exception cref="ArgumentNullException">The <paramref name="resource"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="resourceMetadata"/> is a null reference (Nothing in Visual Basic).</exception> private void FillAtomResource(ISyndicationResource resource, SyndicationResourceMetadata resourceMetadata) { //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(resource, "resource"); Guard.ArgumentNotNull(resourceMetadata, "resourceMetadata"); //------------------------------------------------------------ // Fill syndication resource using appropriate data adapter //------------------------------------------------------------ AtomFeed atomFeed = resource as AtomFeed; AtomEntry atomEntry = resource as AtomEntry; if (resourceMetadata.Version == new Version("1.0")) { Atom10SyndicationResourceAdapter atom10Adapter = new Atom10SyndicationResourceAdapter(this.Navigator, this.Settings); if (atomFeed != null) { atom10Adapter.Fill(atomFeed); } else if (atomEntry != null) { atom10Adapter.Fill(atomEntry); } } }
/// <summary> /// Adds a new syndication resource to the data source. /// </summary> /// <param name="providerResourceKey">The unique identifier that identifies the resource within the syndication data source.</param> /// <param name="resource">The <see cref="ISyndicationResource"/> to be created within the data source.</param> /// <returns>A <see cref="SyndicationResourceCreateStatus"/> enumeration value indicating whether the syndication resource was created successfully.</returns> /// <exception cref="ArgumentNullException">The <paramref name="providerResourceKey"/> 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> public static SyndicationResourceCreateStatus CreateResource(Object providerResourceKey, ISyndicationResource resource) { return SyndicationManager.Provider.CreateResource(providerResourceKey, resource); }
/// <summary> /// Modifies the <see cref="ISyndicationResource"/> to match the data source. /// </summary> /// <param name="resource">The Attention Profiling Markup Language (APML) <see cref="ISyndicationResource"/> to be filled.</param> /// <param name="resourceMetadata">A <see cref="SyndicationResourceMetadata"/> object that represents the meta-data describing the <paramref name="resource"/>.</param> /// <exception cref="ArgumentNullException">The <paramref name="resource"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="resourceMetadata"/> is a null reference (Nothing in Visual Basic).</exception> private void FillApmlResource(ISyndicationResource resource, SyndicationResourceMetadata resourceMetadata) { //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(resource, "resource"); Guard.ArgumentNotNull(resourceMetadata, "resourceMetadata"); //------------------------------------------------------------ // Fill syndication resource using appropriate data adapter //------------------------------------------------------------ ApmlDocument apmlDocument = resource as ApmlDocument; if (resourceMetadata.Version == new Version("0.6")) { Apml06SyndicationResourceAdapter apml06Adapter = new Apml06SyndicationResourceAdapter(this.Navigator, this.Settings); apml06Adapter.Fill(apmlDocument); } }
/// <summary> /// Updates information about a syndication resource in the data source. /// </summary> /// <param name="providerResourceKey">The unique identifier that identifies the resource to be updated.</param> /// <param name="resource"> /// An object that implements the <see cref="ISyndicationResource"/> interface that represents the updated information for the resource. /// </param> /// <exception cref="ArgumentNullException">The <paramref name="providerResourceKey"/> 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> public abstract void UpdateResource(Object providerResourceKey, ISyndicationResource resource);
//============================================================ // PUBLIC METHODS //============================================================ #region CreateResource(Object providerResourceKey, ISyndicationResource resource); /// <summary> /// Adds a new syndication resource to the data source. /// </summary> /// <param name="providerResourceKey">The unique identifier that identifies the resource within the syndication data source.</param> /// <param name="resource">The <see cref="ISyndicationResource"/> to be created within the data source.</param> /// <returns>A <see cref="SyndicationResourceCreateStatus"/> enumeration value indicating whether the syndication resource was created successfully.</returns> /// <exception cref="ArgumentNullException">The <paramref name="providerResourceKey"/> 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> public abstract SyndicationResourceCreateStatus CreateResource(Object providerResourceKey, ISyndicationResource resource);
/// <summary> /// Updates information about a syndication resource in the data source. /// </summary> /// <param name="providerResourceKey">The unique identifier from the syndication data source for the resource to be updated.</param> /// <param name="resource"> /// An object that implements the <see cref="ISyndicationResource"/> interface that represents the updated information for the resource. /// </param> /// <exception cref="ArgumentNullException">The <paramref name="providerResourceKey"/> 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> public static void UpdateResource(Object providerResourceKey, ISyndicationResource resource) { SyndicationManager.Provider.UpdateResource(providerResourceKey, resource); }
/// <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); } } }
/// <summary> /// Modifies the <see cref="ISyndicationResource"/> to match the data source. /// </summary> /// <param name="resource">The <see cref="ISyndicationResource"/> to be filled.</param> /// <param name="format">The <see cref="SyndicationContentFormat"/> enumeration value that indicates the type of syndication format that the <paramref name="resource"/> is expected to conform to.</param> /// <exception cref="ArgumentNullException">The <paramref name="resource"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentException">The <paramref name="format"/> is equal to <see cref="SyndicationContentFormat.None"/>.</exception> /// <exception cref="FormatException">The <paramref name="resource"/> data does not conform to the specified <paramref name="format"/>.</exception> public void Fill(ISyndicationResource resource, SyndicationContentFormat format) { //------------------------------------------------------------ // Validate parameters //------------------------------------------------------------ Guard.ArgumentNotNull(resource, "resource"); if (format == SyndicationContentFormat.None) { throw new ArgumentException(String.Format(null, "The specified syndication content format of {0} is invalid.", format), "format"); } //------------------------------------------------------------ // Extract syndication resource meta-data //------------------------------------------------------------ SyndicationResourceMetadata resourceMetadata = new SyndicationResourceMetadata(this.Navigator); //------------------------------------------------------------ // Verify resource conforms to specified format //------------------------------------------------------------ if (format != resourceMetadata.Format) { throw new FormatException(String.Format(null, "The supplied syndication resource has a content format of {0}, which does not match the expected content format of {1}.", resourceMetadata.Format, format)); } //------------------------------------------------------------ // Fill syndication resource using appropriate data adapter //------------------------------------------------------------ switch (format) { case SyndicationContentFormat.Atom: this.FillAtomResource(resource, resourceMetadata); break; } }
/// <summary> /// Asynchronous PUT to the server /// </summary> /// <param name="request">The request that identifies the resource within the syndication data source.</param> /// <param name="resource">The resource that should be created asynchronously.</param> public virtual AsyncRequest CreateAsync(SDataBaseRequest request, ISyndicationResource resource) { Guard.ArgumentNotNull(request, "request"); Guard.ArgumentNotNull(resource, "resource"); try { var requestUrl = new SDataUri(request.ToString()) {TrackingId = Guid.NewGuid().ToString()}.ToString(); var operation = new RequestOperation(HttpMethod.Post, resource); var response = ExecuteRequest(requestUrl, operation, MediaType.Xml); var tracking = (Tracking) response.Content; return new AsyncRequest(this, response.Location, tracking); } catch (Exception ex) { throw new SDataClientException(ex.Message, ex); } }
/// <summary> /// Adds a new syndication resource to the data source. /// </summary> /// <param name="providerResourceKey">The unique identifier that identifies the resource within the syndication data source.</param> /// <param name="resource">The <see cref="ISyndicationResource"/> to be created within the data source.</param> /// <returns>A <see cref="SyndicationResourceCreateStatus"/> enumeration value indicating whether the syndication resource was created successfully.</returns> /// <exception cref="ArgumentNullException">The <paramref name="providerResourceKey"/> 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> public override SyndicationResourceCreateStatus CreateResource(Object providerResourceKey, ISyndicationResource resource) { Guid resourceKey = Guid.Empty; Guard.ArgumentNotNull(providerResourceKey, "providerResourceKey"); Guard.ArgumentNotNull(resource, "resource"); if (!XmlSyndicationResourceProvider.TryParseGuid(providerResourceKey.ToString(), out resourceKey)) { System.Diagnostics.Trace.TraceError(String.Format(null, "The provider resource key of {0} does not represent a valid System.Guid structure.", providerResourceKey)); return(SyndicationResourceCreateStatus.InvalidProviderResourceKey); } lock (providerSyncObject) { return(this.ResourceAdd(resourceKey, resource)); } }
/// <summary> /// Initializes the generic syndication feed using the supplied <see cref="RssFeed"/>. /// </summary> /// <param name="feed">The <see cref="RssFeed"/> to build an abstraction against.</param> /// <exception cref="ArgumentNullException">The <paramref name="feed"/> is a null reference (Nothing in Visual Basic).</exception> public void Parse(RssFeed feed) { //------------------------------------------------------------ // Validate parameters //------------------------------------------------------------ Guard.ArgumentNotNull(feed, "feed"); //------------------------------------------------------------ // Initialize generic feed //------------------------------------------------------------ feedResource = feed; feedFormat = SyndicationContentFormat.Rss; if (!String.IsNullOrEmpty(feed.Channel.Title)) { feedTitle = feed.Channel.Title; } if (!String.IsNullOrEmpty(feed.Channel.Description)) { feedDescription = feed.Channel.Description; } if (feed.Channel.LastBuildDate != DateTime.MinValue) { feedLastUpdatedOn = feed.Channel.LastBuildDate; } if (feed.Channel.Language != null) { feedLanguage = feed.Channel.Language; } foreach (RssCategory category in feed.Channel.Categories) { GenericSyndicationCategory genericCategory = new GenericSyndicationCategory(category); feedCategories.Add(genericCategory); } foreach (RssItem item in feed.Channel.Items) { GenericSyndicationItem genericItem = new GenericSyndicationItem(item); ((Collection<GenericSyndicationItem>)feedItems).Add(genericItem); } }
/// <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; }
/// <summary> /// Initializes the generic syndication feed using the supplied <see cref="OpmlDocument"/>. /// Since OmplDocument hasn't direct mappings to feeds in this method we simply initialize /// feedFormat to Opml and feedResource to omplDocument /// </summary> /// <param name="feed">The <see cref="RssFeed"/> to build an abstraction against.</param> /// <exception cref="ArgumentNullException">The <paramref name="feed"/> is a null reference (Nothing in Visual Basic).</exception> public void Parse(OpmlDocument opmlDocument) { //------------------------------------------------------------ // Validate parameters //------------------------------------------------------------ Guard.ArgumentNotNull(opmlDocument, "omplDocument"); //------------------------------------------------------------ // Initialize generic feed //------------------------------------------------------------ feedResource = opmlDocument; feedFormat = SyndicationContentFormat.Opml; }
/// <summary> /// Adds a new syndication resource to the data source. /// </summary> /// <param name="providerResourceKey">The unique identifier that identifies the resource within the syndication data source.</param> /// <param name="resource">The <see cref="ISyndicationResource"/> to be created within the data source.</param> /// <returns>A <see cref="SyndicationResourceCreateStatus"/> enumeration value indicating whether the syndication resource was created successfully.</returns> /// <exception cref="ArgumentNullException">The <paramref name="providerResourceKey"/> 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> public override SyndicationResourceCreateStatus CreateResource(Object providerResourceKey, ISyndicationResource resource) { //------------------------------------------------------------ // Local members //------------------------------------------------------------ Guid resourceKey = Guid.Empty; //------------------------------------------------------------ // Validate parameters //------------------------------------------------------------ Guard.ArgumentNotNull(providerResourceKey, "providerResourceKey"); Guard.ArgumentNotNull(resource, "resource"); if (!XmlSyndicationResourceProvider.TryParseGuid(providerResourceKey.ToString(), out resourceKey)) { System.Diagnostics.Trace.TraceError(String.Format(null, "The provider resource key of {0} does not represent a valid System.Guid structure.", providerResourceKey)); return SyndicationResourceCreateStatus.InvalidProviderResourceKey; } //------------------------------------------------------------ // Add syndication resource to data store //------------------------------------------------------------ lock (providerSyncObject) { return this.ResourceAdd(resourceKey, resource); } }
/// <summary> /// Initializes the generic syndication feed using the supplied <see cref="AtomFeed"/>. /// </summary> /// <param name="feed">The <see cref="AtomFeed"/> to build an abstraction against.</param> /// <exception cref="ArgumentNullException">The <paramref name="feed"/> is a null reference (Nothing in Visual Basic).</exception> public void Parse(AtomFeed feed) { //------------------------------------------------------------ // Validate parameters //------------------------------------------------------------ Guard.ArgumentNotNull(feed, "feed"); //------------------------------------------------------------ // Initialize generic feed //------------------------------------------------------------ feedResource = feed; feedFormat = SyndicationContentFormat.Atom; if (feed.Title != null && !String.IsNullOrEmpty(feed.Title.Content)) { feedTitle = feed.Title.Content; } if (feed.Subtitle != null && !String.IsNullOrEmpty(feed.Title.Content)) { feedDescription = feed.Subtitle.Content; } if (feed.UpdatedOn != DateTime.MinValue) { feedLastUpdatedOn = feed.UpdatedOn; } if(feed.Language != null) { feedLanguage = feed.Language; } foreach(AtomCategory category in feed.Categories) { GenericSyndicationCategory genericCategory = new GenericSyndicationCategory(category); feedCategories.Add(genericCategory); } foreach(AtomEntry entry in feed.Entries) { GenericSyndicationItem genericItem = new GenericSyndicationItem(entry); ((Collection<GenericSyndicationItem>)feedItems).Add(genericItem); } }
/// <summary> /// Adds a new syndication resource to the data source. /// </summary> /// <param name="providerResourceKey">The unique identifier that identifies the resource within the syndication data source.</param> /// <param name="resource">The <see cref="ISyndicationResource"/> to be created within the data source.</param> /// <returns>A <see cref="SyndicationResourceCreateStatus"/> enumeration value indicating whether the syndication resource was created successfully.</returns> /// <exception cref="ArgumentNullException">The <paramref name="providerResourceKey"/> 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> public abstract SyndicationResourceCreateStatus CreateResource(Object providerResourceKey, ISyndicationResource resource);