Configuration.cs :  » Network-Clients » VNC-Client » VNC » 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 » Network Clients » VNC Client 
VNC Client » VNC » Config » Configuration.cs
using System;
using System.Xml;
using System.Xml.Schema;
using System.Collections;



// author: Dominic Ullmann, dominic_ullmann@swissonline.ch
// Version: 1.03
  
// VNC-Client for .NET
// Copyright (C) 2002  Dominic Ullmann

// 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 2
// 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, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.




namespace VNC.Config{

  /// <summary>
  /// this class reads in, handles and contains the configuration for the VNCClient
  /// </summary>
  public class VNCConfiguration {
  
    /// <summary> the configuration file </summary>
    private const string configFile = "VNCClient.config.xml";
    /// <summary> the schema for the configuration file </summary>
    private const string configXSD = "VNCClient.config.xsd";

  
    /// <summary>
    /// reads in the configuration from VNCClient.config.xml and validates 
    ///  against schemaFile VNCClient.config.xsd
    /// </summary>
    public VNCConfiguration() {
      try {
        readConfig();
        validateConfig();
      } catch (System.Xml.Schema.XmlSchemaException schemaEx) {
        Console.WriteLine("validation problem: " + schemaEx);
        throw new Exception("config XML-File is not valid against the schema: " + schemaEx);
      } catch (System.Xml.XmlException xmlEx) {
        Console.WriteLine("config-file problem: " + xmlEx);
        throw new Exception("config XML-File contains syntactic errors: " + xmlEx);
      }
    }
    
    private DrawTypes drawType;
    /// <summary> the drawing type: use DirectDraw or pure GDIPlus </summary>
    public DrawTypes DrawType {
      get {
        return drawType;
      }
    }
    
    private int nrOfViews;
    /// <summary> the nr of views to display, >1 only supported for GDI+-mode
    /// </summary>
    public int NrOfViews {
      get {
        return nrOfViews;
      }
    }
    
    private ArrayList decoders = new ArrayList();
    /// <summary> the configured decoders </summary>
    public ArrayList Decoders {
      get {
        return decoders;
      }
    }
    
     /// <summary> read in the configuration information </summary>
     private void readConfig() {
       XmlTextReader reader = new XmlTextReader(configFile);
       XmlValidatingReader valReader = new XmlValidatingReader(reader);
       XmlSchemaCollection xsc = new XmlSchemaCollection();
       XmlSchema schema = XmlSchema.Read(new XmlTextReader(configXSD), null);
       xsc.Add(schema);
       valReader.Schemas.Add(xsc);

      // process the xml file, validate against schema
       XmlDocument doc = new XmlDocument();
       doc.Load(valReader);
      // read in config parameters
      XmlNode drawTypeNode = doc.SelectSingleNode("/config/graphics/drawingType");
      XmlNode nrOfViewsNode = doc.SelectSingleNode("/config/graphics/nrOfViews");
      string drawTypeAsString = drawTypeNode.FirstChild.Value;
      drawType = getDrawType(drawTypeAsString);
      nrOfViews = Int32.Parse(nrOfViewsNode.FirstChild.Value);
      
      // reading in the the decoders
      readDecoders(doc);
     }
     
     /// <summary> get a DrawTypes for a drawType as string </summary>
     private DrawTypes getDrawType(string drawTypeAsString) {
       if (drawTypeAsString.Equals("DirectDraw")) {
         return DrawTypes.DirectDraw;
       } else if (drawTypeAsString.Equals("GDIPlus")) {
         return DrawTypes.GDIPlus;
       } else {
        // this should not be the case, because of validation
         Console.WriteLine("config not ok: drawType = {0} unknown", drawTypeAsString);
         throw new Exception("config not ok: drawType unknown");
       }
     }
     
     /// <summary> reads in the configured decoders </summary>
     private void readDecoders(XmlDocument configDoc) {
       XmlNodeList decoderList = configDoc.SelectNodes("/config/decoders/decoder");
      // because of schema validation, should get >= 1 decoder
      if (decoderList.Count == 0) { throw new Exception("no decoders in config-file, check config/decoders in VNCClient.config.xml"); }

      decoders.Clear();
      foreach (XmlNode dec in decoderList) {
        // adding the decoder to the decoder list
        decoders.Add(dec.FirstChild.Value);
       }
     }
     
     /// <summary> validate the config-Information </summary>
     private void validateConfig() {
       if (drawType == DrawTypes.DirectDraw) {
         if (nrOfViews > 1) {
           Console.WriteLine("for DirectDrawMode only one view allowed!, setting to one");
           nrOfViews = 1;
         }
       }
     }
  
  }
  
  
  /// <summary> enumeration of the possible draw types </summary>
  public enum DrawTypes {
    /// <summary> using DirectDraw for drawing </summary>
    DirectDraw = 0,
    /// <summary> using GDIPlus for drawing </summary>
    GDIPlus = 1
  }

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