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

HicServices / RDMP / 7194961165

13 Dec 2023 12:07PM UTC coverage: 56.776% (-0.2%) from 57.013%
7194961165

push

github

web-flow
Merge Latest Release into main (#1702)

* Bump YamlDotNet from 13.3.1 to 13.4.0

Bumps [YamlDotNet](https://github.com/aaubry/YamlDotNet) from 13.3.1 to 13.4.0.
- [Release notes](https://github.com/aaubry/YamlDotNet/releases)
- [Commits](https://github.com/aaubry/YamlDotNet/compare/v13.3.1...v13.4.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 shogo82148/actions-setup-perl from 1.23.1 to 1.24.1

Bumps [shogo82148/actions-setup-perl](https://github.com/shogo82148/actions-setup-perl) from 1.23.1 to 1.24.1.
- [Release notes](https://github.com/shogo82148/actions-setup-perl/releases)
- [Commits](https://github.com/shogo82148/actions-setup-perl/compare/v1.23.1...v1.24.1)

---
updated-dependencies:
- dependency-name: shogo82148/actions-setup-perl
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

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

* fix checkbox issue

* improve confirmation text (#1639)

* improve confirmation text
* Loop tidyup, use var where possible

---------

Co-authored-by: jas88 <j.a.sutherland@dundee.ac.uk>

* correct typo in create logging sql (#1640)

* Feature/ci codescan (#1641)

* Move SecurityCodescan.VS2019 to run on Github CI alone, integrate results with CodeQL
* Remove SecurityCodescan from Packages.md, no longer used via Nuget

---------

Co-authored-by: James A Sutherland <j@sutherland.pw>

* hide source control when not available

* Remove old Plugin object bits, tidy up (#1636)

* Remove old Plugin object bits, tidy up

* Purge remaining bits of AllExpiredPluginsNode

* Fix plugin display name in tree

* Update CreateNewDataExtractionProjectUI.cs

Casting fix

* Feature/rdmp42 delete plugins (#1642)

* add ui plugin delete functionality

* Warning and inherita... (continued)

10722 of 20351 branches covered (0.0%)

Branch coverage included in aggregate %.

215 of 789 new or added lines in 63 files covered. (27.25%)

39 existing lines in 16 files now uncovered.

30650 of 52518 relevant lines covered (58.36%)

7294.17 hits per line

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

0.0
/Rdmp.Core/CommandExecution/AtomicCommands/ExecuteCommandCreateNewFileBasedProcessTask.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.IO;
9
using System.Linq;
10
using Rdmp.Core.Curation;
11
using Rdmp.Core.Curation.Data.DataLoad;
12
using Rdmp.Core.Icons.IconOverlays;
13
using Rdmp.Core.Icons.IconProvision;
14
using Rdmp.Core.Repositories;
15
using Rdmp.Core.ReusableLibraryCode.Icons.IconProvision;
16
using SixLabors.ImageSharp;
17
using SixLabors.ImageSharp.PixelFormats;
18

19
namespace Rdmp.Core.CommandExecution.AtomicCommands;
20

21
public class ExecuteCommandCreateNewFileBasedProcessTask : BasicCommandExecution
22
{
23
    private readonly ProcessTaskType _taskType;
24
    private readonly LoadMetadata _loadMetadata;
25
    private readonly LoadStage _loadStage;
26
    private readonly LoadDirectory _loadDirectory;
27
    private FileInfo _file;
28

29
    public ExecuteCommandCreateNewFileBasedProcessTask(IBasicActivateItems activator, ProcessTaskType taskType,
30
        LoadMetadata loadMetadata, LoadStage loadStage, FileInfo file = null) : base(activator)
×
31
    {
32
        _taskType = taskType;
×
33
        _loadMetadata = loadMetadata;
×
34
        _loadStage = loadStage;
×
35

36
        try
37
        {
38
            _loadDirectory = new LoadDirectory(_loadMetadata.LocationOfFlatFiles);
×
39
        }
×
40
        catch (Exception)
×
41
        {
42
            SetImpossible("Could not construct LoadDirectory");
×
43
        }
×
44

NEW
45
        ProcessTaskType[] AcceptedProcessTaskTypes = { ProcessTaskType.SQLFile, ProcessTaskType.Executable, ProcessTaskType.SQLBakFile };
×
NEW
46
        if (!AcceptedProcessTaskTypes.Contains(taskType))
×
NEW
47
            SetImpossible("Only SQLFile, SqlBakFile and Executable task types are supported by this command");
×
48

49
        if (!ProcessTask.IsCompatibleStage(taskType, loadStage))
×
50
            SetImpossible($"You cannot run {taskType} in {loadStage}");
×
51

52
        _file = file;
×
53
    }
×
54

55
    public override void Execute()
56
    {
57
        base.Execute();
×
58

59
        if (_file == null)
×
60
        {
NEW
61
            if (_taskType == ProcessTaskType.SQLBakFile)
×
62
            {
NEW
63
                if (!BasicActivator.TypeText("Enter a name for the SQL Bak file", "File name", 100, "database.bak",
×
NEW
64
                       out var selected, false)) return;
×
65

NEW
66
                var target = Path.Combine(_loadDirectory.ExecutablesPath.FullName, selected);
×
67

NEW
68
                if (!File.Exists(target))
×
69
                {
NEW
70
                    return; //File doesn't exist
×
71
                }
72

NEW
73
                _file = new FileInfo(target);
×
74

75
            }
NEW
76
            else if (_taskType == ProcessTaskType.SQLFile)
×
77
            {
NEW
78
                if (!BasicActivator.TypeText("Enter a name for the SQL file", "File name", 100, "myscript.sql",
×
NEW
79
                        out var selected, false)) return;
×
80

NEW
81
                var target = Path.Combine(_loadDirectory.ExecutablesPath.FullName, selected);
×
82

NEW
83
                if (!target.EndsWith(".sql"))
×
NEW
84
                    target += ".sql";
×
85

86
                //create it if it doesn't exist
NEW
87
                if (!File.Exists(target))
×
NEW
88
                    File.WriteAllText(target, "/*todo Type some SQL*/");
×
89

NEW
90
                _file = new FileInfo(target);
×
91

92
            }
93
            else if (_taskType == ProcessTaskType.Executable)
×
94
            {
95
                _file = BasicActivator.SelectFile("Enter executable's path", "Executables", "*.exe");
×
96

97
                // they didn't pick one
98
                if (_file == null)
×
99
                    return;
×
100

101
                if (!_file.Exists)
×
102
                    throw new FileNotFoundException("File did not exist");
×
103
            }
104
            else
105
            {
106
                throw new ArgumentOutOfRangeException($"Unexpected _taskType:{_taskType}");
×
107
            }
108
        }
109

110
        var task = new ProcessTask((ICatalogueRepository)_loadMetadata.Repository, _loadMetadata, _loadStage)
×
111
        {
×
112
            ProcessTaskType = _taskType,
×
113
            Path = _file.FullName
×
114
        };
×
115
        SaveAndShow(task);
×
116
    }
×
117

118
    private void SaveAndShow(ProcessTask task)
119
    {
120
        task.Name = $"Run '{Path.GetFileName(task.Path)}'";
×
121
        task.SaveToDatabase();
×
122

123
        Publish(_loadMetadata);
×
124
        Activate(task);
×
125
    }
×
126

127
    public override string GetCommandName()
128
    {
129
        return _taskType switch
×
130
        {
×
131
            ProcessTaskType.Executable => "Add Run .exe File Task",
×
132
            ProcessTaskType.SQLFile => "Add Run SQL Script Task",
×
NEW
133
            ProcessTaskType.SQLBakFile => "Add SQL backup File Task",
×
134
            _ => throw new ArgumentOutOfRangeException()
×
135
        };
×
136
    }
137

138
    public override Image<Rgba32> GetImage(IIconProvider iconProvider)
139
    {
140
        return _taskType switch
×
141
        {
×
142
            ProcessTaskType.SQLFile => iconProvider.GetImage(RDMPConcept.SQL, OverlayKind.Add),
×
NEW
143
            ProcessTaskType.SQLBakFile => iconProvider.GetImage(RDMPConcept.SQL, OverlayKind.Add), //todo maybe better
×
144
            ProcessTaskType.Executable => IconOverlayProvider.GetOverlayNoCache(
×
145
                Image.Load<Rgba32>(CatalogueIcons.Exe), OverlayKind.Add),
×
146
            _ => null
×
147
        };
×
148
    }
149
}
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