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

HicServices / RDMP / 15871186964

25 Jun 2025 08:21AM UTC coverage: 57.505% (+0.2%) from 57.314%
15871186964

Pull #2203

github

JFriel
fix up help text
Pull Request #2203: Multi-project catalogues

11401 of 21380 branches covered (53.33%)

Branch coverage included in aggregate %.

51 of 58 new or added lines in 6 files covered. (87.93%)

300 existing lines in 5 files now uncovered.

32348 of 54698 relevant lines covered (59.14%)

17534.37 hits per line

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

36.84
/Rdmp.Core/ReusableLibraryCode/Settings/UserSettings.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 FAnsi.Discovery;
12
using Rdmp.Core.ReusableLibraryCode.Checks;
13

14
namespace Rdmp.Core.ReusableLibraryCode.Settings;
15

16
/// <summary>
17
/// This is the Settings static class that can be used in your Core solution or in any
18
/// of your client applications. All settings are laid out the same exact way with getters
19
/// and setters.
20
/// </summary>
21
public static class UserSettings
22
{
23
    private static readonly Lazy<RDMPApplicationSettings> Implementation =
4✔
24
        new(static () => new RDMPApplicationSettings(), System.Threading.LazyThreadSafetyMode.ExecutionAndPublication);
8✔
25

26
    private static RDMPApplicationSettings AppSettings => Implementation.Value ??
50,840!
27
                                                          throw new NotImplementedException(
50,840✔
28
                                                              "Isolated Storage does not work in this environment...");
50,840✔
29

30

31
    public static bool UseLocalFileSystem
32
    {
33
        get => AppSettings.GetValueOrDefault("UseLocalFileSystem", false);
×
34
        set => AppSettings.AddOrUpdateValue("UseLocalFileSystem", value);
×
35
    }
36

37
    public static string LocalFileSystemLocation 
38
    {
39
        get => AppSettings.GetValueOrDefault("LocalFileSystemLocation", Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "rdmp")); 
×
40
        set => AppSettings.AddOrUpdateValue("LocalFileSystemLocation", value);
×
41
    }
42

43
    /// <summary>
44
    /// Show a Yes/No confirmation dialog box when closing RDMP
45
    /// </summary>
46
    public static bool ConfirmApplicationExiting
47
    {
48
        get => AppSettings.GetValueOrDefault("ConfirmExit", true);
×
49
        set => AppSettings.AddOrUpdateValue("ConfirmExit", value);
×
50
    }
51

52
    /// <summary>
53
    /// True if the user has accepted the open source license agreements for RDMP and
54
    /// dependencies used in the software (i.e. MIT and GNU licenses).
55
    /// </summary>
56
    public static string LicenseAccepted
57
    {
58
        get => AppSettings.GetValueOrDefault("LicenseAccepted", null);
×
59
        set => AppSettings.AddOrUpdateValue("LicenseAccepted", value);
×
60
    }
61

62
    /// <summary>
63
    /// Automatically launch the RDMP Home Screen on launch of the RDMP application, regardless of the last window you viewed.
64
    /// </summary>
65
    public static bool ShowHomeOnStartup
66
    {
67
        get => AppSettings.GetValueOrDefault("ShowHomeOnStartup", false);
×
68
        set => AppSettings.AddOrUpdateValue("ShowHomeOnStartup", value);
×
69
    }
70

71
    /// <summary>
72
    /// If checked series included in graphs that have no values will not be displayed
73
    /// </summary>
74
    public static bool IncludeZeroSeriesInGraphs
75
    {
76
        get => AppSettings.GetValueOrDefault("IncludeZeroSeriesInGraphs", true);
4✔
77
        set => AppSettings.AddOrUpdateValue("IncludeZeroSeriesInGraphs", value);
6✔
78
    }
79

80
    /// <summary>
81
    /// Adds an additional behaviour when changing tabs that highlights the tree view
82
    /// collection that has that object visible in it.
83
    /// </summary>
84
    public static bool EmphasiseOnTabChanged
85
    {
86
        get => AppSettings.GetValueOrDefault("EmphasiseOnTabChanged", false);
×
87
        set => AppSettings.AddOrUpdateValue("EmphasiseOnTabChanged", value);
×
88
    }
