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

HicServices / RDMP / 11978888584

22 Nov 2024 07:27PM UTC coverage: 57.383% (-0.002%) from 57.385%
11978888584

push

github

jas88
Fix up redundant type inheritance

11206 of 21050 branches covered (53.24%)

Branch coverage included in aggregate %.

65 of 249 new or added lines in 42 files covered. (26.1%)

17 existing lines in 14 files now uncovered.

31718 of 53752 relevant lines covered (59.01%)

8290.69 hits per line

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

0.0
/Rdmp.Core/CommandExecution/AtomicCommands/ExecuteCommandAddParameter.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 Rdmp.Core.Curation.Data;
8
using Rdmp.Core.Curation.Data.Cohort;
9
using Rdmp.Core.Curation.FilterImporting;
10
using Rdmp.Core.Icons.IconProvision;
11
using Rdmp.Core.ReusableLibraryCode.Icons.IconProvision;
12
using SixLabors.ImageSharp;
13
using SixLabors.ImageSharp.PixelFormats;
14

15
namespace Rdmp.Core.CommandExecution.AtomicCommands;
16

17
/// <summary>
18
/// Adds a new SqlParameter to an <see cref="ICollectSqlParameters"/>
19
/// </summary>
20
public class ExecuteCommandAddParameter : BasicCommandExecution
21
{
22
    private readonly ICollectSqlParameters _collector;
23
    private readonly string _parameterName;
24
    private readonly string _datatype;
25
    private readonly string _value;
26
    private const float DefaultWeight = 2.1f;
27

28
    public ExecuteCommandAddParameter(IBasicActivateItems activator, ICollectSqlParameters collector,
29
        string parameterName, string datatype, string value) : base(activator)
×
30
    {
NEW
31
        Weight = DefaultWeight;
×
32
        _collector = collector;
×
33
        _parameterName = parameterName;
×
34
        _datatype = datatype;
×
35
        _value = value;
×
36
        UseTripleDotSuffix = true;
×
37

38
        if (collector is IMightBeReadOnly r) SetImpossibleIfReadonly(r);
×
39
    }
×
40

41
    public override Image<Rgba32> GetImage(IIconProvider iconProvider) =>
42
        iconProvider.GetImage(RDMPConcept.ParametersNode);
×
43

44
    public override void Execute()
45
    {
46
        var factory = new ParameterCollectionUIOptionsFactory();
×
47
        var options = factory.Create(_collector, BasicActivator.CoreChildProvider);
×
48

49
        var n = _parameterName;
×
50
        var d = _datatype;
×
51
        var v = _value;
×
52

53
        if (n == null)
×
54
        {
55
            // get user to type the name of the parameter
56
            if (BasicActivator.TypeText(new DialogArgs
×
57
            {
×
58
                EntryLabel = "Name",
×
59
                TaskDescription =
×
60
                        "A name is required for the parameter.  It must start with '@' e.g. @myparameter.  Do not add spaces or start the name with a number.",
×
61
                WindowTitle = "Add Parameter"
×
62
            }, 99, "@myVariable", out var name, false))
×
63
                // user did type a name
64
                n = name;
×
65
            else
66
                // user cancelled typing the parameter name
67
                return;
×
68
        }
69

70

71
        if (d == null)
×
72
        {
73
            // get user to type the name of the parameter
74
            if (BasicActivator.TypeText(new DialogArgs
×
75
            {
×
76
                EntryLabel = "DataType",
×
77
                TaskDescription = "What data type are you storing in the parameter (e.g. datetime2)",
×
78
                WindowTitle = "Parameter Data Type"
×
79
            }, 99, "varchar(10)", out var datatype, false))
×
80
                // user did type
81
                d = datatype;
×
82
            else
83
                // user cancelled typing
84
                return;
×
85
        }
86

87
        if (v == null)
×
88
        {
89
            // get user to type the name of the parameter
90
            if (BasicActivator.TypeText(new DialogArgs
×
91
            {
×
92
                EntryLabel = "Value",
×
93
                TaskDescription =
×
94
                        "What value should the parameter have.  Ensure if you are using text that it is appropriately quoted",
×
95
                WindowTitle = "Parameter Value"
×
96
            }, int.MaxValue, AnyTableSqlParameter.DefaultValue, out var value, false))
×
97
                // user did type
98
                v = value;
×
99
            else
100
                // user cancelled typing
101
                return;
×
102
        }
103

104
        var p = options.CreateNewParameter(n);
×
105
        p.ParameterSQL = $"DECLARE {p.ParameterName} as {d}";
×
106
        p.Value = v;
×
107
        p.SaveToDatabase();
×
108

109
        if (_collector is DatabaseEntity de) Publish(de);
×
110
    }
×
111
}
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