• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

HicServices / RDMP / 6245535001

20 Sep 2023 07:44AM UTC coverage: 57.013%. First build
6245535001

push

github

web-flow
8.1.0 Release (#1628)

* Bump Newtonsoft.Json from 13.0.1 to 13.0.2

Bumps [Newtonsoft.Json](https://github.com/JamesNK/Newtonsoft.Json) from 13.0.1 to 13.0.2.
- [Release notes](https://github.com/JamesNK/Newtonsoft.Json/releases)
- [Commits](https://github.com/JamesNK/Newtonsoft.Json/compare/13.0.1...13.0.2)

---
updated-dependencies:
- dependency-name: Newtonsoft.Json
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

* Bump NLog from 5.0.5 to 5.1.0

Bumps [NLog](https://github.com/NLog/NLog) from 5.0.5 to 5.1.0.
- [Release notes](https://github.com/NLog/NLog/releases)
- [Changelog](https://github.com/NLog/NLog/blob/dev/CHANGELOG.md)
- [Commits](https://github.com/NLog/NLog/compare/v5.0.5...v5.1.0)

---
updated-dependencies:
- dependency-name: NLog
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* Bump NLog from 5.0.5 to 5.1.0

* Fix -r flag - should have been --results-directory all along

* Bump Newtonsoft.Json from 13.0.1 to 13.0.2

* Bump YamlDotNet from 12.0.2 to 12.1.0

Bumps [YamlDotNet](https://github.com/aaubry/YamlDotNet) from 12.0.2 to 12.1.0.
- [Release notes](https://github.com/aaubry/YamlDotNet/releases)
- [Commits](https://github.com/aaubry/YamlDotNet/compare/v12.0.2...v12.1.0)

---
updated-dependencies:
- dependency-name: YamlDotNet
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* Bump Moq from 4.18.2 to 4.18.3

Bumps [Moq](https://github.com/moq/moq4) from 4.18.2 to 4.18.3.
- [Release notes](https://github.com/moq/moq4/releases)
- [Changelog](https://github.com/moq/moq4/blob/main/CHANGELOG.md)
- [Commits](https://github.com/moq/moq4/compare/v4.18.2...v4.18.3)

---
updated-dependencies:
- dependency-name: Moq
... (continued)

10732 of 20257 branches covered (0.0%)

Branch coverage included in aggregate %.

48141 of 48141 new or added lines in 1086 files covered. (100.0%)

30685 of 52388 relevant lines covered (58.57%)

7387.88 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

27.83
/Rdmp.Core/DataLoad/Engine/LoadExecution/Components/Runtime/ExecutableRuntimeTask.cs
1
// Copyright (c) The University of Dundee 2018-2019
2
// This file is part of the Research Data Management Platform (RDMP).
3
// RDMP is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
4
// RDMP is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
5
// You should have received a copy of the GNU General Public License along with RDMP. If not, see <https://www.gnu.org/licenses/>.
6

7
using System;
8
using System.Collections.Generic;
9
using System.Diagnostics;
10
using System.IO;
11
using System.Linq;
12
using System.Xml.Schema;
13
using Rdmp.Core.Curation.Data.DataLoad;
14
using Rdmp.Core.DataFlowPipeline;
15
using Rdmp.Core.DataLoad.Engine.Checks.Checkers;
16
using Rdmp.Core.DataLoad.Engine.Job;
17
using Rdmp.Core.DataLoad.Engine.LoadExecution.Components.Arguments;
18
using Rdmp.Core.ReusableLibraryCode.Checks;
19
using Rdmp.Core.ReusableLibraryCode.Progress;
20

21
namespace Rdmp.Core.DataLoad.Engine.LoadExecution.Components.Runtime;
22

23
/// <summary>
24
/// RuntimeTask that executes a single .exe file specified by the user in a ProcessTask with ProcessTaskType Executable.  The exe will be given command line
25
/// arguments for the database connection / loading directory via RuntimeArgumentCollection
26
/// </summary>
27
public class ExecutableRuntimeTask : RuntimeTask
28
{
29
    public string ExeFilepath { get; set; }
40✔
30
    public string ErrorText { get; set; }
×
31
    private Process _currentProcess;
32

33
    public ExecutableRuntimeTask(IProcessTask processTask, RuntimeArgumentCollection args) : base(processTask, args)
18✔
34
    {
35
        ExeFilepath = processTask.Path;
18✔
36
    }
18✔
37

38
    public override ExitCodeType Run(IDataLoadJob job, GracefulCancellationToken cancellationToken)
39
    {
40
        job.OnNotify(this,
×
41
            new NotifyEventArgs(ProgressEventType.Information, $"About to run Task '{ProcessTask.Name}'"));
×
42

43
        var info = new ProcessStartInfo
×
44
        {
×
45
            FileName = ExeFilepath,
×
46
            Arguments = CreateArgString(),
×
47
            RedirectStandardOutput = true,
×
48
            RedirectStandardError = true,
×
49
            UseShellExecute = false,
×
50
            CreateNoWindow = false
×
51
        };
×
52

53
        job.OnNotify(this, new NotifyEventArgs(ProgressEventType.Information,
×
54
            $"Starting '{info.FileName}' with args '{info.Arguments}'"));
×
55

56
        _currentProcess = new Process { StartInfo = info };
×
57
        _currentProcess.OutputDataReceived += (sender, eventArgs) =>
×
58
            job.OnNotify(this, new NotifyEventArgs(ProgressEventType.Information, eventArgs.Data));
×
59

60
        try
61
        {
62
            _currentProcess.Start();
×
63
        }
×
64
        catch (Exception e)
×
65
        {
66
            throw new Exception($"Executable process '{info.FileName}' could not be started: {e}");
×
67
        }
68

69
        _currentProcess.BeginOutputReadLine();
×
70
        var reader = _currentProcess.StandardError;
×
71

72
        job.OnNotify(this,
×
73
            new NotifyEventArgs(ProgressEventType.Information, "Executable has been started successfully"));
×
74
        job.OnNotify(this, new NotifyEventArgs(ProgressEventType.Information, "Waiting for executable to complete"));
×
75

76
        try
77
        {
78
            _currentProcess.WaitForExit();
×
79
        }
×
80
        catch (Exception e)
×
81
        {
82
            ErrorText = reader.ReadToEnd();
×
83
            job.OnNotify(this, new NotifyEventArgs(ProgressEventType.Error, e.ToString(), e));
×
84
            throw new Exception($"Exception whilst waiting for the executable process to finish: {e}");
×
85
        }
86

87
        var exitCode = ParseExitCode(_currentProcess.ExitCode);
×
88
        job.OnNotify(this,
×
89
            new NotifyEventArgs(
×
90
                exitCode != ExitCodeType.Error ? ProgressEventType.Information : ProgressEventType.Error,
×
91
                $"Executable has exited with state '{exitCode}'"));
×
92

93
        if (exitCode == ExitCodeType.Error)
×
94
        {
95
            ErrorText = reader.ReadToEnd();
×
96
            job.OnNotify(this, new NotifyEventArgs(ProgressEventType.Error, ErrorText));
×
97
            throw new Exception($"Executable process '{info.FileName} {info.Arguments}' failed: {ErrorText}");
×
98
        }
99

100
        _currentProcess = null;
×
101

102
        return exitCode;
×
103
    }
104

105

106
    public string CreateArgString()
107
    {
108
        var args = new List<string>();
2✔
109
        RuntimeArguments.IterateAllArguments((name, value) =>
2✔
110
        {
2✔
111
            if (value != null)
2✔
112
                args.Add(CommandLineHelper.CreateArgString(name, value));
2✔
113
            return true;
2✔
114
        });
2✔
115
        return string.Join(" ", args);
2✔
116
    }
117

118
    private static ExitCodeType ParseExitCode(int value)
119
    {
120
        var success = Enum.TryParse(value.ToString(), out ExitCodeType exitCode);
×
121
        return !success ? throw new ArgumentException($"Could not parse exit code from value: {value}") : exitCode;
×
122
    }
123

124
    public override bool Exists() => File.Exists(ExeFilepath);
×
125

126
    public override void Abort(IDataLoadEventListener postDataLoadEventListener)
127
    {
128
        if (_currentProcess == null) return;
×
129

130
        try
131
        {
132
            if (!_currentProcess.HasExited)
×
133
                _currentProcess.Kill();
×
134
        }
×
135
        catch (Exception e)
×
136
        {
137
            throw new Exception($"Could not abort process '{_currentProcess.ProcessName}'{e}");
×
138
        }
139
    }
×
140

141
    public override void LoadCompletedSoDispose(ExitCodeType exitCode, IDataLoadEventListener postLoadEventListener)
142
    {
143
    }
×
144

145
    public override void Check(ICheckNotifier notifier)
146
    {
147
        if (string.IsNullOrWhiteSpace(ExeFilepath))
12✔
148
        {
149
            notifier.OnCheckPerformed(
6✔
150
                new CheckEventArgs($"Executable ProcessTask {ProcessTask} does not have a path specified",
6✔
151
                    CheckResult.Fail));
6✔
152
            return;
×
153
        }
154

155
        var parser = new CommandLineParser();
6✔
156

157
        //see if we can find what their executable is
158
        var exeParsed = parser.Parse(ExeFilepath).ToArray();
6✔
159

160
        //if it is an SQL file they are pointing us at by accident
161
        if (new FileInfo(exeParsed[0]).Extension.Equals(".sql")) //yes it is
6!
162
            notifier.OnCheckPerformed(
×
163
                new CheckEventArgs(
×
164
                    $"ProcessTask called {ProcessTask.Name} is marked as an Executable but seems to point at an SQL file.  You should set the process task type to SQLFile instead",
×
165
                    CheckResult.Fail));
×
166

167
        //we cant tell
168
        if (exeParsed.Length == 0)
6!
169
            throw new Exception(
×
170
                $"Could not parse process task {ProcessTask.Path} into a valid command line instruction for process task {ProcessTask}");
×
171

172
        //the first argument in a parsed windows command will be bob.exe, make sure it exists
173
        if (File.Exists(exeParsed[0]))
6!
174
            notifier.OnCheckPerformed(
×
175
                new CheckEventArgs(
×
176
                    $"Found file {exeParsed[0]} referenced by {ProcessTask.Name}",
×
177
                    CheckResult.Success));
×
178
        else
179
            notifier.OnCheckPerformed(
6✔
180
                new CheckEventArgs(
6✔
181
                    $"Process Task called {ProcessTask.Name} references a file called {exeParsed[0]} which does not exist at this time.",
6✔
182
                    CheckResult.Warning));
6✔
183
    }
×
184

185
    public override string ToString() =>
186
        string.IsNullOrEmpty(ExeFilepath) ? "No executable" : $"{ExeFilepath} {CreateArgString()}";
×
187

188
    public static XmlSchema GetSchema() => null;
×
189
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc