// 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.Collections.Generic; using System.Xml; using Rauchy.Regionerate.Shared.Components.Rendering; namespace Rauchy.Regionerate.Shared.Components { /// /// Provides quick access to opeartions on objects. /// public class CodeLayoutOperations { #region Fields (2)  private readonly CodeLayout _codeLayout; private readonly XmlNamespaceManager _namespaceManager; #endregion Fields  #region Constructors (1)  /// /// Initializes a new instance of the class. /// /// The code layout. public CodeLayoutOperations( CodeLayout codeLayout ) { _codeLayout = codeLayout; _namespaceManager = new XmlNamespaceManager( _codeLayout.NameTable ); string codeLayoutNamespaceUri = string.Concat( Templates.BaseNamespaceUri, Templates.CodeLayoutSchemaName ); _namespaceManager.AddNamespace( "cl", codeLayoutNamespaceUri ); } #endregion Constructors  #region Methods (7)  // Public Methods (2)  // [rgn] Public Methods (2) public CodeLayout.Configuration GetConfiguration() { XmlNode configurationNode = _codeLayout.SelectSingleNode( "./cl:CodeLayout/cl:Configuration", _namespaceManager ); // Read the symbol and rendering options. Symbol symbol = ReadSymbolValue(); bool showCount = ReadShowCountValue(); int tabAmount = ReadTabAmountValue(); bool useTabs = ReadUseTabsValue(); int spaceAmount = ReadSpaceAmountValue(); // Create the Configuration object. CodeLayout.RenderingOptions renderingOptions = new CodeLayout.RenderingOptions(showCount, tabAmount, useTabs, spaceAmount); CodeLayout.UnpackOptions unpackOptions = ReadUnpackOptions(); CodeLayout.Configuration configuration = new CodeLayout.Configuration( symbol, renderingOptions, unpackOptions ); return configuration; } /// /// Gets the symbol declared in the provided . /// public string GetSymbol() { return _codeLayout.SelectSingleNode( "./cl:CodeLayout/@Symbol", _namespaceManager ).Value; } // Private Methods (7)  // [rgn] Private Methods (7) private bool ReadShowCountValue() { XmlNode showCountNode = SelectSingleNode( "./cl:CodeLayout/cl:Configuration/cl:Rendering/@ShowCount" ); return bool.Parse( showCountNode.Value ); } private Symbol ReadSymbolValue() { XmlNode symbolNode = SelectSingleNode( "./cl:CodeLayout/cl:Configuration/cl:Symbol" ); Symbol symbol = Symbol.Parse( symbolNode ); return symbol; } private int ReadTabAmountValue() { XmlNode tabAmountNode = SelectSingleNode( "./cl:CodeLayout/cl:Configuration/cl:Rendering/@Tabs" ); return int.Parse( tabAmountNode.Value ); } private bool ReadUseTabsValue() { XmlNode useTabsNode = SelectSingleNode("./cl:CodeLayout/cl:Configuration/cl:Rendering/@UseTabs"); return bool.Parse(useTabsNode.Value); } private int ReadSpaceAmountValue() { XmlNode spaceAmountNode = SelectSingleNode("./cl:CodeLayout/cl:Configuration/cl:Rendering/@Spaces"); return int.Parse(spaceAmountNode.Value); } private CodeLayout.UnpackOptions ReadUnpackOptions() { IList regionPatterns = new List(); foreach ( XmlNode node in _codeLayout.SelectNodes( "./cl:CodeLayout/cl:Configuration/cl:Unpack/cl:Regions", _namespaceManager ) ) { string regionPattern = node.Attributes[ "ThatMatch" ].Value; regionPatterns.Add( regionPattern ); } CodeLayout.UnpackOptions unpackOptions = new CodeLayout.UnpackOptions( regionPatterns ); return unpackOptions; } /// /// Runs an XPath query on the . /// /// private XmlNode SelectSingleNode( string query ) { return _codeLayout.SelectSingleNode( query, _namespaceManager ); } #endregion Methods  } }