forked from BeyondDimension/SteamTools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVisualStudioAppCenterSDK.cs
More file actions
229 lines (195 loc) · 7.11 KB
/
VisualStudioAppCenterSDK.cs
File metadata and controls
229 lines (195 loc) · 7.11 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
#if !APP_REVERSE_PROXY && (WINDOWS || LINUX || MACCATALYST || MACOS)
using BD_AppCenter = BD.AppCenter.AppCenter;
#endif
/// <summary>
/// Visual Studio App Center
/// <list type="bullet">
/// <item>将移动开发人员常用的多种服务整合到一个集成的产品中。</item>
/// <item>您可以构建,测试,分发和监控移动应用程序,还可以实施推送通知。</item>
/// <item>https://docs.microsoft.com/zh-cn/appcenter/sdk/getting-started/xamarin</item>
/// <item>https://visualstudio.microsoft.com/zh-hans/app-center</item>
/// </list>
/// </summary>
static partial class VisualStudioAppCenterSDK
{
internal static void Init()
{
var appSecret = AppSecret;
if (string.IsNullOrWhiteSpace(appSecret))
return;
#if WINDOWS || LINUX || MACCATALYST || MACOS || APP_REVERSE_PROXY
var utils = UtilsImpl.Instance;
#endif
#if !USE_MS_APPCENTER_ANALYTICS && !APP_REVERSE_PROXY && (WINDOWS || LINUX || MACCATALYST || MACOS)
if (Startup.Instance.IsMainProcess)
{
BD_AppCenter.SetDeviceInformationHelper(utils);
BD_AppCenter.SetPlatformHelper(utils);
#pragma warning disable CS0612 // 类型或成员已过时
BD_AppCenter.SetApplicationSettingsFactory(utils);
#pragma warning restore CS0612 // 类型或成员已过时
#if DEBUG
BD_AppCenter.SetLogUrl(Constants.Urls.BaseUrl_API_Development);
#endif
BD_AppCenter.Start(appSecret, typeof(BD.AppCenter.Analytics.Analytics));
}
#endif
}
#if WINDOWS || LINUX || MACCATALYST || MACOS || APP_REVERSE_PROXY
internal sealed partial class UtilsImpl
{
private UtilsImpl() { }
public static UtilsImpl Instance { get; } = new();
#region IPlatformHelper
public string? ProductVersion => AssemblyInfo.InformationalVersion;
#if !APP_REVERSE_PROXY
public bool? IsAnyWindowNotMinimized()
{
var result = IApplication.Instance.IsAnyWindowNotMinimized();
return result;
}
public bool IsSupportedUnhandledException => true;
#endif
public Action<object?, Exception>? InvokeUnhandledExceptionOccurred { get; set; }
public bool IsSupportedApplicationExit => true;
public event EventHandler? ApplicationExit;
internal void OnExit(object? sender, EventArgs e)
{
ApplicationExit?.Invoke(sender, e);
}
#endregion
#region IAbstractDeviceInformationHelper
public string? GetDeviceModel()
{
return null;
}
public string? GetDeviceOemName()
{
return null;
}
public string? GetOsName()
{
if (OperatingSystem.IsLinux())
{
#if LINUX || APP_REVERSE_PROXY
var d = IPlatformService.LinuxDistribution;
if (d.IsDefined())
return d.ToString().ToUpperInvariant();
var osName = IPlatformService.GetLinuxReleaseValue(IPlatformService.LinuxConstants.ReleaseKey_NAME);
if (!string.IsNullOrWhiteSpace(osName))
return osName.ToUpperInvariant();
osName = IPlatformService.GetLinuxReleaseValue(IPlatformService.LinuxConstants.ReleaseKey_ID);
if (!string.IsNullOrWhiteSpace(osName))
return osName.ToUpperInvariant();
#endif
return "LINUX";
}
else if (OperatingSystem.IsMacOS())
{
return "MACOS";
}
return null;
}
public string? GetOsBuild()
{
if (!OperatingSystem.IsWindows())
{
return Environment.OSVersion.Version.ToString();
}
return null;
}
public string? GetOsVersion()
{
if (!OperatingSystem.IsWindows())
{
return Environment.OSVersion.Version.ToString();
}
return null;
}
public string? GetAppVersion()
{
return AssemblyInfo.InformationalVersion;
}
public string? GetAppBuild()
{
return AssemblyInfo.FileVersion;
}
public System.Drawing.Size? GetScreenSize()
{
#if !APP_REVERSE_PROXY
var result = IApplication.Instance.GetScreenSize();
return result;
#else
return default;
#endif
}
#endregion
#region IApplicationSettings
static readonly object configLock = new();
readonly ISecureStorage storage = Ioc.Get<ISecureStorage>();
public bool ContainsKey(string key)
{
lock (configLock)
{
Func<Task<bool>> func = () => storage.ContainsKeyAsync(key);
var r = func.RunSync();
return r;
}
}
#pragma warning disable CS8633 // 类型参数的约束中的为 Null 性与隐式实现接口方法中的类型参数的约束不匹配。
#pragma warning disable CS8766 // 返回类型中引用类型的为 Null 性与隐式实现的成员不匹配(可能是由于为 Null 性特性)。
public T? GetValue<T>(string key, T? defaultValue = default) where T : notnull
#pragma warning restore CS8766 // 返回类型中引用类型的为 Null 性与隐式实现的成员不匹配(可能是由于为 Null 性特性)。
#pragma warning restore CS8633 // 类型参数的约束中的为 Null 性与隐式实现接口方法中的类型参数的约束不匹配。
{
lock (configLock)
{
Func<Task<string?>> func = () => storage.GetAsync(key);
var r = func.RunSync();
if (r != null)
{
try
{
var r2 = (T)TypeDescriptor.GetConverter(typeof(T)).ConvertFromInvariantString(r)!;
return r2;
}
catch
{
}
}
}
return defaultValue;
}
public void Remove(string key)
{
lock (configLock)
{
Func<Task> func = () => storage.RemoveAsync(key);
func.RunSync();
}
}
public void SetValue(string key, object value)
{
var invariant = value != null ? TypeDescriptor.GetConverter(value.GetType()).ConvertToInvariantString(value) : null;
lock (configLock)
{
Func<Task> func = () => storage.SetAsync(key, invariant);
func.RunSync();
}
}
#endregion
}
#if !APP_REVERSE_PROXY
partial class UtilsImpl :
BD.AppCenter.Utils.IAbstractDeviceInformationHelper,
BD.AppCenter.Utils.IPlatformHelper,
BD.AppCenter.Utils.IApplicationSettingsFactory,
BD.AppCenter.Utils.IApplicationSettings
{
#region IApplicationSettingsFactory
BD.AppCenter.Utils.IApplicationSettings BD.AppCenter.Utils.IApplicationSettingsFactory.CreateApplicationSettings() => this;
#endregion
}
#endif
#endif
}