File size: 4,342 Bytes
8c763fb | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | // Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
namespace System.Management.Automation
{
/// <summary>
/// Provides information for applications that are not directly executable by PowerShell.
/// </summary>
/// <remarks>
/// An application is any file that is executable by Windows either directly or through
/// file associations excluding any .ps1 files or cmdlets.
/// </remarks>
public class ApplicationInfo : CommandInfo
{
#region ctor
/// <summary>
/// Creates an instance of the ApplicationInfo class with the specified name, and path.
/// </summary>
/// <param name="name">
/// The name of the application.
/// </param>
/// <param name="path">
/// The path to the application executable
/// </param>
/// <param name="context">
/// THe engine execution context for this command...
/// </param>
/// <exception cref="ArgumentException">
/// If <paramref name="path"/> or <paramref name="name"/> is null or empty
/// or contains one or more of the invalid
/// characters defined in InvalidPathChars.
/// </exception>
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
/// <summary>
/// Gets the path for the application file.
/// </summary>
public string Path { get; } = string.Empty;
/// <summary>
/// Gets the extension of the application file.
/// </summary>
public string Extension { get; } = string.Empty;
/// <summary>
/// Gets the path of the application file.
/// </summary>
public override string Definition
{
get
{
return Path;
}
}
/// <summary>
/// Gets the source of this command.
/// </summary>
public override string Source
{
get { return this.Definition; }
}
/// <summary>
/// Gets the source version.
/// </summary>
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;
/// <summary>
/// Determine the visibility for this script...
/// </summary>
public override SessionStateEntryVisibility Visibility
{
get
{
return _context.EngineSessionState.CheckApplicationVisibility(Path);
}
set
{
throw PSTraceSource.NewNotImplementedException();
}
}
/// <summary>
/// An application could return nothing, but commonly it returns a string.
/// </summary>
public override ReadOnlyCollection<PSTypeName> OutputType
{
get
{
if (_outputType == null)
{
List<PSTypeName> l = new List<PSTypeName>();
l.Add(new PSTypeName(typeof(string)));
_outputType = new ReadOnlyCollection<PSTypeName>(l);
}
return _outputType;
}
}
private ReadOnlyCollection<PSTypeName> _outputType = null;
}
}
|