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

HicServices / RDMP / 9758065908

02 Jul 2024 09:03AM UTC coverage: 56.679% (-0.2%) from 56.914%
9758065908

push

github

web-flow
Release/8.2.0 (#1867)

* add extraction additions

* interim

* add test

* interim

* working dedupe

* improved checking

* add timestamp option

* fix extra looping

* add check

* start on tests

* tidy up code

* update link

* tidy up

* Rename executeFullExtractionToDatabaseMSSql.md to ExecuteFullExtractionToDatabaseMSSql.md

* fix typo

* add docs

* update

* update documentation

* attempt fix docs

* update docs

* tidy up code

* better tests

* add real test

* tidy up

* interim

* grab existiing entity

* no new data

* add basic tests

* attempt to fix test

* interim

* interim commit

* working clash

* add test

* fix test

* improved clash checker

* tidy up

* update test

* fix up test

* update from codeql

* tidy up code

* fix bad merge

* fix typo

* skip over for now

* revert change

* Task/RDMP-180 Add instance settings table (#1820)

* working settings interface

* add documentation

* add missing files

* update namespace

* add icon

* update from run

* make key unique

* add tests

* update tests

* update for tests

* fix unique name issue

* tidy up

* tidy up from review

* works

* nested deprications

* recursive deprication

* tidy up

* add newline

* Task/rdmp 174 dqe improvements (#1849)

* working scallable graph

* add changelog

* add axis override

* interim

* working increments

* working ui refresh

* update changelog

* tidy up code

* add missing file

* tidy up

* Task/rdmp 155 migrate catalogue tables (#1805)

* start of UI

* interim

* working switch

* improved ui

* fix build

* rename duped file

* imterim

* add checks

* start of tests

* local tests  working

* add tests

* improved ui

* tidy up

* add single item use

* broken test

* updated tests

* tidy up imports

* add some documentation

* fix docume... (continued)

10912 of 20750 branches covered (52.59%)

Branch coverage included in aggregate %.

369 of 831 new or added lines in 38 files covered. (44.4%)

375 existing lines in 25 files now uncovered.

30965 of 53135 relevant lines covered (58.28%)

7845.71 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
        {
NEW
38
            _loadDirectory = new LoadDirectory(_loadMetadata.LocationOfForLoadingDirectory, _loadMetadata.LocationOfForArchivingDirectory, _loadMetadata.LocationOfExecutablesDirectory, _loadMetadata.LocationOfCacheDirectory );
×
39
        }
×
NEW
40
        catch (Exception e )
×
41
        {
NEW
42
            Console.WriteLine(e.Message);
×
43
            SetImpossible("Could not construct LoadDirectory");
×
44
        }
×
45

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

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

53
        _file = file;
×
54
    }
×
55

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

60
        if (_file == null)
×
61
        {
62
            if (_taskType == ProcessTaskType.SQLBakFile)
×
63
            {
64
                _file = BasicActivator.SelectFile("Enter the .bak file's path", "*.bak", "*.bak");
×
65
            }
66
            else if (_taskType == ProcessTaskType.SQLFile)
×
67
            {
68
                if (!BasicActivator.TypeText("Enter a name for the SQL file", "File name", 100, "myscript.sql",
×
69
                        out var selected, false)) return;
×
70

71
                var target = Path.Combine(_loadDirectory.ExecutablesPath.FullName, selected);
×
72

73
                if (!target.EndsWith(".sql"))
×
74
                    target += ".sql";
×
75

76
                //create it if it doesn't exist
77
                if (!File.Exists(target))
×
78
                    File.WriteAllText(target, "/*todo Type some SQL*/");
×
79

80
                _file = new FileInfo(target);
×
81

82
            }
83
            else if (_taskType == ProcessTaskType.Executable)
×
84
            {
85
                _file = BasicActivator.SelectFile("Enter executable's path", "Executables", "*.exe");
×
86

87
                // they didn't pick one
88
                if (_file == null)
×
89
                    return;
×
90

91
                if (!_file.Exists)
×
92
                    throw new FileNotFoundException("File did not exist");
×
93
            }
94
            else
95
            {
96
                throw new ArgumentOutOfRangeException($"Unexpected _taskType:{_taskType}");
×
97
            }
98
        }
99

100
        var task = new ProcessTask((ICatalogueRepository)_loadMetadata.Repository, _loadMetadata, _loadStage)
×
101
        {
×
102
            ProcessTaskType = _taskType,
×
103
            Path = _file.FullName
×
104
        };
×
105
        SaveAndShow(task);
×
106
    }
×
107

108
    private void SaveAndShow(ProcessTask task)
109
    {
110
        task.Name = $"Run '{Path.GetFileName(task.Path)}'";
×
111
        task.SaveToDatabase();
×
112

113
        Publish(_loadMetadata);
×
114
        Activate(task);
×
115
    }
×
116

117
    public override string GetCommandName()
118
    {
119
        return _taskType switch
×
120
        {
×
121
            ProcessTaskType.Executable => "Add Run .exe File Task",
×
122
            ProcessTaskType.SQLFile => "Add Run SQL Script Task",
×
123
            ProcessTaskType.SQLBakFile => "Add SQL backup File Task",
×
124
            _ => throw new ArgumentOutOfRangeException()
×
125
        };
×
126
    }
127

128
    public override Image<Rgba32> GetImage(IIconProvider iconProvider)
129
    {
130
        return _taskType switch
×
131
        {
×
132
            ProcessTaskType.SQLFile => iconProvider.GetImage(RDMPConcept.SQL, OverlayKind.Add),
×
133
            ProcessTaskType.SQLBakFile => iconProvider.GetImage(RDMPConcept.SQL, OverlayKind.Add), //todo maybe better
×
134
            ProcessTaskType.Executable => IconOverlayProvider.GetOverlayNoCache(
×
135
                Image.Load<Rgba32>(CatalogueIcons.Exe), OverlayKind.Add),
×
136
            _ => null
×
137
        };
×
138
    }
139
}
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