Configuration.cs :  » Profilers » Prof-It » at » jku » ssw » ProfIt » 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 » Profilers » Prof It 
Prof It » at » jku » ssw » ProfIt » Configuration.cs
/*----------------------------------------------------------------------
Prof-It for C#
Copyright (c) 2004 Klaus Lehner, University of Linz

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, 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.
----------------------------------------------------------------------*/

using System;
using System.Collections;
using System.Drawing;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;

namespace at.jku.ssw.ProfIt{

  /// <summary>
  /// This class encapsulates the configuration of Prof-It, such as
  /// colors, the last opened solutions, etc...
  /// </summary>
  [Serializable]
  public class Configuration {
    [NonSerialized]
    private static Configuration currentConfig;

    [NonSerialized]
    private static string fileName = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\ProfIt\\" + "ProfIt.config";

    private ColoredFont blockFont;
    private ImportCounters importCounters;
    private ResetCounters resetCounters;
    private bool[][] tableColumns;
    private RangeCollection colorRanges;
    private bool colorRangesActive;
    private ArrayList lastSolutions;

    static Configuration() {
      currentConfig = new Configuration();
      currentConfig.blockFont = new ColoredFont(new Font("Courier New", 10), Color.Black, Color.LightGray);
      currentConfig.importCounters = ImportCounters.All | ImportCounters.AskMe;
      currentConfig.resetCounters = ResetCounters.AskMe;
      currentConfig.tableColumns = new bool[3][];
      currentConfig.tableColumns[(int)Tables.Blocks] = new bool[] { false, true, true, true, true};
      currentConfig.tableColumns[(int)Tables.Methods] = new bool[] { true, true, true, true, true, true };
      currentConfig.tableColumns[(int)Tables.Classes] = new bool[] { true, true, true, true, true, true };
      currentConfig.colorRanges = new RangeCollection();
      currentConfig.colorRangesActive = false;
      currentConfig.lastSolutions = new ArrayList();
    }

    
    public static ColoredFont BlockFont {
      get { return currentConfig.blockFont; }
      set { currentConfig.blockFont = value; Store(); }
    }

    public static ImportCounters ImportCountersStrategy {
      get { return currentConfig.importCounters; }
      set { currentConfig.importCounters = value; Store(); }
    }

    public static ResetCounters ResetCountersStrategy {
      get { return currentConfig.resetCounters; }
      set { currentConfig.resetCounters = value; Store(); }
    }

    public static bool IsColumnVisible(Tables table, int column) {
      return currentConfig.tableColumns[(int)table][column];
    }

    public static void SetColumnVisible(Tables table, int column, bool value) {
      currentConfig.tableColumns[(int)table][column] = value;
      Store();
    }

    public static RangeCollection ColorRanges {
      set { currentConfig.colorRanges = value; Store(); }
      get { return currentConfig.colorRanges; }
    }

    public static bool ColorRangesActive {
      set { currentConfig.colorRangesActive = value; Store(); }
      get { return currentConfig.colorRangesActive; }
    }

    public static ArrayList LastSolutions {
      get { return currentConfig.lastSolutions; }
    }

    public static void AddSolution(string fileName) {
      if (currentConfig.lastSolutions.Contains(fileName)) {
        currentConfig.lastSolutions.Remove(fileName);
      } else {
        while (currentConfig.lastSolutions.Count > 5) currentConfig.lastSolutions.RemoveAt(4);
      }
      currentConfig.lastSolutions.Insert(0, fileName);
      Store();
    }

    public static void Load() {
      try {
        FileStream myStream = File.OpenRead(fileName);
        BinaryFormatter formatter = new BinaryFormatter();
        Configuration conf = (Configuration)formatter.Deserialize(myStream);
        myStream.Close();
        currentConfig = conf;
      } catch {}
    }

    public static void Store() {
      FileStream myStream = File.Create(fileName);
      BinaryFormatter formatter = new BinaryFormatter();
      formatter.Serialize(myStream, currentConfig);
      myStream.Close();
    }
  }

  public enum ImportCounters { All=1, Reset=2, None=4, AskMe=8 }
  public enum ResetCounters { Always=1, Never=2, AskMe=4 }
  public enum Tables { Blocks=0, Methods=1, Classes=2 } 

  [Serializable]
  public class Range {
    private int from; 
    private int to;
    private ColoredFont font;

    public Range(int from, int to, ColoredFont font) {
      this.from = from; this.to = to;
      this.font = font;
    }

    public int From { get { return from; } }
    public int To { get { return to; } }
    public ColoredFont Font { get { return font; } }

    public override string ToString() {
      if (from == int.MinValue) return "less than " + to;
      if (to == int.MaxValue) return "greater than " + from;
      if (from == to) { return "equal to " + from; } 
      else { return "from " + from + " to " + to; }
    }
  }
  
  [Serializable]
  public class RangeCollection : IEnumerable {
    private ArrayList ranges = new ArrayList();
    private static RangeComparer rangeComparer = new RangeComparer();

    public void AddRange(Range range) {
      ranges.Add(range);
      ranges.Sort(rangeComparer);
    }

    public Range this[int i] {
      get { if (i>=ranges.Count) return null; else return (Range)ranges[i]; }
    }

    public Range GetRange(int cnt) {
      foreach (Range range in ranges) {
        if (range.From <= cnt && range.To >= cnt)
          return range;
      }
      return null;
    }

    public Range Contain(Range range) {
      foreach (Range r in ranges) {
        if ((range.From >= r.From && range.From <= r.To) || 
          (range.To >= r.From && range.To <= r.To)) return r;
      }
      return null;
    }

    #region IEnumerable Members

    public IEnumerator GetEnumerator() {
      return ranges.GetEnumerator();
    }

    #endregion

    private class RangeComparer : IComparer {
      #region IComparer Members

      public int Compare(object x, object y) {
        return ((Range)x).From - ((Range)y).From;
      }

      #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.