// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; namespace System.Management.Automation { /// /// Provides information for applications that are not directly executable by PowerShell. /// /// /// 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(nameof(path)); } if (context == null) { throw PSTraceSource.NewArgumentNullException(nameof(context)); } Path = path; Extension = System.IO.Path.GetExtension(path); _context = context; } private readonly 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; } }