using System; using System.Collections.Generic; using Sarand.Net.Standard.Base.Core; using Sarand.Net.Standard.Base.Utils; namespace Sarand.Net.Standard.Base.App { //======================================================================= /// /// Aids in parsing the command line at application startup. /// Ref. CCommandLineInfo Class /// public class SacsCommandLineInfo { //------------------------------------------------------------------- // Definitions. public class Param { internal Param (String name, String value) { Name = StringUtil.EmptyOnNull(name); Value = StringUtil.EmptyOnNull(value); } public String Name { get; } public String Value { get; } } public enum ShellCommand { /// Indicates that no file name was found on the command line. FileNew, /// Indicates that a file name was found on the command line and that none of the following flags were found on the command line: /p, /pt, /dde. FileOpen, /// Indicates that the /p flag was found on the command line. FilePrint, /// Indicates that the /pt flag was found on the command line. FilePrintTo, /// Indicates that the /dde flag was found on the command line. FileDDE, /// Indicates that the /Register or /Regserver flag was found on the command line and the application was asked to register. AppRegister, /// Indicates that the /Unregister or /Unregserver application was asked to unregister. AppUnregister, /// Indicates that the application was restarted by the restart manager. RestartByRestartManager, FileNothing = -1 }; //------------------------------------------------------------------- // Data members. private readonly List parameters = new List(); //------------------------------------------------------------------- // Construction. public SacsCommandLineInfo (string[] args) { // Intercept specific arguments. foreach (String arg in args) { if (arg.EqualsCI("/Automation")) RunAutomated = true; if (arg.EqualsCI("/Embedding")) RunEmbedded = true; } // Store raw parameters. parameters.AddRange(args); // Extract process definitions. foreach (String arg in args) { if (arg.StartsWith("-") || arg.StartsWith("/")) { String processDfnArg = StringUtil.SubstringSafe(arg,1); if (SacsProcessDefinition.IsValidProcessDefinition(processDfnArg)) { try { processDefinitions.Add(new SacsProcessDefinition(processDfnArg)); } catch (Exception exc) { SaLogger.Warn($"{GetType().Name}.CTR Invalid process definition: {exc.Message}", true); } } } } } //------------------------------------------------------------------- // Properties. /// Indicates that the /Automation flag was found on the command line. public bool RunAutomated { get; private set; } = false; /// Indicates that the /Embedding flag was found on the command line. public bool RunEmbedded { get; private set; } = false; /// Indicates that the splash screen should be displayed. public bool ShowSplash { get; private set; } = false; //------------------------------------------------------------------- // Printing properties. /// Indicates the file name to be opened or printed; empty if the shell command is New or DDE.The value of the first non-flag parameter on the command line. public String FileName { get; private set; } = ""; /// Indicates the printer name if the shell command is Print To; otherwise empty.The value of the second non-flag parameter on the command line. public String PrinterName { get; private set; } = ""; /// Indicates the driver name if the shell command is Print To; otherwise empty.The value of the third non-flag parameter on the command line. public String DriverName { get; private set; } = ""; /// Indicates the port name if the shell command is Print To; otherwise empty.The value of the fourth non-flag parameter on the command line. public String PortName { get; private set; } = ""; //------------------------------------------------------------------- // Restart properties. /// /// Indicates the unique restart identifier for the restart manager if the restart manager restarted the application. /// The restart identifier is unique for each instance of the application. /// If the restart manager exits the application and is configured to restart it, the restart manager executes the application from the command line with the restart identifier as an optional parameter. /// When the restart manager uses the restart identifier, the application can reopen the previously open documents and recover autosaved files. /// public String RestartIdentifier { get; private set; } = ""; //------------------------------------------------------------------- // Application parameters. public int ParamCount { get { return parameters.Count; } } public List Params { get { return new List(parameters); } } // Redirected from. public String RedirectedFrom { get; private set; } = ""; //------------------------------------------------------------------- // Process definitions. public readonly List processDefinitions = new List(); public List ProcessDefinitions { get { return new List(processDefinitions); } } //------------------------------------------------------------------- } //======================================================================= }