コード例 #1
0
ファイル: Kernel.cs プロジェクト: IPA-CyberLab/IPA-DN-Cores
        public ExecOptions(string commandName, IEnumerable <string> argumentsList, string?currentDirectory = null, ExecFlags flags = ExecFlags.Default,
                           int easyOutputMaxSize = Consts.Numbers.DefaultLargeBufferSize, string?easyInputStr = null, string printTag = "",
                           Func <string, Task <bool> >?easyOneLineRecvCallbackAsync = null,
                           Func <ReadOnlyMemory <byte>, ReadOnlyMemory <byte>, Task <bool> >?easyRealtimeRecvBufCallbackAsync = null,
                           int easyRealtimeRecvBufCallbackDelayTickMsecs = 0, StrDictionary <string>?additionalEnvVars = null)
        {
            this.CommandName = commandName._NullCheck();
            if (Env.IsUnix == false || flags.Bit(ExecFlags.UnixAutoFullPath) == false)
            {
                this.FileName = this.CommandName._NullCheck();
            }
            else
            {
                try
                {
                    this.FileName = Lfs.UnixGetFullPathFromCommandName(this.CommandName._NullCheck());
                }
                catch
                {
                    this.FileName = this.CommandName._NullCheck();
                }
            }

            this.Arguments                                 = "";
            this.ArgumentsList                             = argumentsList;
            this.CurrentDirectory                          = currentDirectory._NonNull();
            this.Flags                                     = flags;
            this.EasyOutputMaxSize                         = easyOutputMaxSize._Max(1);
            this.EasyInputStr                              = easyInputStr._NullIfZeroLen();
            this.PrintTag                                  = printTag;
            this.EasyOneLineRecvCallbackAsync              = easyOneLineRecvCallbackAsync;
            this.EasyRealtimeRecvBufCallbackAsync          = easyRealtimeRecvBufCallbackAsync;
            this.EasyRealtimeRecvBufCallbackDelayTickMsecs = easyRealtimeRecvBufCallbackDelayTickMsecs;
            this.AdditionalEnvVars                         = additionalEnvVars;
        }
コード例 #2
0
    public GitLabMainteClient(GitLabMainteClientSettings settings)
    {
        try
        {
            this.Settings = settings;

            if (Env.IsWindows)
            {
                this.GitExe = Util.GetGitForWindowsExeFileName();
            }
            else
            {
                this.GitExe = Lfs.UnixGetFullPathFromCommandName("git");
            }

            this.Web = new WebApi(new WebApiOptions(new WebApiSettings {
                SslAcceptAnyCerts = true,
            }));
        }
        catch
        {
            this._DisposeSafe();
            throw;
        }
    }
コード例 #3
0
ファイル: Kernel.cs プロジェクト: IPA-CyberLab/IPA-DN-Cores
        public static async Task <EasyExecResult> ExecBashAsync(string command, string?currentDirectory = null,
                                                                ExecFlags flags          = ExecFlags.Default | ExecFlags.EasyInputOutputMode,
                                                                int easyOutputMaxSize    = Consts.Numbers.DefaultLargeBufferSize, string?easyInputStr = null, int?timeout = null,
                                                                CancellationToken cancel = default, bool debug = false, bool throwOnErrorExitCode = true,
                                                                string printTag          = "",
                                                                Func <string, Task <bool> >?easyOneLineRecvCallbackAsync = null,
                                                                Func <ReadOnlyMemory <byte>, ReadOnlyMemory <byte>, Task <bool> >?easyRealtimeRecvBufCallbackAsync = null,
                                                                int easyRealtimeRecvBufCallbackDelayTickMsecs = 0, StrDictionary <string>?additionalEnvVars = null)
        {
            if (timeout <= 0)
            {
                timeout = Timeout.Infinite;
            }

            List <string> args = new List <string>();

            args.Add("-c");
            args.Add(command);

            ExecOptions opt = new ExecOptions(Lfs.UnixGetFullPathFromCommandName(Consts.LinuxCommands.Bash),
                                              args, currentDirectory, flags, easyOutputMaxSize, easyInputStr, printTag,
                                              easyOneLineRecvCallbackAsync, easyRealtimeRecvBufCallbackAsync, easyRealtimeRecvBufCallbackDelayTickMsecs, additionalEnvVars);

            if (debug)
            {
                Dbg.WriteLine($"ExecBashAsync: --- Starting bash command \"{command}\" ---");
            }

            EasyExecResult result;

            try
            {
                using ExecInstance exec = new ExecInstance(opt);

                try
                {
                    await exec.WaitForExitAsync(timeout._NormalizeTimeout(CoresConfig.Timeouts.DefaultEasyExecTimeout), cancel);
                }
                finally
                {
                    await exec.CancelAsync();
                }

                result = new EasyExecResult(exec);
            }
            catch (Exception ex)
            {
                Dbg.WriteLine($"Error on bash process \"{command}\". Exception: {ex.Message}");
                throw;
            }

            if (debug)
            {
                Dbg.WriteLine($"ExecAsync: The result of bash \"{command}\": " + result.ToString(Str.GetCrlfStr(), false));
            }

            if (throwOnErrorExitCode)
            {
                result.ThrowExceptionIfError();
            }

            return(result);
        }