/// <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> /// 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> /// 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> /// 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> /// 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; }