• 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

8.21
/Rdmp.Core/Curation/Data/LoadModuleAssembly.cs
1
// Copyright (c) The University of Dundee 2018-2024
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.IO;
10
using System.Linq;
11
using System.Xml;
12
using ICSharpCode.SharpZipLib.Zip;
13
using Rdmp.Core.ReusableLibraryCode.Checks;
14

15
namespace Rdmp.Core.Curation.Data;
16

17
/// <summary>
18
/// This entity wraps references to plugin .nupkg files on disk.
19
/// </summary>
20
public sealed class LoadModuleAssembly
21
{
22
    private static readonly bool IsWin = AppDomain.CurrentDomain.GetAssemblies()
4✔
23
        .Any(static a => a.FullName?.StartsWith("Rdmp.UI", StringComparison.Ordinal) == true);
354!
24

25
    private static readonly string PluginsList = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "rdmpplugins.txt");
4✔
26

27
    internal static readonly List<LoadModuleAssembly> Assemblies = [];
4✔
28
    private readonly FileInfo _file;
29

30
    private LoadModuleAssembly(FileInfo file)
×
31
    {
32
        _file = file;
×
33
    }
×
34

35

36
    private static bool IsReleaseCandidcate(string filename)
37
    {
NEW
38
        return filename.Split('.')[^2].Contains("-rc");
×
39
    }
40

41
    private static int GetReleaseCandidateId(string filename)
42
    {
43
        //expects the rc to be something like My.Plugin.3.0.0-rc2
NEW
44
        int.TryParse(filename.Split("-rc")[1].Split('.')[0], out var result);
×
NEW
45
        return result;
×
46
    }
47

48
    private static Dictionary<string, string> HandlePluginVersioning()
49
    {
NEW
50
        var PluginVersionLookup = new Dictionary<string, string>();
×
NEW
51
        var PluginPathLookup = new Dictionary<string, string>();
×
NEW
52
        var pluginFiles = Directory.EnumerateFiles(AppDomain.CurrentDomain.BaseDirectory, "*.rdmp");
×
NEW
53
        foreach (var pluginFile in pluginFiles)
×
54
        {
NEW
55
            using FileStream fs = new(pluginFile, FileMode.Open);
×
NEW
56
            using ZipFile zip = new(fs);
×
NEW
57
            foreach (ZipEntry ze in zip)
×
58
            {
NEW
59
                if (ze.Name.Contains(".nuspec"))
×
60
                {
NEW
61
                    using StreamReader sr = new StreamReader(zip.GetInputStream(ze.ZipFileIndex));
×
NEW
62
                    var content = sr.ReadToEnd();
×
NEW
63
                    var xmlDoc = new XmlDocument();
×
NEW
64
                    xmlDoc.LoadXml(content);
×
65

NEW
66
                    var name = xmlDoc.GetElementsByTagName("id").Item(0).InnerText;
×
NEW
67
                    var version = xmlDoc.GetElementsByTagName("version").Item(0).InnerText;
×
NEW
68
                    if (PluginVersionLookup.TryGetValue(name, out var currentVersion))
×
69
                    {
70
                        //already found a version
NEW
71
                        var result = new Version(currentVersion).CompareTo(new Version(version));
×
NEW
72
                        if (result < 0)
×
73
                        {
74
                            //this version is the latest version
NEW
75
                            PluginVersionLookup[name] = version;
×
NEW
76
                            PluginPathLookup[name] = pluginFile;
×
77
                        }
NEW
78
                        if(result == 0)
×
79
                        {
80
                            //check for RC in the name
NEW
81
                            var currentIsReleaseCandidate = IsReleaseCandidcate(PluginPathLookup[name]);
×
NEW
82
                            var newIsReleaseCandidate = IsReleaseCandidcate(pluginFile);
×
NEW
83
                            if(newIsReleaseCandidate && currentIsReleaseCandidate)
×
84
                            {
NEW
85
                                var newIsLatest = GetReleaseCandidateId(pluginFile) > GetReleaseCandidateId(PluginPathLookup[name]);
×
NEW
86
                                if (newIsLatest)
×
87
                                {
NEW
88
                                    PluginVersionLookup[name] = version;
×
NEW
89
                                    PluginPathLookup[name] = pluginFile;
×
90
                                }
NEW
91
                            } else if (newIsReleaseCandidate)
×
92
                            {
93
                                //new version is the latest
NEW
94
                                PluginVersionLookup[name] = version;
×
NEW
95
                                PluginPathLookup[name] = pluginFile;
×
96
                            }
97
                        }
98
                    }
99
                    else
100
                    {
NEW
101
                        PluginVersionLookup[name] = version;
×
NEW
102
                        PluginPathLookup[name] = pluginFile;
×
103
                    }
NEW
104
                    break;
×
105
                }
106

107
            }
108

109
        }
110

NEW
111
        return PluginPathLookup;
×
112
    }