89

90
    /// <summary>
91
    /// True to disable any auto starting tutorials
92
    /// </summary>
93
    public static bool DisableTutorials
94
    {
95
        get => AppSettings.GetValueOrDefault("DisableTutorials", false);
×
96
        set => AppSettings.AddOrUpdateValue("DisableTutorials", value);
×
97
    }
98

99
    /// <summary>
100
    /// The connection string to the main RDMP platform database
101
    /// </summary>
102
    public static string CatalogueConnectionString
103
    {
104
        get => AppSettings.GetValueOrDefault("CatalogueConnectionString", "");
×
105
        set => AppSettings.AddOrUpdateValue("CatalogueConnectionString", value);
×
106
    }
107

108
    /// <summary>
109
    /// The connection string to the data export RDMP platform database.  This database will contain
110
    /// references to objects in the <see cref="CatalogueConnectionString"/> database
111
    /// </summary>
112
    public static string DataExportConnectionString
113
    {
114
        get => AppSettings.GetValueOrDefault("DataExportConnectionString", "");
×
115
        set => AppSettings.AddOrUpdateValue("DataExportConnectionString", value);
×
116
    }
117

118
    /// <summary>
119
    /// The colour scheme and format for the RDMP gui client application
120
    /// </summary>
121
    public static string Theme
122
    {
123
        get => AppSettings.GetValueOrDefault("Theme", "ResearchDataManagementPlatform.Theme.MyVS2015BlueTheme");
×
124
        set => AppSettings.AddOrUpdateValue("Theme", value);
×
125
    }
126

127
    /// <summary>
128
    /// When selecting a result from the Find dialog the selected item is pinned in the corresponding view.
129
    /// </summary>
130
    public static bool FindShouldPin
131
    {
132
        get => AppSettings.GetValueOrDefault("FindShouldPin", true);
×
133
        set => AppSettings.AddOrUpdateValue("FindShouldPin", value);
×
134
    }
135

136
    /// <summary>
137
    /// Set the amount of time (in seconds) that the Create Database processes should wait before timing out.
138
    /// </summary>
139
    public static int CreateDatabaseTimeout
140
    {
141
        get => AppSettings.GetValueOrDefault("CreateDatabaseTimeout", 30);
16✔
142
        set => AppSettings.AddOrUpdateValue("CreateDatabaseTimeout",
×
143
            DiscoveredServerHelper.CreateDatabaseTimeoutInSeconds = Math.Max(value, 30));
×
144
    }
145

146
    /// <summary>
147
    /// Set the amount of time (in milliseconds) that tooltips should take to appear in the tree collection views (e.g. list of Catalogues etc)
148
    /// </summary>
149
    public static int TooltipAppearDelay
150
    {
151
        get => AppSettings.GetValueOrDefault("TooltipAppearDelay", 750);
20✔
152
        set => AppSettings.AddOrUpdateValue("TooltipAppearDelay", Math.Max(10, value));
×
153
    }
154

155
    /// <summary>
156
    /// When using the Find feature this option will automatically filter out any cohort set containers (i.e. UNION / INTERSECT / EXCEPT containers)
157
    /// </summary>
158
    public static bool ScoreZeroForCohortAggregateContainers
159
    {
160
        get => AppSettings.GetValueOrDefault("ScoreZeroForCohortAggregateContainers", false);
50✔
161
        set => AppSettings.AddOrUpdateValue("ScoreZeroForCohortAggregateContainers", value);
8✔
162
    }
163

164
    /// <summary>
165
    /// Create audit objects for specific objects/changes (e.g. changes to Catalogue Deprecated status).
166
    /// </summary>
167
    public static bool EnableCommits
168
    {
169
        get => AppSettings.GetValueOrDefault("EnableCommits", true);
26✔
170
        set => AppSettings.AddOrUpdateValue("EnableCommits", value);
×
171
    }
172

173

174
    public static bool PromptRenameOnCohortFilterChange
175
    {
176
        get => AppSettings.GetValueOrDefault("PromptRenameOnCohortFilterChange", true);
×
177
        set => AppSettings.AddOrUpdateValue("PromptRenameOnCohortFilterChange", value);
×
178
    }
