-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathConfigValidatorService.cs
More file actions
63 lines (59 loc) · 2 KB
/
ConfigValidatorService.cs
File metadata and controls
63 lines (59 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// ----------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
// ----------------------------------------------------------------------------
namespace UserOwnsData.Services
{
using System;
using System.Configuration;
public class ConfigValidatorService
{
/// <summary>
/// Validates whether all the configuration parameters are set in Web.config file
/// </summary>
/// <returns></returns>
public static string ValidateConfig()
{
string message = null;
if (string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["clientId"]))
{
message = "Client Id is not set in Web.config file";
}
else if (!IsValidGuid(ConfigurationManager.AppSettings["clientId"]))
{
message = "Please provide a valid guid for client Id in Web.config file";
}
else if (string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["clientSecret"]))
{
message = "Client secret is not set in Web.config file";
}
else if (string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["redirectUri"]))
{
message = "Redirect Uri is not set in Web.config file";
}
else if (string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["authorityUrl"]))
{
message = "Authority Url is not set in Web.config file";
}
else if (string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["powerBiApiUrl"]))
{
message = "Power BI Api Url is not set in Web.config file";
}
else if (string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["scopeBase"]))
{
message = "Scope base is not set in Web.config file";
}
return message;
}
/// <summary>
/// Checks whether a string is a valid guid
/// </summary>
/// <param name="configParam">String value</param>
/// <returns>Boolean value indicating validity of the guid</returns>
private static bool IsValidGuid(string configParam)
{
Guid result = Guid.Empty;
return Guid.TryParse(configParam, out result);
}
}
}