MyConfig.cs :  » Network-Clients » SNMP-Observer » SnmpObserver » 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 » SNMP Observer 
SNMP Observer » SnmpObserver » MyConfig.cs
////////////////////////////////////////////////////////////////////////////////
//
// SNMP Observer V 1.0.0.0  (2005-04-01 01:01:01)
//
// Copyright (c) 2005 Bashar A. Hamdan
// Author: Bashar A. Hamdan
//
////////////////////////////////////////////////////////////////////////////////
using System;
using System.Data;
using System.Globalization;

namespace SnmpObserver{
  /// <summary>
  /// MyConfig: This class encapsulates reading / writing to the config file.
  /// </summary>
  public class MyConfig
  {
    private int interval;
    private int iterations;
    private string community;
    private int snmpTimeout;
    private int snmpRetries;

    public int Interval 
    {
      set { this.interval = value; }
      get { return this.interval; }
    }
    public int Iterations 
    {
      set { this.iterations = value; }
      get { return this.iterations; }
    }

    public int SnmpTimeout
    {
      set { this.snmpTimeout = value; }
      get { return this.snmpTimeout; }
    }
    public int SnmpRetries
    {
      set { this.snmpRetries = value; }
      get { return this.snmpRetries; }
    }

    public string Community 
    {
      set { this.community = value.ToLower(); }
      get { return this.community.ToLower(); }
    }

    //Constructor
    public MyConfig()
    {
      // Load the config file on initialize
      LoadData();
    }

    public void LoadData() 
    {
      DataSet ds = new DataSet();
      try 
      {
        //Using the dataset. Its easy to save it as xml and load it back into the dataset.
        ds.ReadXml("SnmpObserver.ini");
        DataRow dr = ds.Tables[0].Rows[0];

        double d = 0.0;

        if (double.TryParse(dr["Interval"].ToString(), NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out d)) 
        {
          this.interval = int.Parse(dr["Interval"].ToString());
        } 
        else 
        {
          this.interval = 0;
        }

        d = 0.0;
        if (double.TryParse(dr["Iterations"].ToString(), NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out d)) 
        {
          this.iterations = int.Parse(dr["Iterations"].ToString());
        } 
        else 
        {
          this.iterations = 0;
        }

        if (double.TryParse(dr["SnmpRetries"].ToString(), NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out d)) 
        {
          this.snmpRetries = int.Parse(dr["SnmpRetries"].ToString());
        } 
        else 
        {
          this.snmpRetries = 1;
        }
        if (double.TryParse(dr["SnmpTimeout"].ToString(), NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out d)) 
        {
          this.snmpTimeout = int.Parse(dr["SnmpTimeout"].ToString());
        } 
        else 
        {
          this.snmpTimeout = 30;
        }

        this.community = dr["Community"].ToString();
      } 
      catch(Exception) 
      {
        this.interval = 0;
        this.snmpTimeout = 1;
        this.snmpRetries = 1;
        this.community = "Public";
        this.iterations = 1;
      }
    }

    public void SaveData() 
    {
      // create a new dataset
      DataSet ds = new DataSet("SnmpObserver");
      DataColumn dc;

      // create a table
      DataTable dt = new DataTable("AppOptions");
      DataRow dr = dt.NewRow();
      
      //create columns
      dc = new DataColumn("Community", System.Type.GetType("System.String"));
      dt.Columns.Add(dc);
      
      dc = new DataColumn("Iterations", System.Type.GetType("System.String"));
      dt.Columns.Add(dc);
      
      dc = new DataColumn("Interval", System.Type.GetType("System.String"));
      dt.Columns.Add(dc);
      
      dc = new DataColumn("SnmpTimeout", System.Type.GetType("System.String"));
      dt.Columns.Add(dc);
      
      dc = new DataColumn("SnmpRetries", System.Type.GetType("System.String"));
      dt.Columns.Add(dc);

      // load data into the dataset
      dr["Community"] = this.community;
      dr["Iterations"] = this.iterations;
      dr["Interval"] = this.interval;
      dr["SnmpTimeout"] = this.snmpTimeout;
      dr["SnmpRetries"] = this.snmpRetries;

      dt.Rows.Add(dr);
      ds.Tables.Add(dt);

      // write the dataset to the file
      ds.WriteXml("SnmpObserver.ini");
    }

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