179

180
    public static bool NewFindAndReplace
181
    {
182
        get => AppSettings.GetValueOrDefault("NewFindAndReplace", false);
×
183
        set => AppSettings.AddOrUpdateValue("NewFindAndReplace", value);
×
184
    }
185

186

187
    #region Catalogue flag visibility settings
188

189
    public static bool ShowInternalCatalogues
190
    {
191
        get => AppSettings.GetValueOrDefault("ShowInternalCatalogues", true);
40✔
192
        set => AppSettings.AddOrUpdateValue("ShowInternalCatalogues", value);
48✔
193
    }
194

195
    public static bool ShowDeprecatedCatalogues
196
    {
197
        get => AppSettings.GetValueOrDefault("ShowDeprecatedCatalogues", true);
40✔
198
        set => AppSettings.AddOrUpdateValue("ShowDeprecatedCatalogues", value);
48✔
199
    }
200

201
    public static bool ShowColdStorageCatalogues
202
    {
203
        get => AppSettings.GetValueOrDefault("ShowColdStorageCatalogues", true);
40✔
204
        set => AppSettings.AddOrUpdateValue("ShowColdStorageCatalogues", value);
48✔
205
    }
206

207
    public static bool ShowProjectSpecificCatalogues
208
    {
209
        get => AppSettings.GetValueOrDefault("ShowProjectSpecificCatalogues", true);
40✔
210
        set => AppSettings.AddOrUpdateValue("ShowProjectSpecificCatalogues", value);
48✔
211
    }
212

213
    public static bool ShowNonExtractableCatalogues
214
    {
215
        get => AppSettings.GetValueOrDefault("ShowNonExtractableCatalogues", true);
40✔
216
        set => AppSettings.AddOrUpdateValue("ShowNonExtractableCatalogues", value);
48✔
217
    }
218

219
    /// <summary>
220
    /// True to apply theme changes to context menus and tool strips.
221
    /// </summary>
222
    public static bool ApplyThemeToMenus
223
    {
UNCOV
224
        get => AppSettings.GetValueOrDefault("ApplyThemeToMenus", true);
×
UNCOV
225
        set => AppSettings.AddOrUpdateValue("ApplyThemeToMenus", value);
×
226
    }
227

228
    /// <summary>
229
    /// Determines line wrapping in multi line editor controls when lines stretch off the control client area
230
    /// </summary>
231
    public static int WrapMode
232
    {
233
        get => AppSettings.GetValueOrDefault("WrapMode", 0);
40✔
UNCOV
234
        set => AppSettings.AddOrUpdateValue("WrapMode", value);
×
235
    }
236

237
    /// <summary>
238
    /// <para>Base colours used for generating heatmaps in HEX format.  Colour intensity will vary
239
    /// from the first color to the second.</para>
240
    /// 
241
    /// <para>The first colour represents the lowest values and should
242
    /// typically be darker than the second which represents high values.</para>
243
    /// </summary>
244
    public static string HeatMapColours
245
    {
UNCOV
246
        get => AppSettings.GetValueOrDefault("HeatMapColours", null);
×
UNCOV
247
        set => AppSettings.AddOrUpdateValue("HeatMapColours", value);
×
248
    }
249

250
    /// <summary>
251
    /// <para>Adds a 5 second delay after startup</para>
252
    /// <para>Use this option to add a delay that can be helpful for troubleshooting issues on RDMP startup. </para>
253
    /// </summary>
254
    public static bool Wait5SecondsAfterStartupUI
255
    {
256
        get => AppSettings.GetValueOrDefault("Wait5SecondsAfterStartupUI", true);
10✔
257
        set => AppSettings.AddOrUpdateValue("Wait5SecondsAfterStartupUI", value);
12✔
258
    }
259

260
    /// <summary>
261
    /// True to show the cohort creation wizard when creating new cohorts.  False to create
262
    /// a default empty configuration.
263
    /// </summary>
264
    public static bool ShowCohortWizard
265
    {
UNCOV
266
        get => AppSettings.GetValueOrDefault("ShowCohortWizard", false);
×
UNCOV
267
        set => AppSettings.AddOrUpdateValue("ShowCohortWizard", value);
×
268
    }
