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

HicServices / RDMP / 6245535001

20 Sep 2023 07:44AM UTC coverage: 57.013%. First build
6245535001

push

github

web-flow
8.1.0 Release (#1628)

* Bump Newtonsoft.Json from 13.0.1 to 13.0.2

Bumps [Newtonsoft.Json](https://github.com/JamesNK/Newtonsoft.Json) from 13.0.1 to 13.0.2.
- [Release notes](https://github.com/JamesNK/Newtonsoft.Json/releases)
- [Commits](https://github.com/JamesNK/Newtonsoft.Json/compare/13.0.1...13.0.2)

---
updated-dependencies:
- dependency-name: Newtonsoft.Json
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

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

* Bump NLog from 5.0.5 to 5.1.0

Bumps [NLog](https://github.com/NLog/NLog) from 5.0.5 to 5.1.0.
- [Release notes](https://github.com/NLog/NLog/releases)
- [Changelog](https://github.com/NLog/NLog/blob/dev/CHANGELOG.md)
- [Commits](https://github.com/NLog/NLog/compare/v5.0.5...v5.1.0)

---
updated-dependencies:
- dependency-name: NLog
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

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

* Bump NLog from 5.0.5 to 5.1.0

* Fix -r flag - should have been --results-directory all along

* Bump Newtonsoft.Json from 13.0.1 to 13.0.2

* Bump YamlDotNet from 12.0.2 to 12.1.0

Bumps [YamlDotNet](https://github.com/aaubry/YamlDotNet) from 12.0.2 to 12.1.0.
- [Release notes](https://github.com/aaubry/YamlDotNet/releases)
- [Commits](https://github.com/aaubry/YamlDotNet/compare/v12.0.2...v12.1.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 Moq from 4.18.2 to 4.18.3

Bumps [Moq](https://github.com/moq/moq4) from 4.18.2 to 4.18.3.
- [Release notes](https://github.com/moq/moq4/releases)
- [Changelog](https://github.com/moq/moq4/blob/main/CHANGELOG.md)
- [Commits](https://github.com/moq/moq4/compare/v4.18.2...v4.18.3)

---
updated-dependencies:
- dependency-name: Moq
... (continued)

10732 of 20257 branches covered (0.0%)

Branch coverage included in aggregate %.

48141 of 48141 new or added lines in 1086 files covered. (100.0%)

30685 of 52388 relevant lines covered (58.57%)

7387.88 hits per line

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

89.23
/Rdmp.Core/QueryBuilding/DataAccessPointCollection.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.Collections.Generic;
9
using System.Linq;
10
using System.Security.Cryptography;
11
using FAnsi;
12
using FAnsi.Discovery;
13
using Rdmp.Core.ReusableLibraryCode.DataAccess;
14

15
namespace Rdmp.Core.QueryBuilding;
16

17
/// <summary>
18
/// Tracks a collection of <see cref="IDataAccessPoint"/> and optionally ensures that they all open connections
19
/// to the same server (and server type e.g. MySql on localhost).
20
/// </summary>
21
public class DataAccessPointCollection
22
{
23
    /// <summary>
24
    /// True to require all <see cref="IDataAccessPoint"/> added to be on the same server
25
    /// </summary>
26
    public bool SingleServer { get; }
1,136✔
27

28
    /// <summary>
29
    /// All <see cref="IDataAccessPoint"/> that have been added so far.
30
    /// </summary>
31
    public IReadOnlyCollection<IDataAccessPoint> Points => _points;
692✔
32

33
    public DataAccessContext DataAccessContext { get; }
1,134✔
34

35
    private HashSet<IDataAccessPoint> _points = new();
574✔
36

37
    /// <summary>
38
    /// Creates a new collection of <see cref="IDataAccessPoint"/> for collecting dependencies e.g.
39
    /// when building a query in which there are subqueries run on different databases
40
    /// </summary>
41
    /// <param name="singleServer">True to require all <see cref="Points"/> to be on the same server (and type).</param>
42
    /// <param name="context"></param>
43
    public DataAccessPointCollection(bool singleServer,
574✔
44
        DataAccessContext context = DataAccessContext.InternalDataProcessing)
574✔
45
    {
46
        SingleServer = singleServer;
574✔
47
        DataAccessContext = context;
574✔
48
    }
574✔
49

50
    /// <summary>
51
    /// Adds the given <paramref name="point"/> to the collection. Throws InvalidOperationException if <see cref="SingleServer"/>
52
    /// is set and the new <paramref name="point"/> is on a different server or <see cref="DatabaseType"/>
53
    /// </summary>
54
    /// <param name="point"></param>
55
    public void Add(IDataAccessPoint point)
56
    {
57
        AddRange(new[] { point });
36✔
58
    }
26✔
59

60
    /// <summary>
61
    /// Attempts to add <paramref name="point"/> to the collection returning true if it was successfully added.  Returns false
62
    /// if not added (e.g. if <see cref="SingleServer"/> is true and <paramref name="point"/> is to a different server/type).
63
    /// </summary>
64
    /// <param name="point"></param>
65
    /// <returns></returns>
66
    public bool TryAdd(IDataAccessPoint point)
67
    {
68
        return TryAddRange(new[] { point });
624✔
69
    }
70

71
    /// <summary>
72
    /// Attempts to add <paramref name="points"/> to the collection returning true if it was successfully added.  Returns false
73
    /// if not added (e.g. if <see cref="SingleServer"/> is true and <paramref name="points"/> is to a different server/type).
74
    ///
75
    ///  <para>Either all or none of the <paramref name="points"/> will be added (i.e. not half)</para>
76
    /// </summary>
77
    /// <param name="points"></param>
78
    /// <returns></returns>
79
    public bool TryAddRange(IDataAccessPoint[] points)
80
    {
81
        try
82
        {
83
            AddRange(points);
624✔
84
            return true;
584✔
85
        }
86
        catch (InvalidOperationException)
40✔
87
        {
88
            return false;
40✔
89
        }
90
    }
624✔
91

92

93
    /// <summary>
94
    /// Adds the given <paramref name="points"/> to the collection. Throws InvalidOperationException if <see cref="SingleServer"/>
95
    /// is set and the new <paramref name="points"/> is on a different server or <see cref="DatabaseType"/>
96
    /// </summary>
97
    /// <param name="points"></param>
98
    public void AddRange(IDataAccessPoint[] points)
99
    {
100
        //if we already have all the points then don't bother checking
101
        if (points.All(p => _points.Contains(p)))
1,472✔
102
            return;
96✔
103

104
        if (SingleServer)
640✔
105
        {
106
            var tempList = new HashSet<IDataAccessPoint>(_points);
638✔
107

108
            foreach (var p in points)
2,572✔
109
                tempList.Add(p);
648✔
110

111
            try
112
            {
113
                DataAccessPortal
638✔
114
                    .ExpectDistinctServer(tempList.ToArray(), DataAccessContext, false);
638✔
115

116
                //now add to the proper collection
117
                foreach (var p in points)
2,372✔
118
                    _points.Add(p);
598✔
119
            }
588✔
120
            catch (Exception e)
50✔
121
            {
122
                if (e is CryptographicException)
50!
123
                    throw;
×
124

125
                throw new InvalidOperationException(
50✔
126
                    $"Could not identify single set of server/credentials to use with points:{string.Join(Environment.NewLine, tempList)}",
50✔
127
                    e);
50✔
128
            }
129
        }
130
        else
131
        {
132
            foreach (var p in points)
8✔
133
                _points.Add(p);
2✔
134
        }
135
    }
590✔
136

137
    /// <summary>
138
    /// Clears <see cref="Points"/>
139
    /// </summary>
140
    public void Clear()
141
    {
142
        _points.Clear();
×
143
    }
×
144

145
    /// <summary>
146
    /// Returns comma separated list of <see cref="Points"/>
147
    /// </summary>
148
    /// <returns></returns>
149
    public override string ToString()
150
    {
151
        return string.Join(",", Points.Select(p => p.ToString()));
×
152
    }
153

154
    /// <summary>
155
    /// Returns as single server on which all <see cref="Points"/> can be reached (even if they are in
156
    /// separate databases on that server).  Only valid if <see cref="SingleServer"/> is set (otherwise
157
    /// throws <see cref="NotSupportedException"/>
158
    /// </summary>
159
    /// <returns></returns>
160
    public DiscoveredServer GetDistinctServer()
161
    {
162
        if (!SingleServer)
336!
163
            throw new NotSupportedException("Only valid when SingleServer flag is set");
×
164

165
        //they all have to be in the same server but do they also reside in the same database?
166
        var allOnSameDatabase = Points.Select(p => p.Database).Distinct().Count() == 1;
724✔
167

168
        return DataAccessPortal.ExpectDistinctServer(Points.ToArray(),
336✔
169
            DataAccessContext, allOnSameDatabase);
336✔
170
    }
171

172
    /// <summary>
173
    /// Returns a new collection with a new set of <see cref="Points"/> matching the old set (but not instance).
174
    /// </summary>
175
    /// <returns></returns>
176
    public DataAccessPointCollection Clone()
177
    {
178
        var col = new DataAccessPointCollection(SingleServer, DataAccessContext)
160✔
179
        {
160✔
180
            _points = new HashSet<IDataAccessPoint>(_points)
160✔
181
        };
160✔
182
        return col;
160✔
183
    }
184

185
    /// <summary>
186
    /// Tests whether the supplied <paramref name="point"/> could be added to the current collection (without
187
    /// actually adding it).
188
    /// </summary>
189
    /// <param name="point"></param>
190
    /// <returns></returns>
191
    public bool AddWouldBePossible(IDataAccessPoint point) => Clone().TryAdd(point);
160✔
192
}
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