// Copyright (c) 2007 Omer Rauchwerger (a.k.a rauchy) (omer@rauchy.net)
// All rights reserved.
//
// This file is part of Regionerate.
//
// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License,
// or (at your option) any later version.
//
// This program 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 General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see .
using System;
using System.Collections.Generic;
using System.IO;
using System.Xml;
using System.Xml.Schema;
using Rauchy.Regionerate.Shared.Components.Rendering;
namespace Rauchy.Regionerate.Shared.Components
{
///
/// Provides a set of rules that define the layout of a Regionerated type.
///
public sealed class CodeLayout : XmlDocument
{
#region Constructors (1)
///
/// Initializes a new instance of the class.
///
private CodeLayout() {}
#endregion Constructors
#region Properties (1)
///
/// Gets the default layout.
///
/// The default layout.
public static CodeLayout DefaultLayout
{
get
{
return LoadXml( Templates.DefaultCodeLayout );
}
}
#endregion Properties
#region Methods (4)
// Public Methods (2)
// [rgn] Public Methods (2)
///
/// Loads a from the specified file name.
///
/// Name of the file.
public new static CodeLayout Load( string fileName )
{
XmlDocument document = new CodeLayout();
document.Load( fileName );
ValidateDocument( document );
return ( CodeLayout )document;
}
///
/// Loads a from the specified XML.
///
/// The XML.
public new static CodeLayout LoadXml( string xml )
{
XmlDocument document = new CodeLayout();
document.LoadXml( xml );
ValidateDocument( document );
return ( CodeLayout )document;
}
// Private Methods (2)
// [rgn] Private Methods (2)
///
/// Validates the document.
///
/// The document.
private static void ValidateDocument( XmlDocument document )
{
string requiredNamespaceURI = string.Concat( Templates.BaseNamespaceUri, Templates.CodeLayoutSchemaName );
if ( document.DocumentElement.NamespaceURI != requiredNamespaceURI )
{
string message = string.Format( "{0}. \nIt should be {1}", ExceptionMessages.InvalidNamespaceURI,
requiredNamespaceURI );
throw new ArgumentException( message );
}
Stream schemaStream = new MemoryStream();
TextWriter writer = new StreamWriter( schemaStream );
writer.Write( Templates.CodeLayoutSchema );
writer.Flush();
schemaStream.Position = 0;
XmlSchema schema = XmlSchema.Read( schemaStream, validationEventHandler );
document.Schemas.Add( schema );
document.Validate( validationEventHandler, document[ Templates.RootNodeName ] );
}
private static void validationEventHandler( object sender, ValidationEventArgs e )
{
if ( e.Severity ==
XmlSeverityType.Error )
{
throw new ArgumentException( "layout", e.Exception );
}
}
#endregion Methods
#region Nested Classes (3)
public class Configuration
{
#region Fields (3)
private readonly RenderingOptions _renderingOptions;
private readonly Symbol _symbol;
private readonly UnpackOptions _unpackOptions;
#endregion Fields
#region Constructors (1)
public Configuration( Symbol symbol, RenderingOptions renderingOptions, UnpackOptions unpackOptions )
{
_symbol = symbol;
_renderingOptions = renderingOptions;
_unpackOptions = unpackOptions;
}
#endregion Constructors
#region Properties (3)
public RenderingOptions RenderingOptions
{
get
{
return _renderingOptions;
}
}
public Symbol Symbol
{
get
{
return _symbol;
}
}
public UnpackOptions UnpackOptions
{
get
{
return _unpackOptions;
}
}
#endregion Properties
}
public class RenderingOptions
{
#region Fields (2)
private readonly bool _showCount;
private readonly int _tabAmuont;
private readonly bool _useTabs;
private readonly int _spaceAmount;
#endregion Fields
#region Constructors (1)
public RenderingOptions(bool showCount, int tabAmount, bool useTabs, int spaceAmount)
{
_showCount = showCount;
_tabAmuont = tabAmount;
_useTabs = useTabs;
_spaceAmount = spaceAmount;
}
#endregion Constructors
#region Properties (4)
public bool ShowCount
{
get
{
return _showCount;
}
}
public int TabAmount
{
get
{
return _tabAmuont;
}
}
public bool UseTabs
{
get
{
return _useTabs;
}
}
public int SpaceAmount
{
get
{
return _spaceAmount;
}
}
#endregion Properties
}
public class UnpackOptions
{
#region Fields (1)
private readonly IList _regionPatterns;
#endregion Fields
#region Constructors (1)
public UnpackOptions( IList regionPatterns )
{
_regionPatterns = regionPatterns;
}
#endregion Constructors
#region Properties (1)
public IList RegionPatterns
{
get
{
return _regionPatterns;
}
}
#endregion Properties
}
#endregion Nested Classes
}
}