Skip to content

Commit c97eaa3

Browse files
committed
Added Helpers and Enums
1 parent 4156f2b commit c97eaa3

File tree

5 files changed

+191
-0
lines changed

5 files changed

+191
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
MIT License
3+
4+
Copyright (c) Léo Corporation
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.
23+
*/
24+
25+
namespace InternetTest.Enums;
26+
27+
public enum Types
28+
{
29+
A = 1,
30+
NS = 2,
31+
CNAME = 5,
32+
SOA = 6,
33+
PTR = 12,
34+
MX = 15,
35+
TXT = 16,
36+
AAAA = 28,
37+
}
38+
39+
public enum Status
40+
{
41+
Success,
42+
NoRecords,
43+
FormatError = 9501,
44+
ServerFailure = 9502,
45+
NotExist = 9503,
46+
Refused = 9505
47+
}
48+
49+
public enum Section
50+
{
51+
Question = 0,
52+
Answer = 1,
53+
Authority = 2,
54+
Additional = 3
55+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
MIT License
3+
4+
Copyright (c) Léo Corporation
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.
23+
*/
24+
25+
namespace InternetTest.Enums;
26+
public enum Theme
27+
{
28+
Light,
29+
Dark,
30+
System
31+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
MIT License
3+
4+
Copyright (c) Léo Corporation
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.
23+
*/
24+
namespace InternetTest.Helpers;
25+
26+
public static class Context
27+
{
28+
public static string Version => "9.0.0.2508-pre1";
29+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
MIT License
3+
4+
Copyright (c) Léo Corporation
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.
23+
*/
24+
using InternetTest.Enums;
25+
using MicaWPF.Core.Enums;
26+
using MicaWPF.Core.Services;
27+
using Microsoft.Win32;
28+
using PeyrSharp.Enums;
29+
using PeyrSharp.Env;
30+
using System.Windows;
31+
using System.Windows.Media;
32+
33+
namespace InternetTest.Helpers;
34+
35+
public class ThemeHelper
36+
{
37+
public static SolidColorBrush GetSolidColorBrush(string resource) => (SolidColorBrush)Application.Current.Resources[resource];
38+
39+
public static void ChangeTheme(Theme theme)
40+
{
41+
bool isDark = theme switch
42+
{
43+
Theme.Dark => true,
44+
Theme.Light => false,
45+
Theme.System => IsSystemThemeDark(),
46+
_ => false
47+
};
48+
49+
var dictionary = new ResourceDictionary
50+
{
51+
Source = new Uri($"..\\Themes\\{(isDark ? "Dark" : "Light")}.xaml", UriKind.Relative)
52+
};
53+
54+
MicaWPFServiceUtility.ThemeService.ChangeTheme((WindowsTheme)theme);
55+
56+
Application.Current.Resources.MergedDictionaries.Clear();
57+
Application.Current.Resources.MergedDictionaries.Add(dictionary);
58+
}
59+
60+
public static bool IsSystemThemeDark()
61+
{
62+
if (Sys.CurrentWindowsVersion is not WindowsVersion.Windows10 and not WindowsVersion.Windows11)
63+
{
64+
return false; // Avoid errors on older OSs
65+
}
66+
67+
var t = Registry.GetValue(@"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize", "SystemUsesLightTheme", "1");
68+
return t switch
69+
{
70+
0 => true,
71+
1 => false,
72+
_ => false
73+
};
74+
}
75+
}

InternetTest/InternetTest/InternetTest.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
<ItemGroup>
2929
<PackageReference Include="MicaWPF.Lite" Version="6.3.0" />
3030
<PackageReference Include="PeyrSharp.Core" Version="2.1.0.2312" />
31+
<PackageReference Include="PeyrSharp.Env" Version="2.1.0.2312" />
3132
</ItemGroup>
3233

3334
<ItemGroup>

0 commit comments

Comments
 (0)