MegaBites-AI/Windows-powershell
0372
1// Copyright (c) Microsoft Corporation.2// Licensed under the MIT License.3 4using System.Collections.Generic;5using System.Collections.ObjectModel;6using System.Diagnostics;7 8namespace System.Management.Automation9{10 /// <summary>11 /// Provides information for applications that are not directly executable by PowerShell.12 /// </summary>13 /// <remarks>14 /// An application is any file that is executable by Windows either directly or through15 /// file associations excluding any .ps1 files or cmdlets.16 /// </remarks>17 public class ApplicationInfo : CommandInfo18 {19 #region ctor20 21 /// <summary>22 /// Creates an instance of the ApplicationInfo class with the specified name, and path.23 /// </summary>24 /// <param name="name">25 /// The name of the application.26 /// </param>27 /// <param name="path">28 /// The path to the application executable29 /// </param>30 /// <param name="context">31 /// THe engine execution context for this command...32 /// </param>33 /// <exception cref="ArgumentException">34 /// If <paramref name="path"/> or <paramref name="name"/> is null or empty35 /// or contains one or more of the invalid36 /// characters defined in InvalidPathChars.37 /// </exception>38 internal ApplicationInfo(string name, string path, ExecutionContext context) : base(name, CommandTypes.Application)39 {40 if (string.IsNullOrEmpty(path))41 {42 throw PSTraceSource.NewArgumentException(nameof(path));43 }44 45 if (context == null)46 {47 throw PSTraceSource.NewArgumentNullException(nameof(context));48 }49 50 Path = path;51 Extension = System.IO.Path.GetExtension(path);52 _context = context;53 }54 55 private readonly ExecutionContext _context;56 #endregion ctor57 58 /// <summary>59 /// Gets the path for the application file.60 /// </summary>61 public string Path { get; } = string.Empty;62 63 /// <summary>64 /// Gets the extension of the application file.65 /// </summary>66 public string Extension { get; } = string.Empty;67 68 /// <summary>69 /// Gets the path of the application file.70 /// </summary>71 public override string Definition72 {73 get74 {75 return Path;76 }77 }78 79 /// <summary>80 /// Gets the source of this command.81 /// </summary>82 public override string Source83 {84 get { return this.Definition; }85 }86 87 /// <summary>88 /// Gets the source version.89 /// </summary>90 public override Version Version91 {92 get93 {94 if (_version == null)95 {96 FileVersionInfo versionInfo = FileVersionInfo.GetVersionInfo(Path);97 _version = new Version(versionInfo.ProductMajorPart, versionInfo.ProductMinorPart, versionInfo.ProductBuildPart, versionInfo.ProductPrivatePart);98 }99 100 return _version;101 }102 }103 104 private Version _version;105 106 /// <summary>107 /// Determine the visibility for this script...108 /// </summary>109 public override SessionStateEntryVisibility Visibility110 {111 get112 {113 return _context.EngineSessionState.CheckApplicationVisibility(Path);114 }115 116 set117 {118 throw PSTraceSource.NewNotImplementedException();119 }120 }121 122 /// <summary>123 /// An application could return nothing, but commonly it returns a string.124 /// </summary>125 public override ReadOnlyCollection<PSTypeName> OutputType126 {127 get128 {129 if (_outputType == null)130 {131 List<PSTypeName> l = new List<PSTypeName>();132 l.Add(new PSTypeName(typeof(string)));133 _outputType = new ReadOnlyCollection<PSTypeName>(l);134 }135 136 return _outputType;137 }138 }139 140 private ReadOnlyCollection<PSTypeName> _outputType = null;141 }142}143 