"Fossies" - the Fresh Open Source Software Archive

Member "PowerShell-7.2.6/src/System.Management.Automation/engine/ApplicationInfo.cs" (11 Aug 2022, 4337 Bytes) of package /linux/misc/PowerShell-7.2.6.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C# source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "ApplicationInfo.cs" see the Fossies "Dox" file reference documentation.

    1 // Copyright (c) Microsoft Corporation.
    2 // Licensed under the MIT License.
    3 
    4 using System.Collections.Generic;
    5 using System.Collections.ObjectModel;
    6 using System.Diagnostics;
    7 
    8 namespace System.Management.Automation
    9 {
   10     /// <summary>
   11     /// Provides information for applications that are not directly executable by Monad.
   12     /// </summary>
   13     /// <remarks>
   14     /// An application is any file that is executable by Windows either directly or through
   15     /// file associations excluding any .ps1 files or cmdlets.
   16     /// </remarks>
   17     public class ApplicationInfo : CommandInfo
   18     {
   19         #region ctor
   20 
   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 executable
   29         /// </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 empty
   35         /// or contains one or more of the invalid
   36         /// 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 ctor
   57 
   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 Definition
   72         {
   73             get
   74             {
   75                 return Path;
   76             }
   77         }
   78 
   79         /// <summary>
   80         /// Gets the source of this command.
   81         /// </summary>
   82         public override string Source
   83         {
   84             get { return this.Definition; }
   85         }
   86 
   87         /// <summary>
   88         /// Gets the source version.
   89         /// </summary>
   90         public override Version Version
   91         {
   92             get
   93             {
   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 Visibility
  110         {
  111             get
  112             {
  113                 return _context.EngineSessionState.CheckApplicationVisibility(Path);
  114             }
  115 
  116             set
  117             {
  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> OutputType
  126         {
  127             get
  128             {
  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 }