- mhtmllib_src.zip
- Rilling.MhtmlLib
- docs
- api
- design
- ClassDiagram.vsd
- tutorials
- MhtmlLib.sln
- src
- Rilling.Web.Mhtml.TestHarness
- Rilling.Web.Mhtml.TestHarness_old
- Rilling.Web.Mhtml.TestSite
- Rilling.Web.Mhtml
- WinCapture
- mhtmllib_demo.zip
|
using System;
using System.Collections;
using System.Configuration;
using System.Xml;
using Rilling.MhtmlLib.Media.Handlers;
namespace Rilling.Web.Mhtml.Configuration
{
/// <summary>
/// Reads the mimeHandlers configuration settings from the app.config.
/// Initializes all the configured <see cref="MimeHandleBase"/> object
/// as defined in the app.config.
/// </summary>
public class MimeHandlersConfigurationHandler : IConfigurationSectionHandler
{
/// <summary>
/// Initializes the <see cref="MimeHandlerBase"/> objects as defined
/// in the app.config.
/// </summary>
/// <param name="parent">
/// Not used.
/// </param>
/// <param name="input">
/// Not used.
/// </param>
/// <param name="node">
/// The Xml as laid out in the app.config.
/// </param>
/// <returns>
/// A collection of <see cref="MimeHandlerBase"/> objects.
/// </returns>
public object Create(object parent, object input, XmlNode node)
{
if(node == null) throw(new ArgumentNullException("node"));
ArrayList al = new ArrayList();
foreach(XmlElement mimeHandlerNode in node.SelectNodes("add"))
{
if(mimeHandlerNode.Attributes["mimePattern"] == null)
throw(new ConfigurationException("Required 'mimePattern' attribute missing from configuration section.", node));
if(mimeHandlerNode.Attributes["type"] == null)
throw(new ConfigurationException("Required 'type' attribute missing from configuration section.", node));
string mimePattern =
mimeHandlerNode.Attributes["mimePattern"].Value.Trim();
Type mimeHandlerType =
Type.GetType(mimeHandlerNode.Attributes["type"].Value.Trim());
if(mimeHandlerType != null)
{
foreach(string specificPattern in ExtractMimeAssociations(mimePattern))
{
//object[] args = new object[] { specificPattern };
IContentFactory mh = (IContentFactory)Activator.CreateInstance(mimeHandlerType, null, null);
//XmlNode settingParam = mimeHandlerNode.FirstChild;
//if( settingParam != null )
// mh.Configure( (XmlElement)settingParam );
al.Add(new MimeHandlerInfo(mh, specificPattern));
}
}
// TODO: Throw exception when type could not be loaded.
}
return al;
}
private string[] ExtractMimeAssociations(string mimePattern)
{
if(mimePattern == null || mimePattern.Trim() == String.Empty)
throw(new ArgumentNullException("mimePattern"));
return mimePattern.Split(',', ';');
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.