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

HicServices / RDMP / 6664164762

26 Oct 2023 06:10PM UTC coverage: 56.914% (-0.08%) from 56.99%
6664164762

push

github

web-flow
RDMP-15 Use .bak files as Data Loads (#1656)

* basic ui triggers
* working dl

---------

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

10697 of 20239 branches covered (0.0%)

Branch coverage included in aggregate %.

89 of 89 new or added lines in 6 files covered. (100.0%)

30536 of 52209 relevant lines covered (58.49%)

7348.34 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

45
        ProcessTaskType[] AcceptedProcessTaskTypes = { ProcessTaskType.SQLFile, ProcessTaskType.Executable, ProcessTaskType.SQLBakFile };
×
46
        if (!AcceptedProcessTaskTypes.Contains(taskType))
×
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
        {
61
            if (_taskType == ProcessTaskType.SQLBakFile)
×
62
            {
63
                if (!BasicActivator.TypeText("Enter a name for the SQL Bak file", "File name", 100, "database.bak",
×
64
                       out var selected, false)) return;
×
65

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

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

73
                _file = new FileInfo(target);
×
74

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

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

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

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

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",
×
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),
×
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