269

270
    /// <summary>
271
    /// <para>True to enable "stirct validation" for containers in Cohort Builder Queries.</para>
272
    ///
273
    /// <para>Will not allow empty sets, or sets that only have one item.</para>
274
    /// </summary>
275
    public static bool StrictValidationForCohortBuilderContainers
276
    {
277
        get => AppSettings.GetValueOrDefault("StrictValidationForCohortBuilderContainers", true);
38✔
278
        set => AppSettings.AddOrUpdateValue("StrictValidationForCohortBuilderContainers", value);
×
279
    }
280

281
    /// <summary>
282
    /// Changes the behaviour of mouse double clicks in tree views.  When enabled double
283
    /// click expands nodes instead of opening the double clicked object (the default behaviour).
284
    /// </summary>
285
    public static bool DoubleClickToExpand
286
    {
UNCOV
287
        get => AppSettings.GetValueOrDefault("DoubleClickToExpand", false);
×
UNCOV
288
        set => AppSettings.AddOrUpdateValue("DoubleClickToExpand", value);
×
289
    }
290

291
    public static string RecentHistory
292
    {
293
        get => AppSettings.GetValueOrDefault("RecentHistory", "");
60✔
294
        set => AppSettings.AddOrUpdateValue("RecentHistory", value);
18✔
295
    }
296

297
    /// <summary>
298
    /// <para>When enabled RDMP will record certain performance related metrics (how long refresh takes etc).</para>
299
    /// <para>These figures are completely internal to the application and are not transmitted anywhere.You can view the results in the toolbar.</para>
300
    /// </summary>
301
    public static bool DebugPerformance
302
    {
303
        get => AppSettings.GetValueOrDefault("DebugPerformance", false);
43,750✔
UNCOV
304
        set => AppSettings.AddOrUpdateValue("DebugPerformance", value);
×
305
    }
306

307
    /// <summary>
308
    /// <para>Automatically resize columns in the RDMP user interface with fit contents.</para>
309
    /// <para>Can be disabled if problems arise with column content or header visibility</para>
310
    /// </summary>
311
    public static bool AutoResizeColumns
312
    {
313
        get => AppSettings.GetValueOrDefault("AutoResizeColumns", true);
30✔
UNCOV
314
        set => AppSettings.AddOrUpdateValue("AutoResizeColumns", value);
×
315
    }
316

317

318
    /// <summary>
319
    /// Show a popup confirmation dialog at the end of a pipeline completing execution
320
    /// </summary>
321
    public static bool ShowPipelineCompletedPopup
322
    {
UNCOV
323
        get => AppSettings.GetValueOrDefault("ShowPipelineCompletedPopup", true);
×
UNCOV
324
        set => AppSettings.AddOrUpdateValue("ShowPipelineCompletedPopup", value);
×
325
    }
326

327
    /// <summary>
328
    /// <para>Enable to skip the checking stage of pipeline source component CohortIdentificationConfigurationSource.</para>
329
    /// <para>In slow computer, or contesest databases this can take a while to compile. This option lets you disable it.</para>
330
    /// </summary>
331
    public static bool SkipCohortBuilderValidationOnCommit
332
    {
UNCOV
333
        get => AppSettings.GetValueOrDefault("SkipCohortBuilderValidationOnCommit", false);
×
334
        set => AppSettings.AddOrUpdateValue("SkipCohortBuilderValidationOnCommit", value);
×
335
    }
336

337
    public static string ConsoleColorScheme
338
    {
UNCOV
339
        get => AppSettings.GetValueOrDefault("ConsoleColorScheme", "default");
×
UNCOV
340
        set => AppSettings.AddOrUpdateValue("ConsoleColorScheme", value);
×
341
    }
342

343
    /// <summary>
344
    /// <para>When true RDMP log viewer will hide table load audits where no inserts/updates/deletes were applied.</para>
345
    /// <para>This is helpful if a load targets many tables not all of which will be updated in a given run</para>
346
    /// </summary>
347
    public static bool HideEmptyTableLoadRunAudits
348
    {
UNCOV
349
        get => AppSettings.GetValueOrDefault("HideEmptyTableLoadRunAudits", false);
×
350
        set => AppSettings.AddOrUpdateValue("HideEmptyTableLoadRunAudits", value);
×
351
    }
