#region Copyright 2009-2014 by Roger Knapp, Licensed under the Apache License, Version 2.0
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
using System;
using System.Collections.Generic;
using System.Reflection;
namespace CSharpTest.Net
{
///
/// This class name is actually wrong... These values are only constant for the life the current
/// app domain ;)
///
public static class Constants
{
/// Returns the string '[Unknown]'
public const string UNKNOWN = "[Unknown]";
#region Process Data
/// Returns the current process id
public static readonly Int32 ProcessId = 0;
/// Returns the current process name without an extension
public static readonly string ProcessName = UNKNOWN;
/// Returns the file path to the exe for this process
public static readonly string ProcessFile = UNKNOWN;
#endregion
#region AppDomain Data
/// Returns the current AppDomain's friendly name
public static readonly string AppDomainName = UNKNOWN;
/// Returns the entry-point assembly or the highest stack assembly
public static readonly Assembly EntryAssembly = typeof(Constants).Assembly;
/// Returns the product version of the entry assembly
public static readonly Version ProductVersion = new Version();
/// Returns the product name of the entry assembly
public static readonly string ProductName = UNKNOWN;
/// Returns the company name of the entry assembly
public static readonly string CompanyName = UNKNOWN;
/// Returns true if the current process is running a unit test
public static readonly bool IsUnitTest;
#endregion
#region Misc
/// Returns true if a debugger is attached to the process
public static readonly bool IsDebugging = false;
#endregion
#region Derived Paths
///
/// Returns the HKCU or HKLM path for this software application based
/// on the process that is running: Software\{CompanyName}\{ProductName}
///
public static readonly string RegistrySoftwarePath = UNKNOWN;
///
/// Returns the roaming user profile path for the currently running software
/// application: {SpecialFolder.ApplicationData}\{CompanyName}\{ProductName}
///
public static readonly string ApplicationData = UNKNOWN;
///
/// Returns the non-roaming user profile path for the currently running software
/// application: {SpecialFolder.LocalApplicationData}\{CompanyName}\{ProductName}
///
public static readonly string LocalApplicationData = UNKNOWN;
///
/// Returns a default log file name derived as:
/// {SpecialFolder.LocalApplicationData}\{CompanyName}\{ProductName}\{AppDomainName}.txt
///
public static readonly string DefaultLogFile = UNKNOWN;
#endregion
///
/// This is some ugly code, the intent is to be able to answer the above questions in
/// a wide array of environments. I admit now this will fail eventually.
///
static Constants()
{
CSharpTest.Net.Utils.ProcessInfo info = null;
try { info = new CSharpTest.Net.Utils.ProcessInfo(); }
catch { return; }
ProcessId = info.ProcessId;
ProcessName = info.ProcessName;
ProcessFile = info.ProcessFile;
AppDomainName = info.AppDomainName;
EntryAssembly = info.EntryAssembly;
ProductVersion = info.ProductVersion;
ProductName = info.ProductName;
CompanyName = info.CompanyName;
IsDebugging = info.IsDebugging;
RegistrySoftwarePath = info.RegistrySoftwarePath;
ApplicationData = info.ApplicationData;
LocalApplicationData = info.LocalApplicationData;
DefaultLogFile = info.DefaultLogFile;
IsUnitTest = (ProcessName.IndexOf("NUnit", StringComparison.OrdinalIgnoreCase) >= 0);
}
}
}