SourceFile.cs :  » Profilers » Prof-It » at » jku » ssw » ProfIt » Components » 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 » Components » SourceFile.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.IO;
using System.Xml;

namespace at.jku.ssw.ProfIt.Components{

  /// <summary>
  /// This class represents one SourceFile and all of its blocks.
  /// It does not contain the content of the file itself!!
  /// </summary>
  [Serializable]
  public class SourceFile {

    private string filename;
    private BuildAction buildAction;
    private bool profile = true;
    private Project project;

    /// <summary>
    /// The counters of a source file aren't stored in the project file.
    /// </summary>
    [NonSerialized]
    private CounterCollection counters;

    public SourceFile(Project project, string filename) {
      this.project = project;
      this.filename = filename;
    }

    /// <summary>
    /// Returns the current CounterCollection, if the SourceFile hasn't changed
    /// since the last parsing; null otherwise.
    /// </summary>
    public CounterCollection Counters {
      get { if (IsParsingNecessary) return null; else return this.counters; }
    }

    /// <summary>
    /// Sets the corresponding project of the SourceFile
    /// </summary>
    internal void SetProject(Project project) {
      this.project = project;
    }

    /// <summary>
    /// Returns the absolute path of the filename
    /// </summary>
    public string FileName {
      get { return project.RootPath + "\\" + filename; }
    }

    /// <summary>
    /// Returns a block at a specified position in the file
    /// </summary>
    /// <param name="p">the position of the block</param>
    /// <returns>null, if IsParsingNecessary is false or no block can be
    /// found at the specified position</returns>
    public IBlock GetBlock(Position p) {
      if (IsParsingNecessary) return null;
      IBlock result = findBlock(p, this.counters.blocks);
      if (result != null) return result;
      result = findBlock(p, this.counters.methods);
      if (result != null) return result;
      result = findBlock(p, this.counters.classes);
      return result;
    }

    private IBlock findBlock(Position p, ArrayList list) {
      foreach (IBlock block in list) {
        if (block.Start.CompareTo(p) <= 0 && block.End.CompareTo(p) >= 0) return block;
      }
      return null;
    }

    /// <summary>
    /// Returns true if the file has to be included in profiling
    /// </summary>
    public bool Profile {
      get { return this.profile; }
    }

    /// <summary>
    /// Sets the value whether the file has to be profiled or not
    /// </summary>
    internal void SetProfile(bool value) { 
      this.profile = value; 
    }

    /// <summary>
    /// Returns true, if the file has been modified since the last parsing.
    /// </summary>
    public bool IsParsingNecessary {
      get {
        if (counters == null) return true;
        DateTime time = File.GetLastWriteTime(this.FileName);
        if (counters.FileName == null || counters.FileName.Length == 0) return true;
        return (time >= this.counters.LastParseTime);
      }
    }

    public Project Project { get { return project; } }

    public void SetCounters(CounterCollection c) {
      if (c == null) {
        this.counters = new CounterCollection("");
      } else {
        this.counters = c;
        this.counters.SetFileName(this.FileName);
        this.counters.LastParseTime = c.LastParseTime;
      }
    }

    /// <summary>
    /// Gets or sets the BuildAction for this file. (Compile, EmbeddedResource, Content)
    /// This is needed for VS.NET projects.
    /// </summary>
    public BuildAction BuildAction {
      get { return buildAction; }
      set { buildAction = value; }
    }


    #region Implementation of Equals and HashCode
    /// <summary>
    /// A CSFile is equal to another if it has the same FileName
    /// </summary>
    /// <param name="obj">object to compare, must be a CSFile</param>
    /// <returns>true if filenames are identical</returns>
    public override bool Equals(object obj) {
      if (!(obj is SourceFile)) return false;
      return this.FileName == ((SourceFile)obj).FileName;
    }

    public override int GetHashCode() {
      return FileName.GetHashCode ();
    }
    #endregion

    #region Print methods
    /// <summary>
    /// Prints all blocks of the file to the console
    /// </summary>
    public void PrintBlocks() {
      foreach (IBlock block in counters.blocks) {
        Console.WriteLine(block.ToString());
      }
    }

    /// <summary>
    /// For testing only
    /// </summary>
    /// <returns>A summary of all blocks</returns>
    public override string ToString() {
      string s = "";
      foreach (IBlock block in counters.blocks) {
        s += block.ToString() + "\r\n";
      }
      return s;
    }
    #endregion
  }

  public enum BuildAction { Compile, EmbeddedResource, Content }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.