352

353
    /// <summary>
354
    /// <para>Enables additional Find filters for objects that are in:</para>
355
    /// <para>Cold Storage, Internal, Deprecated, Project Specific and Non Extractable</para>
356
    /// </summary>
357
    public static bool AdvancedFindFilters
358
    {
UNCOV
359
        get => AppSettings.GetValueOrDefault("AdvancedFindFilters", false);
×
360
        set => AppSettings.AddOrUpdateValue("AdvancedFindFilters", value);
×
361
    }
362

363
    /// <summary>
364
    /// Timeout in seconds to allow for creating archive trigger, index etc
365
    /// </summary>
366
    public static int ArchiveTriggerTimeout
367
    {
368
        get => AppSettings.GetValueOrDefault("ArchiveTriggerTimeout", 30);
1,380✔
UNCOV
369
        set => AppSettings.AddOrUpdateValue("ArchiveTriggerTimeout", value);
×
370
    }
371

372
    public static int FindWindowWidth
373
    {
UNCOV
374
        get => AppSettings.GetValueOrDefault("FindWindowWidth", 730);
×
UNCOV
375
        set => AppSettings.AddOrUpdateValue("FindWindowWidth", value);
×
376
    }
377

378
    public static int FindWindowHeight
379
    {
380
        get => AppSettings.GetValueOrDefault("FindWindowHeight", 400);
×
UNCOV
381
        set => AppSettings.AddOrUpdateValue("FindWindowHeight", value);
×
382
    }
383

384
    /// <summary>
385
    /// Enable to refresh only objects which you make changes to instead of
386
    /// fetching all database changes since your last edit.  This improves
387
    /// performance in large RDMP deployments with thousands of Projects configured.
388
    /// </summary>
389
    public static bool SelectiveRefresh
390
    {
391
        get => AppSettings.GetValueOrDefault("SelectiveRefresh", false);
268✔
392
        set => AppSettings.AddOrUpdateValue("SelectiveRefresh", value);
×
393
    }
394

395
    /// <summary>
396
    /// Set to true to always attempt to force joins on all tables under a Catalogue
397
    /// when building queries (in Cohort Builder).  This makes it impossible to untick
398
    /// force joins.
399
    /// </summary>
400
    public static bool AlwaysJoinEverything
401
    {
402
        get => AppSettings.GetValueOrDefault("AlwaysJoinEverything", false);
676✔
403
        set => AppSettings.AddOrUpdateValue("AlwaysJoinEverything", value);
×
404
    }
405

406
    /// <summary>
407
    /// <para>
408
    /// Determines whether queries are automatically sent and results displayed in
409
    /// data tabs in RDMP (e.g. View top 100 etc).  Enable to automatically send the
410
    /// queries.  Disable to show the SQL but require the user to press F5 or click Run
411
    /// to execute.
412
    /// </para>
413
    /// </summary>
414
    public static bool AutoRunSqlQueries
415
    {
UNCOV
416
        get => AppSettings.GetValueOrDefault("AutoRunSqlQueries", false);
×
UNCOV
417
        set => AppSettings.AddOrUpdateValue("AutoRunSqlQueries", value);
×
418
    }
419

420
    /// <summary>
421
    /// Enable to automatically expand the tree when opening or creating cohorts in
422
    /// Cohort Builder
423
    /// </summary>
424
    public static bool ExpandAllInCohortBuilder
425
    {
426
        get => AppSettings.GetValueOrDefault("ExpandAllInCohortBuilder", true);
2✔
427
        set => AppSettings.AddOrUpdateValue("ExpandAllInCohortBuilder", value);
×
428
    }
429

430
    /// <summary>
431
    /// True to show ProjectSpecific Catalogues' columns in extraction configuration user interface
432
    /// </summary>
433
    public static bool ShowProjectSpecificColumns
434
    {
435
        get => AppSettings.GetValueOrDefault("ShowProjectSpecificColumns", true);
18✔
UNCOV
436
        set => AppSettings.AddOrUpdateValue("ShowProjectSpecificColumns", value);
×
437
    }
438

439
    /// <summary>
