-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathSettingsHelper.cs
More file actions
91 lines (73 loc) · 2.55 KB
/
SettingsHelper.cs
File metadata and controls
91 lines (73 loc) · 2.55 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
using ServiceHelpers;
using System;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using Windows.Storage;
using Windows.UI.Xaml.Controls;
namespace DigitalAssetManagementTemplate
{
public class SettingsHelper
{
ApplicationDataContainer _settings = ApplicationData.Current.LocalSettings;
public static SettingsHelper Instance { get; private set; }
public static Func<Task> InitCustomVisionHandler { get; set; }
static SettingsHelper()
{
Instance = new SettingsHelper();
}
T Get<T>(T defaultValue, [CallerMemberName] string key = null)
{
var value = _settings.Values[key];
return value is T ? (T)value : defaultValue;
}
void Set<T>(T value, [CallerMemberName] string key = null)
{
_settings.Values[key] = value;
}
public string FaceApiKey { get => CognitiveServiceApiKey; }
public string VisionApiKey { get => CognitiveServiceApiKey; }
public string CognitiveServiceApiKey
{
get => Get<string>(null);
set => Set(value);
}
public string CognitiveServiceEndpoint
{
get => Get<string>("https://westus2.api.cognitive.microsoft.com");
set => Set(value);
}
public bool ShowAgeAndGender
{
get => Get<bool>(true);
set => Set(value);
}
public string CustomVisionTrainingApiKey
{
get => Get<string>(null);
set => Set(value);
}
public string CustomVisionPredictionApiKey
{
get => Get<string>(null);
set => Set(value);
}
public string CustomVisionApiKeyEndpoint
{
get => Get<string>("https://westus2.api.cognitive.microsoft.com");
set => Set(value);
}
public string CustomVisionTrainingApiKeyEndpoint { get => CustomVisionApiKeyEndpoint; }
public string CustomVisionPredictionApiKeyEndpoint { get => CustomVisionApiKeyEndpoint; }
public async Task PushSettingsToServices()
{
//face API
FaceServiceHelper.ApiKey = FaceApiKey;
FaceServiceHelper.ApiEndpoint = CognitiveServiceEndpoint;
//vision API
VisionServiceHelper.ApiKey = VisionApiKey;
VisionServiceHelper.ApiEndpoint = CognitiveServiceEndpoint;
//custom vision API
await (InitCustomVisionHandler?.Invoke() ?? Task.CompletedTask);
}
}
}