#region License
/**
* Ingenious MVC : An MVC framework for .NET 2.0
* Copyright (C) 2006, JDP Group
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Authors: - Kent Boogaart (kentcb@internode.on.net)
*/
#endregion
using System;
using System.Drawing;
using System.IO;
using System.Reflection;
using System.Resources;
using System.Xml;
using System.Xml.Schema;
using Ingenious.Mvc.Configuration;
using Ingenious.Mvc.Configuration.Configurators;
using Ingenious.Mvc.Util;
namespace Ingenious.Mvc.Windows.Forms.Views{
/// <include file='WizardFormXmlCustomParser.doc.xml' path='/doc/member[@name="T:WizardFormXmlCustomParser"]/*'/>
internal sealed class WizardFormXmlCustomParser : IXmlCustomParser
{
private XmlSchema _schema;
/// <include file='WizardFormXmlCustomParser.doc.xml' path='/doc/member[@name="P:Schema"]/*'/>
XmlSchema IXmlCustomParser.Schema
{
get
{
if (_schema == null)
{
_schema = XmlSchema.Read(Assembly.GetExecutingAssembly().GetManifestResourceStream(GetType(), "WizardFormXmlCustomParser.xsd"), null);
}
return _schema;
}
}
/// <include file='WizardFormXmlCustomParser.doc.xml' path='/doc/member[@name="P:TypeName"]/*'/>
string IXmlCustomParser.TypeName
{
get
{
return "wizardForm";
}
}
/// <include file='WizardFormXmlCustomParser.doc.xml' path='/doc/member[@name="M:Parse(Ingenious.Mvc.Configuration.ConfigurationInfo,System.Object,System.Xml.XmlNode)"]/*'/>
public object Parse(ConfigurationInfo configurationInfo, object parent, XmlNode section)
{
ArgumentHelper.AssertNotNull(section, "section");
ArgumentHelper.AssertNotNull(parent, "parent");
ViewInfo viewInfo = parent as ViewInfo;
System.Diagnostics.Debug.Assert(!viewInfo.Id.IsEmpty);
XmlAttribute titleAttribute = section.Attributes["title"];
XmlAttribute imageAttribute = section.Attributes["image"];
XmlAttribute previousTextAttribute = section.Attributes["previousText"];
XmlAttribute nextTextAttribute = section.Attributes["nextText"];
XmlAttribute finishTextAttribute = section.Attributes["finishText"];
XmlAttribute cancelTextAttribute = section.Attributes["cancelText"];
WizardForm.CustomConfiguration retVal = new Ingenious.Mvc.Windows.Forms.Views.WizardForm.CustomConfiguration();
if (titleAttribute != null)
{
retVal.Title = titleAttribute.Value;
}
if (previousTextAttribute != null)
{
retVal.PreviousText = previousTextAttribute.Value;
}
if (nextTextAttribute != null)
{
retVal.NextText = nextTextAttribute.Value;
}
if (finishTextAttribute != null)
{
retVal.FinishText = finishTextAttribute.Value;
}
if (cancelTextAttribute != null)
{
retVal.CancelText = cancelTextAttribute.Value;
}
if (imageAttribute != null)
{
Image image = null;
string imageString = imageAttribute.Value;
//first look for an appropriate resource
if (imageString.IndexOf(",") != -1)
{
string resourceName = imageString.Substring(0, imageString.IndexOf(","));
string typeName = imageString.Substring(resourceName.Length + 1).Trim();
Type type = System.Type.GetType(typeName);
if (type != null)
{
ResourceManager resourceManager = new ResourceManager(type);
image = resourceManager.GetObject(resourceName) as Image;
}
}
//next, look for a file
if (image == null)
{
if (File.Exists(imageString))
{
image = Image.FromFile(imageString);
}
}
//we must have an image by now otherwise we throw
ExceptionHelper.ThrowIf(image == null, "Parse.imageNotFound", imageString, viewInfo.Id);
retVal.Image = image;
}
return retVal;
}
}
}
|