AggieConfig.cs :  » RSS-RDF » Aggie » Bitworking » 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 » RSS RDF » Aggie 
Aggie » Bitworking » AggieConfig.cs
// AggieConfig.cs
//
// Holds the configuration class that controls Aggie's behavior.
//
// Code written for use by Aggie.
using System;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
  
namespace Bitworking{

  public class AggieConfig { // TODO: Handle templates/template @name/dynaskin pattern
#region Configuration data
    [XmlStringSerialize("//AggieConfig/SiteListFileName", "myChannels.opml")]
    public string siteListFileName_;
    [XmlBoolSerialize( "//AggieConfig/ShowOldItems", false )]     
    public bool showOldItems_;
    [XmlStringSerialize( "//AggieConfig/Proxy", "" )]            
    public string proxy_;
    [XmlStringSerialize( "//AggieConfig/Skin", "Default" )]             
    public string skin_;
    [XmlStringSerialize( "//AggieConfig/WeblogUrl", "" )]        
    public string weblogUrl_;
    [XmlIntSerialize( "//AggieConfig/MaxThreads", 3 )]       
    public int maxThreads_;
    public SmtpConfigInfo smtpConfig_;
#endregion

#region Class constants
    private const string defaultConfigFile = "Aggie.xfg";
    private const string defaultFactoryConfigFile = "Aggie.xfg.orig";
    private const string defaultSiteListFileName = "myChannels.opml";
    private const string defaultSkin = "Default";
#endregion

#region Private data (not serialized)
    private string loadedFromFile; // File we were loaded from
#endregion

#region Creation (deserialize)
    private AggieConfig() {
      smtpConfig_ = new SmtpConfigInfo();
    }

    static public AggieConfig Create() {
      return Create( defaultConfigFile, defaultFactoryConfigFile );
    } // Create()

    static public AggieConfig Create( string configFile, string factoryConfigFile ) {
      // If first time after install, create a new config
      // file from the factory default
      if ( !File.Exists( configFile ) ) {
        File.Copy( factoryConfigFile, configFile );
      }

      // Load the configuration information from the file
      AggieConfig config = Load( configFile );

      // Mandatory configuration values, without which
      // nothing could work
      config.PostLoad();

      return config;
    } // AggieConfig( string, string )

    private void PostLoad() {
      // Any field which is empty but shouldn't be is set here
      siteListFileName_ = StringUtils.StringOrFallback( siteListFileName_, defaultSiteListFileName );
      skin_             = StringUtils.StringOrFallback( skin_, defaultSkin );

      // Ensure existence of a skin
      // 1. If any file of the skin is missing, we revert to the skin "Default"
      string skindir = "templates/" + skin_;
      if ( !Directory.Exists( skindir ) ||
        !File.Exists( skindir + "/skin.xsl" ) ||
        !File.Exists( skindir + "/About.xml" )
        ) {
        skin_ = defaultSkin;
        skindir = "templates/" + skin_;

        if ( !Directory.Exists( skindir ) ) {
          Directory.CreateDirectory( skindir );
        }
        if ( !File.Exists( skindir + "/skin.xsl" ) ) {
          File.Copy( "Aggie.xsl.orig", skindir + "/skin.xsl" );
        }
        if ( !File.Exists( skindir + "/About.xml" ) ) {
          File.Copy( "about.xml.orig", skindir + "/About.xml" );
        }
      }
    } // PostLoad()

    static private AggieConfig Load( string file ) {
      AggieConfig     config = new AggieConfig();
      SerializeByAttributes.Read(config, file);
      SerializeByAttributes.Read(config.smtpConfig_, file);
      config.loadedFromFile = file; // Save so we could use this name when writing
      return config;
    } 

    public void RevertToDefaultChannelList() {
      siteListFileName_ = defaultSiteListFileName;
    }
#endregion

#region Serialize
    public void Save() { // Save to the same file you were loaded from
      Save( loadedFromFile );
    }

    public void Save( string file ) {
      SerializeByAttributes.Write(this, file);
      SerializeByAttributes.Write(this.smtpConfig_, file);
    } 

#endregion

  } // class AggieConfig

} // namespace Bitworking

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.