ArgvConfigSource.cs :  » Development » Nini » Nini » Config » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Development » Nini 
Nini » Nini » Config » ArgvConfigSource.cs
#region Copyright
//
// Nini Configuration Project.
// Copyright (C) 2006 Brent R. Matzelle.  All rights reserved.
//
// This software is published under the terms of the MIT X11 license, a copy of 
// which has been included with this distribution in the LICENSE.txt file.
// 
#endregion

using System;
using System.IO;
using System.Text;
using System.Collections;
using Nini.Util;

namespace Nini.Config{
  /// <include file='ArgvConfigSource.xml' path='//Class[@name="ArgvConfigSource"]/docs/*' />
  public class ArgvConfigSource : ConfigSourceBase
  {
    #region Private variables
    ArgvParser parser = null;
    string[] arguments = null;
    #endregion

    #region Constructors
    /// <include file='ArgvConfigSource.xml' path='//Constructor[@name="Constructor"]/docs/*' />
    public ArgvConfigSource (string[] arguments)
    {
      parser = new ArgvParser (arguments);
      this.arguments = arguments;
    }
    #endregion
    
    #region Public properties
    #endregion
    
    #region Public methods
    /// <include file='ArgvConfigSource.xml' path='//Method[@name="Save"]/docs/*' />
    public override void Save ()
    {
      throw new ArgumentException ("Source is read only");
    }

    /// <include file='ArgvConfigSource.xml' path='//Method[@name="Reload"]/docs/*' />
    public override void Reload ()
    {
      throw new ArgumentException ("Source cannot be reloaded");
    }
    
    /// <include file='ArgvConfigSource.xml' path='//Method[@name="AddSwitch"]/docs/*' />
    public void AddSwitch (string configName, string longName)
    {
      AddSwitch (configName, longName, null);
    }
    
    /// <include file='ArgvConfigSource.xml' path='//Method[@name="AddSwitchShort"]/docs/*' />
    public void AddSwitch (string configName, string longName, 
                string shortName)
    {
      IConfig config = GetConfig (configName);
      
      if (shortName != null && 
        (shortName.Length < 1 || shortName.Length > 2)) {
        throw new ArgumentException ("Short name may only be 1 or 2 characters");
      }

      // Look for the long name first
      if (parser[longName] != null) {
        config.Set (longName, parser[longName]);
      } else if (shortName != null && parser[shortName] != null) {
        config.Set (longName, parser[shortName]);
      }
    }
    
    /// <include file='ArgvConfigSource.xml' path='//Method[@name="GetArguments"]/docs/*' />
    public string[] GetArguments ()
    {
      string[] result = new string[this.arguments.Length];
      Array.Copy (this.arguments, 0, result, 0, this.arguments.Length);

      return result;
    }
    #endregion

    #region Private methods
    /// <summary>
    /// Returns an IConfig.  If it does not exist then it is added.
    /// </summary>
    private IConfig GetConfig (string name)
    {
      IConfig result = null;
      
      if (this.Configs[name] == null) {
        result = new ConfigBase (name, this);
        this.Configs.Add (result);
      } else {
        result = this.Configs[name];
      }
      
      return result;
    }
    #endregion
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.