/********************************************************************++
Copyright (c) Microsoft Corporation. All rights reserved.
--********************************************************************/
using System.Diagnostics;
using System.Collections.ObjectModel;
using System.Collections.Generic;
namespace System.Management.Automation
{
///
/// Provides information for applications that are not directly executable by Monad.
///
///
///
/// An application is any file that is executable by Windows either directly or through
/// file associations excluding any .ps1 files or cmdlets.
///
public class ApplicationInfo : CommandInfo
{
#region ctor
///
/// Creates an instance of the ApplicationInfo class with the specified name, and path.
///
///
///
/// The name of the application.
///
///
///
/// The path to the application executable
///
///
///
/// THe engine execution context for this command...
///
///
/// If or is null or empty
/// or contains one or more of the invalid
/// characters defined in InvalidPathChars.
///
///
internal ApplicationInfo(string name, string path, ExecutionContext context) : base(name, CommandTypes.Application)
{
if (String.IsNullOrEmpty(path))
{
throw PSTraceSource.NewArgumentException("path");
}
if (context == null)
{
throw PSTraceSource.NewArgumentNullException("context");
}
Path = path;
Extension = System.IO.Path.GetExtension(path);
_context = context;
} // ApplicationInfo ctor
private ExecutionContext _context;
#endregion ctor
///
/// Gets the path for the application file.
///
public string Path { get; } = String.Empty;
///
/// Gets the extension of the application file.
///
public string Extension { get; } = String.Empty;
///
/// Gets the path of the application file.
///
public override string Definition
{
get
{
return Path;
}
}
///
/// Gets the source of this command
///
public override string Source
{
get { return this.Definition; }
}
///
/// Gets the source version
///
public override Version Version
{
get
{
if (_version == null)
{
FileVersionInfo versionInfo = FileVersionInfo.GetVersionInfo(Path);
_version = new Version(versionInfo.ProductMajorPart, versionInfo.ProductMinorPart, versionInfo.ProductBuildPart, versionInfo.ProductPrivatePart);
}
return _version;
}
}
private Version _version;
///
/// Determine the visibility for this script...
///
public override SessionStateEntryVisibility Visibility
{
get
{
return _context.EngineSessionState.CheckApplicationVisibility(Path);
}
set { throw PSTraceSource.NewNotImplementedException(); }
}
///
/// An application could return nothing, but commonly it returns a string.
///
public override ReadOnlyCollection OutputType
{
get
{
if (_outputType == null)
{
List l = new List();
l.Add(new PSTypeName(typeof(string)));
_outputType = new ReadOnlyCollection(l);
}
return _outputType;
}
}
private ReadOnlyCollection _outputType = null;
} // ApplicationInfo
} // namespace System.Management.Automation