Ejemplo n.º 1
0
        /// <summary>
        /// Выполнить команду (с набором аргументов)
        /// </summary>
        /// <param name="Command"></param>
        /// <param name="Args"></param>
        /// <returns></returns>
        public override ExecResult Exec(string Command, ArgumentList Args, OptRewrite[] Rewrite)
        {
            string Dir    = Args.Get("$dir");
            string Option = Args.Get("value");

            return(Exec(Command, Dir, Option, Args, Rewrite));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Implementation of the cmdlet.
        /// When calling the base class, it obtains the values from the ComputerName, Username and Password parameters and populates the corresponding variables.
        /// </summary>
        /// <param name="pipeIn">Output from previous command in pipe</param>
        /// <returns></returns>
        public virtual CommandResult Execute(CommandResult pipeIn = null)
        {
            // Remote parameters
            computername = _arguments.Get <StringArgument>("ComputerName").Value;
            username     = _arguments.Get <StringArgument>("Username").Value;
            password     = _arguments.Get <StringArgument>("Password").Value;

            return(pipeIn);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Обработка командной строки
        /// </summary>
        /// <param name="Command"></param>
        /// <param name="Args"></param>
        /// <returns></returns>
        private static string ProcessCommand(string Command, ArgumentList Args, OptRewrite[] Rewrite)
        {
            var Params = GetParams(Command);

            while (Params.Length > 0)
            {
                foreach (var K in Params)
                {
                    var Res = Args.Get(K);
                    if (Res == null)
                    {
                        // Такого параметра нет, проверим переназначение
                        foreach (var R in Rewrite)
                        {
                            if (R.Check(K))
                            {
                                Res = R.GetValue(K, Args);
                                break;
                            }
                        }
                    }
                    if (Res == null)
                    {
                        // Увы, но заменять не на что, генерируем исключение
                        throw new InvalidOperationException($"no argument for param {{{K}}}: {Command}");
                    }
                    Command = Command.Replace($"{{{K}}}", Res);
                }

                Params = GetParams(Command);
            }

            return(Command);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Выполнить внешнее ПО
        /// </summary>
        /// <param name="Program"></param>
        /// <param name="ProgArgs"></param>
        /// <param name="Args"></param>
        /// <param name="Rewrite"></param>
        /// <returns></returns>
        public static ExternalToolResult Exec(string Program, string ProgArgs, ArgumentList Args, OptRewrite[] Rewrite)
        {
            var CmdPath = ProcessCommand(Program, Args, Rewrite);
            var CmdArgs = ProcessCommand(ProgArgs, Args, Rewrite);

            string Dir = Args.Get("$dir");

            return(ExternalTool.Run(CmdPath, CmdArgs, Dir));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Выполнить команду
        /// </summary>
        /// <param name="Command"></param>
        /// <param name="Args"></param>
        /// <param name="Rewrite"></param>
        /// <returns></returns>
        public ExecResult Exec(string Command, ArgumentList Args, OptRewrite[] Rewrite)
        {
            var A = GetAction(Command);

            if (A != null)
            {
                //var Cmd = ProcessCommand(A.Command, Args, Rewrite);

                string Dir = Args.Get("$dir");
                string P   = (A.CustomToolPath != null) ? A.CustomToolPath : ToolPath;
                if (!File.Exists(P))
                {
                    return(new ERError($"No specified path for tool: {P}"));
                }
                ExternalToolResult Result;

                try
                {
                    Result = ExternalExec.Exec(P, A.Command, Args, Rewrite);
                }
                catch (Exception Exc)
                {
                    return(new ERError(Exc.Message));
                }
                //string Output = ExternalTool.Run(P, Cmd, Dir);
                if (Result == null)
                {
                    return(new ERError("No output"));
                }

                var E = GetMessage(Result, A.ErrorMask);
                if (E != null)
                {
                    return(new ERError(E));
                }

                var W = GetMessage(Result, A.WarningMask);
                if (W != null)
                {
                    return(new ERWarning(W));
                }

                return(new EROk());
            }
            else
            {
                return(new ERError($"No available command '{Command}'"));
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Получить полный список аргументов к команде
        /// </summary>
        /// <param name="T">Программатор</param>
        /// <param name="P">Проект</param>
        /// <param name="S">Скрипт</param>
        /// <param name="Options">Опции программатора (из доступных к выбору пользователя) и пользовательский ввод</param>
        /// <returns></returns>
        public ArgumentList GetArgs(UniTool T, Project.Project P, Script S, Project.Action A, ArgumentList Options)
        {
            var    Res  = new ArgumentList();
            string Soft = Path.GetDirectoryName(Path.GetFullPath(System.Reflection.Assembly.GetEntryAssembly().Location)) + "\\Soft";

            // Этап 0
            // Пропишем параметры проекта (путь)
            Res.Set("$dir", P.Dir);
            Res.Set("dir", P.Dir);
            Res.Set("soft", Soft);

            // Этап 1
            // Аргументы из скрипта (тип контроллера и т.д.)
            foreach (var K in S.Arguments.Keys)
            {
                Res.Set(K, S.Arguments.Get(K));
            }

            // Этап 2
            // Аргументы из программатора, если они есть (дефолтные)
            foreach (var O in T.GetOptions())
            {
            }

            // Этап 3
            // Аргументы из команды (параметры команды)
            foreach (var K in A.Arguments.Keys)
            {
                Res.Set(K, A.Arguments.Get(K));
            }

            // Этап 4
            // Пропишем опции из ввода пользователя
            foreach (var K in Options.Keys)
            {
                Res.Set(K, Options.Get(K));
            }

            return(Res);
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Получить значение аргумента или null
 /// </summary>
 /// <param name="Argument"></param>
 /// <returns></returns>
 public string GetValue(string Argument)
 {
     return(Args.Get(Argument));
 }
Ejemplo n.º 8
0
        // Module defining this command


        // Optional custom code for this activity


        /// <summary>
        /// Returns a configured instance of System.Management.Automation.PowerShell, pre-populated with the command to run.
        /// </summary>
        /// <param name="context">The NativeActivityContext for the currently running activity.</param>
        /// <returns>A populated instance of Sytem.Management.Automation.PowerShell</returns>
        /// <remarks>The infrastructure takes responsibility for closing and disposing the PowerShell instance returned.</remarks>
        protected override ActivityImplementationContext GetPowerShell(NativeActivityContext context)
        {
            System.Management.Automation.PowerShell invoker       = global::System.Management.Automation.PowerShell.Create();
            System.Management.Automation.PowerShell targetCommand = invoker.AddCommand(PSCommandName);

            // Initialize the arguments

            if (FilePath.Expression != null)
            {
                targetCommand.AddParameter("FilePath", FilePath.Get(context));
            }

            if (ArgumentList.Expression != null)
            {
                targetCommand.AddParameter("ArgumentList", ArgumentList.Get(context));
            }

            if (Credential.Expression != null)
            {
                targetCommand.AddParameter("Credential", Credential.Get(context));
            }

            if (WorkingDirectory.Expression != null)
            {
                targetCommand.AddParameter("WorkingDirectory", WorkingDirectory.Get(context));
            }

            if (LoadUserProfile.Expression != null)
            {
                targetCommand.AddParameter("LoadUserProfile", LoadUserProfile.Get(context));
            }

            if (NoNewWindow.Expression != null)
            {
                targetCommand.AddParameter("NoNewWindow", NoNewWindow.Get(context));
            }

            if (PassThru.Expression != null)
            {
                targetCommand.AddParameter("PassThru", PassThru.Get(context));
            }

            if (RedirectStandardError.Expression != null)
            {
                targetCommand.AddParameter("RedirectStandardError", RedirectStandardError.Get(context));
            }

            if (RedirectStandardInput.Expression != null)
            {
                targetCommand.AddParameter("RedirectStandardInput", RedirectStandardInput.Get(context));
            }

            if (RedirectStandardOutput.Expression != null)
            {
                targetCommand.AddParameter("RedirectStandardOutput", RedirectStandardOutput.Get(context));
            }

            if (Verb.Expression != null)
            {
                targetCommand.AddParameter("Verb", Verb.Get(context));
            }

            if (WindowStyle.Expression != null)
            {
                targetCommand.AddParameter("WindowStyle", WindowStyle.Get(context));
            }

            if (Wait.Expression != null)
            {
                targetCommand.AddParameter("Wait", Wait.Get(context));
            }

            if (UseNewEnvironment.Expression != null)
            {
                targetCommand.AddParameter("UseNewEnvironment", UseNewEnvironment.Get(context));
            }


            return(new ActivityImplementationContext()
            {
                PowerShellInstance = invoker
            });
        }
Ejemplo n.º 9
0
        // Module defining this command


        // Optional custom code for this activity


        /// <summary>
        /// Returns a configured instance of System.Management.Automation.PowerShell, pre-populated with the command to run.
        /// </summary>
        /// <param name="context">The NativeActivityContext for the currently running activity.</param>
        /// <returns>A populated instance of System.Management.Automation.PowerShell</returns>
        /// <remarks>The infrastructure takes responsibility for closing and disposing the PowerShell instance returned.</remarks>
        protected override ActivityImplementationContext GetPowerShell(NativeActivityContext context)
        {
            System.Management.Automation.PowerShell invoker       = global::System.Management.Automation.PowerShell.Create();
            System.Management.Automation.PowerShell targetCommand = invoker.AddCommand(PSCommandName);

            // Initialize the arguments

            if (Name.Expression != null)
            {
                targetCommand.AddParameter("Name", Name.Get(context));
            }

            if (Verb.Expression != null)
            {
                targetCommand.AddParameter("Verb", Verb.Get(context));
            }

            if (Noun.Expression != null)
            {
                targetCommand.AddParameter("Noun", Noun.Get(context));
            }

            if (Module.Expression != null)
            {
                targetCommand.AddParameter("Module", Module.Get(context));
            }

            if (FullyQualifiedModule.Expression != null)
            {
                targetCommand.AddParameter("FullyQualifiedModule", FullyQualifiedModule.Get(context));
            }

            if (CommandType.Expression != null)
            {
                targetCommand.AddParameter("CommandType", CommandType.Get(context));
            }

            if (TotalCount.Expression != null)
            {
                targetCommand.AddParameter("TotalCount", TotalCount.Get(context));
            }

            if (Syntax.Expression != null)
            {
                targetCommand.AddParameter("Syntax", Syntax.Get(context));
            }

            if (ShowCommandInfo.Expression != null)
            {
                targetCommand.AddParameter("ShowCommandInfo", ShowCommandInfo.Get(context));
            }

            if (ArgumentList.Expression != null)
            {
                targetCommand.AddParameter("ArgumentList", ArgumentList.Get(context));
            }

            if (All.Expression != null)
            {
                targetCommand.AddParameter("All", All.Get(context));
            }

            if (ListImported.Expression != null)
            {
                targetCommand.AddParameter("ListImported", ListImported.Get(context));
            }

            if (ParameterName.Expression != null)
            {
                targetCommand.AddParameter("ParameterName", ParameterName.Get(context));
            }

            if (ParameterType.Expression != null)
            {
                targetCommand.AddParameter("ParameterType", ParameterType.Get(context));
            }


            return(new ActivityImplementationContext()
            {
                PowerShellInstance = invoker
            });
        }
Ejemplo n.º 10
0
 /// <summary>
 /// Получить значение
 /// </summary>
 /// <param name="Args"></param>
 /// <returns></returns>
 public override string GetValue(string Name, ArgumentList Args)
 {
     return Args.Get(Alias);
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Прочитать предпочтения
 /// </summary>
 /// <param name="ID"></param>
 public string Get(string ID)
 {
     return(Pref.Get(ID));
 }