113

114
    /// <summary>
115
    /// List the plugin files to load
116
    /// </summary>
117
    /// <returns></returns>
118
    internal static IEnumerable<string> PluginFiles()
119
    {
120
        if (Directory.EnumerateFiles(AppDomain.CurrentDomain.BaseDirectory, "*.rdmp").Count() > 0)
16!
121
        {
122
            //use the modern .RDMP plugins
NEW
123
            var plugins = HandlePluginVersioning();
×
NEW
124
            return plugins.Values.ToArray();
×
125

126
        }
127
        return File.Exists(PluginsList)
16!
128
            ? File.ReadAllLines(PluginsList)
16✔
129
                .Select(static name => Path.Combine(AppDomain.CurrentDomain.BaseDirectory, name))
×
130
            : Directory.EnumerateFiles(AppDomain.CurrentDomain.BaseDirectory, "*.nupkg");
16✔
131
    }
132

133
    /// <summary>
134
    /// Unpack the plugin DLL files, excluding any Windows UI specific dlls when not running a Windows GUI
135
    /// </summary>
136
    internal static IEnumerable<(string, MemoryStream)> GetContents(string path)
137
    {
138
        var info = new FileInfo(path);
×
139
        if (!info.Exists || info.Length < 100) yield break; // Ignore missing or empty files
×
140

141
        var pluginStream = info.OpenRead();
×
142
        if (!pluginStream.CanSeek)
×
143
            throw new ArgumentException("Seek needed", nameof(path));
×
144

145
        Assemblies.Add(new LoadModuleAssembly(info));
×
146

147
        using var zip = new ZipFile(pluginStream);
×
148
        foreach (var e in zip.Cast<ZipEntry>()
×
149
                     .Where(static e => e.IsFile && e.Name.EndsWith(".dll", StringComparison.OrdinalIgnoreCase) &&
150
                                        (IsWin || !e.Name.Contains("/windows/"))))
151
        {
152
            using var s = zip.GetInputStream(e);
×
153
            using var ms2 = new MemoryStream();
×
154
            s.CopyTo(ms2);
×
155
            ms2.Position = 0;
×
156
            yield return (e.Name, ms2);
×
157
        }
×
158
    }
×
159

160
    /// <summary>
161
    /// Copy the plugin nupkg to the given directory
162
    /// </summary>
163
    /// <param name="downloadDirectory"></param>
164
    public void DownloadAssembly(DirectoryInfo downloadDirectory)
165
    {
166
        if (!downloadDirectory.Exists)
×
167
            downloadDirectory.Create();
×
168
        var targetFile = Path.Combine(downloadDirectory.FullName, _file.Name);
×
169
        _file.CopyTo(targetFile, true);
×
170
    }
×
171

172
    /// <summary>
173
    /// Delete the plugin file from disk, and remove it from rdmpplugins.txt if in use
174
    /// </summary>
175
    public void Delete()
176
    {
177
        _file.Delete();
×
178
        if (!File.Exists(PluginsList)) return;
×
179

180
        var tmp = $"{PluginsList}.tmp";
×
181
        File.WriteAllLines(tmp, File.ReadAllLines(PluginsList).Where(l => !l.Contains(_file.Name)));
×
182
        File.Move(tmp, PluginsList, true);
×
183
    }
×
184

185
    public override string ToString() => _file.Name;
×
186

187
    public static void UploadFile(ICheckNotifier checkNotifier, FileInfo toCommit)
188
    {
189
        try
190
        {
191
            toCommit.CopyTo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, toCommit.Name), true);
×
192
            if (!File.Exists(PluginsList)) return;
×
193

194
            // Now the tricky bit: add this new file, and remove any other versions of the same
195
            // e.g. adding DummyPlugin-1.2.3 should delete DummyPlugin-2.0 and DummyPlugin-1.0 if present
196
            var list = File.ReadAllLines(PluginsList);
×
197
            var tmp = $"{PluginsList}.tmp";
×
198

199
            var versionPos = toCommit.Name.IndexOf('-');
×
200
            if (versionPos != -1)
×
201
            {
202
                var stub = toCommit.Name[..(versionPos + 1)];
×
203
                list = list.Where(l => !l.StartsWith(stub, StringComparison.OrdinalIgnoreCase)).ToArray();
×
204
            }
205

206
            File.WriteAllLines(tmp, list.Union([toCommit.Name]));
×
207
            File.Move(tmp, PluginsList, true);
×
208
        }
×
209
        catch (Exception e)
×
210
        {
211
            checkNotifier.OnCheckPerformed(new CheckEventArgs($"Failed copying plugin {toCommit.Name}",
×
212
                CheckResult.Fail, e));
×
213
            throw;
×
214
        }
215
    }
×
216
}
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