ExecutionEnvironment.cs :  » Build-Systems » CruiseControl.NET » ThoughtWorks » CruiseControl » Core » Util » 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 » Build Systems » CruiseControl.NET 
CruiseControl.NET » ThoughtWorks » CruiseControl » Core » Util » ExecutionEnvironment.cs

using System;
using System.IO;
using System.Runtime.InteropServices;

namespace ThoughtWorks.CruiseControl.Core.Util{
  public sealed class ExecutionEnvironment : IExecutionEnvironment
  {
    private static bool? isRunningOnWindows;

    public char DirectorySeparator
    {
      get { return Path.DirectorySeparatorChar; }
    }

    /// <summary>
    /// Returns true if CruiseControl is running on a windows platform
    /// </summary>
    /// <remarks>
    /// If this method returns false, expect any DllImport not to work!
    /// </remarks>
    public bool IsRunningOnWindows
    {
      get
      {
        if (isRunningOnWindows.HasValue)
          return isRunningOnWindows.Value;

        // mono returns 4, 128 when running on linux, .NET 2.0 returns 4
        // and 6 for MacOSX
        // see http://www.mono-project.com/FAQ:_Technical
        int platform = (int) Environment.OSVersion.Platform;
        isRunningOnWindows = ((platform != 4) // PlatformID.Unix
          && (platform != 6) // PlatformID.MacOSX
          && (platform != 128)); // Mono compability value for PlatformID.Unix on .NET 1.x profile

        return isRunningOnWindows.Value;
      }
    }

    /// <summary>
    /// Gets the directory where the common language runtime is installed. 
    /// </summary>
    public string RuntimeDirectory
    {
      get
      {
        return RuntimeEnvironment.GetRuntimeDirectory();
      }
    }

    /// <summary>
    /// Get the directory for the default location of the CruiseControl.NET data files.
    /// </summary>
    /// <param name="application">Type of the application. E.g. Server or WebDashboard.</param>
    /// <returns>The location of the CruiseControl.NET data files.</returns>
    public string GetDefaultProgramDataFolder(ApplicationType application)
    {
            if (application == ApplicationType.Unknown)
            {
                throw new ArgumentOutOfRangeException("application");
            }

            var pgfPath = AppDomain.CurrentDomain.BaseDirectory;
            return pgfPath;
    }

    /// <summary>
    /// Enstures the path is rooted.
    /// </summary>
    /// <param name="path"></param>
    /// <returns></returns>
    public string EnsurePathIsRooted(string path)
    {
      if (!Path.IsPathRooted(path))
      {
        path = Path.Combine(
          GetDefaultProgramDataFolder(ApplicationType.Server),
          path);
      }
      return path;
    }
  }

  public interface IExecutionEnvironment
  {
    char DirectorySeparator { get; }
    bool IsRunningOnWindows { get; }
    string RuntimeDirectory { get; }
    string GetDefaultProgramDataFolder(ApplicationType application);
    string EnsurePathIsRooted(string path);
  }

  public enum ApplicationType
  {
    Unknown = 0,
    Server = 1,
    WebDashboard = 2
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.