• 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/DataLoad/Engine/LoadExecution/Components/Runtime/ExecuteSqlBakFileRuntimeTask.cs
1
// Copyright (c) The University of Dundee 2018-2023
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.Data;
9
using System.IO;
10
using Microsoft.Data.SqlClient;
11
using Rdmp.Core.Curation.Data.DataLoad;
12
using Rdmp.Core.DataFlowPipeline;
13
using Rdmp.Core.DataLoad.Engine.Job;
14
using Rdmp.Core.DataLoad.Engine.LoadExecution.Components.Arguments;
15
using Rdmp.Core.ReusableLibraryCode.Checks;
16
using Rdmp.Core.ReusableLibraryCode.Progress;
17

18
namespace Rdmp.Core.DataLoad.Engine.LoadExecution.Components.Runtime;
19

20
/// <summary>
21
/// RuntimeTask that executes a single .bak file specified by the user in a ProcessTask with ProcessTaskType SQLBakFile.
22
/// </summary>
23
public class ExecuteSqlBakFileRuntimeTask : RuntimeTask
24
{
25
    public string Filepath;
26
    private readonly IProcessTask _task;
27

28
    private LoadStage _loadStage;
29

NEW
30
    public ExecuteSqlBakFileRuntimeTask(IProcessTask task, RuntimeArgumentCollection args) : base(task, args)
×
31
    {
NEW
32
        _task = task;
×
NEW
33
        Filepath = task.Path;
×
NEW
34
    }
×
35

36
    public override ExitCodeType Run(IDataLoadJob job, GracefulCancellationToken cancellationToken)
37
    {
NEW
38
        var db = RuntimeArguments.StageSpecificArguments.DbInfo;
×
NEW
39
        _loadStage = RuntimeArguments.StageSpecificArguments.LoadStage;
×
40

NEW
41
        if (!Exists())
×
NEW
42
            throw new Exception($"The sql bak file {Filepath} does not exist");
×
43

NEW
44
        var fileOnlyCommand = $"RESTORE FILELISTONLY FROM DISK = '{Filepath}'";
×
NEW
45
        using var fileInfo = new DataTable();
×
NEW
46
        using var con = (SqlConnection)db.Server.GetConnection();
×
NEW
47
        using (var cmd = new SqlCommand(fileOnlyCommand, con))
×
NEW
48
          using (var da = new SqlDataAdapter(cmd))
×
NEW
49
            da.Fill(fileInfo);
×
NEW
50
        var primaryFiles = fileInfo.Select("Type = 'D'");
×
NEW
51
        var logFiles = fileInfo.Select("Type = 'L'");
×
NEW
52
        if (primaryFiles.Length != 1 || logFiles.Length != 1)
×
53
        {
54
            //Something has gone wrong
NEW
55
            return ExitCodeType.Error;
×
56
        }
57

58

NEW
59
        var primaryFile = primaryFiles[0];
×
NEW
60
        var logFile = logFiles[0];
×
NEW
61
        var primaryFilePhysicalName = primaryFile["PhysicalName"].ToString();
×
NEW
62
        var logFilePhysicalName = logFile["PhysicalName"].ToString();
×
63

NEW
64
        if (File.Exists(primaryFilePhysicalName) || File.Exists(logFilePhysicalName))
×
65
        {
NEW
66
            var timestamp = DateTime.Now.Millisecond.ToString();
×
NEW
67
            var primaryFileName = primaryFilePhysicalName[..^4];
×
NEW
68
            var primaryFileExtension = primaryFilePhysicalName[^4..];
×
NEW
69
            primaryFilePhysicalName = $"{primaryFileName}_{timestamp}{primaryFileExtension}";
×
NEW
70
            var logFileName = logFilePhysicalName[..^4];
×
NEW
71
            var logFileExtension = logFilePhysicalName[^4..];
×
NEW
72
            logFilePhysicalName = $"{logFileName}_{timestamp}{logFileExtension}";
×
73
        }
74

NEW
75
        var name = db.ToString();
×
76

NEW
77
        var restoreCommand = @$"
×
NEW
78
        use master;
×
NEW
79
        ALTER DATABASE {name} SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
×
NEW
80
        RESTORE DATABASE {name}
×
NEW
81
        FROM DISK = '{Filepath}'
×
NEW
82
        WITH MOVE '{primaryFile["LogicalName"]}' TO '{primaryFilePhysicalName}',
×
NEW
83
        MOVE '{logFile["LogicalName"]}' TO '{logFilePhysicalName}' ,  NOUNLOAD,  REPLACE,  STATS = 5;
×
NEW
84
        ALTER DATABASE {name} SET MULTI_USER;
×
NEW
85
        ";
×
86

NEW
87
        job.OnNotify(this, new NotifyEventArgs(ProgressEventType.Information,
×
NEW
88
            $"Executing script {Filepath} ( against {db})"));
×
89

NEW
90
        var executer = new ExecuteSqlInDleStage(job, _loadStage);
×
NEW
91
        return executer.Execute(restoreCommand, db);
×
NEW
92
    }
×
93

94

NEW
95
    public override bool Exists() => File.Exists(Filepath);
×
96

97
    public override void Abort(IDataLoadEventListener postLoadEventListener)
98
    {
NEW
99
    }
×
100

101
    public override void LoadCompletedSoDispose(ExitCodeType exitCode, IDataLoadEventListener postLoadEventListener)
102
    {
NEW
103
    }
×
104

105
    public override void Check(ICheckNotifier notifier)
106
    {
NEW
107
        if (string.IsNullOrWhiteSpace(Filepath))
×
108
        {
NEW
109
            notifier.OnCheckPerformed(
×
NEW
110
                new CheckEventArgs($"ExecuteSqlFileTask {_task} does not have a path specified",
×
NEW
111
                    CheckResult.Fail));
×
NEW
112
            return;
×
113
        }
114

NEW
115
        if (!File.Exists(Filepath))
×
NEW
116
            notifier.OnCheckPerformed(
×
NEW
117
                new CheckEventArgs(
×
NEW
118
                    $"File '{Filepath}' does not exist! (the only time this would be legal is if you have an exe or a freaky plugin that creates this file)",
×
NEW
119
                    CheckResult.Warning));
×
120
        else
NEW
121
            notifier.OnCheckPerformed(new CheckEventArgs($"Found File '{Filepath}'",
×
NEW
122
                CheckResult.Success));
×
NEW
123
    }
×
124
}
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

© 2026 Coveralls, Inc