440
    /// <para>When generating an aggregate graph, use the column alias instead of the select sql.  For example
441
    /// when you have the select column 'SELECT YEAR(dt) as myYear' then the GROUP BY will default to
442
    /// 'GROUP BY YEAR(dt)'.  Setting this property to true will instead use 'GROUP BY myYear'.  Typically
443
    /// this only works in MySql but it is not universally supported by all MySql versions and server settings
444
    /// </para>
445
    /// <para>Defaults to false.</para>
446
    /// </summary>
447
    public static bool UseAliasInsteadOfTransformInGroupByAggregateGraphs
448
    {
449
        get => AppSettings.GetValueOrDefault("ShowProjectSpecificColumns", false);
292✔
450
        set => AppSettings.AddOrUpdateValue("ShowProjectSpecificColumns", value);
8✔
451
    }
452

453
    #endregion
454

455
    /// <summary>
456
    /// Returns the error level the user wants for <paramref name="errorCode"/> or <see cref="ErrorCode.DefaultTreatment"/> (if no custom
457
    /// reporting level has been set up for this error code).
458
    /// </summary>
459
    /// <param name="errorCode"></param>
460
    /// <returns></returns>
461
    public static CheckResult GetErrorReportingLevelFor(ErrorCode errorCode)
462
    {
463
        var result = AppSettings.GetValueOrDefault($"EC_{errorCode.Code}", errorCode.DefaultTreatment.ToString());
32✔
464

465
        return Enum.Parse<CheckResult>(result);
32✔
466
    }
467

468
    /// <summary>
469
    /// Changes the reporting level of the given error to <paramref name="value"/> instead of its <see cref="ErrorCode.DefaultTreatment"/>
470
    /// </summary>
471
    /// <param name="errorCode"></param>
472
    /// <param name="value"></param>
473
    public static void SetErrorReportingLevelFor(ErrorCode errorCode, CheckResult value)
474
    {
475
        AppSettings.AddOrUpdateValue($"EC_{errorCode.Code}", value.ToString());
16✔
476
    }
16✔
477

478
    public static bool GetTutorialDone(Guid tutorialGuid) =>
UNCOV
479
        tutorialGuid != Guid.Empty && AppSettings.GetValueOrDefault($"T_{tutorialGuid:N}", false);
×
480

481
    public static void SetTutorialDone(Guid tutorialGuid, bool value)
482
    {
UNCOV
483
        if (tutorialGuid == Guid.Empty)
×
UNCOV
484
            return;
×
485

UNCOV
486
        AppSettings.AddOrUpdateValue($"T_{tutorialGuid:N}", value);
×
UNCOV
487
    }
×
488

489
    public static void SetColumnWidth(Guid columnGuid, int width)
490
    {
491
        if (columnGuid == Guid.Empty)
3,132!
UNCOV
492
            return;
×
493
        SetColumnWidth(columnGuid.ToString("N"), width);
3,132✔
494
    }
3,132✔
495

496
    public static void SetColumnWidth(string colIdentifier, int width)
497
    {
498
        AppSettings.AddOrUpdateValue($"ColW_{colIdentifier}", width);
3,132✔
499
    }
3,132✔
500

501
    public static void SetColumnVisible(Guid columnGuid, bool visible)
502
    {
503
        if (columnGuid == Guid.Empty)
×
UNCOV
504
            return;
×
505

UNCOV
506
        SetColumnVisible(columnGuid.ToString("N"), visible);
×
UNCOV
507
    }
×
508

509
    public static void SetColumnVisible(string colIdentifier, bool visible)
510
    {
UNCOV
511
        AppSettings.AddOrUpdateValue($"ColV_{colIdentifier}", visible);
×
UNCOV
512
    }
×
513

514
    public static int GetColumnWidth(Guid columnGuid) =>
515
        columnGuid == Guid.Empty ? 100 : GetColumnWidth(columnGuid.ToString("N"));
128!
516

517
    public static int GetColumnWidth(string colIdentifier) =>
518
        AppSettings.GetValueOrDefault($"ColW_{colIdentifier}", 100);
128✔
519

520
    public static bool GetColumnVisible(Guid columnGuid) =>
521
        columnGuid == Guid.Empty || GetColumnVisible(columnGuid.ToString("N"));
128!
522

523
    public static bool GetColumnVisible(string colIdentifier) =>
524
        AppSettings.GetValueOrDefault($"ColV_{colIdentifier}", true);
128✔
525

526
    public static string[] GetHistoryForControl(Guid controlGuid)
527
    {
528
        return AppSettings.GetValueOrDefault($"A_{controlGuid:N}", "").Split(new[] { "#!#" }, StringSplitOptions.None);
22✔
529
    }
530

531
    public static void SetHistoryForControl(Guid controlGuid, IEnumerable<string> history)
532
    {
533
        AppSettings.AddOrUpdateValue($"A_{controlGuid:N}", string.Join("#!#", history));
204✔
534
    }
204✔
535

536
    public static void AddHistoryForControl(Guid guid, string v)
537
    {
UNCOV
538
        if (string.IsNullOrWhiteSpace(v))
×
UNCOV
539
            return;
×
540

UNCOV
541
        var l = GetHistoryForControl(guid).ToList();
×
542

UNCOV
543
        if (l.Contains(v))
×
UNCOV
544
            return;
×
545

UNCOV
546
        l.Add(v);
×
547

UNCOV
548
        SetHistoryForControl(guid, l.Distinct().ToList());
×
549
    }
×
550

551
    public static Tuple<string, bool> GetLastColumnSortForCollection(Guid controlGuid)
552
    {
553
        lock (_oLockUserSettings)
2✔
554
        {
555
            var value = AppSettings.GetValueOrDefault($"LastColumnSort_{controlGuid:N}", null);
2✔
556

557
            //if we don't have a value
558
            if (string.IsNullOrWhiteSpace(value))
2!
559
                return null;
2✔
560

UNCOV
561
            var args = value.Split(new[] { "#!#" }, StringSplitOptions.RemoveEmptyEntries);
×
562

563
            //or it doesn't split properly
UNCOV
564
            if (args.Length != 2)
×
UNCOV
565
                return null;
×
566

567
            //or either element is null
UNCOV
568
            if (string.IsNullOrWhiteSpace(args[0]) || string.IsNullOrWhiteSpace(args[1]))
×
UNCOV
569
                return null;
×
570

UNCOV
571
            if (bool.TryParse(args[1], out var ascending))
×
572
                return Tuple.Create(args[0], ascending);
×
UNCOV
573
        }
×
574

575
        return null;
×
576
    }
2✔
577

578
    private static object _oLockUserSettings = new();
4✔
579

580
    public static void SetLastColumnSortForCollection(Guid controlGuid, string columnName, bool ascending)
581
    {
582
        lock (_oLockUserSettings)
2✔
583
        {
584
            AppSettings.AddOrUpdateValue($"LastColumnSort_{controlGuid:N}", $"{columnName}#!#{ascending}");
2✔
585
        }
2✔
586
    }
2✔
587

588

589
    /// <summary>
590
    /// Returns the last known manually set splitter distance for the Control who is
591
    /// identified by <paramref name="controlGuid"/> or -1 if none set yet
592
    /// </summary>
593
    /// <param name="controlGuid"></param>
594
    /// <returns></returns>
595
    public static int GetSplitterDistance(Guid controlGuid) =>
UNCOV
596
        AppSettings.GetValueOrDefault($"SplitterDistance_{controlGuid:N}", -1);
×
597

598
    /// <summary>
599
    /// Records that the user has manually changed the splitter distance of the Control
600
    /// who is identified by <paramref name="controlGuid"/>
601
    /// </summary>
602
    /// <param name="controlGuid"></param>
603
    /// <param name="splitterDistance"></param>
604
    public static void SetSplitterDistance(Guid controlGuid, int splitterDistance)
605
    {
UNCOV
606
        lock (_oLockUserSettings)
×
607
        {
UNCOV
608
            AppSettings.AddOrUpdateValue($"SplitterDistance_{controlGuid:N}", splitterDistance);
×
UNCOV
609
        }
×
UNCOV
610
    }
×
611

612
    public static void ClearUserSettings()
613
    {
614
        AppSettings.Clear();
2✔
615
    }
2✔
616
}
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